1 readline = require "./node_readline.coffee"
2 types = require "./types.coffee"
3 reader = require "./reader.coffee"
4 printer = require "./printer.coffee"
5 Env = require("./env.coffee").Env
8 READ = (str) -> reader.read_str str
11 eval_ast = (ast, env) ->
12 if types._symbol_Q(ast) then env.get ast
13 else if types._list_Q(ast) then ast.map((a) -> EVAL(a, env))
14 else if types._vector_Q(ast)
15 types._vector(ast.map((a) -> EVAL(a, env))...)
16 else if types._hash_map_Q(ast)
18 new_hm[k] = EVAL(ast[k],env) for k,v of ast
23 #console.log "EVAL:", printer._pr_str ast
24 if !types._list_Q ast then return eval_ast ast, env
25 if ast.length == 0 then return ast
28 [a0, a1, a2, a3] = ast
31 env.set(a1, EVAL(a2, env))
33 let_env = new Env(env)
34 for k,i in a1 when i %% 2 == 0
35 let_env.set(a1[i], EVAL(a1[i+1], let_env))
38 [f, args...] = eval_ast ast, env
43 PRINT = (exp) -> printer._pr_str exp, true
47 rep = (str) -> PRINT(EVAL(READ(str), repl_env))
49 repl_env.set types._symbol("+"), (a,b) -> a+b
50 repl_env.set types._symbol("-"), (a,b) -> a-b
51 repl_env.set types._symbol("*"), (a,b) -> a*b
52 repl_env.set types._symbol("/"), (a,b) -> a/b
55 while (line = readline.readline("user> ")) != null
56 continue if line == ""
60 continue if exc instanceof reader.BlankException
61 if exc.stack? and exc.stack.length > 2000
62 console.log exc.stack.slice(0,1000) + "\n ..." + exc.stack.slice(-1000)
63 else if exc.stack? then console.log exc.stack