Mercurial > repos > tabletprog
diff jsbackend.js @ 110:d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 13 Apr 2013 23:37:54 -0700 |
parents | 648659961e0e |
children | a83989115028 |
line wrap: on
line diff
--- a/jsbackend.js Sat Apr 13 17:33:14 2013 -0700 +++ b/jsbackend.js Sat Apr 13 23:37:54 2013 -0700 @@ -34,8 +34,14 @@ } op.prototype.toJS = function(isReceiver) { - var opmap = {'=': '==', '.': '+'}; - var ret = '(' + this.left.toJS() +' '+ (this.op in opmap ? opmap[this.op] : this.op) +' '+ this.right.toJS() + ')'; + if (this.op == '&&') { + var ret = 'toobj(' + this.left.toJS() + ').sif(' + this.right.toJS() + ')'; + } else if(this.op == '||') { + var ret = 'toobj(' + this.left.toJS() + ').ifnot(' + this.right.toJS() + ')'; + } else { + var opmap = {'=': '==', '.': '+'}; + var ret = '(' + this.left.toJS() +' '+ (this.op in opmap ? opmap[this.op] : this.op) +' '+ this.right.toJS() + ')'; + } return ret; }; @@ -315,8 +321,10 @@ 'Number.prototype.__defineGetter__("string", function() { return "" + this; });\n' + 'String.prototype.__defineGetter__("string", function() { return this; });\n' + 'String.prototype.__defineGetter__("print", function() { write(this); });\n' + - 'Array.prototype = function(action) { var ret = module_false; for (var i = 0; i < this.length; i++) { ret = action(i, this[i]) }; return ret; };\n' + + 'Object.defineProperty(Array.prototype, "foreach", {value: function(action) { var ret = module_false; for (var i = 0; i < this.length; i++) { ret = action(i, this[i]) }; return ret; }});\n' + 'Function.prototype.whileCN_do = function(action) { var ret = module_false; while(toobj(this()) == module_true) { ret = action(); } return ret; };\n' + + 'module_true.valueOf = function() { return true; }\n' + + 'module_false.valueOf = function() { return false; }\n' + 'function toobj(val) {\n' + ' return (typeof val == "boolean") ? (val ? module_true : module_false) : val;\n' + '}\n' +