# HG changeset patch # User Mike Pavone # Date 1376037329 25200 # Node ID bf8f75b690488acba989c514f1c7db9a9c270cf8 # Parent 9bce890a7ff2a17d972732a92a90dfaee6de1789 Minor progress towards supporting imports in the C backend diff -r 9bce890a7ff2 -r bf8f75b69048 cbackend.js --- 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) {