Commits

allisonrandal  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.

  • Participants
  • Parent commits d401305

Comments (0)

Files changed (2)

File 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} );
 }

File 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