Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Get Threads.pm6 working again after the backend rewrite
  • Loading branch information
sorear committed Mar 6, 2011
1 parent b5e8bce commit 9598dde
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
31 changes: 23 additions & 8 deletions lib/CLRBackend.cs
Expand Up @@ -2610,6 +2610,13 @@ class NamProcessor {
static Dictionary<string, Func<CpsOp[], CpsOp>> thandlers;
static Dictionary<string, Type> namtypes;

static Type namtype(object z) {
string name = JScalar.S(z);
if (name.Length > 4 && name.Substring(0,4) == "clr:")
return Type.GetType(name.Substring(4));
return namtypes[name];
}

static NamProcessor() {
namtypes = new Dictionary<string, Type>();
namtypes["str"] = Tokens.String;
Expand All @@ -2632,7 +2639,7 @@ class NamProcessor {


handlers["null"] = delegate(NamProcessor th, object[] zyg) {
return CpsOp.Null(namtypes[((JScalar)zyg[1]).str]); };
return CpsOp.Null(namtype(zyg[1])); };
handlers["str"] = delegate(NamProcessor th, object[] zyg) {
return CpsOp.StringLiteral(((JScalar)zyg[1]).str); };
handlers["int"] = delegate(NamProcessor th, object[] zyg) {
Expand Down Expand Up @@ -2677,12 +2684,12 @@ class NamProcessor {
return CpsOp.MethodCall(null, Tokens.P6any_SetSlot, new CpsOp[] {
th.Scan(zyg[2]), th.AnyStr(zyg[1]), th.Scan(zyg[3]) }); };
handlers["getslot"] = delegate(NamProcessor th, object[] zyg) {
Type ty = namtypes[FixStr(zyg[2])];
Type ty = namtype(zyg[2]);
return CpsOp.UnboxAny(ty, CpsOp.MethodCall(null,
Tokens.P6any_GetSlot, new CpsOp[] { th.Scan(zyg[3]),
th.AnyStr(zyg[1]) })); };
handlers["cast"] = delegate(NamProcessor th, object[] zyg) {
Type tty = namtypes[FixStr(zyg[1])];
Type tty = namtype(zyg[1]);
CpsOp z = th.Scan(zyg[2]);
Type fty = z.head.Returns;

Expand Down Expand Up @@ -2759,7 +2766,7 @@ class NamProcessor {
return CpsOp.MethodCall(null, Tokens.Kernel.GetMethod("BoxAnyMO").MakeGenericMethod(boxee.head.Returns), new CpsOp[2] { boxee, mo });
};
handlers["unbox"] = delegate(NamProcessor th, object[] zyg) {
Type t = namtypes[((JScalar)zyg[1]).str];
Type t = namtype(zyg[1]);
CpsOp unboxee = th.Scan(zyg[2]);
return CpsOp.MethodCall(null, Tokens.Kernel.GetMethod("UnboxAny").MakeGenericMethod(t), new CpsOp[1] { unboxee });
};
Expand Down Expand Up @@ -3048,14 +3055,22 @@ class NamProcessor {
return CpsOp.MethodCall(null, mi, rst); };
handlers["rawscall"] = delegate(NamProcessor th, object[] z) {
string name = JScalar.S(z[1]);
int ixn = name.LastIndexOf(':');
Type cpsrt;
if (ixn >= 0) {
cpsrt = Type.GetType(name.Substring(ixn+1));
name = name.Substring(0, ixn);
}
int ix = name.LastIndexOf('.');
CpsOp[] rst = JScalar.A<CpsOp>(2, z, th.Scan);
Type[] tx = new Type[rst.Length];
for (int i = 0; i < tx.Length; i++)
tx[i] = rst[i].head.Returns;
int k = (cpsrt != null) ? 1 : 0;
Type[] tx = new Type[rst.Length + k];
for (int i = 0; i < rst.Length; i++)
tx[i+k] = rst[i].head.Returns;
if (cpsrt != null) tx[0] = Tokens.Frame;
MethodInfo mi = Type.GetType(name.Substring(0, ix))
.GetMethod(name.Substring(ix+1), tx);
return CpsOp.MethodCall(null, mi, JScalar.A<CpsOp>(2, z, th.Scan)); };
return CpsOp.MethodCall(cpsrt, mi, JScalar.A<CpsOp>(2, z, th.Scan)); };

thandlers["var_islist"] = FieldGet(Tokens.Variable, "islist");
thandlers["llhow_name"] = FieldGet(Tokens.STable, "name");
Expand Down
19 changes: 8 additions & 11 deletions lib/Threads.pm6
@@ -1,18 +1,15 @@
my module Threads;
module Threads;

# Should be a role, since it can be applied to any class with minimal overhead
# XXX STD doesn't want to do the export if the class is our
my class Monitor is export {
class Monitor is export {
method enter() {
Q:CgOp {
(rnull (rawscall System.Threading.Monitor.Enter:m,Void
(@ {self})))
(rnull (rawscall System.Threading.Monitor.Enter (@ {self})))
}
}
method exit() {
Q:CgOp {
(rnull (rawscall System.Threading.Monitor.Exit:m,Void
(@ {self})))
(rnull (rawscall System.Threading.Monitor.Exit (@ {self})))
}
}
# TODO exception handling
Expand All @@ -21,20 +18,20 @@ my class Monitor is export {

sub lock($m,$f) is export { $m.lock($f); }

my class Thread is export {
class Thread is export {
has $!value;
method new($func) {
Q:CgOp { (box (@ {Thread}) (rawscall
Kernel.StartP6Thread:c,System.Threading.Thread (@ {$func}))) }
Niecza.Kernel,Kernel.StartP6Thread:System.Threading.Thread (@ {$func}))) }
}

method join() {
Q:CgOp { (rnull (rawcall (unbox clr:System.Threading.Thread (@ {self})) Join:m,Void)) }
Q:CgOp { (rnull (rawcall Join (unbox clr:System.Threading.Thread (@ {self})))) }
}

method sleep($time) {
my $t = $time * 1000;
Q:CgOp { (rnull (rawscall System.Threading.Thread.Sleep:m,Void (cast int (unbox num (@ {$t}))))) }
Q:CgOp { (rnull (rawscall System.Threading.Thread.Sleep (cast int (unbox num (@ {$t}))))) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Metamodel.pm6
Expand Up @@ -633,7 +633,7 @@ class Unit {
has $.next_anon_stash = 0; # is rw, Int

method bind_item($path,$item) { $!ns.bind_item($path,$item) }
method bind_graft($path1,$path2) { $!ns.bind_graph($path1,$path2) }
method bind_graft($path1,$path2) { $!ns.bind_graft($path1,$path2) }
method create_stash(@path) { $!ns.create_stash(@path) }
method create_var(@path) { $!ns.create_var(@path) }
method list_stash(@path) { $!ns.list_stash(@path) }
Expand Down

0 comments on commit 9598dde

Please sign in to comment.