Changeset 16415
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/AST.hs
r16383 r16415 375 375 { isMulti = True 376 376 , subName = cast name 377 , subLexPads = [] 377 , subOuterPads = [] 378 , subInnerPad = emptyPad 379 -- , subLexical = emptyPad 380 , subStarted = Nothing 378 381 , subPackage = emptyPkg 379 382 , subType = SubMacro -
src/Pugs/Eval.hs
r16383 r16415 415 415 reduceSyn "" [Syn "block" [Val (VCode code)]] = do 416 416 -- Reclose all global pads! 417 glob <- asks envGlobal417 glob <- asks envGlobal 418 418 stm $ do 419 419 pad <- readMPad glob … … 1359 1359 _ -> return [] 1360 1360 -} 1361 let withInv | styp <= SubMethod = (ApplyArg (cast " &self") (argValue arg) False:)1361 let withInv | styp <= SubMethod = (ApplyArg (cast "$__SELF__") (argValue arg) False:) 1362 1362 | otherwise = id 1363 1363 sequence_ [ bindVar var val … … 1370 1370 bindVar :: Var -> Val -> Eval () 1371 1371 bindVar var val 1372 | isLexicalVar var = doBindVar (asks envLexical) 1373 | otherwise = doBindVar askGlobal 1372 | isLexicalVar var = do 1373 -- warn "Binding lexical" var 1374 doBindVar (asks envLexical) 1375 | otherwise = do 1376 -- warn "Binding global" var 1377 doBindVar askGlobal 1374 1378 where 1375 1379 doBindVar askPad = do … … 1378 1382 Just PEConstant{} -> fail $ "Cannot rebind constant: " ++ show var 1379 1383 Just c -> do 1384 -- warn "Binding lexical on" (var, c) 1380 1385 ref <- fromVal val 1381 1386 stm $ writeTVar (pe_store c) ref … … 1420 1425 -> [Exp] -- ^ List of arguments (not including explicit invocant) 1421 1426 -> Eval Val 1422 doApply appKind sub@MkCode{ subCont = cont, subBody = fun, subType = typ } invs args = do1427 doApply appKind origSub@MkCode{ subCont = cont, subBody = fun, subType = typ } invs args = do 1423 1428 realInvs <- fmapM reduceNamedArg invs 1424 1429 realArgs <- mapM reduceNamedArg args … … 1435 1440 bound <- mapM doBind (subBindings sub) 1436 1441 -- trace (show bound) $ return () 1437 val <- local fixEnv $ do1442 val <- localEnv $ do 1438 1443 (`juncApply` bound) $ \realBound -> do 1439 enterSub appKind sub $ case cont of 1440 Just tvar -> do 1441 thunk <- stm $ readTVar tvar 1442 applyThunk (subType sub) realBound thunk 1443 Nothing -> applyExp (subType sub) realBound fun 1444 enterSub appKind sub $ do 1445 lex <- asks envLexical 1446 recRef <- fromVal (VCode origSub) 1447 let tryRecBind var 1448 | Just{} <- lookupPad var (subInnerPad sub) 1449 , Just c <- lookupPad var lex 1450 = writePadEntry c recRef 1451 | otherwise = return () 1452 tryRecBind (cast "&?BLOCK") 1453 tryRecBind (cast "&?ROUTINE") 1454 case cont of 1455 Just tvar -> do 1456 thunk <- stm $ readTVar tvar 1457 applyThunk (subType sub) realBound thunk 1458 Nothing -> applyExp (subType sub) realBound fun 1444 1459 case typ of 1445 1460 SubMacro -> applyMacroResult val … … 1461 1476 applyMacroResult VUndef = retEmpty 1462 1477 applyMacroResult _ = fail "Macro did not return an AST, a Str or a Code!" 1478 localEnv = case appKind of 1479 AKDisplaced -> enterCaller 1480 _ -> id 1463 1481 fixSub sub env = env 1464 1482 { envPackage = subPackage sub 1465 1483 , envLexPads = subOuterPads sub 1466 1484 } 1467 fixEnv :: Env -> Env1468 fixEnv | typ >= SubBlock = id1469 | otherwise = envEnterCaller1470 1485 doBind :: (Param, Exp) -> Eval ApplyArg -- ([PadMutator], [ApplyArg]) 1471 1486 doBind (prm, exp) = do … … 1474 1489 (val, coll) <- enterContext cxt $ case exp of 1475 1490 Syn "param-default" [exp, Val (VCode sub)] -> do 1476 local (fixEnv .fixSub sub) $ expToVal prm exp1491 localEnv . local (fixSub sub) $ expToVal prm exp 1477 1492 _ -> expToVal prm exp 1478 1493 -- traceM ("==> " ++ (show val))
