diff jsbackend.js @ 21:6c8ae6b47ab5

Small improvements to property support and elimination of setP and getP functions as they are no longer needed
author Mike Pavone <pavone@retrodev.com>
date Sun, 25 Mar 2012 21:11:10 -0700
parents bf03c9f0dd55
children 068d63627b16
line wrap: on
line diff
--- a/jsbackend.js	Sun Mar 25 16:52:11 2012 -0700
+++ b/jsbackend.js	Sun Mar 25 21:11:10 2012 -0700
@@ -16,17 +16,6 @@
 	throw new Error("can't make val into object");
 }
 
-function setP(o, p, val)
-{
-	o[p] = val;
-	return o;
-}
-
-function getP(o, p)
-{
-	return o[p];
-}
-
 op.prototype.toJS = function(isReceiver) {
 	var ret = '(' + this.left.toJS() +' '+ (this.op == '=' ? '==' : this.op) +' '+ this.right.toJS() + ')';
 	if (isReceiver) {
@@ -75,8 +64,6 @@
 	if (this.receiver) {
 		args.splice(0, 0, this.receiver);
 	}
-	console.log(this);
-	console.log('Checking symbol table for ' + name);
 	var funinfo = this.symbols.find(name);
 	if (!funinfo || funinfo.def instanceof setter) {
 		var receiver = args[0];
@@ -85,11 +72,16 @@
 			args[i] = args[i].toJS();
 		}
 		var rJS = receiver.toJS(true);
-		var jsName = (new symbol(name, this.symbols)).toJS();
 		if ((name[name.length-1] == '!' && args.length == 1) || (funinfo && funinfo.def instanceof setter)) {
-			return  '(' + rJS + '.' + jsName + ' = ' + args[0] + ', ' + rJS + ')'
+			console.log(name.substr(0, name.length-1));
+			return  '(' + rJS + '.' + (new symbol(name.substr(0, name.length-1), this.symbols)).toJS()  + ' = ' + args[0] + ', ' + rJS + ')'
 		} else {
-			return rJS + '.' + jsName + '(' + args.join(', ') + ')';
+			var callCode = rJS + '.' + (new symbol(name, this.symbols)).toJS() + '(' + args.join(', ') + ')';
+			if (args.length == 0) {
+				return '(' + rJS + ' instanceof Function ? ' + callCode + ' : ' + callCode.substr(0, callCode.length-2) + ')';
+			} else {
+				return callCode;
+			}
 		}
 	}
 	var ret = '';