Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Be a little bit more late-bound in a couple of places to bre…
…ak some circularities. Thankfully, not anywhere in hot paths.
  • Loading branch information
jnthn committed Nov 19, 2010
1 parent 2e58221 commit fc4d3ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions dotnet/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.cs
Expand Up @@ -94,24 +94,28 @@ public static RakudoObject Bootstrap()
{
// Safe to just return a P6list instance that points at
// the same thing we hold internally, since a list is
// immutable.
// immutable. However, if default list type has no HOW,
// we will see if we can find one that does have it.
var HOW = (KnowHOWREPR.KnowHOWInstance)CaptureHelper.GetPositional(Cap, 0);
var Result = TC.DefaultListType.STable.REPR.instance_of(TC, TC.DefaultListType);
var ListType = MostDefinedListType(TC);
var Result = ListType.STable.REPR.instance_of(TC, ListType);
((P6list.Instance)Result).Storage = HOW.Attributes;
return Result;
}));
KnowHOWMeths.Add("methods", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
{
// Return the methods list.
var HOW = (KnowHOWREPR.KnowHOWInstance)CaptureHelper.GetPositional(Cap, 0);
var Result = TC.DefaultListType.STable.REPR.instance_of(TC, TC.DefaultListType);
var ListType = MostDefinedListType(TC);
var Result = ListType.STable.REPR.instance_of(TC, ListType);
((P6list.Instance)Result).Storage.AddRange(HOW.Methods.Values);
return Result;
}));
KnowHOWMeths.Add("parents", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
{
// A pure prototype never has any parents, so return an empty list.
return TC.DefaultListType.STable.REPR.instance_of(TC, TC.DefaultListType);
var ListType = MostDefinedListType(TC);
return ListType.STable.REPR.instance_of(TC, ListType);
}));
KnowHOWMeths.Add("type_check", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
{
Expand Down Expand Up @@ -182,5 +186,22 @@ public static RakudoObject SetupKnowHOWAttribute(RakudoObject KnowHOW)

return KnowHOWAttribute;
}

/// <summary>
/// Makes sure that we hand back an NQPList that has a HOW once it
/// is defined. Important for the bootstrap.
/// </summary>
/// <param name="TC"></param>
/// <returns></returns>
private static RakudoObject MostDefinedListType(ThreadContext TC)
{
// Have a HOW? Then return it right away.
if (TC.DefaultListType.STable.HOW != null)
return TC.DefaultListType;

// Otherwise, go and look for a list type that has one.
TC.DefaultListType = Ops.get_lex(TC, "NQPList");
return TC.DefaultListType;
}
}
}
2 changes: 1 addition & 1 deletion dotnet/runtime/Metamodel/Representations/P6opaque.cs
Expand Up @@ -276,7 +276,7 @@ private void ComputeSlotAllocation(ThreadContext TC, RakudoObject WHAT)
{
// Get the attribute, then get its name.
var Attr = AttrAtPosMeth.STable.Invoke(TC, AttrAtPosMeth, CaptureHelper.FormWith(
new RakudoObject[] { Attributes, Ops.box_int(TC, i, TC.DefaultIntBoxType) }));
new RakudoObject[] { Attributes, Ops.box_int(TC, i, Ops.get_lex(TC, "NQPInt")) }));
var NameMeth = Attr.STable.FindMethod(TC, Attr, "name", Hints.NO_HINT);
var Name = Ops.unbox_str(TC, NameMeth.STable.Invoke(TC, NameMeth, CaptureHelper.FormWith(
new RakudoObject[] { Attr })));
Expand Down

0 comments on commit fc4d3ce

Please sign in to comment.