Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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...
commit 5d5adc8d94ce669e9ae0ba91031d0f7af6a78380 1 parent fc4d3ce
Jonathan Worthington authored November 19, 2010
36  common/NQP/NQPSetting.pm
@@ -761,8 +761,34 @@ my knowhow NQPAttribute {
761 761
     }
762 762
 }
763 763
 
764  
-# GLOBAL stash.
765  
-# (XXX Really want one per compilation unit and unify, but this will get us
766  
-# started. Also really want a stash type that knows its name rather than just
767  
-# a hash, I guess.)
768  
-::GLOBAL := NQPHash.new();
  764
+my knowhow NQPStash {
  765
+    has $!name;
  766
+    has $!namespaces;
  767
+    has $!entries;
  768
+    method new($name?) {
  769
+        my $obj := nqp::instance_of(self);
  770
+        $obj.BUILD($name);
  771
+        $obj
  772
+    }
  773
+    method BUILD($name) {
  774
+        $!name := $name;
  775
+        $!namespaces := NQPHash.new();
  776
+        $!entries := NQPHash.new();
  777
+    }
  778
+    method get_namespace($name) {
  779
+        my $got := $!namespaces.at_key($name);
  780
+        unless $got.defined {
  781
+            $got := NQPStash.new($name);
  782
+            $!namespaces.bind_key($name, $got);
  783
+        }
  784
+        $got
  785
+    }
  786
+    method at_key($name) {
  787
+        $!entries.at_key($name)
  788
+    }
  789
+    method bind_key($name, $value) {
  790
+        $!entries.bind_key($name, $value)
  791
+    }
  792
+}
  793
+
  794
+::GLOBAL := NQPStash.new('GLOBAL');
18  dotnet/compiler/PAST2DNSTCompiler.pm
@@ -998,16 +998,13 @@ our multi sub dnst_for(PAST::Var $var) {
998 998
             $lookup := emit_lexical_lookup(@parts.shift);
999 999
         }
1000 1000
 
1001  
-        # If we're in bind context, need to treat last part specially.
1002  
-        my $bindee;
1003  
-        if $*BIND_CONTEXT {
1004  
-            $bindee := @parts.pop;
1005  
-        }
  1001
+        # Also need to treat last part specially.
  1002
+        my $target := @parts.pop;
1006 1003
 
1007 1004
         # Now chase down the rest.
1008 1005
         for @parts {
1009 1006
             $lookup := dnst_for(PAST::Op.new(
1010  
-                :pasttype('callmethod'), :name('at_key'),
  1007
+                :pasttype('callmethod'), :name('get_namespace'),
1011 1008
                 $lookup,
1012 1009
                 PAST::Val.new( :value(~$_) )
1013 1010
             ));
@@ -1019,10 +1016,17 @@ our multi sub dnst_for(PAST::Var $var) {
1019 1016
             $lookup := dnst_for(PAST::Op.new(
1020 1017
                 :pasttype('callmethod'), :name('bind_key'),
1021 1018
                 $lookup,
1022  
-                PAST::Val.new( :value(~$bindee) ),
  1019
+                PAST::Val.new( :value(~$target) ),
1023 1020
                 $*BIND_VALUE
1024 1021
             ));
1025 1022
         }
  1023
+        else {
  1024
+            $lookup := dnst_for(PAST::Op.new(
  1025
+                :pasttype('callmethod'), :name('at_key'),
  1026
+                $lookup,
  1027
+                PAST::Val.new( :value(~$target) )
  1028
+            ));
  1029
+        }
1026 1030
 
1027 1031
         return $lookup;
1028 1032
     }

0 notes on commit 5d5adc8

Please sign in to comment.
Something went wrong with that request. Please try again.