diff options
Diffstat (limited to 'DSL/Interpretation.hs')
| -rw-r--r-- | DSL/Interpretation.hs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/DSL/Interpretation.hs b/DSL/Interpretation.hs index a53be8b..e02bc74 100644 --- a/DSL/Interpretation.hs +++ b/DSL/Interpretation.hs @@ -7,7 +7,7 @@ import DSL.Util import DSL.Intrinsics newMachine :: Machine -newMachine = Machine { ok=True, stack=[] } +newMachine = Machine { ok=True, stack=[], pTable=[] } pushData :: Machine -> StackData -> Machine pushData m@Machine{ stack=xs } x = m{ stack=x:xs } @@ -43,11 +43,18 @@ applyIntrinsic i m = do I_LESSTHAN -> lessThan I_GREATERTHAN -> greaterThan +applyCall :: ProcName -> Machine -> IO Machine +applyCall _ m@Machine{ ok=False } = return m +applyCall name m@Machine{ pTable=t } = case lookup name t of + Nothing -> hcf m $ "PROCCALL: undefined proc: " ++ name + Just bs -> evalBlocks bs m + applyOperation :: Machine -> Operation -> IO Machine -- take no action if a previous step failed applyOperation m@Machine{ ok=False } _ = return m applyOperation m (OpPushData x) = return $ pushData m x applyOperation m (OpIntrinsic i) = applyIntrinsic i m +applyOperation m (OpCall name) = applyCall name m applyLinear :: Machine -> [Operation] -> IO Machine applyLinear = foldlM applyOperation @@ -95,6 +102,6 @@ evalBlocks (BIf c b:bs) m = applyIf c b m >>= evalBlocks bs evalBlocks (BIfElse c b1 b2:bs) m = applyIfElse c b1 b2 m >>= evalBlocks bs evalBlocks (BWhile c b:bs) m = applyWhile c b m >>= evalBlocks bs -interpret :: Program -> IO () -interpret p = evalBlocks p newMachine >> return () +interpret :: ([ProcSpec], Program) -> IO () +interpret (t, p) = evalBlocks p newMachine{ pTable=t } >> return () |
