Anonymous avatar Anonymous committed a0a2ded

Fix the dictionary builder. Simple named parameters only work with
literal string keys, so need to use a more complex method of building
up the dictionary key/value pairs.

Comments (0)

Files changed (2)

Grammar/Actions.nqp

 method key_datum_list($/) {
     my $past := PAST::Op.new( :name('dictmaker'), :pasttype('call'), :node($/) );
     for $<key_datum> {
-        $past.push( $( $_ ) );
+        $past.push( $( $_<key> ) );
+        $past.push( $( $_<value> ) );
     }
     make $past;
 }
 
-method key_datum($/) {
-    my $key   := $( $<key> );
-    my $value := $( $<value> );
-    ## this only works if $key /has/ a name() method
-    ## XXX need for some generic solution for all PAST node types.
-    my $hashedkey := PAST::Val.new( :value($key.name()) );
-    $value.named($hashedkey);
-    make $value;
-}
-
 method tuple_or_scalar($/, $key) {
     make $( $/{$key} );
 }

src/builtins/lists.pir

 
 
 .sub 'dictmaker'
-    .param pmc args  :slurpy :named
-    .return (args)
+    .param pmc args  :slurpy
+    .local pmc result
+    .local pmc iterator
+    .local pmc key, value
+
+    result = new 'Hash'
+
+    if null args goto done
+    iterator = iter args
+
+    unless iterator goto done
+    key = shift iterator
+    value = shift iterator
+    result[key] = value
+  done:
+
+    .return (result)
 .end
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.