Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[odd] apparently I'm still git-clueless
  • Loading branch information
diakopter committed Nov 19, 2010
2 parents dd7ed60 + 5d5adc8 commit d6ea428
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 42 deletions.
36 changes: 31 additions & 5 deletions common/NQP/NQPSetting.pm
Expand Up @@ -779,8 +779,34 @@ my knowhow NQPAttribute {
}
}

# GLOBAL stash.
# (XXX Really want one per compilation unit and unify, but this will get us
# started. Also really want a stash type that knows its name rather than just
# a hash, I guess.)
::GLOBAL := NQPHash.new();
my knowhow NQPStash {
has $!name;
has $!namespaces;
has $!entries;
method new($name?) {
my $obj := nqp::instance_of(self);
$obj.BUILD($name);
$obj
}
method BUILD($name) {
$!name := $name;
$!namespaces := NQPHash.new();
$!entries := NQPHash.new();
}
method get_namespace($name) {
my $got := $!namespaces.at_key($name);
unless $got.defined {
$got := NQPStash.new($name);
$!namespaces.bind_key($name, $got);
}
$got
}
method at_key($name) {
$!entries.at_key($name)
}
method bind_key($name, $value) {
$!entries.bind_key($name, $value)
}
}

::GLOBAL := NQPStash.new('GLOBAL');
18 changes: 11 additions & 7 deletions dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -998,16 +998,13 @@ our multi sub dnst_for(PAST::Var $var) {
$lookup := emit_lexical_lookup(@parts.shift);
}

# If we're in bind context, need to treat last part specially.
my $bindee;
if $*BIND_CONTEXT {
$bindee := @parts.pop;
}
# Also need to treat last part specially.
my $target := @parts.pop;

# Now chase down the rest.
for @parts {
$lookup := dnst_for(PAST::Op.new(
:pasttype('callmethod'), :name('at_key'),
:pasttype('callmethod'), :name('get_namespace'),
$lookup,
PAST::Val.new( :value(~$_) )
));
Expand All @@ -1019,10 +1016,17 @@ our multi sub dnst_for(PAST::Var $var) {
$lookup := dnst_for(PAST::Op.new(
:pasttype('callmethod'), :name('bind_key'),
$lookup,
PAST::Val.new( :value(~$bindee) ),
PAST::Val.new( :value(~$target) ),
$*BIND_VALUE
));
}
else {
$lookup := dnst_for(PAST::Op.new(
:pasttype('callmethod'), :name('at_key'),
$lookup,
PAST::Val.new( :value(~$target) )
));
}

return $lookup;
}
Expand Down
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
50 changes: 25 additions & 25 deletions dotnet/runtime/Runtime/Ops/Metamodel.cs
Expand Up @@ -42,7 +42,7 @@ public static RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT)
/// <param name="Obj"></param>
/// <returns></returns>
public static RakudoObject repr_defined(ThreadContext TC, RakudoObject Obj)
{
{
return Ops.box_int(TC, !(Obj is object) || Obj.STable.REPR.defined(TC, Obj) ? 1 : 0, TC.DefaultBoolBoxType);
}

Expand All @@ -56,18 +56,18 @@ public static RakudoObject repr_defined(ThreadContext TC, RakudoObject Obj)
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, string Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Name);
}

/// <summary>
/// Gets the value of an attribute.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
/// <returns></returns>
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Ops.unbox_str(TC, Name));
}

/// <summary>
/// Gets the value of an attribute.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
/// <returns></returns>
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Ops.unbox_str(TC, Name));
}

/// <summary>
Expand All @@ -93,18 +93,18 @@ public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, Raku
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Name, Value);
return Value;
}

/// <summary>
/// Binds the value of an attribute to the given value.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name, RakudoObject Value)
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Ops.unbox_str(TC, Name), Value);
return Value;
}

/// <summary>
/// Binds the value of an attribute to the given value.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name, RakudoObject Value)
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Ops.unbox_str(TC, Name), Value);
return Value;
}

/// <summary>
Expand Down

0 comments on commit d6ea428

Please sign in to comment.