fjsc: add callcc0 and continue
parent
f25f82cc97
commit
070d38c850
|
@ -22,6 +22,12 @@ Stack.prototype.pop = function(world,next) {
|
||||||
next(world);
|
next(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stack.prototype.clone = function() {
|
||||||
|
var stack = new Stack();
|
||||||
|
stack.stack = this.stack.slice(0);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
function Factor() {
|
function Factor() {
|
||||||
this.words = { };
|
this.words = { };
|
||||||
this.data_stack = new Stack();
|
this.data_stack = new Stack();
|
||||||
|
@ -165,6 +171,31 @@ factor.words["run-file"] = new Word("run-file", "primitive", function(world, nex
|
||||||
YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
|
YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
factor.words["callcc0"] = new Word("callcc0", "primitive", function(world, next) {
|
||||||
|
var stack = world.data_stack;
|
||||||
|
var quot = stack.stack.pop();
|
||||||
|
var new_stack = stack.clone();
|
||||||
|
var old_next = world.next;
|
||||||
|
var cont = {
|
||||||
|
world: world,
|
||||||
|
next: function(world) {
|
||||||
|
world.next = old_next;
|
||||||
|
next(world);
|
||||||
|
},
|
||||||
|
stack: stack
|
||||||
|
};
|
||||||
|
new_stack.stack.push(cont);
|
||||||
|
world.data_stack = new_stack;
|
||||||
|
quot.execute(world, next);
|
||||||
|
});
|
||||||
|
|
||||||
|
factor.words["continue"] = new Word("continue", "primitive", function(world, next) {
|
||||||
|
var stack = world.data_stack;
|
||||||
|
var cont = stack.stack.pop();
|
||||||
|
world.data_stack = cont.stack.clone();
|
||||||
|
(cont.next)(world);
|
||||||
|
});
|
||||||
|
|
||||||
Factor.prototype.define_word = function(name, source, func, world, next) {
|
Factor.prototype.define_word = function(name, source, func, world, next) {
|
||||||
factor.words[name] = new Word(name, source, function(world, next) {
|
factor.words[name] = new Word(name, source, function(world, next) {
|
||||||
var old = world.next;
|
var old = world.next;
|
||||||
|
|
Loading…
Reference in New Issue