aboutsummaryrefslogtreecommitdiff
path: root/snug-clean/src/snug.icl
diff options
context:
space:
mode:
authorCamil Staps2023-01-27 21:14:39 +0100
committerCamil Staps2023-01-27 21:15:57 +0100
commitbda2ff9eea470e7eb6dc573849dfc6abe8365069 (patch)
tree1fa299d5be537c6dc33a4d9289d9358723cd5490 /snug-clean/src/snug.icl
parentAdd Clean parser for snug (diff)
Add compilation of constructors and basic values
Diffstat (limited to 'snug-clean/src/snug.icl')
-rw-r--r--snug-clean/src/snug.icl25
1 files changed, 23 insertions, 2 deletions
diff --git a/snug-clean/src/snug.icl b/snug-clean/src/snug.icl
index 1cdfcf6..23d24d0 100644
--- a/snug-clean/src/snug.icl
+++ b/snug-clean/src/snug.icl
@@ -3,20 +3,41 @@ module snug
import StdEnv
import StdMaybe
+import Data.Error
+import Data.List
import System.CommandLine
+import System.File
+import System.FilePath
+import Text
+import MIPS.MIPS32
+import Snug.Compile
import Snug.Parse
+/* Note: after compiling with
+ * snug program.snug
+ * an assembly file program.s is generated, which can be run with SPIM using
+ * spim -delayed_branches <(cat driver.s program.s)
+ */
+
Start w
# ([prog:args],w) = getCommandLine w
| length args <> 1 = abort ("Usage: " +++ prog +++ " INPUT\n")
# input = hd args
+ output = dropExtension input +++ ".s"
# (mbInput,w) = readFile input w
input = fromJust mbInput
| isNone mbInput = abort "Failed to read input\n"
- | otherwise = parseSnug input
+ # mbDefs = parseSnug input
+ defs = fromOk mbDefs
+ | isError mbDefs = abort ("Failed to parse: " +++ fromError mbDefs +++ "\n")
+ # assembly = compile "main" defs
+ # assembly = join "\n" (map toString assembly)
+ # (mbErr,w) = writeFile output assembly w
+ | isError mbErr = abort ("Failed to write output: " +++ toString (fromError mbErr) +++ "\n")
+ | otherwise = w
-readFile :: !String !*World -> (!?[Char], !*World)
+readFile :: !FilePath !*World -> (!?[Char], !*World)
readFile path w
# (ok,f,w) = fopen path FReadData w
| not ok = (?None, w)