diff options
author | David Robillard <d@drobilla.net> | 2009-03-06 22:12:36 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-06 22:12:36 +0000 |
commit | ecef8f697c66e15b85beb934d2b617b915a97aab (patch) | |
tree | 576af3f3063f07c08ecbbd1cfdb9d8034cc5bc2b /tuplr.cpp | |
parent | 382d3051052fd20ab55f40beb7664bfb3f0379a1 (diff) | |
download | resp-ecef8f697c66e15b85beb934d2b617b915a97aab.tar.gz resp-ecef8f697c66e15b85beb934d2b617b915a97aab.tar.bz2 resp-ecef8f697c66e15b85beb934d2b617b915a97aab.zip |
Cleanup and de-llvm-ify primitive stuff.
Fix type inference (only treat actual type expressions as type expressions).
git-svn-id: http://svn.drobilla.net/resp/tuplr@64 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.cpp')
-rw-r--r-- | tuplr.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -31,6 +31,7 @@ Funcs ASTConsCall::funcs; std::ostream& err = std::cerr; std::ostream& out = std::cout; + /*************************************************************************** * S-Expression Lexer :: text -> S-Expressions (SExp) * ***************************************************************************/ @@ -93,6 +94,45 @@ readExpression(Cursor& cur, std::istream& in) /*************************************************************************** + * Standard Definitions * + ***************************************************************************/ + +void +initLang(PEnv& penv, TEnv& tenv) +{ + // Literals + static bool trueVal = true; + static bool falseVal = false; + penv.reg(false, "#t", PEnv::Handler(parseLiteral<bool>, &trueVal)); + penv.reg(false, "#f", PEnv::Handler(parseLiteral<bool>, &falseVal)); + + // Special forms + penv.reg(true, "fn", PEnv::Handler(parseFn)); + penv.reg(true, "if", PEnv::Handler(parseCall<ASTIf>)); + penv.reg(true, "def", PEnv::Handler(parseCall<ASTDefinition>)); + penv.reg(true, "cons", PEnv::Handler(parseCall<ASTConsCall>)); + penv.reg(true, "car", PEnv::Handler(parseCall<ASTCarCall>)); + penv.reg(true, "cdr", PEnv::Handler(parseCall<ASTCdrCall>)); + + // Numeric primitives + penv.reg(true, "+", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "-", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "*", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "/", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "%", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "&", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "|", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "^", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "=", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "!=", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, ">", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, ">=", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "<", PEnv::Handler(parseCall<ASTPrimitive>)); + penv.reg(true, "<=", PEnv::Handler(parseCall<ASTPrimitive>)); +} + + +/*************************************************************************** * EVAL/REPL/MAIN * ***************************************************************************/ @@ -115,6 +155,7 @@ main(int argc, char** argv) { PEnv penv; TEnv tenv(penv); + initTypes(penv, tenv); initLang(penv, tenv); CEnv* cenv = newCenv(penv, tenv); @@ -154,7 +195,7 @@ main(int argc, char** argv) is.close(); } - if (files.empty() || args.find("-r") != args.end()) + if (args.find("-r") != args.end() || (files.empty() && args.find("-e") == args.end())) ret = repl(*cenv); a = args.find("-o"); |