Skip to content

Commit

Permalink
Refactor trampoline for a couple more percent
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 15, 2010
1 parent db99704 commit 43d8d6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
52 changes: 28 additions & 24 deletions lib/Kernel.cs
Expand Up @@ -147,6 +147,7 @@ public class SubInfo {
public DynMetaObject mo;
// for inheriting hints
public SubInfo outer;
public string name;
public Dictionary<string, object> hints;
// maybe should be a hint
public LAD ltm;
Expand All @@ -168,17 +169,18 @@ public class SubInfo {
}
}

public SubInfo(int[] lines, DynBlockDelegate code, SubInfo outer,
Dictionary<string,object> hints, LAD ltm) {
public SubInfo(string name, int[] lines, DynBlockDelegate code,
SubInfo outer, Dictionary<string,object> hints, LAD ltm) {
this.lines = lines;
this.code = code;
this.outer = outer;
this.hints = hints;
this.ltm = ltm;
this.name = name;
}

public SubInfo(DynBlockDelegate code) :
this(null, code, null, null, null) { }
public SubInfo(string name, DynBlockDelegate code) :
this(name, null, code, null, null, null) { }
}

// We need hashy frames available to properly handle BEGIN; for the time
Expand Down Expand Up @@ -641,7 +643,7 @@ public class Kernel {

return n;
}
private static SubInfo SubInvokeSubSI = new SubInfo(SubInvokeSubC);
private static SubInfo SubInvokeSubSI = new SubInfo("Sub.INVOKE", SubInvokeSubC);
private static Frame SubInvokeSubC(Frame th) {
Variable[] post;
switch (th.ip) {
Expand Down Expand Up @@ -701,7 +703,7 @@ public class Kernel {
return w.Invoke(th, new Variable[1] { v }, null);
}

private static SubInfo BindROSI = new SubInfo(BindROC);
private static SubInfo BindROSI = new SubInfo("Bind/RO", BindROC);
private static Frame BindROC(Frame th) {
switch (th.ip) {
case 0:
Expand All @@ -721,7 +723,7 @@ public class Kernel {
}
}

private static SubInfo BindSI = new SubInfo(BindC);
private static SubInfo BindSI = new SubInfo("Bind", BindC);
private static Frame BindC(Frame th) {
switch (th.ip) {
case 0:
Expand Down Expand Up @@ -790,7 +792,7 @@ public class Kernel {
}

// This isn't just a fetch and a store...
private static SubInfo AssignSI = new SubInfo(AssignC);
private static SubInfo AssignSI = new SubInfo("Assign", AssignC);
private static Frame AssignC(Frame th) {
switch (th.ip) {
case 0:
Expand Down Expand Up @@ -935,16 +937,7 @@ public class Kernel {
public static Frame StartP6Thread(Frame th, IP6 sub) {
Thread thr = new Thread(delegate () {
Frame current = sub.Invoke(th, new Variable[0], null);

while (current != th) {
try {
current = current.Continue();
} catch (Exception ex) {
ExceptionPacket ep = new FatalException(
new CLRImportObject(ex));
current = ep.SearchForHandler(current);
}
}
RunCore(current, th);
});
thr.Start();
th.resultSlot = thr;
Expand All @@ -953,15 +946,26 @@ public class Kernel {

public static void RunLoop(SubInfo boot) {
Kernel.TraceCont = (Environment.GetEnvironmentVariable("NIECZA_TRACE") != null);
Frame root_f = new Frame(null, null, boot);
Frame current = root_f;
while (current != null) {
RunCore(new Frame(null, null, boot), null);
}

public static void RunCore(Frame cur, Frame root) {
while (cur != root) {
try {
current = current.Continue();
if (TraceCont) {
while (cur != root) {
System.Console.WriteLine("{0}|{1} @ {2}",
cur.DepthMark(), cur.info.name, cur.ip);
cur = cur.code(cur);
}
} else {
while (cur != root)
cur = cur.code(cur);
}
} catch (Exception ex) {
ExceptionPacket ep = new FatalException(
new CLRImportObject(ex));
current = ep.SearchForHandler(current);
cur = ep.SearchForHandler(cur);
}
}
}
Expand Down Expand Up @@ -1256,7 +1260,7 @@ public sealed class VarDeque {
public class NULL {
public static Niecza.Frame Environment = null;

private static Niecza.SubInfo MAINSI = new Niecza.SubInfo(MAIN);
private static Niecza.SubInfo MAINSI = new Niecza.SubInfo("Null.MAIN", MAIN);
public static Niecza.IP6 Installer = Niecza.Kernel.MakeSub(MAINSI, null);
private static Niecza.Frame MAIN(Niecza.Frame th) {
switch (th.ip) {
Expand Down
3 changes: 1 addition & 2 deletions src/CodeGen.pm
Expand Up @@ -827,7 +827,6 @@ use 5.010;
if ($self->outcap) {
print ::NIECZA_OUT " " x 8, "IP6 _inv; List<Variable> _pos; Dictionary<string,Variable> _nam;\n";
}
print ::NIECZA_OUT " " x 8, "if (Kernel.TraceCont) { Console.WriteLine(th.DepthMark() + \"$::UNITNAME : $name @ \" + th.ip); }\n";
print ::NIECZA_OUT " " x 8, "switch (th.ip) {\n";
print ::NIECZA_OUT " " x 12, "case 0:\n";
if ($self->numlets + $self->minlets > 4) {
Expand All @@ -848,7 +847,7 @@ use 5.010;
print ::NIECZA_OUT " " x 4, "private static int[] ${name}_lines = {",
join (", ", map { ($_ // 0) } @{ $self->lineinfo }), "};\n";
print ::NIECZA_OUT " " x 4, "private static SubInfo ${name}_info = ",
"new SubInfo(${name}_lines, ${name}, null, null, null);\n";
"new SubInfo(\"$::UNITNAME ${name}\", ${name}_lines, ${name}, null, null, null);\n";
for (@{ $self->consttab }) {
print ::NIECZA_OUT " " x 4, "private static $_;\n";
}
Expand Down

0 comments on commit 43d8d6e

Please sign in to comment.