Mercurial > repos > tabletprog
comparison 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 |
comparison
equal
deleted
inserted
replaced
41:0558dad9d061 | 42:4e983fe32047 |
---|---|
43 | 43 |
44 function osymbols(parent) | 44 function osymbols(parent) |
45 { | 45 { |
46 this.parent = parent; | 46 this.parent = parent; |
47 this.names = {}; | 47 this.names = {}; |
48 } | 48 this.needsenv = false; |
49 osymbols.prototype.find = function(name) { | 49 } |
50 osymbols.prototype.find = function(name, nestedcall) { | |
50 if (name in this.names) { | 51 if (name in this.names) { |
51 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { | 52 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { |
52 return { | 53 return { |
53 type: 'foreign', | 54 type: 'foreign', |
54 def: this.names[name] | 55 def: this.names[name] |
57 return { | 58 return { |
58 type: 'self', | 59 type: 'self', |
59 def: this.names[name], | 60 def: this.names[name], |
60 }; | 61 }; |
61 } else if(this.parent) { | 62 } else if(this.parent) { |
62 var ret = this.parent.find(name); | 63 var ret = this.parent.find(name, nestedcall); |
63 if (ret) { | 64 if (ret) { |
64 if(ret.type == 'self') { | 65 if(ret.type == 'self') { |
65 ret.type = 'parent'; | 66 ret.type = 'parent'; |
66 ret.depth = 1; | 67 ret.depth = 1; |
67 } else if(ret.type == 'parent') { | 68 } else if(ret.type == 'parent') { |
68 ret.depth++; | 69 ret.depth++; |
70 } else if(ret.type == 'closedover' || ret.type == 'upvar') { | |
71 this.needsenv = true; | |
69 } | 72 } |
70 } | 73 } |
71 return ret; | 74 return ret; |
72 } | 75 } |
73 return null; | 76 return null; |
98 } | 101 } |
99 return curlist; | 102 return curlist; |
100 } | 103 } |
101 osymbols.prototype.getEnvType = function() { | 104 osymbols.prototype.getEnvType = function() { |
102 return this.parent.getEnvType(); | 105 return this.parent.getEnvType(); |
106 } | |
107 osymbols.prototype.envVar = function() { | |
108 return this.parent.envVar(); | |
103 } | 109 } |
104 | 110 |
105 function lsymbols(parent) | 111 function lsymbols(parent) |
106 { | 112 { |
107 this.parent = parent; | 113 this.parent = parent; |
185 return this.parent.getEnvType(); | 191 return this.parent.getEnvType(); |
186 } else { | 192 } else { |
187 return this.envtype; | 193 return this.envtype; |
188 } | 194 } |
189 } | 195 } |
196 lsymbols.prototype.envVar = function() { | |
197 if (Object.keys(this.closedover).length) { | |
198 return 'myenv'; | |
199 } else if(this.passthruenv) { | |
200 return 'env'; | |
201 } | |
202 return null; | |
203 } | |
190 | 204 |
191 var mainModule; | 205 var mainModule; |
192 | 206 |
193 function toobj(val) | 207 function toobj(val) |
194 { | 208 { |