Skip to content

Commit

Permalink
Make signature-setting system a bit more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jan 7, 2012
1 parent a17d4eb commit 45ad814
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
47 changes: 25 additions & 22 deletions lib/CodeGen.cs
Expand Up @@ -3611,7 +3611,8 @@ public class DowncallReceiver : CallReceiver {
if (cmd == "gettype") {
object o = Handle.Unbox(args[1]);
return (o is SubInfo) ? "sub" : (o is RuntimeUnit) ? "unit" :
(o is STable) ? "type" : (o is Frame) ? "frame" : "unknown";
(o is STable) ? "type" : (o is Frame) ? "frame" :
(o is Parameter) ? "param" : "unknown";
} else if (cmd == "set_binding") {
if (Environment.GetEnvironmentVariable("NIECZA_DEFER_TRACE") != null) {
Kernel.TraceFlags = Kernel.TRACE_CUR;
Expand Down Expand Up @@ -4272,31 +4273,33 @@ public class DowncallReceiver : CallReceiver {
SubInfo tgt = (SubInfo)Handle.Unbox(args[1]);
tgt.sig = null;
return null;
} else if (cmd == "set_signature") {
} else if (cmd == "param_new") {
SubInfo tgt = (SubInfo)Handle.Unbox(args[1]);
int ix = 2;
List<Parameter> sig = new List<Parameter>();
List<string> names = new List<string>();
while (ix != args.Length) {
int flags = (int) args[ix++];
string name = (string)args[ix++];
string slot = (string)args[ix++];
names.Clear();
while(true) {
string a_name = (string)args[ix++];
if (a_name == null) break;
names.Add(a_name);
}
SubInfo deflt = (SubInfo)Handle.Unbox(args[ix++]);
STable type = (STable)Handle.Unbox(args[ix++]);
if (deflt != null) flags |= Parameter.HASDEFAULT;
if (type != null) flags |= Parameter.HASTYPE;

sig.Add(new Parameter(flags,
(slot == null ? -1 : tgt.dylex[slot].SigIndex()),
name, (names.Count == 0 ? null : names.ToArray()),
deflt, type ?? Kernel.AnyMO));
int flags = (int) args[ix++];
string name = (string)args[ix++];
string slot = (string)args[ix++];
while(true) {
string a_name = (string)args[ix++];
if (a_name == null) break;
names.Add(a_name);
}
SubInfo deflt = (SubInfo)Handle.Unbox(args[ix++]);
STable type = (STable)Handle.Unbox(args[ix++]);
if (deflt != null) flags |= Parameter.HASDEFAULT;
if (type != null) flags |= Parameter.HASTYPE;

return Handle.Wrap(new Parameter(flags,
(slot == null ? -1 : tgt.dylex[slot].SigIndex()),
name, (names.Count == 0 ? null : names.ToArray()),
deflt, type ?? Kernel.AnyMO));
} else if (cmd == "set_signature") {
SubInfo tgt = (SubInfo)Handle.Unbox(args[1]);
int ix = 2;
List<Parameter> sig = new List<Parameter>();
while (ix != args.Length)
sig.Add((Parameter)Handle.Unbox(args[ix++]));
tgt.sig = new Signature(sig.ToArray());
return null;
} else if (cmd == "sub_contains_phaser") {
Expand Down
6 changes: 4 additions & 2 deletions src/CompilerBlob.cs
Expand Up @@ -48,7 +48,7 @@ public class UpcallReceiver : CallReceiver {
public class Downcaller {
internal static Variable upcall_cb;
static IDictionary responder;
static P6any UnitP, StaticSubP, TypeP;
static P6any UnitP, StaticSubP, TypeP, ParamP;
static string obj_dir;

// let the CLR load assemblies from obj/ too
Expand All @@ -64,12 +64,13 @@ public class Downcaller {
}
// Better, but still fudgy. Relies too much on path structure.
public static void InitSlave(Variable cb, Variable unit,
Variable staticSub, Variable type) {
Variable staticSub, Variable type, Variable param) {
if (responder != null) return;

UnitP = unit.Fetch();
StaticSubP = staticSub.Fetch();
TypeP = type.Fetch();
ParamP = param.Fetch();

obj_dir = Path.GetFullPath(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Expand Down Expand Up @@ -131,6 +132,7 @@ public class Downcaller {
string t = (string)RawDowncall("gettype", r);
P6any pr = (t == "type") ? TypeP :
(t == "sub") ? StaticSubP :
(t == "param") ? ParamP :
(t == "unit") ? UnitP : Kernel.AnyP;
return Kernel.BoxAnyMO(r, pr.mo);
}
Expand Down
12 changes: 9 additions & 3 deletions src/NieczaBackendDotnet.pm6
Expand Up @@ -57,13 +57,14 @@ sub upcalled(*@args) {
}
}

class Param { ... }
class Unit { ... }
class StaticSub { ... }
class Type { ... }

method new(*%_) {
my $self = callsame;
Q:CgOp { (rnull (rawscall Niecza.Downcaller,CompilerBlob.InitSlave {&upcalled} {Unit} {StaticSub} {Type})) };
Q:CgOp { (rnull (rawscall Niecza.Downcaller,CompilerBlob.InitSlave {&upcalled} {Unit} {StaticSub} {Type} {Param})) };
downcall("safemode") if $self.safemode;
$self;
}
Expand All @@ -90,6 +91,11 @@ method accept($unit, :$filename, :$run, :$evalmode, :$repl) {
$*repl_outer = $unit.mainline if $repl;
}

class Param {
method kind { "param" }
method FALLBACK($name, *@args) { downcall("param_$name", self, @args) }
}

class StaticSub {
method kind { "sub" }
method FALLBACK($name, *@args) { downcall("sub_$name", self, @args) }
Expand All @@ -110,8 +116,8 @@ class StaticSub {
return;
}
for @( $sig.params ) {
push @args, .flags, .name, .slot, @( .names ), Str,
.mdefault, .tclass;
push @args, downcall("param_new", self, .flags, .name, .slot,
@( .names ), Str, .mdefault, .tclass);
}
downcall("set_signature", self, @args);
}
Expand Down

0 comments on commit 45ad814

Please sign in to comment.