summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2017-07-30 01:07:10 -0700
committerMatthew Sotoudeh <matthewsot@outlook.com>2017-07-30 01:07:10 -0700
commit4c3c7de3e8b2375dd90a0a4b9922b0e4a9cf0c1f (patch)
tree9322e3ea7823ab0d5f07fbc267428c37a7b107b2
parent173c79c5a11126240c3377493ee74386839bb05c (diff)
fixed jumps with callbacks
-rw-r--r--interpreter/interpreter.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/interpreter/interpreter.js b/interpreter/interpreter.js
index fe3daed..a267695 100644
--- a/interpreter/interpreter.js
+++ b/interpreter/interpreter.js
@@ -41,7 +41,7 @@ Yaepl.prototype.globalScope = {
"gt-eq": function (a, b) { return (a >= b); },
"or": function (a, b) { return (a || b); },
"and": function (a, b) { return (a && b); },
- "jump-bwd": function (b) {
+ "jump-bwd": function (b, callback) {
var lines = this.fullText;
var yaepl = this;
function interpretLine(l) {
@@ -49,14 +49,16 @@ Yaepl.prototype.globalScope = {
l++;
if (l < lines.length) {
interpretLine(l);
+ } else {
+ callback();
}
}, false);
}
interpretLine(b.targetIndex);
},
- "jump-bwd-if": function (a, b) {
- if (!a) return;
- this.globalScope["jump-bwd"].call(this, b);
+ "jump-bwd-if": function (a, b, callback) {
+ if (!a) return callback();
+ this.globalScope["jump-bwd"].call(this, b, callback);
},
"jump-fwd": function (l) {
this.flags.jumpingFwd = true;
@@ -66,22 +68,22 @@ Yaepl.prototype.globalScope = {
if (!a) return;
this.globalScope["jump-fwd"].call(this, l);
},
- "jump": function (l) {
+ "jump": function (l, callback) {
var label_target = this.scopes[this.currScopeIndex][l];
if (label_target == undefined) {
this.globalScope["jump-fwd"].call(this, l);
- return;
+ return callback();
}
- this.globalScope["jump-bwd"].call(this, label_target);
+ this.globalScope["jump-bwd"].call(this, label_target, callback);
},
- "jump-if": function (a, l) {
- if (!a) return;
- this.globalScope["jump"].call(this, l);
+ "jump-if": function (a, l, callback) {
+ if (!a) return callback();
+ this.globalScope["jump"].call(this, l, callback);
}
};
//These are the ops that use callbacks
-Yaepl.prototype.callbackOps = [ "prompt" ];
+Yaepl.prototype.callbackOps = [ "prompt", "jump-bwd", "jump-bwd-if", "jump", "jump-if" ];
//Splits a YAEPL parameter string into a list of different
//string YAPEL parameters. Does NOT evaluate them - they're
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback