From 32c4d89f5636ef26989b5557c897e74103f21ad2 Mon Sep 17 00:00:00 2001 From: Manuel Simoni Date: Tue, 30 Jan 2018 17:49:11 +0000 Subject: [PATCH] Proof of concept of new calling convention --- build/wat.js | 16 ++++++++-------- vm.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build/wat.js b/build/wat.js index 8c2818a..513da95 100644 --- a/build/wat.js +++ b/build/wat.js @@ -763,7 +763,7 @@ module.exports = function Qua() { Sym.prototype.wat_eval = function(m, e) { return lookup(e, this.name); }; function Cons(car, cdr) { this.car = car; this.cdr = cdr; } Cons.prototype.wat_eval = function(m, e) { var that = this; - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(that)); }, function(op) { return combine(null, e, op, cdr(that)); }); }; @@ -779,22 +779,22 @@ module.exports = function Qua() { return apv instanceof Apv ? apv.cmb : error("cannot unwrap: " + apv); } Opv.prototype.wat_combine = function(m, e, o) { var that = this; var xe = make_env(that.e); - return monadic(m, + return monadic(null, function() { return bind(xe, that.p, o); }, function() { - return monadic(m, + return monadic(null, function() { return bind(xe, that.ep, e); }, function() { return evaluate(null, xe, that.x); }); }); }; Apv.prototype.wat_combine = function(m, e, o) { var that = this; - return monadic(m, + return monadic(null, function() { return evalArgs(null, e, o, NIL); }, function(args) { return that.cmb.wat_combine(null, e, args); }); }; function evalArgs(m, e, todo, done) { if (todo === NIL) { return reverse_list(done); } - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(todo)); }, function(arg) { return evalArgs(null, e, cdr(todo), cons(arg, done)); @@ -807,7 +807,7 @@ module.exports = function Qua() { Def.prototype.wat_combine = function self(m, e, o) { // error handling var lhs = elt(o, 0); var rhs = elt(o, 1); - return monadic(m, + return monadic(null, function() { return evaluate(null, e, rhs); }, function(val) { return bind(e, lhs, val); }); } @@ -821,7 +821,7 @@ module.exports = function Qua() { Begin.prototype.wat_combine = function(m, e, o) { if (o === NIL) return null; else return begin(m, e, o); }; function begin(m, e, xs) { - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(xs)); }, function(res) { var kdr = cdr(xs); @@ -829,7 +829,7 @@ module.exports = function Qua() { }); } If.prototype.wat_combine = function self(m, e, o) { - return monadic(m, + return monadic(null, function() { return evaluate(null, e, elt(o, 0)); }, function(test) { return evaluate(null, e, test ? elt(o, 1) : elt(o, 2)); diff --git a/vm.js b/vm.js index a32b82a..71afcd8 100644 --- a/vm.js +++ b/vm.js @@ -32,7 +32,7 @@ module.exports = function Qua() { Sym.prototype.wat_eval = function(m, e) { return lookup(e, this.name); }; function Cons(car, cdr) { this.car = car; this.cdr = cdr; } Cons.prototype.wat_eval = function(m, e) { var that = this; - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(that)); }, function(op) { return combine(null, e, op, cdr(that)); }); }; @@ -48,22 +48,22 @@ module.exports = function Qua() { return apv instanceof Apv ? apv.cmb : error("cannot unwrap: " + apv); } Opv.prototype.wat_combine = function(m, e, o) { var that = this; var xe = make_env(that.e); - return monadic(m, + return monadic(null, function() { return bind(xe, that.p, o); }, function() { - return monadic(m, + return monadic(null, function() { return bind(xe, that.ep, e); }, function() { return evaluate(null, xe, that.x); }); }); }; Apv.prototype.wat_combine = function(m, e, o) { var that = this; - return monadic(m, + return monadic(null, function() { return evalArgs(null, e, o, NIL); }, function(args) { return that.cmb.wat_combine(null, e, args); }); }; function evalArgs(m, e, todo, done) { if (todo === NIL) { return reverse_list(done); } - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(todo)); }, function(arg) { return evalArgs(null, e, cdr(todo), cons(arg, done)); @@ -76,7 +76,7 @@ module.exports = function Qua() { Def.prototype.wat_combine = function self(m, e, o) { // error handling var lhs = elt(o, 0); var rhs = elt(o, 1); - return monadic(m, + return monadic(null, function() { return evaluate(null, e, rhs); }, function(val) { return bind(e, lhs, val); }); } @@ -90,7 +90,7 @@ module.exports = function Qua() { Begin.prototype.wat_combine = function(m, e, o) { if (o === NIL) return null; else return begin(m, e, o); }; function begin(m, e, xs) { - return monadic(m, + return monadic(null, function() { return evaluate(null, e, car(xs)); }, function(res) { var kdr = cdr(xs); @@ -98,7 +98,7 @@ module.exports = function Qua() { }); } If.prototype.wat_combine = function self(m, e, o) { - return monadic(m, + return monadic(null, function() { return evaluate(null, e, elt(o, 0)); }, function(test) { return evaluate(null, e, test ? elt(o, 1) : elt(o, 2));