diff 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
line wrap: on
line diff
--- a/cbackend.js	Sat Mar 28 13:26:44 2015 -0700
+++ b/cbackend.js	Sat Mar 28 14:21:04 2015 -0700
@@ -227,39 +227,41 @@
 		return null;
 	}
 	var args = this.args.slice(0, this.args.length);
+	var method = false;
+	var start = 0;
 	if (this.receiver) {
 		args.splice(0, 0, this.receiver);
-	}
-	var method = false;
-	var funinfo = this.symbols.find(name);
-	var start = 0;
-	if (!funinfo || funinfo.def instanceof setter || funinfo.type == 'toplevel') {
 		method = true;
 	} else {
-		switch(funinfo.type)
-		{
-		case 'self':
-		case 'parent':
-			var defargs = funinfo.def.args.length;
-			if (!defargs || funinfo.def.args[0].cleanName() != 'self') {
-				defargs ++
+		var funinfo = this.symbols.find(name);
+		if (!funinfo || funinfo.def instanceof setter || funinfo.type == 'toplevel') {
+			method = true;
+		} else {
+			switch(funinfo.type)
+			{
+			case 'self':
+			case 'parent':
+				var defargs = funinfo.def.args.length;
+				if (!defargs || funinfo.def.args[0].cleanName() != 'self') {
+					defargs ++
+				}
+				if (args.length < defargs) {
+					if (funinfo.type == 'self') {
+						args.splice(0, 0, new symbol('self', this.symbols));
+					} else {
+						var obj = (new symbol('self', this.symbols)).toC() + '->header.';
+						for (var i = 0; i < funinfo.depth; ++i) {
+							obj += (i ? '->' : '') + 'parent';
+						}
+						args.splice(0, 0, ', ' + obj);
+						start = 1;
+					}
+				} else if(!(args[0] instanceof symbol) || args[0].name != 'self') {
+					funinfo = null;
+				}
+				method = true;
+				break;
 			}
-			if (args.length < defargs) {
-				if (funinfo.type == 'self') {
-					args.splice(0, 0, new symbol('self', this.symbols));
-				} else {
-					var obj = (new symbol('self', this.symbols)).toC() + '->header.';
-					for (var i = 0; i < funinfo.depth; ++i) {
-						obj += (i ? '->' : '') + 'parent';
-					}
-					args.splice(0, 0, ', ' + obj);
-					start = 1;
-				}
-			} else if(!(args[0] instanceof symbol) || args[0].name != 'self') {
-				funinfo = null;
-			}
-			method = true;
-			break;
 		}
 	}
 	for (var i = start; i < args.length; i++) {