Changeset 10645
- Timestamp:
- 06/12/06 11:51:43 (2 years ago)
- Location:
- src
- Files:
-
- 7 modified
-
Pugs.hs (modified) (1 diff)
-
Pugs/AST/Internals/Instances.hs (modified) (4 diffs)
-
Pugs/AST/Scope.hs (modified) (1 diff)
-
Pugs/Eval.hs (modified) (2 diffs)
-
Pugs/Internals.hs (modified) (2 diffs)
-
Pugs/Parser.hs (modified) (21 diffs)
-
Pugs/Parser/Export.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs.hs
r10461 r10645 353 353 Val err@(VError (VStr msg) _) 354 354 | runOptShowPretty opts 355 , any (== "unexpected end of input") (lines msg) -> do 355 , any (== "unexpected end of input") (lines msg) 356 , not (any ("unexpected global symbol " `isPrefixOf`) (lines msg)) -> do 356 357 cont <- readline "....> " 357 358 case cont of -
src/Pugs/AST/Internals/Instances.hs
r10528 r10645 570 570 "SMy" -> do 571 571 return SMy 572 "SParam" -> do 573 return SParam 572 574 "SOur" -> do 573 575 return SOur 574 576 "SGlobal" -> do 575 577 return SGlobal 576 _ -> fail $ "unhandled tag: " ++ show t ++ ", expecting " ++ show ["SState","SLet","STemp","SEnv","SMy","S Our","SGlobal"] ++ " in node " ++ show e578 _ -> fail $ "unhandled tag: " ++ show t ++ ", expecting " ++ show ["SState","SLet","STemp","SEnv","SMy","SParam","SOur","SGlobal"] ++ " in node " ++ show e 577 579 fromYAML _ = fail "no tag found" 578 580 asYAML (SState) = asYAMLcls "SState" … … 581 583 asYAML (SEnv) = asYAMLcls "SEnv" 582 584 asYAML (SMy) = asYAMLcls "SMy" 585 asYAML (SParam) = asYAMLcls "SParam" 583 586 asYAML (SOur) = asYAMLcls "SOur" 584 587 asYAML (SGlobal) = asYAMLcls "SGlobal" … … 590 593 showJSON (SEnv) = showJSScalar "SEnv" 591 594 showJSON (SMy) = showJSScalar "SMy" 595 showJSON (SParam) = showJSScalar "SParam" 592 596 showJSON (SOur) = showJSScalar "SOur" 593 597 showJSON (SGlobal) = showJSScalar "SGlobal" … … 599 603 showPerl5 (SEnv) = showP5Class "SEnv" 600 604 showPerl5 (SMy) = showP5Class "SMy" 605 showPerl5 (SParam) = showP5Class "SParam" 601 606 showPerl5 (SOur) = showP5Class "SOur" 602 607 showPerl5 (SGlobal) = showP5Class "SGlobal" -
src/Pugs/AST/Scope.hs
r8694 r10645 12 12 | SEnv -- ^ Environment (declared with @env@) 13 13 | SMy -- ^ Lexical 14 | SParam -- ^ Parameter 14 15 | SOur -- ^ Package 15 16 | SGlobal -- ^ Global -
src/Pugs/Eval.hs
r10619 r10645 307 307 308 308 reducePad :: Scope -> Pad -> Exp -> Eval Val 309 reducePad SParam _ exp = evalExp exp 309 310 reducePad SEnv lex@(MkPad lex') exp = do 310 311 local (\e -> e{ envImplicit = Map.map (const ()) lex' `Map.union` envImplicit e }) $ … … 344 345 -- Special case: my (undef) is no-op 345 346 reduceSym _ "" exp = evalExp exp 347 348 reduceSym SParam name exp = do 349 let sym (MkPad map) = MkPad $ Map.insert name (MkEntryMulti []) map 350 enterLex [sym] $ evalExp exp 346 351 347 352 reduceSym scope name exp | scope <= SMy = do -
src/Pugs/Internals.hs
r10532 r10645 67 67 inlinePerformIO, 68 68 inlinePerformSTM, 69 unsafePerformSTM, 69 70 possiblyFixOperatorName, 70 71 maybeM, … … 245 246 inlinePerformSTM m = inlinePerformIO (atomically m) 246 247 248 {-# NOINLINE unsafePerformSTM #-} 249 unsafePerformSTM :: STM a -> a 250 unsafePerformSTM m = unsafePerformIO (atomically m) 251 247 252 {-| 248 253 Read an STM variable, apply some transformation function to it, and write the -
src/Pugs/Parser.hs
r10638 r10645 40 40 41 41 ruleBlock :: RuleParser Exp 42 ruleBlock = do 42 ruleBlock = ruleBlockWithParams [] 43 44 ruleBlockWithParams :: [Param] -> RuleParser Exp 45 ruleBlockWithParams params = do 43 46 lvl <- gets ruleBracketLevel 44 47 case lvl of 45 StatementBracket -> rule Block'46 _ -> lexeme ruleVerbatimBlock48 StatementBracket -> ruleStatementBlock 49 _ -> lexeme (ruleVerbatimBlockWithParams params) 47 50 where 48 rule Block'= do49 rv <- ruleVerbatimBlock 51 ruleStatementBlock = do 52 rv <- ruleVerbatimBlockWithParams params 50 53 -- Implementation of 'line-ending } terminates statement' 51 54 -- See L<S04/Statement-ending blocks>. … … 62 65 63 66 ruleVerbatimBlock :: RuleParser Exp 64 ruleVerbatimBlock = verbatimRule "block" $ do 65 body <- verbatimBraces ruleBlockBody 67 ruleVerbatimBlock = ruleVerbatimBlockWithParams [] 68 69 ruleVerbatimBlockWithParams :: [Param] -> RuleParser Exp 70 ruleVerbatimBlockWithParams params = verbatimRule "block" $ do 71 body <- verbatimBraces (ruleBlockBodyWithParams params) 66 72 return $ Syn "block" [body] 67 73 … … 72 78 73 79 ruleBlockBody :: RuleParser Exp 74 ruleBlockBody = 75 localEnv $ do 80 ruleBlockBody = ruleBlockBodyWithParams [] 81 82 ruleBlockBodyWithParams :: [Param] -> RuleParser Exp 83 ruleBlockBodyWithParams params = localEnv $ do 84 unless (null params) $ do 85 lexDiff <- unsafeEvalLexDiff $ 86 combine [Sym SParam (paramName p) | p <- params ] emptyExp 87 addBlockPad SParam lexDiff 76 88 whiteSpace 77 89 pre <- many ruleEmptyExp … … 120 132 sepLoop rule = do 121 133 whiteSpace 122 (eof >> return Noop) <|> do134 (eof >> return emptyExp) <|> do 123 135 (exp, terminate) <- rule 124 136 if terminate then return exp else do 125 rest <- option Noop (sepLoop rule)137 rest <- option emptyExp (sepLoop rule) 126 138 return $ exp `mergeStmts` rest 127 139 … … 130 142 ruleBlockDeclaration :: RuleParser Exp 131 143 ruleBlockDeclaration = rule "block declaration" $ choice 132 [ ruleSubDeclaration 133 , ruleClosureTrait False 144 [ ruleClosureTrait False 134 145 , ruleRuleDeclaration 135 146 , rulePackageBlockDeclaration … … 281 292 282 293 -- bodyPos <- getPosition 283 body <- ruleBlock 294 body <- ruleBlockWithParams (maybe [] id formal) 284 295 let (fun, names, params) = doExtract styp formal body 285 296 -- Check for placeholder vs formal parameters … … 314 325 mkExp n = Syn ":=" [Var n, Syn "sub" [Val sub]] 315 326 mkSym n = Sym scope (mkMulti n) (mkExp n) 327 mkSymGlobal globalName lexicalName = Stmts 328 (Sym SMy (mkMulti lexicalName) (mkExp lexicalName)) 329 (Sym SGlobal (mkMulti globalName) (Syn ":=" [Var globalName, Var lexicalName])) 316 330 -- Horrible hack! Sym "&&" is the multi form. 317 331 mkMulti | isMulti = ('&':) … … 320 334 isBuiltin = ("builtin" `elem` traits) 321 335 isExported = ("export" `elem` traits) 336 isScopeGlobal = case scope of 337 SGlobal -> True 338 SOur -> True 339 _ -> False 340 expMakeSym 341 | isScopeGlobal = mkSymGlobal nameQualified name 342 | otherwise = mkSym nameQualified 343 expImmediate 344 | isExported = Stmts expMakeSym $ 345 (App (Var "&push") 346 (Just (Syn "{}" [Var ("%" ++ pkg ++ "::EXPORTS"), Val $ VStr name])) 347 [Var name]) 348 | otherwise = expMakeSym 322 349 323 350 -- XXX this belongs in semantic analysis, not in the parser … … 334 361 -- Don't add the sub if it's unsafe and we're in safemode. 335 362 if "unsafe" `elem` traits && safeMode then return emptyExp else do 336 rv <- case scope of 337 SGlobal | isExported -> do 338 -- we mustn't perform the export immediately upon parse, because 339 -- then only the first consumer of a module will see it. Instead, 340 -- make a note of this symbol being exportable, and defer the 341 -- actual symbol table manipulation to opEval. 342 unsafeEvalExp $ mkSym nameQualified 343 -- push %*INC<This::Package><exports><&this_sub>, expression-binding-&this_sub 344 -- ==> 345 -- push %This::Package::EXPORTS<&this_sub>, expression-binding-&this_sub 346 -- (a singleton list for subs, a full list of subs for multis) 347 return $ 348 App (Var "&push") 349 (Just (Syn "{}" [Var ("%" ++ pkg ++ "::EXPORTS"), Val $ VStr name])) 350 [Val sub] 351 SGlobal -> do 352 unsafeEvalExp $ mkSym nameQualified 353 return emptyExp 354 _ -> do 355 lexDiff <- unsafeEvalLexDiff $ mkSym nameQualified 356 addBlockPad scope lexDiff 357 return $ mkExp name 363 lexDiff <- unsafeEvalLexDiff expImmediate 364 addBlockPad SMy lexDiff 358 365 clearDynParsers 359 return rv 360 366 return (Var name) 361 367 362 368 ruleSubNamePossiblyWithTwigil :: RuleParser String … … 421 427 let sigil' = (if isOptional then '?' else '!'):sigil1 422 428 exp <- case opt of 423 FormalsSimple -> return Noop429 FormalsSimple -> return emptyExp 424 430 FormalsComplex -> do 425 431 rv <- ruleParamDefault (not isOptional) … … 427 433 symbol "-->" 428 434 ruleParamList ParensOptional $ choice 429 [ ruleType 430 , ruleFormalParam FormalsComplex >> return ""435 [ ruleType >> return () 436 , ruleFormalParam FormalsComplex >> return () 431 437 ] 432 438 return rv … … 439 445 440 446 ruleParamDefault :: Bool -> RuleParser Exp 441 ruleParamDefault True = return Noop442 ruleParamDefault False = rule "default value" $ option Noop $ do447 ruleParamDefault True = return emptyExp 448 ruleParamDefault False = rule "default value" $ option emptyExp $ do 443 449 symbol "=" 444 450 parseExpWithItemOps … … 911 917 (Just (Var end)) 912 918 [Val code] 913 return Noop919 return emptyExp 914 920 "BEGIN" -> do 915 921 -- We've to exit if the user has written code like BEGIN { exit }. … … 917 923 -- And install any pragmas they've requested. 918 924 env <- ask 919 let idat = inlinePerformSTM . readTVar $ envInitDat env925 let idat = unsafePerformSTM . readTVar $ envInitDat env 920 926 install $ initPragmas idat 921 927 clearDynParsers … … 960 966 ] 961 967 -- ...and then exit. 962 return $ inlinePerformIO $ exitWith exit968 return $ unsafePerformIO $ exitWith exit 963 969 possiblyExit x = return x 964 970 … … 1176 1182 (typ, formal, lvalue) <- option (SubBlock, Nothing, False) 1177 1183 $ choice variants 1178 body <- ruleBlock1184 body <- ruleBlockWithParams (maybe [] id formal) 1179 1185 retBlock typ formal lvalue body 1180 1186 … … 1279 1285 return exp 1280 1286 where 1281 deSigil (sig:'!':rest ) = (sig:rest)1287 deSigil (sig:'!':rest@(_:_)) = (sig:rest) 1282 1288 deSigil (sig:'.':rest) = (sig:rest) 1283 1289 deSigil x = x … … 1296 1302 parseTerm = rule "term" $ do 1297 1303 term <- choice 1298 [ ruleDereference 1304 [ ruleSubDeclaration 1305 , ruleDereference 1299 1306 , ruleVarDecl 1300 1307 , ruleVar … … 1652 1659 then ruleSubNamePossiblyWithTwigil 1653 1660 else do twigil <- ruleTwigil 1654 name <- many1 wordAny 1661 name <- case twigil of 1662 "" -> many1 wordAny <|> string "/" 1663 "!" -> many wordAny 1664 _ -> many1 wordAny 1655 1665 return $ sigil ++ twigil ++ name 1656 1666 … … 1682 1692 1683 1693 ruleSigiledVar :: RuleParser Exp 1684 ruleSigiledVar = (<|> ruleSymbolicDeref) . try$ do1694 ruleSigiledVar = (<|> ruleSymbolicDeref) $ do 1685 1695 name <- ruleVarNameString 1686 let (sigil, rest) = break isWordAnyname1696 let (sigil, rest) = span (`elem` "$@%&:^") name 1687 1697 case rest of 1688 1698 [] -> return (makeVar name) 1689 1699 _ | any (not . isWordAny) rest -> return (makeVar name) 1700 _ | all isDigit rest -> return (makeVar name) 1701 "_" -> return (makeVar name) 1690 1702 _ -> do 1691 1703 -- Plain and simple variable -- do a lexical check … … 1698 1710 -- If it's visible in the total lexical scope, yet not 1699 1711 -- defined in the current scope, then generate OUTER. 1700 if lexVisible && not curVisible && not inTopLevel 1701 then return (Var $ sigil ++ "OUTER::" ++ rest) 1702 else return (makeVar name) 1712 case (lexVisible, curVisible) of 1713 (True, False) | not inTopLevel 1714 -> return (Var $ sigil ++ "OUTER::" ++ rest) 1715 (False, False) 1716 -> unexpected $ 1717 "global symbol \"" ++ name 1718 ++ "\" requires explicit package name" 1719 _ -> return (makeVar name) 1703 1720 1704 1721 ruleVar :: RuleParser Exp -
src/Pugs/Parser/Export.hs
r10634 r10645 29 29 doExport scope mkSym 30 30 case scope of 31 SMy -> addBlockPad SState 31 SMy -> addBlockPad SState 32 32 (foldl unionPads (mkPad []) [ pad | Pad SMy pad _ <- exps ]) 33 33 _ -> return ()
