Mercurial > repos > tabletprog
diff compiler.js @ 42:4e983fe32047
Fix closures as methods so that private vars work
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 12 Jul 2012 20:14:15 -0700 |
parents | e7be612fd3ae |
children | 18ab96287c3a |
line wrap: on
line diff
--- a/compiler.js Wed Jul 11 21:57:38 2012 -0700 +++ b/compiler.js Thu Jul 12 20:14:15 2012 -0700 @@ -45,8 +45,9 @@ { this.parent = parent; this.names = {}; + this.needsenv = false; } -osymbols.prototype.find = function(name) { +osymbols.prototype.find = function(name, nestedcall) { if (name in this.names) { if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { return { @@ -59,13 +60,15 @@ def: this.names[name], }; } else if(this.parent) { - var ret = this.parent.find(name); + var ret = this.parent.find(name, nestedcall); if (ret) { if(ret.type == 'self') { ret.type = 'parent'; ret.depth = 1; } else if(ret.type == 'parent') { ret.depth++; + } else if(ret.type == 'closedover' || ret.type == 'upvar') { + this.needsenv = true; } } return ret; @@ -101,6 +104,9 @@ osymbols.prototype.getEnvType = function() { return this.parent.getEnvType(); } +osymbols.prototype.envVar = function() { + return this.parent.envVar(); +} function lsymbols(parent) { @@ -187,6 +193,14 @@ return this.envtype; } } +lsymbols.prototype.envVar = function() { + if (Object.keys(this.closedover).length) { + return 'myenv'; + } else if(this.passthruenv) { + return 'env'; + } + return null; +} var mainModule;