changeset 140:bf8f75b69048

Minor progress towards supporting imports in the C backend
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 01:35:29 -0700
parents 9bce890a7ff2
children 15aac5334b64
files cbackend.js
diffstat 1 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.js	Fri Aug 09 01:32:35 2013 -0700
+++ b/cbackend.js	Fri Aug 09 01:35:29 2013 -0700
@@ -420,7 +420,24 @@
 
 cObject.prototype.addInit = function(statement) {
 	this.init.push(statement);
-}
+};
+
+cObject.prototype.addImport = function(symbols, source) {
+	this.imported.push(source);
+	var importNum = imported.length - 1;
+	if (symbols) {
+		each(symbols, function(i, sym) {
+			this.addMessage(sym.name, {
+				vars: {},
+				lines: [
+					'return self->import_' + importNum + '->meta->meth_lookup[method_id & 0xF](method_id, num_args, self->import_' + importNum + ', args);'
+				]
+			});
+		});
+	} else {
+		//TODO: handle proxying for unimplemented methods
+	}
+};
 
 cObject.prototype.checkInitMsg = function() {
 	if (!this.initmsgadded && this.init.length) {
@@ -512,8 +529,6 @@
 
 object.prototype.toCObject = function() {
 	var messages = this.messages;
-	var values = [];
-	var imports = [];
 	if (!this.name) {
 		this.name = 'object_' + nextobject++;
 	}
@@ -529,16 +544,16 @@
 	for (var i in messages) {
 		if (messages[i] instanceof funcall) {
 			if (messages[i].name == 'import:' && messages[i].args.length == 1) {
-				imports.push({symbols: false, src: messages[i].args[0]});
+				me.addImport(false, messages[i].args[0]);
 			} else if(messages[i].name == 'import:from:' && messages[i].args.length == 2) {
 				var importsyms = [];
 				each(messages[i].args[0].val, function(i, el) {
 					if (!(el instanceof symbol)) {
 						throw new Error('Names in import:from statement must be symbols');
 					}
-					importsyms.push(new strlit(el.name));
+					importsyms.push(el);
 				});
-				imports.push({symbols: new listlit(importsyms), src: messages[i].args[1]});
+				me.addImport(importsyms, messages[i].args[1]);
 			} else if(messages[i].name == 'llProperty:withType:' && messages[i].args.length == 2) {
 				me.addProperty(messages[i].args[0].name, null, messages[i].args[1].toCTypeName())
 			} else if(messages[i].name == 'llMessage:withVars:andCode:' && messages[i].args.length == 3) {