diff options
Diffstat (limited to 'DSL/Interpretation.hs')
| -rw-r--r-- | DSL/Interpretation.hs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/DSL/Interpretation.hs b/DSL/Interpretation.hs index e68b64f..37165c3 100644 --- a/DSL/Interpretation.hs +++ b/DSL/Interpretation.hs @@ -1,5 +1,6 @@ module DSL.Interpretation where +import qualified Data.Map.Strict as M import Data.Foldable (foldlM) import DSL.Types @@ -8,7 +9,7 @@ import DSL.Intrinsics import DSL.StdLib (stdlib) newMachine :: Machine -newMachine = Machine { ok=True, stack=[], pTable=[] } +newMachine = Machine { ok=True, stack=[], pTable=M.empty } pushData :: Machine -> StackData -> Machine pushData m@Machine{ stack=xs } x = m{ stack=x:xs } @@ -47,7 +48,7 @@ applyIntrinsic i m = do applyCall :: ProcName -> Machine -> IO Machine applyCall _ m@Machine{ ok=False } = return m -applyCall name m@Machine{ pTable=t } = case lookup name t of +applyCall name m@Machine{ pTable=t } = case M.lookup name t of Nothing -> hcf m $ "PROCCALL: undefined proc: " ++ name Just bs -> evalBlocks bs m @@ -92,6 +93,8 @@ evalBlocks (BLinear b:bs) m = applyLinear m b >>= evalBlocks bs evalBlocks (BIf c t f:bs) m = applyIf c t f m >>= evalBlocks bs evalBlocks (BWhile c b:bs) m = applyWhile c b m >>= evalBlocks bs -interpret :: ([ProcSpec], Program) -> IO () -interpret (t, p) = evalBlocks p newMachine{ pTable=stdlib++t } >> return () +interpret :: (ProcTable, Program) -> IO () +interpret (t, p) = case mergeProcTables stdlib t of + Just t' -> () <$ evalBlocks p newMachine{ pTable=t' } + Nothing -> putStrLn "Failed to include stdlib, duplicate proc definition?" |
