|
@ -26,21 +26,16 @@ var testenv = env.makeEnv("toplevel", |
|
|
["b", 3]]); |
|
|
["b", 3]]); |
|
|
|
|
|
|
|
|
function lookup(ident, env) { |
|
|
function lookup(ident, env) { |
|
|
console.log(`trying to look up ${ident}`); |
|
|
|
|
|
var value = env.bindings[ident]; |
|
|
var value = env.bindings[ident]; |
|
|
console.log(env); |
|
|
|
|
|
console.log(value); |
|
|
|
|
|
if (value.exprType !== undefined) { |
|
|
if (value.exprType !== undefined) { |
|
|
console.log("evaluting further"); |
|
|
var result = evaluate(value, env); |
|
|
return evaluate(value, env); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
console.log("returning it without evaluting"); |
|
|
|
|
|
return value; |
|
|
return value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function evaluateString(input) { |
|
|
function evaluateString(input) { |
|
|
var ast = parse.parseFull(tokenizer.tokenize(input)); |
|
|
var ast = parse.parseFull(tokenizer.tokenize(input)); |
|
|
console.log(ast.ast[ast.ast.length-1]); |
|
|
|
|
|
return evaluateAll(ast.ast, testenv); |
|
|
return evaluateAll(ast.ast, testenv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -69,8 +64,6 @@ function extend(def, env) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function evaluate(ast, environment) { |
|
|
function evaluate(ast, environment) { |
|
|
console.log("here"); |
|
|
|
|
|
console.log(JSON.stringify(ast)); |
|
|
|
|
|
if (ast.exprType == "Application") { |
|
|
if (ast.exprType == "Application") { |
|
|
var func = evaluate(ast.func, environment); |
|
|
var func = evaluate(ast.func, environment); |
|
|
return apply( |
|
|
return apply( |
|
@ -97,9 +90,12 @@ function evaluate(ast, environment) { |
|
|
} |
|
|
} |
|
|
else if (ast.exprType === "Definition") { |
|
|
else if (ast.exprType === "Definition") { |
|
|
extend(ast, environment); |
|
|
extend(ast, environment); |
|
|
return ast; |
|
|
return; |
|
|
} |
|
|
} |
|
|
else if (ast.exprType === "Integer" || ast.exprType === "Float" || ast.exprType === "String") { |
|
|
else if (ast.exprType === "Integer" || |
|
|
|
|
|
ast.exprType === "Float" || |
|
|
|
|
|
ast.exprType === "String") { |
|
|
|
|
|
/* Return an atom */ |
|
|
return ast.val; |
|
|
return ast.val; |
|
|
} |
|
|
} |
|
|
else if (ast.exprType === "Closure") { |
|
|
else if (ast.exprType === "Closure") { |
|
|