Changeset 3906
- Timestamp:
- 05/26/05 12:37:22 (4 years ago)
- svk:copy_cache_prev:
- 5482
- Location:
- src
- Files:
-
- 13 modified
-
Main.hs (modified) (1 diff)
-
Pugs/AST.hs (modified) (2 diffs)
-
Pugs/AST/Internals.hs (modified) (2 diffs)
-
Pugs/Bind.hs (modified) (5 diffs)
-
Pugs/Compile/Haskell.hs (modified) (1 diff)
-
Pugs/Compile/Parrot.hs (modified) (7 diffs)
-
Pugs/Eval.hs (modified) (26 diffs)
-
Pugs/Lexer.hs (modified) (1 diff)
-
Pugs/Parser.hs (modified) (20 diffs)
-
Pugs/Parser/Program.hs (modified) (1 diff)
-
Pugs/Pretty.hs (modified) (1 diff)
-
Pugs/Prim.hs (modified) (6 diffs)
-
Pugs/Prim/List.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Main.hs
r3879 r3906 203 203 return () 204 204 where 205 exp = App (Var "&require") [][Val $ VStr fn]205 exp = App (Var "&require") Nothing [Val $ VStr fn] 206 206 207 207 doRunSingle :: TVar Env -> RunOptions -> String -> IO () -
src/Pugs/AST.hs
r3866 r3906 125 125 mergeStmts (Pad scope lex x) y = Pad scope lex (mergeStmts x y) 126 126 mergeStmts x@(Pos pos (Syn syn _)) y | (syn ==) `any` words "subst match //" = 127 mergeStmts (Pos pos (App (Var "&infix:~~") [Var "$_", x] [])) y127 mergeStmts (Pos pos (App (Var "&infix:~~") Nothing [Var "$_", x])) y 128 128 mergeStmts x y@(Pos pos (Syn syn _)) | (syn ==) `any` words "subst match //" = 129 mergeStmts x (Pos pos (App (Var "&infix:~~") [Var "$_", y] []))129 mergeStmts x (Pos pos (App (Var "&infix:~~") Nothing [Var "$_", y])) 130 130 mergeStmts (Pos pos (Syn "sub" [Val (VCode sub)])) y 131 131 | subType sub >= SubBlock, isEmptyParams (subParams sub) = 132 132 -- bare Block in statement level; annul all its parameters and run it! 133 mergeStmts (Pos pos $ App (Val $ VCode sub{ subParams = [] }) [][]) y133 mergeStmts (Pos pos $ App (Val $ VCode sub{ subParams = [] }) Nothing []) y 134 134 mergeStmts x (Pos pos (Syn "sub" [Val (VCode sub)])) 135 135 | subType sub >= SubBlock, isEmptyParams (subParams sub) = 136 136 -- bare Block in statement level; annul all its parameters and run it! 137 mergeStmts x (Pos pos $ App (Val $ VCode sub{ subParams = [] }) [][])137 mergeStmts x (Pos pos $ App (Val $ VCode sub{ subParams = [] }) Nothing []) 138 138 mergeStmts x (Stmts y Noop) = mergeStmts x y 139 139 mergeStmts x (Stmts Noop y) = mergeStmts x y … … 149 149 [ Var (':':'*':name) 150 150 , App (Var "&new") 151 [ Val (VType $ mkType "Class") ]152 [ App (Var "&infix:=>") 151 (Just $ Val (VType $ mkType "Class")) 152 [ App (Var "&infix:=>") Nothing 153 153 [ Val (VStr "traits") 154 154 , Val (VList $ map VStr traits) 155 ] []156 , App (Var "&infix:=>") 155 ] 156 , App (Var "&infix:=>") Nothing 157 157 [ Val (VStr "name") 158 158 , Val (VStr name) 159 ] []159 ] 160 160 ] 161 161 ] -
src/Pugs/AST/Internals.hs
r3901 r3906 775 775 data Exp 776 776 = Noop -- ^ No-op 777 | App !Exp ! [Exp] ![Exp]-- ^ Function application777 | App !Exp !(Maybe Exp) ![Exp] -- ^ Function application 778 778 -- e.g. myfun($invocant: $arg) 779 779 | Syn !String ![Exp] -- ^ Syntactic construct that cannot … … 834 834 where 835 835 (n', vs') = extract n vs 836 (invs', vs'') = foldr extractExp ([], vs') invs836 (invs', vs'') = maybe (invs, vs') (\inv -> let (x, y) = extract inv vs' in (Just x, y)) invs 837 837 (args', vs''') = foldr extractExp ([], vs'') args 838 838 extract (Stmts exp1 exp2) vs = (Stmts exp1' exp2', vs'') -
src/Pugs/Bind.hs
r3565 r3906 150 150 isPair (Cxt _ exp) = isPair exp 151 151 isPair (Syn "=>" [(Val _), _]) = True 152 isPair (App (Var "&infix:=>") [(Cxt _ (Val _)), _] []) = True153 isPair (App (Var "&infix:=>") [(Val _), _] []) = True152 isPair (App (Var "&infix:=>") Nothing [(Cxt _ (Val _)), _]) = True 153 isPair (App (Var "&infix:=>") Nothing [(Val _), _]) = True 154 154 isPair _ = False 155 155 … … 162 162 unPair (Cxt _ exp) = unPair exp 163 163 unPair (Syn "=>" [(Val k), exp]) = (vCast k, exp) 164 unPair (App (Var "&infix:=>") [(Cxt _ (Val k)), exp] []) = (vCast k, exp)165 unPair (App (Var "&infix:=>") [(Val k), exp] []) = (vCast k, exp)164 unPair (App (Var "&infix:=>") Nothing [(Cxt _ (Val k)), exp]) = (vCast k, exp) 165 unPair (App (Var "&infix:=>") Nothing [(Val k), exp]) = (vCast k, exp) 166 166 unPair x = error ("Not a pair: " ++ show x) 167 167 … … 181 181 -} 182 182 bindParams :: VCode -- ^ A code object to perform bindings on 183 -> [Exp]-- ^ List of invocants to bind183 -> (Maybe Exp) -- ^ List of invocants to bind 184 184 -> [Exp] -- ^ List of arguments (actual params) to bind 185 185 -> MaybeError VCode -- ^ Returns either a new 'VCode' with all the … … 232 232 -} 233 233 bindSomeParams :: VCode -- ^ Code object to perform bindings on 234 -> [Exp]-- ^ List of invocant expressions234 -> (Maybe Exp) -- ^ List of invocant expressions 235 235 -> [Exp] -- ^ List of argument expressions 236 236 -> MaybeError VCode -- ^ A new 'VCode' structure, augmented … … 242 242 (invPrms, argPrms) = span isInvocant params 243 243 (givenInvs, givenArgs) = if null invPrms 244 then ([], ( invsExp++argsExp))245 else ( invsExp, argsExp)244 then ([], (maybeToList invsExp++argsExp)) 245 else (maybeToList invsExp, argsExp) 246 246 247 247 let boundInv = invPrms `zip` givenInvs -- invocants are just bound, params to given -
src/Pugs/Compile/Haskell.hs
r3678 r3906 50 50 argC = compile stmt 51 51 argRest = compile rest 52 compile (App (Var op) [] []) = [| op0 op [] |] 53 compile (App (Var op) [] args) = compile (App (Var op) args []) 54 compile (App (Var ('&':op)) [arg] []) = [| do 52 compile (App (Var op) Nothing []) = [| op0 op [] |] 53 compile (App (Var ('&':op)) Nothing [arg]) = [| do 55 54 val <- $(argC) 56 55 op1 op val 57 56 |] where 58 57 argC = compile arg 59 compile (App (Var ('&':op)) [arg1, arg2] []) = [| do58 compile (App (Var ('&':op)) Nothing [arg1, arg2]) = [| do 60 59 val1 <- $(argC1) 61 60 val2 <- $(argC2) -
src/Pugs/Compile/Parrot.hs
r3750 r3906 202 202 -- XXX "module" is handled in glob, need stub here to avoid compile error 203 203 compile (Syn "module" [Val (VStr _)]) = return empty 204 compile (App (Var "&return") [val] []) = do204 compile (App (Var "&return") Nothing [val]) = do 205 205 (valC, p) <- compileArg val 206 206 return $ valC $+$ text ".return" <+> parens p 207 207 compile (App (Var "&last") _ _) = return $ text "invoke last" 208 compile (App (Var "&substr") [str, idx, len] [])208 compile (App (Var "&substr") Nothing [str, idx, len]) 209 209 | Val v <- unwrap len, vCast v == (1 :: VNum) = do 210 210 (strC, p1) <- enterLValue $ compileArg str … … 212 212 rv <- constPMC $ hcat [ p1, text "[" , p2, text "]"] 213 213 return $ vcat [strC, idxC, rv] 214 compile (App (Var "&postfix:++") [inv] []) = do214 compile (App (Var "&postfix:++") Nothing [inv]) = do 215 215 (invC, p) <- enterLValue $ compileArg inv 216 216 return $ invC $+$ text "inc" <+> p 217 compile (App (Var "&postfix:--") [inv] []) = do217 compile (App (Var "&postfix:--") Nothing [inv]) = do 218 218 (invC, p) <- enterLValue $ compileArg inv 219 219 return $ invC $+$ text "dec" <+> p 220 220 -- compile (App "&infix:~" [exp, Val (VStr "")] []) = compile exp 221 compile (App (Var "&infix:~") [exp1, exp2] []) = do221 compile (App (Var "&infix:~") Nothing [exp1, exp2]) = do 222 222 tmp <- currentStash 223 223 (arg1, p1) <- compileArg exp1 … … 229 229 , text "concat" <+> tmp <> comma <+> p1 <> comma <+> p2 230 230 ] 231 compile (App (Var ('&':'i':'n':'f':'i':'x':':':op)) [lhs, rhs] []) = do231 compile (App (Var ('&':'i':'n':'f':'i':'x':':':op)) Nothing [lhs, rhs]) = do 232 232 (lhsC, p1) <- compileArg lhs 233 233 (rhsC, p2) <- compileArg rhs … … 244 244 return $ vcat [ lhsC, rhsC, rv ] 245 245 -- XXX store return code in $@, whereever that may be in Parrotland 246 compile (App (Var "&system") [cmd] []) = do246 compile (App (Var "&system") Nothing [cmd]) = do 247 247 (arg, p) <- compileArg cmd 248 248 rc <- constPMC (text "$I10") … … 255 255 , rc 256 256 ] 257 compile (App (Var "&require_parrot") [arg] []) = do257 compile (App (Var "&require_parrot") Nothing [arg]) = do 258 258 (path, p) <- compileArg arg 259 259 return $ vcat $ … … 265 265 compile $ App (Var "&print") invs (args ++ [Val $ VStr "\n"]) 266 266 compile (App (Var "&print") invs args) = do 267 actions <- fmap vcat $ mapM (compileWith (text "print" <+>)) ( invs ++ args)267 actions <- fmap vcat $ mapM (compileWith (text "print" <+>)) (maybeToList invs ++ args) 268 268 rv <- compile (Val (VBool True)) 269 269 return $ actions $+$ rv 270 compile (App (Var ('&':method)) [(Var ('$':obj))][arg]) = do270 compile (App (Var ('&':method)) (Just (Var ('$':obj))) [arg]) = do 271 271 lhsC <- askPMC 272 272 compileWith (\tmp -> text lhsC <+> text "=" <+> varText ("$" ++ obj) <> text "." <> text ("'" ++ method ++ "'") <> parens tmp) arg 273 compile (App (Var ('&':name)) [arg] _) = do273 compile (App (Var ('&':name)) Nothing [arg]) = do 274 274 lhsC <- askPMC 275 275 compileWith (\tmp -> text lhsC <+> text "=" <+> text name <> parens tmp) arg 276 compile (App (Var "¬") [][]) = return $ text "new PerlUndef"277 compile (App (Var ('&':name)) [][]) = do276 compile (App (Var "¬") Nothing []) = return $ text "new PerlUndef" 277 compile (App (Var ('&':name)) Nothing []) = do 278 278 lhsC <- askPMC 279 279 return $ text lhsC <+> text "=" <+> text name <> text "()" … … 315 315 compile (Syn "," things) = fmap vcat $ mapM compile things 316 316 compile (Syn syn [lhs, exp]) | last syn == '=' = 317 compile $ Syn "=" [lhs, App (Var ("&infix:" ++ init syn)) [lhs, exp] []]317 compile $ Syn "=" [lhs, App (Var ("&infix:" ++ init syn)) Nothing [lhs, exp]] 318 318 compile (Cxt _ exp) = compile exp 319 319 compile (Pos pos exp) = do -
src/Pugs/Eval.hs
r3904 r3906 109 109 initSubs <- fromVals initAV 110 110 enterContext CxtVoid $ do 111 mapM_ evalExp [ App (Val sub) [][] | sub <- initSubs ]111 mapM_ evalExp [ App (Val sub) Nothing [] | sub <- initSubs ] 112 112 -- The main runtime 113 113 val <- resetT $ evaluate exp … … 116 116 endSubs <- fromVals endAV 117 117 enterContext CxtVoid $ do 118 mapM_ evalExp [ App (Val sub) [][] | sub <- endSubs ]118 mapM_ evalExp [ App (Val sub) Nothing [] | sub <- endSubs ] 119 119 return val 120 120 … … 190 190 case rv of 191 191 Nothing -> case name of 192 ('&':_) -> maybeM (findSub name [][]) $ \sub -> do192 ('&':_) -> maybeM (findSub name Nothing []) $ \sub -> do 193 193 return $ codeRef sub 194 194 _ -> return Nothing … … 404 404 genSymCC "&next" $ \symNext -> do 405 405 genSymPrim "&redo" (const $ runBody vs sub') $ \symRedo -> do 406 apply (updateSubPad sub' (symRedo . symNext)) []$406 apply (updateSubPad sub' (symRedo . symNext)) Nothing $ 407 407 map (Val . VRef . MkRef) these 408 408 runBody rest sub' … … 417 417 av <- newArray [] 418 418 symTake <- genSym "@?TAKE" (MkRef av) 419 apply (updateSubPad sub symTake) [][]419 apply (updateSubPad sub symTake) Nothing [] 420 420 fmap VList $ readIVar av 421 421 "loop" -> do … … 444 444 break <- evalVar "&?BLOCK_EXIT" 445 445 vbreak <- fromVal break 446 result <- reduce (App (Var "&infix:~~") [(Var "$_"), match] [])446 result <- reduce (App (Var "&infix:~~") Nothing [(Var "$_"), match]) 447 447 rb <- fromVal result 448 448 if rb 449 then enterWhen (subBody vbreak) $ apply vbreak [body] []449 then enterWhen (subBody vbreak) $ apply vbreak Nothing [body] 450 450 else retVal undef 451 451 "default" -> do … … 453 453 break <- evalVar "&?BLOCK_EXIT" 454 454 vbreak <- fromVal break 455 enterWhen (subBody vbreak) $ apply vbreak [body] []455 enterWhen (subBody vbreak) $ apply vbreak Nothing [body] 456 456 "while" -> doWhileUntil id 457 457 "until" -> doWhileUntil not … … 534 534 -- XXX evil hack for infinite slices 535 535 "[]" | [lhs, App (Var "&postfix:...") invs args] <- unwrap exps 536 , [idx] <- invs ++ args536 , [idx] <- maybeToList invs ++ args 537 537 -- , not (envLValue env) 538 538 -> reduce (Syn "[...]" [lhs, idx]) 539 539 "[]" | [lhs, App (Var "&infix:..") invs args] <- unwrap exps 540 , [idx, Val (VNum n)] <- invs ++ args540 , [idx, Val (VNum n)] <- maybeToList invs ++ args 541 541 , n == 1/0 542 542 -- , not (envLValue env) … … 661 661 let [lhs, exp] = exps 662 662 op = "&infix:" ++ init syn 663 evalExp $ Syn "=" [lhs, App (Var op) [lhs, exp] []]663 evalExp $ Syn "=" [lhs, App (Var op) Nothing [lhs, exp]] 664 664 _ -> retError "Unknown syntactic construct" exp 665 665 where … … 690 690 -- XXX absolutely evil bloody hack for context hinters 691 691 reduce (App (Var "&hash") invs args) = 692 enterEvalContext cxtItemAny $ Syn "\\{}" [Syn "," $ invs ++ args]692 enterEvalContext cxtItemAny $ Syn "\\{}" [Syn "," $ maybeToList invs ++ args] 693 693 694 694 reduce (App (Var "&list") invs args) = 695 enterEvalContext cxtSlurpyAny $ case invs ++ args of695 enterEvalContext cxtSlurpyAny $ case maybeToList invs ++ args of 696 696 [] -> Val (VList []) 697 697 [exp] -> exp … … 699 699 700 700 reduce (App (Var "&scalar") invs args) 701 | [exp] <- invs ++ args = enterEvalContext cxtItemAny exp702 | otherwise = enterEvalContext cxtItemAny $ Syn "," ( invs ++ args)701 | [exp] <- maybeToList invs ++ args = enterEvalContext cxtItemAny exp 702 | otherwise = enterEvalContext cxtItemAny $ Syn "," (maybeToList invs ++ args) 703 703 704 704 -- XXX absolutely evil bloody hack for "zip" 705 705 reduce (App (Var "&zip") invs args) = do 706 vals <- mapM (enterRValue . enterEvalContext (cxtItem "Array")) ( invs ++ args)706 vals <- mapM (enterRValue . enterEvalContext (cxtItem "Array")) (maybeToList invs ++ args) 707 707 val <- op0Zip vals 708 708 retVal val 709 709 710 710 -- XXX absolutely evil bloody hack for "goto" 711 reduce (App (Var "¬") [][]) = retEmpty711 reduce (App (Var "¬") Nothing []) = retEmpty 712 712 713 713 reduce (App (Var "¬") invs args) = do 714 bool <- fromVal =<< evalExp (last $ invs ++ args)714 bool <- fromVal =<< evalExp (last $ maybeToList invs ++ args) 715 715 retVal $ VBool (not bool) 716 716 717 717 -- XXX absolutely evil bloody hack for "goto" 718 reduce (App (Var "&goto") (subExp:invs) args) = do718 reduce (App (Var "&goto") invs@(Just subExp) args) = do 719 719 vsub <- enterEvalContext (cxtItem "Code") subExp 720 720 sub <- fromVal vsub … … 732 732 733 733 -- XXX absolutely evil bloody hack for "assuming" 734 reduce (App (Var "&assuming") (subExp:invs) args) = do734 reduce (App (Var "&assuming") invs@(Just subExp) args) = do 735 735 vsub <- enterEvalContext (cxtItem "Code") subExp 736 736 sub <- fromVal vsub … … 739 739 Right curriedSub -> retVal $ castV $ curriedSub 740 740 741 reduce (App (Var "&infix:=>") invs args) = reduce (Syn "=>" ( invs ++ args))741 reduce (App (Var "&infix:=>") invs args) = reduce (Syn "=>" (maybeToList invs ++ args)) 742 742 743 743 reduce (App (Var name@('&':_)) invs args) = do … … 745 745 case sub of 746 746 Just sub -> applySub sub invs args 747 _ | [Syn "," invs'] <- unwrap invs, nullargs -> do748 sub <- findSub name invs ' []747 _ | [Syn "," args'] <- unwrap args -> do 748 sub <- findSub name invs args' 749 749 if isNothing sub then err else do 750 750 fail $ "Extra space found after " ++ name ++ " (...) -- did you mean " ++ name ++ "(...) instead?" … … 752 752 where 753 753 err = retError "No compatible subroutine found" name 754 applySub :: VCode -> [Exp]-> [Exp] -> Eval Val754 applySub :: VCode -> (Maybe Exp) -> [Exp] -> Eval Val 755 755 applySub sub invs args 756 756 -- list-associativity 757 757 | MkCode{ subAssoc = "list" } <- sub 758 , (App (Var name') invs' []):rest <- invs758 , (App (Var name') Nothing args'):rest <- args 759 759 , name == name' 760 = applySub sub (invs' ++ rest) []760 = applySub sub invs (args' ++ rest) 761 761 -- fix subParams to agree with number of actual arguments 762 762 | MkCode{ subAssoc = "list", subParams = (p:_) } <- sub 763 , null args 764 = apply sub{ subParams = (length invs) `replicate` p } invs [] 763 = apply sub{ subParams = (length args) `replicate` p } invs args 765 764 -- chain-associativity 766 765 | MkCode{ subAssoc = "chain" } <- sub 767 , (App _ _ []):_ <- invs 768 , null args 769 = mungeChainSub sub invs 766 , (App _ _ []):_ <- args 767 = mungeChainSub sub args 770 768 | MkCode{ subAssoc = "chain", subParams = (p:_) } <- sub 771 = apply sub{ subParams = (length invs) `replicate` p } invs []769 = apply sub{ subParams = (length args) `replicate` p } invs args 772 770 -- normal application 773 771 | otherwise 774 772 = apply sub invs args 775 773 mungeChainSub :: VCode -> [Exp] -> Eval Val 776 mungeChainSub sub invs = do774 mungeChainSub sub args = do 777 775 let MkCode{ subAssoc = "chain", subParams = (p:_) } = sub 778 (App (Var name') invs' args'):rest = invs776 (App (Var name') invs' args'):rest = args 779 777 theSub <- findSub name' invs' args' 780 778 case theSub of 781 Just sub' -> applyChainSub sub invs sub' invs' args' rest782 Nothing -> apply sub{ subParams = (length invs) `replicate` p } invs []-- XXX Wrong783 applyChainSub :: VCode -> [Exp] -> VCode -> [Exp] -> [ a] -> [Exp] -> Eval Val784 applyChainSub sub invs sub' invs' args' rest779 Just sub' -> applyChainSub sub args sub' args' rest 780 Nothing -> apply sub{ subParams = (length args) `replicate` p } Nothing args -- XXX Wrong 781 applyChainSub :: VCode -> [Exp] -> VCode -> [Exp] -> [Exp] -> Eval Val 782 applyChainSub sub args sub' args' rest 785 783 | MkCode{ subAssoc = "chain", subBody = fun, subParams = prm } <- sub 786 784 , MkCode{ subAssoc = "chain", subBody = fun', subParams = prm' } <- sub' 787 , null args' 788 = applySub sub{ subParams = prm ++ tail prm', subBody = Prim $ chainFun prm' fun' prm fun } (invs' ++ rest) [] 785 = applySub sub{ subParams = prm ++ tail prm', subBody = Prim $ chainFun prm' fun' prm fun } Nothing (args' ++ rest) 789 786 | MkCode{ subAssoc = "chain", subParams = (p:_) } <- sub 790 = apply sub{ subParams = (length invs) `replicate` p } invs []-- XXX Wrong787 = apply sub{ subParams = (length args) `replicate` p } Nothing args -- XXX Wrong 791 788 | otherwise 792 789 = internalError "applyChainsub did not match a chain subroutine" … … 834 831 cxtOfExp _ = return cxtSlurpyAny 835 832 836 findSub :: String -> [Exp]-> [Exp] -> Eval (Maybe VCode)833 findSub :: String -> Maybe Exp -> [Exp] -> Eval (Maybe VCode) 837 834 findSub name' invs args = do 838 835 let name = possiblyFixOperatorName name' 839 836 case invs of 840 [exp]| not (':' `elem` drop 2 name) -> do837 Just exp | not (':' `elem` drop 2 name) -> do 841 838 typ <- evalExpType exp 842 839 if typ == mkType "Scalar::Perl5" then runPerl5Sub name else do … … 860 857 svs <- fromVals args 861 858 found <- liftIO $ canPerl5 sv (tail name) `mplus` canPerl5 sv "AUTOLOAD" 862 if not found then evalExp (App (Var name) [](map (Val . PerlSV) (sv:svs))) else do859 if not found then evalExp (App (Var name) Nothing (map (Val . PerlSV) (sv:svs))) else do 863 860 cxt <- asks envContext 864 861 rv <- liftIO $ callPerl5 (tail name) (sv:svs) (enumCxt cxt) … … 871 868 -- We use the first two elements of invs as invocants, as these are the 872 869 -- types of the op. 873 rv = findSub ("&infix:" ++ op) (take 2 (invs ++ [Val undef, Val undef])) []870 rv = findSub ("&infix:" ++ op) Nothing (take 2 (maybeToList invs ++ [Val undef, Val undef])) 874 871 maybeM rv $ \code -> return $ mkPrim 875 872 { subName = "&prefix:[" ++ op ++ "]" … … 888 885 possiblyBuildMetaopVCode op' | "&prefix:" `isPrefixOf` op', "<<" `isSuffixOf` op' = do 889 886 let op = drop 8 (init (init op')) 890 rv = findSub ("&prefix:" ++ op) [head $ invs ++ [Val undef]] []887 rv = findSub ("&prefix:" ++ op) Nothing [head $ maybeToList invs ++ [Val undef]] 891 888 maybeM rv $ \code -> return $ mkPrim 892 889 { subName = "&prefix:" ++ op ++ "<<" … … 903 900 possiblyBuildMetaopVCode op' | "&postfix:>>" `isPrefixOf` op' = do 904 901 let op = drop 11 op' 905 rv = findSub ("&postfix:" ++ op) [head $ invs ++ [Val undef]] []902 rv = findSub ("&postfix:" ++ op) Nothing [head $ maybeToList invs ++ [Val undef]] 906 903 maybeM rv $ \code -> return $ mkPrim 907 904 { subName = "&postfix:>>" ++ op … … 918 915 possiblyBuildMetaopVCode op' | "&infix:>>" `isPrefixOf` op', "<<" `isSuffixOf` op' = do 919 916 let op = drop 9 (init (init op')) 920 rv = findSub ("&infix:" ++ op) (take 2 (invs ++ [Val undef, Val undef])) []917 rv = findSub ("&infix:" ++ op) Nothing (take 2 (maybeToList invs ++ [Val undef, Val undef])) 921 918 maybeM rv $ \code -> return $ mkPrim 922 919 { subName = "&infix:>>" ++ op ++ "<<" … … 951 948 findSub' name = do 952 949 subSyms <- findSyms name 953 lens <- mapM argSlurpLen (unwrap $ invs ++ args)950 lens <- mapM argSlurpLen (unwrap $ maybeToList invs ++ args) 954 951 doFindSub (sum lens) subSyms 955 952 argSlurpLen (Val listMVal) = do … … 972 969 sub@(MkCode{ subType = subT, subReturns = ret, subParams = prms }) <- fromVal val 973 970 let isGlobal = '*' `elem` n 974 let rv = return $ arityMatch sub (length ( invs ++ args)) slurpLen971 let rv = return $ arityMatch sub (length (maybeToList invs ++ args)) slurpLen 975 972 maybeM rv $ \fun -> do 976 973 -- if deltaFromCxt ret == 0 then return Nothing else do 977 974 let pairs = map (typeOfCxt . paramContext) prms 978 `zip` (map unwrap $ invs ++ args)975 `zip` (map unwrap $ maybeToList invs ++ args) 979 976 deltaCxt <- deltaFromCxt ret 980 977 deltaArgs <- mapM deltaFromPair pairs … … 1000 997 sub <- fromVal val 1001 998 return $ subReturns sub 1002 evalExpType (App (Var "&new") [(Val (VType typ))]_) = return typ1003 evalExpType (App (Var "&new") [(Var (':':name))]_) = return $ mkType name999 evalExpType (App (Var "&new") (Just (Val (VType typ))) _) = return typ 1000 evalExpType (App (Var "&new") (Just (Var (':':name))) _) = return $ mkType name 1004 1001 evalExpType (App (Var name) invs args) = do 1005 1002 sub <- findSub name invs args … … 1051 1048 Mostly delegates to 'doApply' after explicitly retrieving the local 'Env'. 1052 1049 -} 1053 apply :: VCode -- ^ The sub to apply1054 -> [Exp] -- ^ List of invocants1055 -> [Exp] -- ^ List of arguments (non-invocant)1050 apply :: VCode -- ^ The sub to apply 1051 -> (Maybe Exp) -- ^ invocant 1052 -> [Exp] -- ^ List of arguments (non-invocant) 1056 1053 -> Eval Val 1057 1054 apply sub invs args = do … … 1067 1064 doApply :: Env -- ^ Environment to evaluate in 1068 1065 -> VCode -- ^ Code to apply 1069 -> [Exp]-- ^ Invocants (arguments before the colon)1066 -> (Maybe Exp) -- ^ Invocants (arguments before the colon) 1070 1067 -> [Exp] -- ^ Arguments (not including invocants) 1071 1068 -> Eval Val -
src/Pugs/Lexer.hs
r3612 r3906 144 144 = homogenConcat (Val (VStr (x ++ y)) : xs) 145 145 homogenConcat (x:xs) 146 = App (Var "&infix:~") [x, homogenConcat xs] []146 = App (Var "&infix:~") Nothing [x, homogenConcat xs] 147 147 148 148 stringList = do -
src/Pugs/Parser.hs
r3878 r3906 474 474 val <- unsafeEvalExp $ 475 475 if (map toLower author) == "-perl5" 476 then Stmts (Sym SGlobal (':':'*':pkg) (Syn ":=" [ Var (':':'*':pkg), App (Var "&require_perl5") [Val . VStr $ concat (intersperse "::" names)] [] ])) (Syn "env" [])477
