Changeset 32
- Timestamp:
- 02/16/05 18:48:28 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 11 modified
-
AUTHORS (modified) (1 diff)
-
Makefile.PL (modified) (4 diffs)
-
src/AST.hs (modified) (1 diff)
-
src/Eval.hs (modified) (3 diffs)
-
src/Help.hs (modified) (2 diffs)
-
src/Internals.hs (modified) (1 diff)
-
src/Lexer.hs (modified) (1 diff)
-
src/Main.hs (modified) (4 diffs)
-
src/Parser.hs (modified) (10 diffs)
-
src/Prim.hs (modified) (2 diffs)
-
t/01basic.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
r21 r32 6 6 Bestian Tang 7 7 Brian Ingerson (INGY) 8 Chia-Liang Kao (CLKAO) 8 9 Damian Conway (DCONWAY) 9 10 Hsin-Chan Chien (HCCHIEN) -
Makefile.PL
r9 r32 3 3 use strict; 4 4 use FindBin; 5 use File::Spec; 5 6 use Config; 6 7 use inc::Module::Install; 7 8 8 9 chdir $FindBin::Bin; 10 my $pugs = File::Spec->catfile($FindBin::Bin, "pugs$Config{_exe}"); 9 11 10 12 name ('Perl6-Pugs'); … … 13 15 author ('Autrijus Tang <autrijus@autrijus.org>'); 14 16 license ('perl'); 15 install_script ( "pugs$Config{_exe}");17 install_script ($pugs); 16 18 build_requires ('Test::More'); 17 19 … … 67 69 68 70 postamble(<< "."); 69 pugs$Config{_exe}: @{[glob("src/*.hs")]}70 ghc --make -o pugs -Osrc/Main.hs -isrc71 $pugs: @{[glob("src/*.hs")]} 72 ghc --make -o pugs src/Main.hs -isrc 71 73 72 74 tags :: … … 75 77 76 78 WriteAll( sign => 1 ); 79 80 # FIXUP 81 open MAKEFILE, '< Makefile' or die $!; 82 my $makefile = do { local $/; <MAKEFILE> }; 83 $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/ENV->{HARNESS_PERL} = '$pugs'; $1/; 84 close MAKEFILE; 85 open MAKEFILE, '> Makefile' or die $!; 86 print MAKEFILE $makefile; 87 close MAKEFILE; -
src/AST.hs
r31 r32 46 46 castV = VSub 47 47 doCast (VSub b) = b 48 doCast v = error ("Cannot cast into VSub: " ++ (show v)) 48 49 49 50 instance Value VBool where -
src/Eval.hs
r31 r32 29 29 uniq <- liftIO $ newUnique 30 30 return $ Env 31 { envContext = " List"31 { envContext = "Void" 32 32 , envLexical = [] 33 33 , envGlobal = initSyms … … 57 57 evaluate :: Exp -> Eval Val 58 58 evaluate (Val (VSub sub)) = do 59 pad <- asks envLexical 60 return $ VSub sub{ subPad = pad } -- closure! 59 cxt <- asks envContext 60 if cxt == "Void" && subType sub == SubBlock 61 then do 62 exp <- apply sub [] [] 63 evalExp exp 64 else do 65 pad <- asks envLexical 66 return $ VSub sub{ subPad = pad } -- closure! 61 67 evaluate (Val val) = return val 62 68 evaluate exp = do … … 149 155 let [Sym (Symbol _ _ exp)] = exps 150 156 val <- evalExp exp 151 retVal val157 retVal VUndef 152 158 ":=" -> do 153 159 let [Var var, exp] = exps 154 val <- e valExpexp160 val <- enterEvalContext (cxtOfSigil $ head var) exp 155 161 retVal val 156 162 "::=" -> do -- XXX wrong -
src/Help.hs
r7 r32 1 1 {-# OPTIONS -cpp #-} 2 #define VERSION " "2 #define VERSION "6" 3 3 #define DATE "" 4 4 #include "config.h" … … 13 13 -} 14 14 15 module Help (printHelp, banner, vers ion, copyright, disclaimer) where15 module Help (printHelp, banner, versnum, version, copyright, disclaimer) where 16 16 17 17 printHelp :: IO () -
src/Internals.hs
r29 r32 78 78 show = show . hashUnique 79 79 instance Show (a -> b) where 80 show f = " sub { ... }"80 show f = "(->)" 81 81 instance Eq (a -> b) where 82 82 _ == _ = False -
src/Lexer.hs
r31 r32 18 18 19 19 perl6Def = javaStyle 20 { P.commentStart = " \n=begin\n"21 , P.commentEnd = " \n=cut\n"20 { P.commentStart = "=pod" 21 , P.commentEnd = "=cut" 22 22 , P.commentLine = "#" 23 23 , P.nestedComments = False -
src/Main.hs
r31 r32 25 25 26 26 main :: IO () 27 main = getArgs >>= run 27 main = do 28 args <- getArgs 29 run $ concatMap procArg args 30 where 31 procArg ('-':'e':prog@(_:_)) = ["-e", prog] 32 procArg ('-':'d':rest@(_:_)) = ["-d", ('-':rest)] 33 procArg x = [x] 28 34 29 35 run :: [String] -> IO () 36 run ("-d":rest) = run rest 37 run ("-w":rest) = run rest 30 38 run (('-':'e':prog@(_:_)):args) = doRun "-" args prog 31 39 run ("-e":prog:args) = doRun "-" args prog 32 40 run ("-h":_) = printHelp 41 run ("-":args) = do 42 prog <- getContents 43 doRun "-" [] prog 33 44 run (file:args) = readFile file >>= doRun file args 34 45 run [] = do … … 37 48 if isTTY 38 49 then banner >> repLoop 39 else do 40 prog <- getContents 41 doRun "-" [] prog 50 else run ["-"] 42 51 43 52 repLoop :: IO () … … 61 70 62 71 doEval :: [String] -> String -> IO () 63 doEval = runProgramWith (putStrLn . pretty) "<interactive>" 72 doEval = do 73 runProgramWith id (putStrLn . pretty) "<interactive>" 64 74 65 75 doRun :: String -> [String] -> String -> IO () 66 doRun = runProgramWith (putStr . concatMap vCast . vCast) 76 doRun = do 77 runProgramWith (\e -> e{ envDebug = Nothing }) end 78 where 79 end v@(VError str exp) = do 80 hPutStrLn stderr str 81 exitFailure 82 end _ = return () 67 83 68 runProgramWith :: ( Val -> IO ()) -> String -> [String] -> String -> IO ()69 runProgramWith f name args prog = do84 runProgramWith :: (Env -> Env) -> (Val -> IO ()) -> VStr -> [VStr] -> String -> IO () 85 runProgramWith fenv f name args prog = do 70 86 env <- emptyEnv 71 let env' = runRule (prepare env) id ruleProgram prog87 let env' = runRule (prepare $ fenv env) id ruleProgram prog 72 88 val <- (`runReaderT` env') $ do 73 89 (`runContT` return) $ do … … 80 96 ] ++ envGlobal e } 81 97 98 {- 99 main = do 100 -- (optsIO, rest, errs) <- return . getOpt Permute options $ procArgs args 101 102 options :: [OptDescr (Opts -> Opts)] 103 options = 104 [ reqArg "e" ["eval"] "command" "Command-line program" 105 (\s o -> o { encodings = split "," s }) 106 , noArg "d" ["debug"] "Turn on debugging" 107 (\s o -> o { inputFile = s }) 108 , noArg "h" ["help"] "Show help" 109 (\o -> o { showHelp = usage "" }) 110 ] 111 -} 112 -
src/Parser.hs
r31 r32 13 13 import Internals 14 14 import AST 15 import Help 15 16 import Lexer 16 17 … … 56 57 , rulePackageDeclaration 57 58 , ruleVarDeclaration 59 , ruleUseDeclaration 58 60 ] 59 61 … … 87 89 , ruleSubGlobal 88 90 ] 89 pos <- getPosition90 91 cxt2 <- option cxt1 $ ruleBareTrait "returns" 91 92 formal <- option Nothing $ return . Just =<< parens ruleSubParameters … … 148 149 scope <- ruleScope 149 150 name <- parseVarName 150 return $ Syn "sym" [Sym (Symbol scope name (Val VUndef))] 151 exp <- option (Val VUndef) $ do 152 tryChoice $ map symbol $ words " = := ::= " 153 ruleExpression 154 return $ Syn "sym" [Sym $ Symbol scope name exp] 155 156 ruleUseDeclaration :: RuleParser Exp 157 ruleUseDeclaration = rule "use declaration" $ do 158 symbol "use" 159 option ' ' $ char 'v' 160 version <- many1 (choice [ digit, char '.' ]) 161 when (version > versnum) $ do 162 pos <- getPosition 163 error $ "Perl v" ++ version ++ " required--this is only v" ++ versnum ++ ", stopped at " ++ (show pos) 164 return $ Val VUndef 151 165 152 166 rulePackageDeclaration = rule "package declaration" $ fail "" … … 156 170 ruleConstruct = rule "construct" $ tryChoice 157 171 [ ruleGatherConstruct 158 , ruleBlockConstruct159 172 ] 160 173 … … 163 176 block <- ruleBlock 164 177 retSyn "gather" [block] 165 166 ruleBlockConstruct = rule "block construct" $ do167 formal <- option Nothing $ choice [ ruleBlockFormalStandard, ruleBlockFormalPointy ]168 block <- ruleBlock169 fail ""170 171 ruleBlockFormalStandard = rule "standard block parameters" $ do172 symbol "sub"173 return . Just =<< parens ruleSubParameters174 175 ruleBlockFormalPointy = rule "pointy block parameters" $ do176 symbol "->"177 return . Just =<< ruleSubParameters178 178 179 179 ruleCondConstruct = rule "conditional construct" $ fail "" … … 187 187 ruleExpression = (<?> "expression") $ parseOp 188 188 189 ruleBlockLiteral = rule "block construct" $ do 190 (typ, formal) <- option (SubBlock, Nothing) $ choice 191 [ ruleBlockFormalStandard 192 , ruleBlockFormalPointy 193 ] 194 body <- ruleBlock 195 let (fun, names) = extract (body, []) 196 params = (maybe [] id formal) ++ map nameToParam names 197 -- Check for placeholder vs formal parameters 198 unless (isNothing formal || null names || names == ["$_"] ) $ 199 fail "Cannot mix placeholder variables with formal parameters" 200 let sub = Sub { isMulti = False 201 , subName = "<anon>" 202 , subPad = [] 203 , subType = typ 204 , subAssoc = "pre" 205 , subReturns = "Any" 206 , subParams = if null params then [defaultArrayParam] else params 207 , subFun = fun 208 } 209 return (Val $ VSub sub) 210 211 ruleBlockFormalStandard = rule "standard block parameters" $ do 212 symbol "sub" 213 params <- option Nothing $ return . Just =<< parens ruleSubParameters 214 return $ (SubRoutine, params) 215 216 ruleBlockFormalPointy = rule "pointy block parameters" $ do 217 symbol "->" 218 params <- ruleSubParameters 219 return $ (SubBlock, Just params) 220 189 221 190 222 … … 211 243 , postOps " ++ -- " -- Auto-Increment 212 244 , rightOps " ** " -- Exponentiation 213 , preOps " ! + - ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 245 -- , preOps " ! + - ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 246 , preOps " ! + ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 214 247 , leftOps " * / % x xx +& +< +> ~& ~< ~> " -- Multiplicative 215 248 , leftOps " + - ~ +| +^ ~| ~^ " -- Additive … … 344 377 sigil <- oneOf "$@%&" 345 378 caret <- option "" $ choice [ string "^", string "*" ] 346 name <- many1 wordAny 347 return $ (sigil:caret) ++ name 379 name <- many1 (choice [ wordAny, char ':' ]) 380 return $ if sigil == '&' && not (':' `elem` name) 381 then (sigil:caret) ++ "prefix:" ++ name 382 else (sigil:caret) ++ name 348 383 349 384 parseVar = do … … 356 391 357 392 parseLit = choice 358 [ numLiteral 393 [ ruleBlockLiteral 394 , numLiteral 359 395 , strLiteral 360 396 , arrayLiteral -
src/Prim.hs
r31 r32 58 58 liftIO . putStr . concatMap vCast . vCast $ v 59 59 return $ VUndef 60 op1 "say" = \v -> do 61 liftIO . putStrLn . concatMap vCast . vCast $ v 62 return $ VUndef 63 op1 "die" = \v -> do 64 return $ VError (concatMap vCast . vCast $ v) (Val v) 65 op1 "exit" = \v -> do 66 if vCast v 67 then liftIO $ exitWith (ExitFailure $ vCast v) 68 else liftIO $ exitWith ExitSuccess 60 69 61 70 op1 s = return . (\x -> VError ("unimplemented unaryOp: " ++ s) (Val x)) … … 260 269 \\n Num pre rand (?Num=1)\ 261 270 \\n Action pre print (List)\ 271 \\n Action pre say (List)\ 272 \\n Action pre die (List)\ 273 \\n Any pre do (Str)\ 262 274 \\n Any pre return (Any)\ 263 275 \\n Junction pre any (List)\ -
t/01basic.t
r31 r32 1 #!/usr/bin/perl 1 use v6; 2 2 3 use FindBin; 4 use Config; 5 use File::Spec; 3 =pod 6 4 7 chdir (File::Spec->catdir($FindBin::Bin, File::Spec->updir)); 8 my $pugs = File::Spec->catfile(File::Spec->curdir, "pugs$Config{_exe}"); 5 This is a test file. Whee! 9 6 10 system($pugs, -e => '"1..2\nok 1 # Welcome to Pugs!\n"'); 7 =cut 11 8 12 open PUGS, "| $pugs" or die "Cannot pipe out to $pugs: $!";13 print PUGS << '.';14 sub cool { fine($_) ~ " # We've got " ~ toys }; 15 sub fine { "ok " ~ $_ }; 16 sub toys { "fun and games!\n" }; 17 cool 2 18 . 19 close PUGS; 9 say "1..2"; 10 say "ok 1 # Welcome to Pugs!"; 11 12 sub cool { fine($_) ~ " # We've got " ~ toys } 13 sub fine { "ok " ~ $_ } 14 sub toys { "fun and games!" } 15 16 say cool 2 # and that's it, folks!
