comparison cbackend.js @ 331:61f5b794d939

Breaking change: method call syntax now always uses the syntactic receiver as the actual receiver. This makes its behavior different from function call syntax, but solves some problems with methods being shadowed by local variables and the like.
author Michael Pavone <pavone@retrodev.com>
date Sat, 28 Mar 2015 14:21:04 -0700
parents eef8a5cea812
children 2a0463c46913
comparison
equal deleted inserted replaced
330:e70f9d3f19f8 331:61f5b794d939
225 } 225 }
226 } else if(name == 'llProperty:withType' || name == 'llProperty:withVars:andCode' || name == 'quote') { 226 } else if(name == 'llProperty:withType' || name == 'llProperty:withVars:andCode' || name == 'quote') {
227 return null; 227 return null;
228 } 228 }
229 var args = this.args.slice(0, this.args.length); 229 var args = this.args.slice(0, this.args.length);
230 var method = false;
231 var start = 0;
230 if (this.receiver) { 232 if (this.receiver) {
231 args.splice(0, 0, this.receiver); 233 args.splice(0, 0, this.receiver);
232 }
233 var method = false;
234 var funinfo = this.symbols.find(name);
235 var start = 0;
236 if (!funinfo || funinfo.def instanceof setter || funinfo.type == 'toplevel') {
237 method = true; 234 method = true;
238 } else { 235 } else {
239 switch(funinfo.type) 236 var funinfo = this.symbols.find(name);
240 { 237 if (!funinfo || funinfo.def instanceof setter || funinfo.type == 'toplevel') {
241 case 'self': 238 method = true;
242 case 'parent': 239 } else {
243 var defargs = funinfo.def.args.length; 240 switch(funinfo.type)
244 if (!defargs || funinfo.def.args[0].cleanName() != 'self') { 241 {
245 defargs ++ 242 case 'self':
246 } 243 case 'parent':
247 if (args.length < defargs) { 244 var defargs = funinfo.def.args.length;
248 if (funinfo.type == 'self') { 245 if (!defargs || funinfo.def.args[0].cleanName() != 'self') {
249 args.splice(0, 0, new symbol('self', this.symbols)); 246 defargs ++
250 } else { 247 }
251 var obj = (new symbol('self', this.symbols)).toC() + '->header.'; 248 if (args.length < defargs) {
252 for (var i = 0; i < funinfo.depth; ++i) { 249 if (funinfo.type == 'self') {
253 obj += (i ? '->' : '') + 'parent'; 250 args.splice(0, 0, new symbol('self', this.symbols));
251 } else {
252 var obj = (new symbol('self', this.symbols)).toC() + '->header.';
253 for (var i = 0; i < funinfo.depth; ++i) {
254 obj += (i ? '->' : '') + 'parent';
255 }
256 args.splice(0, 0, ', ' + obj);
257 start = 1;
254 } 258 }
255 args.splice(0, 0, ', ' + obj); 259 } else if(!(args[0] instanceof symbol) || args[0].name != 'self') {
256 start = 1; 260 funinfo = null;
257 } 261 }
258 } else if(!(args[0] instanceof symbol) || args[0].name != 'self') { 262 method = true;
259 funinfo = null; 263 break;
260 } 264 }
261 method = true;
262 break;
263 } 265 }
264 } 266 }
265 for (var i = start; i < args.length; i++) { 267 for (var i = start; i < args.length; i++) {
266 args[i] = ', ' + (!i && method ? '(object *)(' : '') + args[i].toC() + (!i && method ? ')' : ''); 268 args[i] = ', ' + (!i && method ? '(object *)(' : '') + args[i].toC() + (!i && method ? ')' : '');
267 } 269 }