Merge branch 'master' of https://github.com/dopefishh/cc1516
[cc1516.git] / spl.icl
diff --git a/spl.icl b/spl.icl
index b5738ee..383b84e 100644 (file)
--- a/spl.icl
+++ b/spl.icl
@@ -34,6 +34,16 @@ from yard import :: Error, instance toString Error
 
 derive gPrint TokenValue
 
+preamble :: AST -> AST
+preamble (AST fd) = AST (pre ++ fd)
+       where
+               pre = [
+                       FunDecl zero "1printstr" ["x"] Nothing [] [
+                               IfStmt (FunExpr zero "isEmpty" [VarExpr zero (VarDef "x" [])] [])
+                                       []
+                                       [FunStmt "1printchar" [VarExpr zero (VarDef "x" [FieldHd])] []
+                                       ,FunStmt "1printstr" [VarExpr zero (VarDef "x" [FieldTl])] []]]]
+
 Start :: *World -> *World
 Start w
 # (args, w) = parseArgs w
@@ -70,7 +80,7 @@ Start w
                        (Right parseOut)
                        # stdin = if (not args.parse) stdin (
                                stdin <<<  "//PARSER\n" <<< toString parseOut <<< "//PARSER\n")
-                       = case sem parseOut of
+                       = case sem (preamble parseOut) of
                                (Left e) = snd $ fclose (stdin <<< join "\n" (map toString e) <<< "\n") w
                                (Right ast)
                                # stdin = if (not args.sem) stdin (stdin