fjsc: add callcc0 and continue

chris.double 2006-12-16 14:24:39 +00:00
parent f25f82cc97
commit 070d38c850
1 changed files with 31 additions and 0 deletions

View File

@ -22,6 +22,12 @@ Stack.prototype.pop = function(world,next) {
next(world);
}
Stack.prototype.clone = function() {
var stack = new Stack();
stack.stack = this.stack.slice(0);
return stack;
}
function Factor() {
this.words = { };
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);
});
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.words[name] = new Word(name, source, function(world, next) {
var old = world.next;