Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: a3531d86ee
...
compare: 1834e706e9
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 17 additions and 25 deletions.
  1. +17 −25 src/interpreter.js
View
42 src/interpreter.js
@@ -53,22 +53,16 @@
var value = assignmentValue(valueNode);
var env = assign(env, assignee, value);
- return nreturn(env.ctx);
+ return rmRet(env);
})
.when("type_assignment", function(ast, env) {
var node = Isla.Parser.extract(ast, "type_assignment");
var assignee = node[0];
var typeIdentifier = interpretAst(node[2], env);
-
- var typeFn = env.ctx._types[typeIdentifier];
- if(typeFn === undefined) {
- typeFn = env.ctx._types.generic;
- }
-
- var value = instantiateType(typeFn, typeIdentifier);
+ var value = instantiateType(typeIdentifier, env.ctx);
var env = assign(env, assignee, value);
- return nreturn(env.ctx);
+ return rmRet(env);
})
.when("list_assignment", function(ast, env) {
@@ -85,7 +79,7 @@
list[operation](item);
var env = assign(env, assignee, currentListEval.val);
- return nreturn(env.ctx);
+ return rmRet(env);
})
.when("invocation", function(ast, env) {
@@ -95,8 +89,8 @@
var param = resolve(interpretAst(Isla.Parser.extract(ast,
"invocation", 1),
env).val, env);
- var returnVal = fn(env, param);
- return nreturn(env.ctx, returnVal);
+ env.ret = fn(env, param);
+ return env;
})
.when("value", function(ast, env) {
@@ -286,26 +280,24 @@
}
}
- var instantiateType = function(typeFn, identifier) {
- var value = typeFn();
- value._meta = { type: identifier };
- return value;
- }
-
var rmRet = function(env) {
env.ret = null;
return env;
}
- var nreturn = function(ctx, ret) {
- if(ret === undefined) {
- return { ctx: ctx, ret: null };
+ // makes a new Isla object of the passed type
+ var instantiateType = function(type, ctx) {
+ var typeFn = ctx._types[type];
+ if(typeFn === undefined) {
+ typeFn = ctx._types.generic;
}
- else {
- return { ctx: ctx, ret: ret };
- }
- }
+ var obj = typeFn();
+ obj._meta = { type:type };
+ return obj;
+ };
+
+ exports.Interpreter.instantiateType = instantiateType;
exports.Interpreter.resolve = resolve;
exports.Interpreter.evaluateValue = evaluateValue;
exports.Interpreter.interpretAst = interpretAst;

No commit comments for this range

Something went wrong with that request. Please try again.