fjsc: remove 'world' parameter
parent
81820c1bca
commit
0350a00acc
|
@ -4,8 +4,8 @@ function Word(name, source, func) {
|
||||||
this.func = func;
|
this.func = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
Word.prototype.execute = function(world, next) {
|
Word.prototype.execute = function(next) {
|
||||||
this.func(world,next);
|
this.func(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Continuation() {
|
function Continuation() {
|
||||||
|
@ -29,188 +29,187 @@ function Factor() {
|
||||||
|
|
||||||
var factor = new Factor();
|
var factor = new Factor();
|
||||||
|
|
||||||
factor.words["dup"] = new Word("dup", "primitive", function(world, next) {
|
factor.words["dup"] = new Word("dup", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack[stack.length] = stack[stack.length-1];
|
stack[stack.length] = stack[stack.length-1];
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["drop"] = new Word("drop", "primitive", function(world, next) {
|
factor.words["drop"] = new Word("drop", "primitive", function(next) {
|
||||||
world.cont.data_stack.pop();
|
factor.cont.data_stack.pop();
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["nip"] = new Word("nip", "primitive", function(world, next) {
|
factor.words["nip"] = new Word("nip", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack[stack.length-2] = stack[stack.length-1];
|
stack[stack.length-2] = stack[stack.length-1];
|
||||||
stack.pop();
|
stack.pop();
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["over"] = new Word("over", "primitive", function(world, next) {
|
factor.words["over"] = new Word("over", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack[stack.length] = stack[stack.length-2];
|
stack[stack.length] = stack[stack.length-2];
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["swap"] = new Word("swap", "primitive", function(world, next) {
|
factor.words["swap"] = new Word("swap", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var temp = stack[stack.length-2];
|
var temp = stack[stack.length-2];
|
||||||
stack[stack.length-2] = stack[stack.length-1];
|
stack[stack.length-2] = stack[stack.length-1];
|
||||||
stack[stack.length-1] = temp;
|
stack[stack.length-1] = temp;
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words[">r"] = new Word(">r", "primitive", function(world, next) {
|
factor.words[">r"] = new Word(">r", "primitive", function(next) {
|
||||||
var data_stack = world.cont.data_stack;
|
var data_stack = factor.cont.data_stack;
|
||||||
var retain_stack = world.cont.retain_stack;
|
var retain_stack = factor.cont.retain_stack;
|
||||||
retain_stack.push(data_stack.pop());
|
retain_stack.push(data_stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["r>"] = new Word("r>", "primitive", function(world, next) {
|
factor.words["r>"] = new Word("r>", "primitive", function(next) {
|
||||||
var data_stack = world.cont.data_stack;
|
var data_stack = factor.cont.data_stack;
|
||||||
var retain_stack = world.cont.retain_stack;
|
var retain_stack = factor.cont.retain_stack;
|
||||||
data_stack.push(retain_stack.pop());
|
data_stack.push(retain_stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["*"] = new Word("*", "primitive", function(world, next) {
|
factor.words["*"] = new Word("*", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack.push(stack.pop() * stack.pop());
|
stack.push(stack.pop() * stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["+"] = new Word("+", "primitive", function(world, next) {
|
factor.words["+"] = new Word("+", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack.push(stack.pop() + stack.pop());
|
stack.push(stack.pop() + stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["-"] = new Word("-", "primitive", function(world, next) {
|
factor.words["-"] = new Word("-", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var v1 = stack.pop();
|
var v1 = stack.pop();
|
||||||
var v2 = stack.pop();
|
var v2 = stack.pop();
|
||||||
stack.push(v2 - v1);
|
stack.push(v2 - v1);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["/"] = new Word("/", "primitive", function(world, next) {
|
factor.words["/"] = new Word("/", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var v1 = stack.pop();
|
var v1 = stack.pop();
|
||||||
var v2 = stack.pop();
|
var v2 = stack.pop();
|
||||||
stack.push(v2 / v1);
|
stack.push(v2 / v1);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["."] = new Word(".", "primitive", function(world, next) {
|
factor.words["."] = new Word(".", "primitive", function(next) {
|
||||||
alert(world.cont.data_stack.pop());
|
alert(factor.cont.data_stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["call"] = new Word("call", "primitive", function(world, next) {
|
factor.words["call"] = new Word("call", "primitive", function(next) {
|
||||||
var quot = world.cont.data_stack.pop();
|
var quot = factor.cont.data_stack.pop();
|
||||||
quot.execute(world, next);
|
quot.execute(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["execute"] = new Word("execute", "primitive", function(world, next) {
|
factor.words["execute"] = new Word("execute", "primitive", function(next) {
|
||||||
var quot = world.cont.data_stack.pop();
|
var quot = factor.cont.data_stack.pop();
|
||||||
quot.execute(world, next);
|
quot.execute(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["clear"] = new Word("clear", "primitive", function(world, next) {
|
factor.words["clear"] = new Word("clear", "primitive", function(next) {
|
||||||
world.cont.data_stack = [];
|
factor.cont.data_stack = [];
|
||||||
world.cont.retain_stack = [];
|
factor.cont.retain_stack = [];
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["square"] = new Word("square", "primitive", function(world, next) {
|
factor.words["square"] = new Word("square", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack[stack.length-1] = stack[stack.length-1] * stack[stack.length-1];
|
stack[stack.length-1] = stack[stack.length-1] * stack[stack.length-1];
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["if"] = new Word("if", "primitive", function(world, next) {
|
factor.words["if"] = new Word("if", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var else_quot = stack.pop();
|
var else_quot = stack.pop();
|
||||||
var then_quot = stack.pop();
|
var then_quot = stack.pop();
|
||||||
var condition = stack.pop();
|
var condition = stack.pop();
|
||||||
if(condition) {
|
if(condition) {
|
||||||
then_quot.execute(world, next);
|
then_quot.execute(next);
|
||||||
} else {
|
} else {
|
||||||
else_quot.execute(world, next);
|
else_quot.execute(next);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["f"] = new Word("f", "primitive", function(world, next) {
|
factor.words["f"] = new Word("f", "primitive", function(next) {
|
||||||
world.cont.data_stack.push(false);
|
factor.cont.data_stack.push(false);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["t"] = new Word("t", "primitive", function(world, next) {
|
factor.words["t"] = new Word("t", "primitive", function(next) {
|
||||||
world.cont.data_stack.push(true);
|
factor.cont.data_stack.push(true);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["="] = new Word("=", "primitive", function(world, next) {
|
factor.words["="] = new Word("=", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
stack.push(stack.pop()==stack.pop());
|
stack.push(stack.pop()==stack.pop());
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["window"] = new Word("window", "primitive", function(world, next) {
|
factor.words["window"] = new Word("window", "primitive", function(next) {
|
||||||
world.cont.data_stack.push(window);
|
factor.cont.data_stack.push(window);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["bootstrap"] = new Word("bootstrap", "primitive", function(world, next) {
|
factor.words["bootstrap"] = new Word("bootstrap", "primitive", function(next) {
|
||||||
world.cont.data_stack.push("/responder/fjsc-resources/bootstrap.factor");
|
factor.cont.data_stack.push("/responder/fjsc-resources/bootstrap.factor");
|
||||||
world.words["run-file"].execute(world, next);
|
factor.words["run-file"].execute(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["run-file"] = new Word("run-file", "primitive", function(world, next) {
|
factor.words["run-file"] = new Word("run-file", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var url = stack.pop();
|
var url = stack.pop();
|
||||||
var callback = {
|
var callback = {
|
||||||
success: function(o) {
|
success: function(o) {
|
||||||
var result = o.responseText;
|
var result = o.responseText;
|
||||||
world.server_eval(result, world, next);
|
factor.server_eval(result, next);
|
||||||
},
|
},
|
||||||
failure: function(o) {
|
failure: function(o) {
|
||||||
alert('run-file failed');
|
alert('run-file failed');
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
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) {
|
factor.words["callcc0"] = new Word("callcc0", "primitive", function(next) {
|
||||||
var data_stack = world.cont.data_stack;
|
var data_stack = factor.cont.data_stack;
|
||||||
var quot = data_stack.pop();
|
var quot = data_stack.pop();
|
||||||
var new_cont = world.cont.clone();
|
var new_cont = factor.cont.clone();
|
||||||
var old_next = world.next;
|
var old_next = factor.next;
|
||||||
var cont = {
|
var cont = {
|
||||||
world: world,
|
next: function() {
|
||||||
next: function(world) {
|
factor.next = old_next;
|
||||||
world.next = old_next;
|
next();
|
||||||
next(world);
|
|
||||||
},
|
},
|
||||||
cont: world.cont
|
cont: factor.cont
|
||||||
};
|
};
|
||||||
new_cont.data_stack.push(cont);
|
new_cont.data_stack.push(cont);
|
||||||
world.cont = new_cont;;
|
factor.cont = new_cont;;
|
||||||
quot.execute(world, next);
|
quot.execute(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["continue"] = new Word("continue", "primitive", function(world, next) {
|
factor.words["continue"] = new Word("continue", "primitive", function(next) {
|
||||||
var data_stack = world.cont.data_stack;
|
var data_stack = factor.cont.data_stack;
|
||||||
var cont = data_stack.pop();
|
var cont = data_stack.pop();
|
||||||
world.cont = cont.cont.clone();
|
factor.cont = cont.cont.clone();
|
||||||
(cont.next)(world);
|
(cont.next)();
|
||||||
});
|
});
|
||||||
|
|
||||||
factor.words["alien-invoke"] = new Word("alien-invoke", "primitive", function(world, next) {
|
factor.words["alien-invoke"] = new Word("alien-invoke", "primitive", function(next) {
|
||||||
var stack = world.cont.data_stack;
|
var stack = factor.cont.data_stack;
|
||||||
var arg_types = stack.pop();
|
var arg_types = stack.pop();
|
||||||
var method_name = stack.pop();
|
var method_name = stack.pop();
|
||||||
var library_name = stack.pop();
|
var library_name = stack.pop();
|
||||||
|
@ -223,38 +222,38 @@ factor.words["alien-invoke"] = new Word("alien-invoke", "primitive", function(wo
|
||||||
var v = obj[method_name].apply(obj, args);
|
var v = obj[method_name].apply(obj, args);
|
||||||
if(return_values.length > 0)
|
if(return_values.length > 0)
|
||||||
stack.push(v);
|
stack.push(v);
|
||||||
next(world);
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
Factor.prototype.push_data = function(v, world, next) {
|
Factor.prototype.push_data = function(v, next) {
|
||||||
world.cont.data_stack.push(v);
|
factor.cont.data_stack.push(v);
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
Factor.prototype.define_word = function(name, source, func, world, next) {
|
Factor.prototype.define_word = function(name, source, func, next) {
|
||||||
factor.words[name] = new Word(name, source, function(world, next) {
|
factor.words[name] = new Word(name, source, function(next) {
|
||||||
var old = world.next;
|
var old = factor.next;
|
||||||
world.next = function(world) {
|
factor.next = function() {
|
||||||
world.next = old;
|
factor.next = old;
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
func(world);
|
func();
|
||||||
});
|
});
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
Factor.prototype.make_quotation = function(source, func) {
|
Factor.prototype.make_quotation = function(source, func) {
|
||||||
return new Word("quotation", source, function(world, next) {
|
return new Word("quotation", source, function(next) {
|
||||||
var old = world.next;
|
var old = factor.next;
|
||||||
world.next = function(world) {
|
factor.next = function() {
|
||||||
world.next = old;
|
factor.next = old;
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
func(world);
|
func();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Factor.prototype.server_eval = function(text, world, next) {
|
Factor.prototype.server_eval = function(text, next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var callback = {
|
var callback = {
|
||||||
success: function(o) {
|
success: function(o) {
|
||||||
|
@ -264,8 +263,8 @@ Factor.prototype.server_eval = function(text, world, next) {
|
||||||
var func = eval(v);
|
var func = eval(v);
|
||||||
factor.next = function() { self.display_datastack(); }
|
factor.next = function() { self.display_datastack(); }
|
||||||
func(factor);
|
func(factor);
|
||||||
if(world && next)
|
if(next)
|
||||||
next(world);
|
next();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.form.code.value=text;
|
this.form.code.value=text;
|
||||||
|
|
|
@ -122,9 +122,9 @@ M: ast-number (literal)
|
||||||
ast-number-value number>string , ;
|
ast-number-value number>string , ;
|
||||||
|
|
||||||
M: ast-number (compile)
|
M: ast-number (compile)
|
||||||
"world.push_data(" ,
|
"factor.push_data(" ,
|
||||||
(literal)
|
(literal)
|
||||||
",world," , ;
|
"," , ;
|
||||||
|
|
||||||
M: ast-string (literal)
|
M: ast-string (literal)
|
||||||
"'" ,
|
"'" ,
|
||||||
|
@ -134,26 +134,26 @@ M: ast-string (literal)
|
||||||
M: ast-string (compile)
|
M: ast-string (compile)
|
||||||
"factor.push_data(" ,
|
"factor.push_data(" ,
|
||||||
(literal)
|
(literal)
|
||||||
",world," , ;
|
"," , ;
|
||||||
|
|
||||||
M: ast-identifier (literal)
|
M: ast-identifier (literal)
|
||||||
"world.words[\"" , ast-identifier-value , "\"]" , ;
|
"factor.words[\"" , ast-identifier-value , "\"]" , ;
|
||||||
|
|
||||||
M: ast-identifier (compile)
|
M: ast-identifier (compile)
|
||||||
(literal) ".execute(world, " , ;
|
(literal) ".execute(" , ;
|
||||||
|
|
||||||
M: ast-define (compile)
|
M: ast-define (compile)
|
||||||
"world.define_word(\"" ,
|
"factor.define_word(\"" ,
|
||||||
dup ast-define-name ,
|
dup ast-define-name ,
|
||||||
"\",\"source\"," ,
|
"\",\"source\"," ,
|
||||||
ast-define-expression (compile)
|
ast-define-expression (compile)
|
||||||
",world," , ;
|
"," , ;
|
||||||
|
|
||||||
: do-expressions ( seq -- )
|
: do-expressions ( seq -- )
|
||||||
dup empty? not [
|
dup empty? not [
|
||||||
unclip
|
unclip
|
||||||
dup ast-comment? not [
|
dup ast-comment? not [
|
||||||
"function(world) {" ,
|
"function() {" ,
|
||||||
(compile)
|
(compile)
|
||||||
do-expressions
|
do-expressions
|
||||||
")}" ,
|
")}" ,
|
||||||
|
@ -161,18 +161,18 @@ M: ast-define (compile)
|
||||||
drop do-expressions
|
drop do-expressions
|
||||||
] if
|
] if
|
||||||
] [
|
] [
|
||||||
drop "world.next" ,
|
drop "factor.next" ,
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: ast-quotation (literal)
|
M: ast-quotation (literal)
|
||||||
"world.make_quotation(\"source\"," ,
|
"factor.make_quotation(\"source\"," ,
|
||||||
ast-quotation-values do-expressions
|
ast-quotation-values do-expressions
|
||||||
")" , ;
|
")" , ;
|
||||||
|
|
||||||
M: ast-quotation (compile)
|
M: ast-quotation (compile)
|
||||||
"world.push_data(world.make_quotation(\"source\"," ,
|
"factor.push_data(factor.make_quotation(\"source\"," ,
|
||||||
ast-quotation-values do-expressions
|
ast-quotation-values do-expressions
|
||||||
"),world," , ;
|
")," , ;
|
||||||
|
|
||||||
M: ast-array (literal)
|
M: ast-array (literal)
|
||||||
"[" ,
|
"[" ,
|
||||||
|
@ -180,7 +180,7 @@ M: ast-array (literal)
|
||||||
"]" , ;
|
"]" , ;
|
||||||
|
|
||||||
M: ast-array (compile)
|
M: ast-array (compile)
|
||||||
"world.push_data(" , (literal) ",world," , ;
|
"factor.push_data(" , (literal) "," , ;
|
||||||
|
|
||||||
|
|
||||||
M: ast-expression (literal)
|
M: ast-expression (literal)
|
||||||
|
@ -199,7 +199,7 @@ M: ast-word (literal)
|
||||||
M: ast-word (compile)
|
M: ast-word (compile)
|
||||||
"factor.push_data(" ,
|
"factor.push_data(" ,
|
||||||
(literal)
|
(literal)
|
||||||
",world," , ;
|
"," , ;
|
||||||
|
|
||||||
M: ast-comment (compile)
|
M: ast-comment (compile)
|
||||||
drop ;
|
drop ;
|
||||||
|
|
Loading…
Reference in New Issue