Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Recursively initialize units
  • Loading branch information
sorear committed Oct 20, 2011
1 parent c52005a commit 29191f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/CodeGen.cs
Expand Up @@ -4132,6 +4132,7 @@ public class DowncallReceiver : CallReceiver {
bool evalmode = (bool)args[2];
Kernel.commandArgs = new string[args.Length - 3];
Array.Copy(args, 3, Kernel.commandArgs, 0, args.Length - 3);
Kernel.currentGlobals = ru.globals;
ru.PrepareEval();
if (!evalmode)
Kernel.RunMain(ru);
Expand Down
12 changes: 10 additions & 2 deletions lib/Kernel.cs
Expand Up @@ -371,6 +371,8 @@ public sealed class RuntimeUnit : IFreeze {
public Assembly assembly;
public List<SubInfo> our_subs;

bool prepared = false;

// used during construction only
public AssemblyBuilder asm_builder;
public ModuleBuilder mod_builder;
Expand Down Expand Up @@ -468,6 +470,12 @@ class IdentityComparer : IEqualityComparer<object> {
}

public void PrepareEval() {
if (prepared) return;
prepared = true;

foreach (RuntimeUnit d in depended_units)
d.PrepareEval(); // would loop without above assignment

if (type == null) {
GenerateCode(true);

Expand All @@ -484,7 +492,6 @@ class IdentityComparer : IEqualityComparer<object> {
Kernel.TraceCount = Kernel.TraceFreq = 1;
}

Kernel.currentGlobals = globals;
Kernel.FirePhasers(this, Kernel.PHASER_UNIT_INIT, false);
Kernel.FirePhasers(this, Kernel.PHASER_INIT, false);
}
Expand Down Expand Up @@ -4987,7 +4994,6 @@ public class MMDCandidateLongname {
}

public static void RunMain(RuntimeUnit main_unit) {
currentGlobals = main_unit.globals;
string trace = Environment.GetEnvironmentVariable("NIECZA_TRACE");
if (trace != null) {
if (trace == "all") {
Expand Down Expand Up @@ -5587,6 +5593,7 @@ class LastFrameNode {
RuntimeUnit ru = (RuntimeUnit)
RuntimeUnit.reg.LoadUnit(uname).root;

Kernel.currentGlobals = ru.globals;
ru.PrepareEval();
RunMain(ru);
}
Expand All @@ -5598,6 +5605,7 @@ class LastFrameNode {
RuntimeUnit ru = (RuntimeUnit)
RuntimeUnit.reg.LoadUnit(args[1]).root;

Kernel.currentGlobals = ru.globals;
ru.PrepareEval();
RunMain(ru);
} else {
Expand Down

0 comments on commit 29191f9

Please sign in to comment.