Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] [common] Add an NQPStash type which is a smarter than just a…
… hash. Use it for implementing packages instead. Hopefully, this will make various broken things Just Work.
  • Loading branch information
jnthn committed Nov 19, 2010
1 parent fc4d3ce commit 5d5adc8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
36 changes: 31 additions & 5 deletions common/NQP/NQPSetting.pm
Expand Up @@ -761,8 +761,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

0 comments on commit 5d5adc8

Please sign in to comment.