X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=spl.icl;h=0f1c07a7ee9845ad9a1f3c452c2b152c47e7e0d3;hb=e33962666f8af6a34432d57180eb322f4543eb78;hp=b5738ee23d7ed3465334febe3cc1cc8b275ccb8e;hpb=29d164f53e029e8133e05b599241eb6c14d7fe47;p=cc1516.git diff --git a/spl.icl b/spl.icl index b5738ee..0f1c07a 100644 --- a/spl.icl +++ b/spl.icl @@ -34,6 +34,22 @@ 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])] []]] + , + FunDecl zero "1printbool" ["x"] Nothing [] [ + IfStmt (VarExpr zero (VarDef "x" [])) + [FunStmt "1printstr" [makeStrExpr zero $ fromString "True"] []] + [FunStmt "1printstr" [makeStrExpr zero $ fromString "False"] []] + ]] + Start :: *World -> *World Start w # (args, w) = parseArgs w @@ -70,7 +86,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