Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created February 27, 2012 20:36
Show Gist options
  • Save halfdan/1926869 to your computer and use it in GitHub Desktop.
Save halfdan/1926869 to your computer and use it in GitHub Desktop.
static void generateCodeCallStmt(Absyn *node, Table *table, Entry *currentMethod,
int returnLabel, int breakLabel) {
Absyn *rcvr = node->u.callStm.rcvr;
Absyn *args = node->u.callStm.args;
Sym *name = node->u.callStm.name;
Class *rcvrClass = node->u.callStm.rcvrClass;
Class *rcvrMetaClass = rcvrClass->metaClass;
Entry *methodEntry;
int offset;
int numParams;
methodEntry = lookup(rcvrClass->mbrTable, name, ENTRY_KIND_METHOD);
if(methodEntry == NULL) {
methodEntry = lookup(rcvrMetaClass->mbrTable, name, ENTRY_KIND_METHOD);
}
if (methodEntry->u.methodEntry.isStatic) {
/* We need to switch over the receiver of the callExp */
switch (node->u.callStm.rcvr->type) {
case ABSYN_SUPEREXP:
break;
case ABSYN_SELFEXP:
break;
default:
generateCodeNode(node->u.callStm.rcvr, table, currentMethod, returnLabel, breakLabel);
break;
}
/* Push static class object onto stack */
fprintf(asmFile, "\tpushg\t%d\n", rcvrMetaClass->globalIndex);
/* Get name of method */
offset = findVMT(rcvrMetaClass->vmt, name);
numParams = methodEntry->u.methodEntry.numParams;
generateCodeNode(args, table, currentMethod, returnLabel, breakLabel);
fprintf(asmFile, "\tvmcall\t%d,%d\n",
numParams + 1,
offset + 1);
} else {
generateCodeNode(rcvr, table, currentMethod, returnLabel, breakLabel);
}
/* ToDo */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment