diff --git a/environments.js b/environments.js index dedd90c..9331aaa 100644 --- a/environments.js +++ b/environments.js @@ -6,23 +6,6 @@ var errors = require("./errors.js"); var rep = require("./representation.js"); - -/* - * returns the new environment after mutating it - * values = [(identifier, JLambda expression)] - */ -function extend(env, values) { - var new_env = {}; - var env_keys = Object.keys(env); - for (var i = 0; i < env_keys.length; i++) { - new_env[env_keys[i]] = env[env_keys[i]]; - } - for (i = 0; i < values.length; i++) { - new_env[values[i][0].val] = values[i][1]; - } - return new_env; -} - // creates a new environment initialized with the pairs in values function makeEnv(name, values) { var env = {}; @@ -46,6 +29,5 @@ function lookup(name, env) { module.exports = { lookup : lookup, - extend : extend, makeEnv : makeEnv }; diff --git a/parse.js b/parse.js index 9d9bbc8..b389060 100755 --- a/parse.js +++ b/parse.js @@ -29,10 +29,12 @@ function addSrcPos(stx, tokens, linenum, charnum) { return stx; } +/* Gets the first token from the right side of the stack */ function fst(ts) { return ts[ts.length-1]; } +/* Gets the second token from the right side of the stack */ function snd(ts) { return ts[ts.length-2]; } @@ -814,7 +816,10 @@ function parseFull(tokenized) { current = closure.annotate_fvs(desugarer.desugar(parse(tokenized), typeBindings)); ast.push(current); } - return [ast, typeBindings]; + return { + "ast" : ast, + "types" : typeBindings + }; } catch (e) { if (e.stxerror !== undefined) { e.stxerror(); diff --git a/representation.js b/representation.js index 39c3543..fc8f7c5 100644 --- a/representation.js +++ b/representation.js @@ -345,7 +345,7 @@ function DataType(name, params, type) { } -//Applies the function ``name'' to the list of parameters +/* Applies the function ``name'' to the list of parameters */ function makeApp(name, parameters) { if (parameters) { return parameters.slice(1).reduce(function(f, ident) { diff --git a/vm.js b/vm.js index a185cfc..0a1eafb 100755 --- a/vm.js +++ b/vm.js @@ -8,8 +8,6 @@ var env = require("./environments.js"); var fs = require("fs"); var istr = fs.readFileSync('/dev/stdin').toString(); -//var istr = "if true then (+ 6 (a+a*b)) else 1"; -//var istr = "def (f a) (a + b)" var ast = parse.parseFull(tokenizer.tokenize(istr)); function apply(func, p) { @@ -46,6 +44,7 @@ function evaluate(ast, environment) { } } else if (ast.exprType === "Definition") { + console.log("XXX"); console.log(ast); } else { @@ -59,8 +58,9 @@ var testenv = env.makeEnv("toplevel", ["a", 2], ["b", 3]]); -var all = evaluate(ast[0][ast[0].length - 1], testenv); -console.log(all); +console.log(ast.types); +//var all = evaluate(ast, testenv); +//console.log(all); //console.log("%j", testenv); //console.log("%j", ast[0][ast[0].length - 1]); //console.log("%j", ast[0][ast[0].length - 1]);