Mercurial > repos > tabletprog
diff compiler.js @ 96:84b65ee8b78b
Optimize self method calls into static function calls
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 26 Jul 2012 18:54:42 -0700 |
parents | 926b65fe92b4 |
children | 59a94f3ad56f |
line wrap: on
line diff
--- a/compiler.js Tue Jul 24 19:13:38 2012 -0700 +++ b/compiler.js Thu Jul 26 18:54:42 2012 -0700 @@ -329,6 +329,7 @@ } funcall.prototype.populateSymbols = function(symbols) { + var isll = false; if (this.name == 'foreign:') { if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object) || (this.args[0] instanceof symbol)) { return; @@ -351,6 +352,7 @@ if (this.args[1] instanceof lambda) { if (this.args[2] instanceof lambda) { symbols.defineMsg(this.args[0].name, this.args[2]); + isll = true; } else { throw new Error("Third argument to llMessage:withVars:andCode: must be a lambda"); } @@ -368,10 +370,10 @@ symbols.find('self'); } for (var i in this.args) { - this.args[i].populateSymbols(symbols); + this.args[i].populateSymbols(symbols, undefined, isll); } if (this.receiver) { - this.receiver.populateSymbols(symbols); + this.receiver.populateSymbols(symbols, undefined, isll); } } @@ -386,8 +388,11 @@ } this.symbols = symbols; } - -lambda.prototype.populateSymbols = function(symbols, isobject) { +var lambdanum = 0; +lambda.prototype.populateSymbols = function(symbols, isobject, isll) { + if (!isll) { + this.name = 'lambda_' + lambdanum++; + } var args = this.args ? this.args.slice(0, this.args.length) : []; var exprs = this.expressions; var symbols = new lsymbols(symbols);