Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give low level code objects a HOW and a !add_dispatchee method that w…
…ill add to its dispatchee list.
  • Loading branch information
jnthn committed Aug 22, 2010
1 parent e21ef65 commit c5ba12f
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions dotnet/runtime/Init.cs
Expand Up @@ -45,8 +45,7 @@ public static ThreadContext Initialize(string SettingName)
CaptureHelper.CaptureTypeObject = SettingContext.LexPad["capture"];
CodeObjectUtility.LLCodeTypeObject = (RakudoCodeRef.Instance)SettingContext.LexPad["LLCode"];

// Create an execution domain and a thread context for it
// and return that.
// Create an execution domain and a thread context for it.
var ExecDom = new ExecutionDomain();
var Thread = new ThreadContext();
Thread.Domain = ExecDom;
Expand All @@ -55,6 +54,10 @@ public static ThreadContext Initialize(string SettingName)
Thread.DefaultIntBoxType = SettingContext.LexPad["NQPInt"];
Thread.DefaultNumBoxType = SettingContext.LexPad["NQPNum"];
Thread.DefaultStrBoxType = SettingContext.LexPad["NQPStr"];

// LLCode type object should get a HOW.
SetupLLCodeHOW(Thread, (RakudoCodeRef.Instance)SettingContext.LexPad["LLCode"]);

return Thread;
}

Expand All @@ -77,6 +80,30 @@ private static void RegisterRepresentations()
}
}

/// <summary>
/// Adds to the low level code object's HOW.
/// </summary>
/// <param name="KnowHOW"></param>
/// <param name="instance"></param>
private static void SetupLLCodeHOW(ThreadContext TC, RakudoCodeRef.Instance LLCode)
{
var HOW = LLCode.STable.HOW;
var Meth = HOW.STable.FindMethod(TC, HOW, "add_method", Hints.NO_HINT);
Meth.STable.Invoke(TC, Meth, CaptureHelper.FormWith(new RakudoObject[] {
HOW, LLCode,
Runtime.Ops.box_str(TC, "!add_dispatchee", TC.DefaultStrBoxType),
CodeObjectUtility.WrapNativeMethod((TC_unused, self, c) =>
{
var Instance = CaptureHelper.GetPositional(c, 0) as RakudoCodeRef.Instance;
var Dispatchee = CaptureHelper.GetPositional(c, 1) as RakudoCodeRef.Instance;
if (Instance.Dispatchees == null)
Instance.Dispatchees = new List<RakudoCodeRef.Instance>();
Instance.Dispatchees.Add(Dispatchee);
return CaptureHelper.Nil();
})
}));
}

/// <summary>
/// Sets up the bootstrapping setting that we use to compile the
/// real setting.
Expand Down Expand Up @@ -111,7 +138,7 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
{ "NQPInt", REPRRegistry.get_REPR_by_name("P6int").type_object_for(null) },
{ "NQPNum", REPRRegistry.get_REPR_by_name("P6num").type_object_for(null) },
{ "NQPStr", REPRRegistry.get_REPR_by_name("P6str").type_object_for(null) },
{ "LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(null) }
{ "LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.STable.REPR.instance_of(KnowHOW)) }
};
return SettingContext;
}
Expand Down Expand Up @@ -156,7 +183,7 @@ public static Context LoadSetting(string Name, RakudoObject KnowHOW)
return CaptureHelper.Nil();
}));
SettingContext.LexPad.Add("capture", REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null));
SettingContext.LexPad.Add("LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(null));
SettingContext.LexPad.Add("LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.STable.REPR.instance_of(KnowHOW)));

return SettingContext;
}
Expand Down

0 comments on commit c5ba12f

Please sign in to comment.