Changeset 6801

Show
Ignore:
Timestamp:
09/06/05 17:00:17 (3 years ago)
Author:
iblech
Message:

* Usual svn props.
* t/var/constant.t: Minor fixes.
* Pugs.PIL1, Pugs.Compile: PSub and PCode contain a p[Sub]?IsMulti? field now,

so PIL2JS and PIL-Run can know which subs are multis and which subs are not.

* Pugs.CodeGen?.PIR: Accomodate for the above change.
* PIL2JS: (Simple) multi subs!

  • PIL2JS.js: If necessary, try to call all .variants of a multi to find out whether the parameters match the sub signature. (Hack)
  • PIL::Subs: Emit appropriate code for multis --

multi foo {...} # is compiled as
our &foo ::= PIL2JS.new_multi(); &foo.add_variant({...});

* Test.pm: Removed the skip_rest_anti_multi-hack which was previously needed

for PIL2JS. :)

Files:
13 modified

Legend:

Unmodified
Added
Removed
  • debian/patches/00list

    • Property svn:mime-type set to text/plain; charset=UTF-8
    • Property svn:eol-style set to native
  • debian/patches/10smoker.dpatch

    • Property svn:mime-type set to text/plain; charset=UTF-8
    • Property svn:eol-style set to native
  • debian/smoker.yml

    • Property svn:mime-type set to text/plain; charset=UTF-8
    • Property svn:eol-style set to native
  • ext/Test/lib/Test.pm

    r6708 r6801  
    182182multi sub skip (Int $count, Str $reason, +$depends) returns Bool is export { 
    183183    for (1 .. $count) { 
    184         # Hack -- PIL2JS doesn't support multisubs yet 
    185         if $*OS eq "browser" { 
    186             Test::proclaim(1, "", "skip $reason", :depends($depends)); 
    187         } else { 
    188             Test::skip $reason, :depends($depends); 
    189         } 
     184        Test::skip $reason, :depends($depends); 
    190185    } 
    191186} 
  • perl5/PIL2JS/lib/PIL.pm

    r6694 r6801  
    201201  # B.pm: use A; my $a = 4;  # ==> my $a_1 = 4; XXX! 
    202202 
    203   { 
    204     my %seen; 
    205     $self->{pilGlob} = [grep { not $seen{$_->{pSubName}}++ } @{ $self->{pilGlob} }]; 
    206   } 
     203  #{ 
     204  #  my %seen; 
     205  #  $self->{pilGlob} = [grep { not $seen{$_->{pSubName}}++ } @{ $self->{pilGlob} }]; 
     206  #} 
    207207 
    208208  my $fixed_tree = $self->fixup; 
  • perl5/PIL2JS/lib/PIL/Subs.pm

    r6693 r6801  
    1414 
    1515  sub prefix { "Sub" } 
    16   sub name   :lvalue { $_[0]->{pSubName}   } 
    17   sub type   :lvalue { $_[0]->{pSubType}   } 
    18   sub params :lvalue { $_[0]->{pSubParams} } 
    19   sub lvalue :lvalue { $_[0]->{pSubLValue} } 
    20   sub body   :lvalue { $_[0]->{pSubBody}   } 
     16  sub name   :lvalue { $_[0]->{pSubName}    } 
     17  sub type   :lvalue { $_[0]->{pSubType}    } 
     18  sub params :lvalue { $_[0]->{pSubParams}  } 
     19  sub lvalue :lvalue { $_[0]->{pSubLValue}  } 
     20  sub body   :lvalue { $_[0]->{pSubBody}    } 
     21  sub multi  :lvalue { $_[0]->{pSubIsMulti} } 
    2122 
    2223  sub fixup { 
     
    5556      if $self->name =~ /^__export_c.*import$/; 
    5657 
    57     my $js = sprintf 
    58       "%s%s = new PIL2JS.Box(%s.FETCH());\n%s.FETCH().pil2js_name = %s;\n", 
    59       $PIL::IN_GLOBPIL ? "" : "var ", 
     58    my $def  = sprintf "new PIL2JS.Box(%s.FETCH())",  $self->SUPER::as_js; 
     59    my $name = sprintf "%s.FETCH().pil2js_name = %s", 
    6060      PIL::name_mangle($self->name), 
    61       $self->SUPER::as_js, 
    62       PIL::name_mangle($self->name), 
     61      PIL::doublequote(($self->name =~ /^&.*::(?:prefix:|postfix:|infix:|circumfix:|coerce:|self:|term:|postcircumfix:|rule_modifier:|trait_verb:|trait_auxiliary:|scope_declarator:|statement_control:|infix_postfix_meta_operator:|postfix_prefix_meta_operator:|prefix_postfix_meta_operator:|infix_circumfix_meta_operator:)?(.+)$/)[0] or $self->name); 
    6362      # "or $self->name" needed for the /^__export/ and /^__init/ subs. 
    64       PIL::doublequote(($self->name =~ /^&.*::(?:prefix:|postfix:|infix:|circumfix:|coerce:|self:|term:|postcircumfix:|rule_modifier:|trait_verb:|trait_auxiliary:|scope_declarator:|statement_control:|infix_postfix_meta_operator:|postfix_prefix_meta_operator:|prefix_postfix_meta_operator:|infix_circumfix_meta_operator:)?(.+)$/)[0] or $self->name); 
     63 
     64    my $decl = $self->multi 
     65      ? sprintf "if(!%s) var %s = new PIL2JS.Box(PIL2JS.new_multi());\n%s.FETCH().pil2js_multi.add_variant(%s, %d)", 
     66        PIL::name_mangle($self->name), 
     67        PIL::name_mangle($self->name), 
     68        PIL::name_mangle($self->name), 
     69        $def, 
     70        $self->arity 
     71      : sprintf "%s%s = %s;", 
     72        $PIL::IN_GLOBPIL ? "" : "var ", 
     73        PIL::name_mangle($self->name), 
     74        $def; 
     75    my $js = "$decl;\n$name;\n"; 
    6576 
    6677    # Special magic for methods. 
     
    96107  sub prefix { "" } 
    97108  sub name   { "<anonymous@{[$PIL::CUR_SUBNAME ? ' in ' . $PIL::CUR_SUBNAME : '']}>" } 
    98   sub type   :lvalue { $_[0]->{pType}   } 
    99   sub params :lvalue { $_[0]->{pParams} } 
    100   sub lvalue :lvalue { $_[0]->{pLValue} } 
    101   sub body   :lvalue { $_[0]->{pBody}   } 
     109  sub arity  { $_[0]->params->arity } 
     110  sub type   :lvalue { $_[0]->{pType}    } 
     111  sub params :lvalue { $_[0]->{pParams}  } 
     112  sub lvalue :lvalue { $_[0]->{pLValue}  } 
     113  sub body   :lvalue { $_[0]->{pBody}    } 
     114  sub multi  :lvalue { $_[0]->{pIsMulti} } 
    102115 
    103116  sub fixup { 
     
    120133        ? (pSubName => $self->name) 
    121134        : (), 
    122       "p" . $self->prefix . "Type"   => $self->type, 
    123       "p" . $self->prefix . "LValue" => $self->lvalue, 
     135      "p" . $self->prefix . "Type"    => $self->type, 
     136      "p" . $self->prefix . "LValue"  => $self->lvalue, 
     137      "p" . $self->prefix . "IsMulti" => $self->multi, 
    124138      $self->params->fixup( 
    125139        $self->prefix, 
     
    199213    my $wrappedbody = "$new_pad;\n$callchain$magical_vars\n$bind;\n\n$body"; 
    200214 
    201     my $jsbody = $params . "\n" . $self->params->autothread_wrapper($wrappedbody); 
    202  
    203     return sprintf "PIL2JS.Box.constant_func(%d, function (args) {\n%s;\n%s;\n%s\n%s\n})", 
    204       $self->params->arity, 
     215    my $jsbody = $self->multi 
     216      ? "$params\nif(only_check_for_params) return;\n\n" . $self->params->autothread_wrapper($wrappedbody) 
     217      : $params . "\n" . $self->params->autothread_wrapper($wrappedbody); 
     218 
     219    return sprintf "PIL2JS.Box.constant_func(%d, function (args) {\n%s;\n%s%s;\n%s\n%s\n})", 
     220      $self->arity, 
    205221      # Lexicalize PIL2JS and thus speed up PIL2JS 
    206222      PIL::add_indent(1, "var PIL2JS = AlsoPIL2JS_SpeedupHack"), 
     223      $self->multi 
     224        ? PIL::add_indent(1, "var only_check_for_params = args.only_check_for_params;\n") 
     225        : "", 
    207226      PIL::add_indent(1, $backup), 
    208227      PIL::add_indent(1, $ccsetup), 
  • perl5/PIL2JS/libjs/PIL2JS.js

    r6693 r6801  
    105105 
    106106  var candidates = []; 
    107   for(var i = 0; i < this.variants; i++) { 
    108     if(this.variants[arity] == argc) { 
    109       candidates.push(this.variants[arity]); 
     107  for(var i = 0; i < this.variants.length; i++) { 
     108    if(this.variants[i].arity == argc) { 
     109      candidates.push(this.variants[i]); 
     110    } 
     111  } 
     112 
     113  if(candidates.length == 0) { 
     114    // Hack? 
     115    for(var i = 0; i < this.variants.length; i++) { 
     116      var pargs = [].concat(orig_args); 
     117      pargs.only_check_for_params = true; 
     118 
     119      var ok = true; 
     120      try { this.variants[i].code.FETCH()(pargs) } catch(err) { 
     121        // The sub wasn't able to bind pargs to its parameters. 
     122        ok = false; 
     123      } 
     124 
     125      // Was the sub able to bind pargs to its parameters? 
     126      if(ok) { 
     127        // Yes, so add the sub to our candidate list! 
     128        candidates.push(this.variants[i]); 
     129      } 
    110130    } 
    111131  } 
     
    117137  } 
    118138 
    119   return canidates[0].code(orig_args); 
     139  return candidates[0].code.FETCH()(orig_args); 
    120140}; 
    121141PIL2JS.new_multi = function () { 
  • src/Pugs/CodeGen/PIR.hs

    r6424 r6801  
    106106        tellLabel endL 
    107107        return (ExpLV this) 
    108     trans (PCode styp params _ body) = do 
     108    trans (PCode styp params _ _ body) = do 
    109109        [begL, endL] <- genLabel ["blockBegin", "blockEnd"] 
    110110        this    <- genPMC "block" 
     
    126126 
    127127instance Translate PIL_Decl Decl where 
    128     trans (PSub name styp params lvalue body) | Just (pkg, name') <- isQualified name = do 
    129         declC <- trans $ PSub name' styp params lvalue body 
     128    trans (PSub name styp params lvalue ismulti body) | Just (pkg, name') <- isQualified name = do 
     129        declC <- trans $ PSub name' styp params lvalue ismulti body 
    130130        return $ DeclNS pkg [declC] 
    131     trans (PSub name styp params _ body) = do 
     131    trans (PSub name styp params _ _ body) = do 
    132132        (_, stmts)  <- listen $ do 
    133133            let prms = map tpParam params 
     
    186186        tellIns $ lhsC <:= rhsC 
    187187        return lhsC 
    188     trans (PApp _ exp@(PCode _ _ _ _) Nothing []) = do 
     188    trans (PApp _ exp@(PCode _ _ _ _ _) Nothing []) = do 
    189189        blockC  <- trans exp 
    190190        tellIns $ [reg tempPMC] <-& blockC $ [] 
     
    383383            , InsNew tempPMC PerlScalar 
    384384            , "store_global"    .- [lit "$_", tempPMC] 
    385             ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ _ <- pilGlob penv ] ++ 
     385            ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ _ _ <- pilGlob penv ] ++ 
    386386            [ StmtRaw (text "main()") 
    387387            , StmtIns $ tempPMC  <-- "find_global" $ [lit "Perl6::Internals", lit "&exit"] 
  • src/Pugs/Compile.hs

    r6682 r6801  
    105105                name' | ':' `elem` name = name 
    106106                      | otherwise = "main::" ++ name -- XXX wrong 
    107             return [PSub initL SubPrim [] False bodyC] 
     107            return [PSub initL SubPrim [] False False bodyC] 
    108108        canCompile _ = return [] 
    109109        doCode name vsub = case subBody vsub of 
     
    117117    compile (name, decls) = do 
    118118        let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) Nothing [] 
    119                     | PSub sub _ _ _ _ <- decls 
     119                    | PSub sub _ _ _ _ _ <- decls 
    120120                    ] 
    121         return (PSub name SubPrim [] False (combine bodyC PNil):decls) 
     121        return (PSub name SubPrim [] False False (combine bodyC PNil):decls) 
    122122 
    123123instance Compile (SubName, VCode) [PIL_Decl] where 
     
    126126            bodyC   = PStmts (PStmt . PExp $ storeC) PNil 
    127127            exportL = "__export_" ++ (render $ varText name) 
    128         return [PSub exportL SubPrim [] False bodyC] 
     128        return [PSub exportL SubPrim [] False False bodyC] 
    129129    compile (name, vsub) = do 
    130130        bodyC   <- enter cxtItemAny . compile $ case subBody vsub of 
     
    132132            body                -> body 
    133133        paramsC <- compile $ subParams vsub 
    134         return [PSub name (subType vsub) paramsC (subLValue vsub) bodyC] 
     134        return [PSub name (subType vsub) paramsC (subLValue vsub) (isMulti vsub) bodyC] 
    135135 
    136136instance Compile (String, [(TVar Bool, TVar VRef)]) PIL_Expr where 
     
    236236 
    237237pBlock :: PIL_Stmts -> PIL_Expr 
    238 pBlock = PCode SubBlock [] False 
     238pBlock = PCode SubBlock [] False False 
    239239 
    240240{- 
     
    372372            exp                 -> exp 
    373373        paramsC <- compile $ subParams sub 
    374         return $ PCode (subType sub) paramsC (subLValue sub) bodyC 
     374        return $ PCode (subType sub) paramsC (subLValue sub) (isMulti sub) bodyC 
    375375    compile (Syn "module" _) = compile Noop 
    376376    compile (Syn "match" exp) = compile $ Syn "rx" exp -- wrong 
  • src/Pugs/PIL1.hs

    r6424 r6801  
    7373        , pParams  :: ![TParam] 
    7474        , pLValue  :: !Bool 
     75        , pIsMulti :: !Bool 
    7576        , pBody    :: !PIL_Stmts 
    7677        } 
     
    8283    , pSubParams    :: ![TParam] 
    8384    , pSubLValue    :: !Bool 
     85    , pSubIsMulti   :: !Bool 
    8486    , pSubBody      :: !PIL_Stmts 
    8587    } 
     
    258260            putByte bh 3 
    259261            put_ bh ad 
    260     put_ bh (PCode ae af ag ah) = do 
     262    put_ bh (PCode ae af ag ah ai) = do 
    261263            putByte bh 4 
    262264            put_ bh ae 
     
    264266            put_ bh ag 
    265267            put_ bh ah 
     268            put_ bh ai 
    266269    get bh = do 
    267270            h <- getByte bh 
     
    284287                    ag <- get bh 
    285288                    ah <- get bh 
    286                     return (PCode ae af ag ah) 
     289                    ai <- get bh 
     290                    return (PCode ae af ag ah ai) 
    287291 
    288292instance Perl5 PIL_Expr where 
     
    293297    showPerl5 (PThunk aa) = showP5HashObj "PThunk" 
    294298              [("pThunk", showPerl5 aa)] 
    295     showPerl5 (PCode aa ab ac ad) = showP5HashObj "PCode" 
     299    showPerl5 (PCode aa ab ac ad ae) = showP5HashObj "PCode" 
    296300              [("pType", showPerl5 aa) , ("pParams", showPerl5 ab) , 
    297                ("pLValue", showPerl5 ac) , ("pBody", showPerl5 ad)] 
     301               ("pLValue", showPerl5 ac) , ("pIsMulti", showPerl5 ad) , 
     302               ("pBody", showPerl5 ae)] 
    298303 
    299304instance JSON PIL_Expr where 
     
    304309    showJSON (PThunk aa) = showJSHashObj "PThunk" 
    305310             [("pThunk", showJSON aa)] 
    306     showJSON (PCode aa ab ac ad) = showJSHashObj "PCode" 
     311    showJSON (PCode aa ab ac ad ae) = showJSHashObj "PCode" 
    307312             [("pType", showJSON aa) , ("pParams", showJSON ab) , 
    308               ("pLValue", showJSON ac) , ("pBody", showJSON ad)] 
     313              ("pLValue", showJSON ac) , ("pIsMulti", showJSON ad) , 
     314              ("pBody", showJSON ae)] 
    309315 
    310316instance Binary PIL_Decl where 
    311     put_ bh (PSub aa ab ac ad ae) = do 
     317    put_ bh (PSub aa ab ac ad ae af) = do 
    312318            put_ bh aa 
    313319            put_ bh ab 
     
    315321            put_ bh ad 
    316322            put_ bh ae 
     323            put_ bh af 
    317324    get bh = do 
    318325    aa <- get bh 
     
    321328    ad <- get bh 
    322329    ae <- get bh 
    323     return (PSub aa ab ac ad ae) 
     330    af <- get bh 
     331    return (PSub aa ab ac ad ae af) 
    324332 
    325333instance Perl5 PIL_Decl where 
    326     showPerl5 (PSub aa ab ac ad ae) = showP5HashObj "PSub" 
     334    showPerl5 (PSub aa ab ac ad ae af) = showP5HashObj "PSub" 
    327335              [("pSubName", showPerl5 aa) , ("pSubType", showPerl5 ab) , 
    328336               ("pSubParams", showPerl5 ac) , ("pSubLValue", showPerl5 ad) , 
    329                ("pSubBody", showPerl5 ae)] 
     337               ("pSubIsMulti", showPerl5 ae) , ("pSubBody", showPerl5 af)] 
    330338 
    331339instance JSON PIL_Decl where 
    332     showJSON (PSub aa ab ac ad ae) = showJSHashObj "PSub" 
     340    showJSON (PSub aa ab ac ad ae af) = showJSHashObj "PSub" 
    333341             [("pSubName", showJSON aa) , ("pSubType", showJSON ab) , 
    334342              ("pSubParams", showJSON ac) , ("pSubLValue", showJSON ad) , 
    335               ("pSubBody", showJSON ae)] 
     343              ("pSubIsMulti", showJSON ae) , ("pSubBody", showJSON af)] 
    336344 
    337345instance Binary PIL_Literal where 
  • src/Pugs/PIL1.hs-drift

    r6424 r6801  
    7171        , pParams  :: ![TParam] 
    7272        , pLValue  :: !Bool 
     73        , pIsMulti :: !Bool 
    7374        , pBody    :: !PIL_Stmts 
    7475        } 
     
    8081    , pSubParams    :: ![TParam] 
    8182    , pSubLValue    :: !Bool 
     83    , pSubIsMulti   :: !Bool 
    8284    , pSubBody      :: !PIL_Stmts 
    8385    } 
  • t/var/constant.t

    r6796 r6801  
    122122    eval ' 
    123123        { 
    124             my constant grtz = 42; 
    125             $ok++ if grtz == 42; 
     124            my constant wack = 42; 
     125            $ok++ if wack == 42; 
    126126        } 
    127127 
    128         $ok++ unless eval "grtz; 1"; 
     128        $ok++ unless eval "wack; 1"; 
    129129    '; 
    130130 
     
    136136 
    137137    eval ' 
    138         my constant grtz = 42; 
    139         $ok++ if grtz == 42; 
     138        my constant wack = 42; 
     139        $ok++ if wack == 42; 
    140140 
    141141        { 
    142             my constant grtz = 23; 
    143             $ok++ if grtz == 23; 
     142            my constant wack = 23; 
     143            $ok++ if wack == 23; 
    144144        } 
    145145 
    146         $ok++ if grtz == 23; 
     146        $ok++ if wack == 23; 
    147147    '; 
    148148 
     
    155155    eval ' 
    156156        { 
    157             our constant grtz = 42; 
    158             $ok++ if grtz == 42; 
     157            our constant globconst1 = 42; 
     158            $ok++ if globconst1 == 42; 
    159159        } 
    160160 
    161         $ok++ if grtz; 
     161        $ok++ if globconst1 == 42; 
    162162    '; 
    163163 
     
    170170    eval ' 
    171171        { 
    172             constant grtz = 42; 
    173             $ok++ if grtz == 42; 
     172            constant globconst2 = 42; 
     173            $ok++ if globconst2 == 42; 
    174174        } 
    175175 
    176         $ok++ if grtz; 
     176        $ok++ if globconst2 == 42; 
    177177    '; 
    178178 
  • util/cperl6-mode.el

    • Property svn:mime-type set to text/plain; charset=UTF-8
    • Property svn:eol-style set to native