diff --git a/lib/Kernel.cs b/lib/Kernel.cs index 94f398f1..572def16 100644 --- a/lib/Kernel.cs +++ b/lib/Kernel.cs @@ -147,6 +147,7 @@ public class SubInfo { public DynMetaObject mo; // for inheriting hints public SubInfo outer; + public string name; public Dictionary hints; // maybe should be a hint public LAD ltm; @@ -168,17 +169,18 @@ public class SubInfo { } } - public SubInfo(int[] lines, DynBlockDelegate code, SubInfo outer, - Dictionary hints, LAD ltm) { + public SubInfo(string name, int[] lines, DynBlockDelegate code, + SubInfo outer, Dictionary 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 @@ -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) { @@ -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: @@ -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: @@ -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: @@ -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; @@ -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); } } } @@ -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) { diff --git a/src/CodeGen.pm b/src/CodeGen.pm index df8eee32..d3b2763c 100644 --- a/src/CodeGen.pm +++ b/src/CodeGen.pm @@ -827,7 +827,6 @@ use 5.010; if ($self->outcap) { print ::NIECZA_OUT " " x 8, "IP6 _inv; List _pos; Dictionary _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) { @@ -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"; }