From c5ba12f75ae7066266c5f8ed412576b14d111f5b Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Sun, 22 Aug 2010 18:40:01 +0200 Subject: [PATCH] Give low level code objects a HOW and a !add_dispatchee method that will add to its dispatchee list. --- dotnet/runtime/Init.cs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/dotnet/runtime/Init.cs b/dotnet/runtime/Init.cs index 7687f39..7e5a2f3 100644 --- a/dotnet/runtime/Init.cs +++ b/dotnet/runtime/Init.cs @@ -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; @@ -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; } @@ -77,6 +80,30 @@ private static void RegisterRepresentations() } } + /// + /// Adds to the low level code object's HOW. + /// + /// + /// + 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(); + Instance.Dispatchees.Add(Dispatchee); + return CaptureHelper.Nil(); + }) + })); + } + /// /// Sets up the bootstrapping setting that we use to compile the /// real setting. @@ -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; } @@ -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; }