Changeset 16416
- Timestamp:
- 05/18/07 00:17:23 (18 months ago)
- Files:
-
- 1 modified
-
src/Pugs/Parser.hs (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Parser.hs
r16392 r16416 389 389 `finallyM` clearDynParsers 390 390 391 -- XXX - Generate init pad for each of our params... 392 391 -- Generate init pad for each of our params, as well as for ourselves... 393 392 paramsPad <- genParamEntries styp signature 394 393 modify $ \s -> s{ s_protoPad = paramsPad } … … 409 408 , subOuterPads = envLexPads env 410 409 , subInnerPad = bi_pad block 410 , subTraitBlocks= bi_traits block (subTraitBlocks template) 411 411 } 412 sub = VCode (bi_traits block template')412 sub = VCode template' 413 413 414 414 -- Don't add the sub if it's unsafe and we're in safemode. … … 436 436 , subParams = multiSig 437 437 } 438 unsafeEvalExp $ Syn " |="438 unsafeEvalExp $ Syn "=" 439 439 [ Syn "{}" [_Var ("%" ++ pkg ++ "::EXPORTS"), Val $ VStr exportedName] 440 440 , Val exportedSub … … 937 937 fail "Closure traits take no formal parameters" 938 938 env <- ask 939 let code = VCodemkSub939 let code = mkSub 940 940 { subName = cast name 941 , subType = Sub Routine -- XXX - This should be SubBlock - See Pugs.Monads.enterSub for "displaced" subs941 , subType = SubBlock 942 942 , subBody = fun 943 , subPackage = envPackage env 943 944 , subInnerPad = (bi_pad block) 944 945 , subOuterPads = (PCompiling (fromJust $ envCompPad env):envLexPads env) … … 1011 1012 possiblyExit x = return x 1012 1013 1013 vcode2 startBlock :: Val -> RuleParser Exp1014 vcode2 startBlock (VCode code)= do1014 vcode2memoized :: VCode -> RuleParser VCode 1015 vcode2memoized code = do 1015 1016 -- Ok. Now the tricky thing. 1016 1017 -- This is the general idea: … … 1029 1030 (_Sym SState "$?START_RUN" mempty emptyExp) $ emptyExp 1030 1031 1031 let code' = code{ subBody = body', subInnerPad = subInnerPad code `mappend` lexDiff } 1032 body' = Syn "if" 1032 let body' = Syn "if" 1033 1033 [ App (_Var "&postfix:++") Nothing [_Var "$?START_RUN"] 1034 1034 , _Var "$?START_RESULT" … … 1036 1036 ] -- { $?START_RUN++; $?START_RESULT = 42 }; 1037 1037 1038 return $ code 1039 { subBody = body' 1040 , subInnerPad = subInnerPad code `mappend` lexDiff 1041 } 1042 1043 vcode2startBlock :: Val -> RuleParser Exp 1044 vcode2startBlock ~(VCode code) = do 1045 code' <- vcode2memoized code 1038 1046 return $ App (Syn "sub" [Val (VCode code')]) Nothing [] 1039 vcode2startBlock _ = fail "impossible"1040 1047 1041 1048 vcode2initBlock :: Val -> RuleParser Exp … … 1047 1054 1048 1055 vcode2checkBlock :: Val -> RuleParser Exp 1049 vcode2checkBlock code = do 1050 body <- vcode2startBlock code 1051 let fstcode = Syn "sub" [ checkForIOLeak mkSub{ subBody = body } ] 1056 vcode2checkBlock ~(VCode code) = do 1057 code' <- vcode2memoized code 1052 1058 Val res <- unsafeEvalExp $ 1053 1059 App (_Var "&unshift") (Just $ _Var "@*CHECK") [ Val (VCode code') ] … … 1287 1293 fail "Cannot mix placeholder variables with formal parameters" 1288 1294 env <- ask 1289 let sub = bi_traits block $mkCode1295 let sub = mkCode 1290 1296 { isMulti = False 1291 1297 , subName = __"<anon>" … … 1326 1332 return $ (SubPointy, params, "rw" `elem` traits) 1327 1333 1334 genNameTypeEntries :: Scope -> [(String, VType, EntryFlags, Exp)] -> RuleParser Pad 1328 1335 genNameTypeEntries scope nameTypes = do 1329 1336 unsafeEvalLexDiff $ combine (map makeBinding nameTypes) emptyExp … … 1338 1345 bindSym = Stmts (Syn "=" [_Var name, Val (VType typ)]) 1339 1346 1347 paramsToNameTypes :: [Param] -> String -> [(String, Type, EntryFlags, Exp)] 1340 1348 paramsToNameTypes params defType = [ (n, t, f, d) | n <- names | t <- types | f <- flags | d <- defs ] 1341 1349 where … … 1349 1357 | otherwise = t 1350 1358 1351 genParamEntries styp params 1352 | styp >= SubBlock = genNameTypeEntries SMy nameTypes 1353 | otherwise = genNameTypeEntries SMy (foldl' withImplicit nameTypes implicitNames) 1359 genParamEntries :: SubType -> Params -> RuleParser Pad 1360 genParamEntries styp params = genNameTypeEntries SMy (foldl' withImplicit nameTypes implicitNames) 1354 1361 where 1355 nameTypes = paramsToNameTypes params "" 1362 params' 1363 | SubMethod <- styp = (defaultSelfParam:params) 1364 | otherwise = params 1365 nameTypes = paramsToNameTypes params' "" 1356 1366 names = Set.fromList $ map (\(n, _, _, _) -> n) nameTypes 1357 implicitNames = ["$_"] -- , "$/", "$!"] 1367 implicitNames = case styp of 1368 SubPrim -> [] 1369 SubPointy -> ["&?BLOCK"] -- , "$/", "$!"] 1370 SubBlock -> ["$_", "&?BLOCK"] -- , "$/", "$!"] 1371 _ -> ["$_", "&?BLOCK", "&?ROUTINE"] -- , "$/", "$!"] 1358 1372 withImplicit ntys name 1359 1373 | Set.member (cast name) names = ntys 1360 1374 | otherwise = (((cast name), anyType, MkEntryFlags True, Noop):ntys) 1375 defaultSelfParam = buildParam "" "" "$__SELF__" (Val VUndef) 1361 1376 1362 1377 ruleVarDecl :: RuleParser Exp … … 2063 2078 _ -> do 2064 2079 -- Plain and simple variable -- do a lexical check 2065 -- Algorithm: Navigate outerward to find the first one defined; 2066 -- record the 2080 -- First check if it's "known". 2081 -- If it is, then simply makeVar. 2082 -- If it is not, then it's "free"; add it to the list of freeVars 2083 -- for the final check. 2084 2067 2085 state <- get 2068 2086
