Skip to content

Commit

Permalink
[dotnet] Somewhat reluctantly move KnowHOWAttribute out of NQPSetting…
Browse files Browse the repository at this point in the history
… and into core. Having meta-object bodies and things that need them at BEGIN time in the same compilation unit doesn't work out and is blocking other progress.
  • Loading branch information
jnthn committed Oct 22, 2010
1 parent 3d934db commit 973c96d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
12 changes: 0 additions & 12 deletions common/NQP/NQPSetting.pm
Expand Up @@ -122,18 +122,6 @@ knowhow NQPHash is repr('P6mapping') {
}
}

# This is a little bit of a cheat. We only really need to keep
# hold of a name for the most basic attribute class, so we just
# use the string representation.
knowhow KnowHOWAttribute is repr('P6str') {
method new(:$name) {
nqp::box_str(nqp::unbox_str($name), KnowHOWAttribute)
}
method name() {
nqp::box_str(nqp::unbox_str(self), NQPStr)
}
}

knowhow NQPCode is repr('RakudoCodeRef') {
method leave($with) {
nqp::leave_block(self, $with)
Expand Down
15 changes: 9 additions & 6 deletions dotnet/runtime/Init.cs
Expand Up @@ -29,16 +29,17 @@ public static ThreadContext Initialize(string SettingName)
// Bootstrap the meta-model.
RegisterRepresentations();
var KnowHOW = KnowHOWBootstrapper.Bootstrap();
var KnowHOWAttribute = KnowHOWBootstrapper.SetupKnowHOWAttribute(KnowHOW);

// See if we're to load a setting or use the fake bootstrapping one.
Context SettingContext;
if (SettingName == null)
{
SettingContext = BootstrapSetting(KnowHOW);
SettingContext = BootstrapSetting(KnowHOW, KnowHOWAttribute);
}
else
{
SettingContext = LoadSetting(SettingName, KnowHOW);
SettingContext = LoadSetting(SettingName, KnowHOW, KnowHOWAttribute);
}

// Cache native capture and LLCode type object.
Expand Down Expand Up @@ -86,14 +87,15 @@ private static void RegisterRepresentations()
/// </summary>
/// <param name="KnowHOW"></param>
/// <returns></returns>
private static Context BootstrapSetting(RakudoObject KnowHOW)
private static Context BootstrapSetting(RakudoObject KnowHOW, RakudoObject KnowHOWAttribute)
{
var SettingContext = new Context();
SettingContext.LexPad = new Lexpad(new string[]
{ "KnowHOW", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list" });
{ "KnowHOW", "KnowHOWAttribute", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list" });
SettingContext.LexPad.Storage = new RakudoObject[]
{
KnowHOW,
KnowHOWAttribute,
REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null, null),
REPRRegistry.get_REPR_by_name("P6int").type_object_for(null, null),
REPRRegistry.get_REPR_by_name("P6num").type_object_for(null, null),
Expand All @@ -119,7 +121,7 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
/// <param name="Name"></param>
/// <param name="KnowHOW"></param>
/// <returns></returns>
public static Context LoadSetting(string Name, RakudoObject KnowHOW)
public static Context LoadSetting(string Name, RakudoObject KnowHOW, RakudoObject KnowHOWAttribute)
{
// Load the assembly.
var SettingAssembly = AppDomain.CurrentDomain.Load(Name);
Expand All @@ -134,8 +136,9 @@ public static Context LoadSetting(string Name, RakudoObject KnowHOW)
// Fudge a few more things in.
// XXX Should be able to toss all of thse but KnowHOW.
SettingContext.LexPad.Extend(new string[]
{ "KnowHOW", "print", "say", "capture" });
{ "KnowHOW", "KnowHOWAttribute", "print", "say", "capture" });
SettingContext.LexPad.SetByName("KnowHOW", KnowHOW);
SettingContext.LexPad.SetByName("KnowHOWAttribute", KnowHOWAttribute);
SettingContext.LexPad.SetByName("print",
CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
Expand Down
30 changes: 30 additions & 0 deletions dotnet/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.cs
Expand Up @@ -145,5 +145,35 @@ public static RakudoObject Bootstrap()
// And we should be done.
return KnowHOW;
}

/// <summary>
/// Sets up the KnowHOWAttribute object/class, which actually is a
/// KnowHOW.
/// </summary>
/// <returns></returns>
public static RakudoObject SetupKnowHOWAttribute(RakudoObject KnowHOW)
{
// Create a new HOW instance.
var HOW = KnowHOW.STable.REPR.instance_of(null, KnowHOW) as KnowHOWREPR.KnowHOWInstance;

// We base the attribute on P6str, since we just want to store an
// attribute name for now.
var KnowHOWAttribute = REPRRegistry.get_REPR_by_name("P6str").type_object_for(null, HOW);

// Add methods new and Str.
HOW.Methods.Add("new", CodeObjectUtility.WrapNativeMethod((TC, Code, Cap) =>
{
var WHAT = CaptureHelper.GetPositional(Cap, 0).STable.WHAT;
var Name = Ops.unbox_str(TC, CaptureHelper.GetNamed(Cap, "name"));
return Ops.box_str(TC, Name, WHAT);
}));
HOW.Methods.Add("name", CodeObjectUtility.WrapNativeMethod((TC, Code, Cap) =>
{
var self = CaptureHelper.GetPositional(Cap, 0);
return Ops.box_str(TC, Ops.unbox_str(TC, self), TC.DefaultStrBoxType);
}));

return KnowHOWAttribute;
}
}
}

0 comments on commit 973c96d

Please sign in to comment.