diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-22 22:23:35 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-22 22:24:29 +1300 |
| commit | bad32a12573bf14968746ea9ad0f6c4f20b50cf1 (patch) | |
| tree | 26ce098f30f054b2f2a742d2c06b857951ea68db /DSL | |
| parent | 0bde837174fcb9c17cb3adbf6bc3c7407cab10df (diff) | |
Re-work program structure, MAIN entrypoint + only PROC definitions
Diffstat (limited to 'DSL')
| -rw-r--r-- | DSL/Interpretation.hs | 11 | ||||
| -rw-r--r-- | DSL/Parsing.hs | 14 | ||||
| -rw-r--r-- | DSL/Types.hs | 2 |
3 files changed, 11 insertions, 16 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' } diff --git a/DSL/Parsing.hs b/DSL/Parsing.hs index 72d6b23..d4d1253 100644 --- a/DSL/Parsing.hs +++ b/DSL/Parsing.hs @@ -191,16 +191,8 @@ blockP = firstOf [ whileP , linearP ] -programP :: DSLParser ([ProcSpec], Program) -programP = phrase $ procs `plus` code +stringToProgram :: String -> Maybe ProcTable +stringToProgram = (>>=buildProcTable . snd) . parse (tokenizer `chain` program) where - procs = mult procP - code = mult1 blockP - -stringToProgram :: String -> Maybe (ProcTable, Program) -stringToProgram = (>>=(f . snd)) . parse (tokenizer `chain` programP) - where - f (ps, b) = case buildProcTable ps of - Nothing -> Nothing - Just t -> Just (t, b) + program = phrase $ mult procP diff --git a/DSL/Types.hs b/DSL/Types.hs index 7467bfd..aa1fb22 100644 --- a/DSL/Types.hs +++ b/DSL/Types.hs @@ -69,8 +69,6 @@ type ProcSpec = (ProcName, [Block]) type ProcTable = Map ProcName [Block] -type Program = [Block] - data Machine = Machine { ok :: Bool , stack :: Stack , pTable :: ProcTable |
