summaryrefslogtreecommitdiff
path: root/DSL/Interpretation.hs
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-02-22 22:23:35 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-02-22 22:24:29 +1300
commitbad32a12573bf14968746ea9ad0f6c4f20b50cf1 (patch)
tree26ce098f30f054b2f2a742d2c06b857951ea68db /DSL/Interpretation.hs
parent0bde837174fcb9c17cb3adbf6bc3c7407cab10df (diff)
Re-work program structure, MAIN entrypoint + only PROC definitions
Diffstat (limited to 'DSL/Interpretation.hs')
-rw-r--r--DSL/Interpretation.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/DSL/Interpretation.hs b/DSL/Interpretation.hs
index 37165c3..d9c53bd 100644
--- a/DSL/Interpretation.hs
+++ b/DSL/Interpretation.hs
@@ -8,6 +8,9 @@ import DSL.Util
import DSL.Intrinsics
import DSL.StdLib (stdlib)
+entrypoint :: ProcName
+entrypoint = "MAIN"
+
newMachine :: Machine
newMachine = Machine { ok=True, stack=[], pTable=M.empty }
@@ -93,8 +96,10 @@ 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 :: (ProcTable, Program) -> IO ()
-interpret (t, p) = case mergeProcTables stdlib t of
- Just t' -> () <$ evalBlocks p newMachine{ pTable=t' }
+interpret :: ProcTable -> IO ()
+interpret t = case mergeProcTables stdlib t of
Nothing -> putStrLn "Failed to include stdlib, duplicate proc definition?"
+ Just t' -> case M.lookup entrypoint t' of
+ Nothing -> putStrLn "No MAIN proc defined, aborting."
+ Just b -> () <$ evalBlocks b newMachine{ pTable=t' }