Changeset 5940

Show
Ignore:
Timestamp:
07/31/05 20:07:25 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
8084
Message:

* Pugs.Compile -- Don't emit [Noop] for the empty arrayref literal ([]).
* t/var/symbolic_deref.t -- Fixed one test.
* PIL2JS:

  • Finally, returning 0- or 1-elem arrays works correctly, causing many tests to pass, currently resmoking...
  • Removed the now unneeded [...] hacks.
  • my ($a, undef, $b) = ... works now.
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • perl5/PIL2JS/lib6/Prelude/JS/Array.pm

    r5932 r5940  
    4343      return arr.join(String(sep)); 
    4444    } 
    45   ')([@things.map:{ ~$_ }], $sep); 
    46   # XXX [...] hack, because @one-elem-array.map:{...} does not return an array 
    47   # currently, but the only item array[0]... 
     45  ')(@things.map:{ ~$_ }, $sep); 
    4846} 
    4947 
     
    181179sub infix:<^..^> (Num $from, Num $to) is primitive { ($from + 1)..($to - 1) } 
    182180 
    183 sub infix:<,>(*@xs) is primitive { 
     181sub infix:<,>(*@xs is rw) is primitive is rw { 
    184182  JS::inline('new PIL2JS.Box.Constant(function (args) { 
    185183    var cxt   = args.shift(); 
     184    var iarr  = args[0].GET(); 
     185 
    186186    var array = []; 
    187     for(var i = 0; i < args[0].GET().length; i++) { 
     187    for(var i = 0; i < iarr.length; i++) { 
    188188      // The extra new PIL2JS.Box is necessary to make the contents of arrays 
    189189      // readwrite, i.e. my @a = (0,1,2); @a[1] = ... should work. 
    190       array[i] = new PIL2JS.Box(args[0].GET()[i].GET()); 
    191     } 
    192     return new PIL2JS.Box.Constant(array); 
     190      array[i] = new PIL2JS.Box(iarr[i].GET()); 
     191    } 
     192 
     193    // Proxy needed for ($a, $b) = (3, 4) which really is 
     194    // &infix:<,>($a, $b) = (3, 4); 
     195    var proxy = new PIL2JS.Box.Proxy( 
     196      function ()  { return array }, 
     197      function (n) { 
     198        var marray = []; 
     199        for(var i = 0; i < iarr.length; i++) { 
     200          marray[i] = new PIL2JS.Box(undefined).BINDTO( 
     201            // Slighly hacky way to determine if iarr[i] is undef, i.e. 
     202            // it\'s needed to make 
     203            //   my ($a, undef, $b) = (3,4,5); 
     204            // work. 
     205            iarr[i].constant && iarr[i].GET() == undefined 
     206              ? new PIL2JS.Box(undefined) 
     207              : iarr[i] 
     208          ); 
     209        } 
     210 
     211        var arr = new PIL2JS.Box([]).STORE(n).GET(); 
     212        for(var i = 0; i < arr.length; i++) { 
     213          if(marray[i]) marray[i].STORE(arr[i]); 
     214        } 
     215 
     216        return this; 
     217      } 
     218    ); 
     219 
     220    return proxy; 
    193221  })')(@xs); 
    194222} 
  • perl5/PIL2JS/lib6/Prelude/JS/ControlFlow.pm

    r5917 r5940  
    1 sub JS::Root::return(*@args) is primitive { 
    2   PIL2JS::Internals::generic_return(5)(@args);  # XXX hardcoded sublevel 
    3 } 
    4  
    5 sub JS::Root::leave(*@args) is primitive { 
    6   PIL2JS::Internals::generic_return(3)(@args);  # XXX hardcoded sublevel 
    7 } 
    8  
    91sub statement_control:<loop>($pre, Code $cond, Code $body, Code $post) is primitive { 
    102  JS::inline(' 
  • perl5/PIL2JS/lib6/Prelude/JS/Keyed.pm

    r5932 r5940  
    1 # XXX: The [...] hacks are there to make operations on one-elem lists work (as 
    2 # sub foo { my @a = <a>; return @a } does not return an array with one elem but 
    3 # the Str "a". 
    4  
    51# No MMD yet. 
    62method exists (Hash|Pair|Array $self: $idx) { 
     
    7773method values (Hash|Pair|Array $self:) { 
    7874  if $self.isa("Hash") { 
    79     # XXX [...] hack, again 
    80     [$self.keys].map:{ $self{$_} }; 
     75    $self.keys.map:{ $self{$_} }; 
    8176  } elsif $self.isa("Pair") { 
    8277    ($self.value,); 
     
    9085method kv (Hash|Pair|Array $self:) { 
    9186  if $self.isa("Hash") { 
    92     # XXX [...] hack 
    93     [$self.keys].map:{ $_, $self{$_} }; 
     87    $self.keys.map:{ $_, $self{$_} }; 
    9488  } elsif $self.isa("Pair") { 
    9589    ($self.key, $self.value); 
    9690  } elsif $self.isa("Array") { 
    97     # XXX [...] hack 
    98     [$self.keys].map:{ $_, $self[$_] }; 
     91    $self.keys.map:{ $_, $self[$_] }; 
    9992  } else { 
    10093    die ".kv does not work on objects of type {$self.ref}!"; 
     
    10497method pairs (Hash|Pair|Array $self:) { 
    10598  if $self.isa("Hash") { 
    106     # XXX [...] hack 
    107     [$self.keys].map:{ $_ => $self{$_}; };    # Don't remove the ";" inside the map! 
     99    $self.keys.map:{ $_ => $self{$_}; };    # Don't remove the ";" inside the map! 
    108100  } elsif $self.isa("Pair") { 
    109101    ($self,); 
    110102  } elsif $self.isa("Array") { 
    111     # XXX [...] hack 
    112     [$self.keys].map:{ $_ => $self[$_]; };    # ditto 
     103    $self.keys.map:{ $_ => $self[$_]; };    # ditto 
    113104  } else { 
    114105    die ".pairs does not work on objects of type {$self.ref}!"; 
  • perl5/PIL2JS/libjs/PIL2JS.js

    r5935 r5940  
    302302  this.uid    = undefined; 
    303303  this.container_type = PIL2JS.container_type(value); 
     304  this.constant       = true; 
    304305}; 
    305306 
     
    500501}; 
    501502 
    502 // &PIL2JS::Internals::generic_return -- generates a function, which, when 
    503 // invoked, will cause a return of the given level by throwing an appropriate 
    504 // exception. 
    505 var _26PIL2JS_3a_3aInternals_3a_3ageneric_return = 
    506   new PIL2JS.Box.Constant(function (args) { 
    507     var cxt   = args.shift(); 
    508     var level = args[0].toNative(); 
    509     return new PIL2JS.Box.Constant(function (args) { 
    510       var cxt_ = args.shift(); 
    511       args     = PIL2JS.make_slurpy_array(args); 
    512       var ret  = 
    513         args.length >  1 ? new PIL2JS.Box.Constant(args) : 
    514         args.length == 1 ? args[0] : 
    515         new PIL2JS.Box.Constant(undefined); 
    516       throw(new PIL2JS.ControlException.ret(level, ret)); 
    517     }); 
     503// PIL2JS.generic_return -- generates a function, which, when invoked, will 
     504// cause a return of the given level by throwing an appropriate exception. 
     505PIL2JS.generic_return = function (level) { 
     506  return new PIL2JS.Box.Constant(function (args) { 
     507    var cxt  = args.shift(); 
     508    // args     = PIL2JS.make_slurpy_array(args); 
     509    var ret  = 
     510      args.length >  1 ? new PIL2JS.Box.Constant(args) : 
     511      args.length == 1 ? args[0] : 
     512      new PIL2JS.Box.Constant(undefined); 
     513    throw(new PIL2JS.ControlException.ret(level, ret)); 
    518514  }); 
     515}; 
     516var _26main_3a_3areturn = PIL2JS.generic_return(5); // XXX hardcoded sublevel 
     517var _26main_3a_3aleave  = PIL2JS.generic_return(3); // XXX hardcoded sublevel 
    519518 
    520519PIL2JS.call_chain = []; 
  • src/Pugs/Compile.hs

    r5890 r5940  
    363363    compile (Syn "," exps) = do 
    364364        compile (App (Var "&infix:,") Nothing exps) 
     365    -- Minor hack, my $a = [] is parsed as my $a = [Noop], resulting in my $a = 
     366    -- [undef], which is wrong. 
     367    compile (Syn "\\[]" [Noop]) = do 
     368        compile (App (Var "&circumfix:[]") Nothing []) 
    365369    compile (Syn "\\[]" exps) = do 
    366370        compile (App (Var "&circumfix:[]") Nothing exps) 
  • t/var/symbolic_deref.t

    r5452 r5940  
    5555  dies_ok { $::("a_var") }, 
    5656    "symbolic dereferentiation does not work for lexicals", :todo<bug>; 
    57   is      $::("MY::a_var"), 
     57  is      $::("MY::a_var"), 42, 
    5858    "symbolic dereferentiation does work for lexicals when using MY::", :todo<bug>; 
    5959}