Changeset 8153
- Timestamp:
- 12/10/05 13:24:15 (3 years ago)
- Location:
- src
- Files:
-
- 14 modified
-
Pugs.hs (modified) (1 diff)
-
Pugs/AST.hs (modified) (1 diff)
-
Pugs/AST/Internals.hs (modified) (5 diffs)
-
Pugs/Bind.hs (modified) (1 diff)
-
Pugs/Compile.hs (modified) (4 diffs)
-
Pugs/Compile/Haskell.hs (modified) (1 diff)
-
Pugs/Compile/PIL2.hs (modified) (4 diffs)
-
Pugs/Compile/Pugs.hs (modified) (1 diff)
-
Pugs/Eval.hs (modified) (2 diffs)
-
Pugs/Eval/Var.hs (modified) (2 diffs)
-
Pugs/Lexer.hs (modified) (1 diff)
-
Pugs/Parser.hs (modified) (5 diffs)
-
Pugs/Pretty.hs (modified) (1 diff)
-
Pugs/Run/Perl5.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs.hs
r7867 r8153 346 346 _ -> return $ makeDumpEnv exp 347 347 -- XXX Generalize this into structural folding 348 makeDumpEnv (Stmts x exp) = Stmts x $ makeDumpEnv exp 349 makeDumpEnv (Cxt x exp) = Cxt x $ makeDumpEnv exp 350 makeDumpEnv (Pad x y exp) = Pad x y $ makeDumpEnv exp 351 makeDumpEnv (Sym x y exp) = Sym x y $ makeDumpEnv exp 352 makeDumpEnv (Pos x exp) = Pos x $ makeDumpEnv exp 348 makeDumpEnv (Stmts x exp) = Stmts x $ makeDumpEnv exp 349 makeDumpEnv (Ann ann exp) = Ann ann $ makeDumpEnv exp 350 makeDumpEnv (Pad x y exp) = Pad x y $ makeDumpEnv exp 351 makeDumpEnv (Sym x y exp) = Sym x y $ makeDumpEnv exp 353 352 makeDumpEnv exp = Stmts exp (Syn "env" []) 354 353 handler err = if not (isUserError err) then ioError err else do -
src/Pugs/AST.hs
r7622 r8153 129 129 mergeStmts (Syn "package" [kind, pkg@(Val (VStr _))]) y = 130 130 Syn "namespace" [kind, pkg, y] 131 mergeStmts x@( Pos pos(Syn syn _)) y | (syn ==) `any` words "subst match //" =132 mergeStmts ( Pos pos(App (Var "&infix:~~") Nothing [Var "$_", x])) y133 mergeStmts x y@( Pos pos(Syn syn _)) | (syn ==) `any` words "subst match //" =134 mergeStmts x ( Pos pos(App (Var "&infix:~~") Nothing [Var "$_", y]))135 mergeStmts ( Pos pos(Syn "sub" [Val (VCode sub)])) y131 mergeStmts x@(Ann ann (Syn syn _)) y | (syn ==) `any` words "subst match //" = 132 mergeStmts (Ann ann (App (Var "&infix:~~") Nothing [Var "$_", x])) y 133 mergeStmts x y@(Ann ann (Syn syn _)) | (syn ==) `any` words "subst match //" = 134 mergeStmts x (Ann ann (App (Var "&infix:~~") Nothing [Var "$_", y])) 135 mergeStmts (Ann ann (Syn "sub" [Val (VCode sub)])) y 136 136 | subType sub >= SubBlock, isEmptyParams (subParams sub) = 137 137 -- bare Block in statement level; annul all its parameters and run it! 138 mergeStmts ( Pos pos$ App (Val $ VCode sub{ subParams = [] }) Nothing []) y139 mergeStmts x ( Pos pos(Syn "sub" [Val (VCode sub)]))138 mergeStmts (Ann ann $ App (Val $ VCode sub{ subParams = [] }) Nothing []) y 139 mergeStmts x (Ann ann (Syn "sub" [Val (VCode sub)])) 140 140 | subType sub >= SubBlock, isEmptyParams (subParams sub) = 141 141 -- bare Block in statement level; annul all its parameters and run it! 142 mergeStmts x ( Pos pos$ App (Val $ VCode sub{ subParams = [] }) Nothing [])142 mergeStmts x (Ann ann $ App (Val $ VCode sub{ subParams = [] }) Nothing []) 143 143 mergeStmts x (Stmts y Noop) = mergeStmts x y 144 144 mergeStmts x (Stmts Noop y) = mergeStmts x y -
src/Pugs/AST/Internals.hs
r8077 r8153 4 4 module Pugs.AST.Internals ( 5 5 Eval, -- uses Val, Env, SIO 6 Ann(..), -- Cxt, Pos, Prag 6 7 Exp(..), -- uses Pad, Eval, Val 7 8 Env(..), -- uses Pad, TVar, Exp, Eval, Val … … 862 863 show _ = "<ref>" 863 864 865 {- Expression annotation 866 -} 867 data Ann 868 = Cxt !Cxt -- ^ Context 869 | Pos !Pos -- ^ Position 870 | Prag ![Pragma] -- ^ Lexical pragmas 871 deriving (Show, Eq, Ord, Typeable) 872 864 873 {- Expressions 865 874 "App" represents function application, e.g. myfun($invocant: $arg) … … 882 891 | Syn !String ![Exp] -- ^ Syntactic construct that cannot 883 892 -- be represented by 'App'. 884 | Cxt !Cxt !Exp -- ^ Context 885 | Pos !Pos !Exp -- ^ Position 886 | Prag ![Pragma] !Exp -- ^ Lexical pragmas 893 | Ann !Ann !Exp -- ^ Annotation (see @Ann@) 887 894 | Pad !Scope !Pad !Exp -- ^ Lexical pad 888 895 | Sym !Scope !Var !Exp -- ^ Symbol declaration … … 925 932 926 933 instance Unwrap Exp where 927 unwrap (Cxt _ exp) = unwrap exp 928 unwrap (Pos _ exp) = unwrap exp 929 unwrap (Prag _ exp) = unwrap exp 934 ---gaal unwrap (Cxt _ exp) = unwrap exp 935 ---gaal unwrap (Pos _ exp) = unwrap exp 936 ---gaal unwrap (Prag _ exp) = unwrap exp 937 unwrap (Ann _ exp) = unwrap exp 930 938 unwrap (Pad _ _ exp) = unwrap exp 931 939 unwrap (Sym _ _ exp) = unwrap exp … … 978 986 | otherwise 979 987 = (Var name, vs) 980 extract (Prag prag ex) vs = ((Prag prag ex'), vs') 981 where 982 (ex', vs') = extract ex vs 983 extract (Pos pos ex) vs = ((Pos pos ex'), vs') 984 where 985 (ex', vs') = extract ex vs 986 extract (Cxt cxt ex) vs = ((Cxt cxt ex'), vs') 988 extract (Ann ann ex) vs = ((Ann ann ex'), vs') 987 989 where 988 990 (ex', vs') = extract ex vs 989 991 extract exp vs = (exp, vs) 992 990 993 991 994 -- can be factored -
src/Pugs/Bind.hs
r7622 r8153 104 104 -> MaybeError (Bindings, SlurpLimit) 105 105 bindArray vs ps oldLimit = do 106 let exp = Cxt cxtSlurpyAny(Syn "," vs)106 let exp = Ann (Cxt cxtSlurpyAny) (Syn "," vs) 107 107 case foldM (doBindArray exp) ([], 0) prms of 108 108 Left errMsg -> fail errMsg -
src/Pugs/Compile.hs
r7696 r8153 137 137 138 138 instance Compile Exp PIL_Stmts where 139 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 140 compile (Cxt cxt rest) = enter cxt $ compile rest 139 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 140 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 141 -- XXX: pragmas? 141 142 compile (Stmts (Pad SOur _ exp) rest) = do 142 143 compile $ mergeStmts exp rest … … 192 193 193 194 instance Compile Exp PIL_Stmt where 194 compile (Pos pos rest) = fmap (PPos pos rest) $ compile rest 195 compile (Cxt cxt rest) = enter cxt $ compile rest 195 compile (Ann (Pos pos) rest) = fmap (PPos pos rest) $ compile rest 196 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 197 -- XXX: pragmas? 196 198 compile Noop = return PNoop 197 199 compile (Val val) = do … … 266 268 267 269 instance Compile Exp PIL_LValue where 268 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 269 compile (Cxt cxt rest) = enter cxt $ compile rest 270 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 271 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 272 -- XXX: pragmas? 270 273 compile (Var name) = return $ PVar name 271 274 compile (Syn (sigil:"::()") exps) = do … … 361 364 {-| Compiles various 'Exp's to 'PIL_Expr's. -} 362 365 instance Compile Exp PIL_Expr where 363 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 364 compile (Cxt cxt rest) = enter cxt $ compile rest 366 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 367 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 368 -- XXX: pragmas? 365 369 compile (Var name) = return . PExp $ PVar name 366 370 compile exp@(Val (VCode _)) = compile $ Syn "sub" [exp] -
src/Pugs/Compile/Haskell.hs
r5890 r8153 65 65 argC1 = compile arg1 66 66 argC2 = compile arg2 67 compile (Cxt _ arg) = compile arg 68 compile (Pos _ arg) = compile arg 67 compile (Ann _ arg) = compile arg 69 68 compile (Val (VInt i)) = [| return (VInt i) |] 70 69 compile (Val (VStr s)) = [| return (VStr s) |] -
src/Pugs/Compile/PIL2.hs
r7866 r8153 128 128 129 129 instance Compile Exp PIL_Stmts where 130 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 131 compile (Cxt cxt rest) = enter cxt $ compile rest 130 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 131 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 132 -- XXX: pragmas? 132 133 compile (Stmts (Pad SOur _ exp) rest) = do 133 134 compile $ mergeStmts exp rest … … 183 184 184 185 instance Compile Exp PIL_Stmt where 185 compile (Pos pos rest) = fmap (PPos pos rest) $ compile rest 186 compile (Cxt cxt rest) = enter cxt $ compile rest 186 compile (Ann (Pos pos) rest) = fmap (PPos pos rest) $ compile rest 187 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 188 -- XXX: pragmas? 187 189 compile Noop = return PNoop 188 190 compile (Val val) = do … … 257 259 258 260 instance Compile Exp PIL_LValue where 259 compile ( Pos _rest) = compile rest -- fmap (PPos pos rest) $ compile rest260 compile ( Cxt cxtrest) = enter cxt $ compile rest261 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 262 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 261 263 compile (Var name) = return $ PVar name 262 264 compile (Syn (sigil:"::()") exps) = do … … 352 354 {-| Compiles various 'Exp's to 'PIL_Expr's. -} 353 355 instance Compile Exp PIL_Expr where 354 compile ( Pos _rest) = compile rest -- fmap (PPos pos rest) $ compile rest355 compile ( Cxt cxtrest) = enter cxt $ compile rest356 compile (Ann (Pos _) rest) = compile rest -- fmap (PPos pos rest) $ compile rest 357 compile (Ann (Cxt cxt) rest) = enter cxt $ compile rest 356 358 compile (Var name) = return . PExp $ PVar name 357 359 compile exp@(Val (VCode _)) = compile $ Syn "sub" [exp] -
src/Pugs/Compile/Pugs.hs
r7843 r8153 61 61 , text "return" <+> parens (text $ "Syn " ++ show syn ++ " exps") 62 62 ] 63 compile (Cxt cxt exp) = compileShow2 "Cxt" cxt exp 64 compile (Pos pos exp) = compileShow2 "Pos" pos exp 63 compile (Ann (Cxt cxt) exp) = compileShow2 "Cxt" cxt exp 64 compile (Ann (Pos pos) exp) = compileShow2 "Pos" pos exp 65 compile (Ann (Prag prag) exp) = compileShow2 "Prag" prag exp 65 66 compile (Pad scope pad exp) = do 66 67 padC <- compile pad -
src/Pugs/Eval.hs
r8076 r8153 230 230 reduce (Stmts this rest) = reduceStmts this rest 231 231 232 reduce ( Prag pragexp) = reducePrag prag exp233 234 reduce ( Pos posexp) = reducePos pos exp232 reduce (Ann (Prag prag) exp) = reducePrag prag exp 233 234 reduce (Ann (Pos pos) exp) = reducePos pos exp 235 235 236 236 reduce (Pad scope lexEnv exp) = reducePad scope lexEnv exp … … 238 238 reduce (Sym scope name exp) = reduceSym scope name exp 239 239 240 reduce ( Cxt cxtexp) = reduceCxt cxt exp240 reduce (Ann (Cxt cxt) exp) = reduceCxt cxt exp 241 241 242 242 -- Reduction for no-operations -
src/Pugs/Eval/Var.hs
r8076 r8153 332 332 cxt <- inferExpCxt idxExp 333 333 return (typeOfCxt cxt) 334 inferExpType ( Cxt cxt_) | typeOfCxt cxt /= (mkType "Any") = return $ typeOfCxt cxt335 inferExpType ( Cxt _exp) = inferExpType exp336 inferExpType ( Pos _exp) = inferExpType exp334 inferExpType (Ann (Cxt cxt) _) | typeOfCxt cxt /= (mkType "Any") = return $ typeOfCxt cxt 335 inferExpType (Ann (Cxt _) exp) = inferExpType exp 336 inferExpType (Ann (Pos _) exp) = inferExpType exp 337 337 inferExpType (Pad _ _ exp) = inferExpType exp 338 338 inferExpType (Sym _ _ exp) = inferExpType exp … … 355 355 inferExpCxt :: Exp -- ^ Expression to find the context of 356 356 -> Eval Cxt 357 inferExpCxt ( Pos _exp) = inferExpCxt exp358 inferExpCxt ( Cxt cxt_) = return cxt357 inferExpCxt (Ann (Pos _) exp) = inferExpCxt exp 358 inferExpCxt (Ann (Cxt cxt) _) = return cxt 359 359 inferExpCxt (Syn "," _) = return cxtSlurpyAny 360 360 inferExpCxt (Syn "[]" [_, exp]) = inferExpCxt exp -
src/Pugs/Lexer.hs
r8006 r8153 163 163 interpolatingStringLiteral startrule endrule interpolator = do 164 164 list <- stringList 0 165 return . Cxt (CxtItem $ mkType "Str") $ homogenConcat list165 return $ Ann (Cxt (CxtItem $ mkType "Str")) (homogenConcat list) 166 166 where 167 167 homogenConcat :: [Exp] -> Exp -
src/Pugs/Parser.hs
r8121 r8153 76 76 exp <- rule 77 77 pos2 <- getPosition 78 return $ Pos (mkPos pos1 pos2) (unwrap exp)78 return $ Ann (Pos (mkPos pos1 pos2)) (unwrap exp) 79 79 80 80 {-| … … 623 623 name | twigil == '.' = '&':(envPackage env ++ "::" ++ key) 624 624 | otherwise = '&':(envPackage env ++ "::" ++ (twigil:key)) 625 fun = Cxt (cxtOfSigil sigil) (Syn "{}" [Var "$?SELF", Val (VStr key)])625 fun = Ann (Cxt (cxtOfSigil sigil)) (Syn "{}" [Var "$?SELF", Val (VStr key)]) 626 626 unsafeEvalExp (Sym SGlobal name exp) 627 627 return emptyExp … … 663 663 -- And note that IIRC not the type object should be the invocant, but 664 664 -- an undef which knows to dispatch .new to the real class. 665 let exp' | Pos _ (App sub Nothing args) <- exp, sym == ".=" && typename /= ""665 let exp' | Ann (Pos _) (App sub Nothing args) <- exp, sym == ".=" && typename /= "" -- XXX: App _ maybe? 666 666 = return $ App sub (Just . Var $ ':':typename) args 667 667 | sym == ".=" && typename /= "" … … 2070 2070 Syn "{}" [Var "$/", doSplitStr (init name)] 2071 2071 makeVar (sigil:'.':name) = 2072 Cxt (cxtOfSigil sigil) (Syn "{}" [Var "$?SELF", Val (VStr name)])2072 Ann (Cxt (cxtOfSigil sigil)) (Syn "{}" [Var "$?SELF", Val (VStr name)]) 2073 2073 makeVar (sigil:'!':name) | not (null name) = 2074 Cxt (cxtOfSigil sigil) (Syn "{}" [Var "$?SELF", Val (VStr name)])2074 Ann (Cxt (cxtOfSigil sigil)) (Syn "{}" [Var "$?SELF", Val (VStr name)]) 2075 2075 makeVar var = Var var 2076 2076 … … 2277 2277 -- words() regards \xa0 as (breaking) whitespace. But \xa0 is 2278 2278 -- a nonbreaking ws char. 2279 doSplit ( Cxt (CxtItem _) (Val (VStr str))) = return $ doSplitStr str2279 doSplit (Ann (Cxt (CxtItem _)) (Val (VStr str))) = return $ doSplitStr str -- XXX: generalize to Ann _? 2280 2280 doSplit expr = doSplitRx expr 2281 2281 -
src/Pugs/Pretty.hs
r8077 r8153 41 41 format (Sym scope name exp) = text "Sym" <+> text (show scope) <+> format name $+$ format exp 42 42 format (Pad scope pad exp) = text "Pad" <+> text (show scope) <+> format pad $+$ format exp 43 format ( Pos_ exp) = format exp43 format (Ann _ exp) = format exp 44 44 format x = text $ show x 45 45 -
src/Pugs/Run/Perl5.hs
r7478 r8153 77 77 _ -> Val sub 78 78 val <- runEvalIO env $ 79 evalExp ( Cxt (cxtEnum cxt) $ App subExp (fmap Val inv) (map Val args))79 evalExp (Ann (Cxt (cxtEnum cxt)) $ App subExp (fmap Val inv) (map Val args)) 80 80 newSVval val 81 81
