changeset 143:282b8056b702

Lambda bugfix and some improvments to the llMessage support
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 03:58:08 -0700
parents 833624457b81
children 547153211389
files cbackend.js
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.js	Fri Aug 09 01:37:09 2013 -0700
+++ b/cbackend.js	Fri Aug 09 03:58:08 2013 -0700
@@ -267,6 +267,11 @@
 		var receiver = this.receiver ? this.receiver : this.args[0];
 		return receiver.toCTypeName() + ' *';
 		break;
+	case 'struct:':
+	case 'struct':
+		var receiver = this.receiver ? this.receiver : this.args[0];
+		return 'struct ' + receiver.toCTypeName();
+		break;
 	default:
 		throw new Error('invalid use of funcall expression where a C type name is expected');
 	}
@@ -329,9 +334,17 @@
 	var args = this.args.slice(0, this.args.length);
 	if (this.receiver) {
 		if(this.args.length == 0) {
-			return this.receiver.toCLLExpr(vars) + '->' + this.name;
+			if (this.receiver instanceof symbol && this.receiver.name in vars && vars[this.receiver.name].substr(-1) != "*") {
+				return this.receiver.toCLLExpr(vars) + '.' + this.name;
+			} else {
+				return this.receiver.toCLLExpr(vars) + '->' + this.name;
+			}
 		} else if (this.args.length == 1 && name[name.length-1] == '!') {
-			return this.receiver.toCLLExpr(vars) + '->' + this.name.substr(0, name.length-1) + ' = ' + args[0].toCLLExpr(vars);
+			if (this.receiver instanceof symbol && this.receiver.name in vars && vars[this.receiver.name].substr(-1) != "*") {
+				return this.receiver.toCLLExpr(vars) + '.' + this.name.substr(0, name.length-1) + ' = ' + args[0].toCLLExpr(vars);
+			} else {
+				return this.receiver.toCLLExpr(vars) + '->' + this.name.substr(0, name.length-1) + ' = ' + args[0].toCLLExpr(vars);
+			}
 		} else {
 			args.splice(0, 0, this.receiver);
 		}
@@ -570,6 +583,8 @@
 					vars: vars,
 					lines: messages[i].args[2].toCLines(vars, true)
 				});
+			} else if(messages[i].name == 'includeSystemHeader:' && messages[i].args.length == 1) {
+				me.addInclude("<" + messages[i].args[0].val + ">");
 			} else {
 
 				throw new Error('Only import and import:from calls allowed in object context. ' + messages[i].name + 'with ' + messages[i].args.length + ' arguments found instead.');
@@ -973,7 +988,7 @@
 			debugprint('//' + this.name, 'has envvar:', envvar, 'num vars closed over:', Object.keys(this.symbols.closedover).length);
 			return 'make_lambda(' + envvar + ', (closure_func)' + this.name + ')';
 		} else {
-			toplevelcode += 'lambda ' + this.name + '_obj = {{&lambda_meta, NULL}, NULL, lambda_' + mynum + '};\n';
+			toplevelcode += 'lambda ' + this.name + '_obj = {{&lambda_meta, NULL}, NULL, ' + this.name + '};\n';
 			return '((object *)&' + this.name + '_obj)';
 		}
 	}