Permalink
Browse files

sig-default jit: get sig from protos, and fill, asm missing for absol…

…ute ARGO
  • Loading branch information...
Reini Urban
Reini Urban committed May 7, 2013
1 parent 74da92a commit 66853aed3446a51fa91b41b9b704c5254fb5578f
Showing with 72 additions and 10 deletions.
  1. +6 −0 core/compile.c
  2. +33 −0 core/objmodel.c
  3. +1 −0 core/potion.h
  4. +24 −7 core/vm-x86.c
  5. +8 −3 core/vm.c
View
@@ -341,6 +341,7 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
breg++;
PN_BLOCK(breg, PN_S(t,2), PN_NIL);
}
DBG_c("; call %d %d VALUE\n", reg, breg);
PN_ASM2(OP_CALL, reg, breg);
}
}
@@ -393,10 +394,12 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
if (lhs->a[1] != PN_NIL) {
breg = reg;
PN_ASM2(opcode, ++breg, num);
DBG_c("; callset %d %d ASSIGN\n", reg, breg);
PN_ASM2(OP_CALLSET, reg, breg);
PN_ARG_TABLE(PN_S(lhs,1), breg, 1);
// TODO: no block allowed here?
potion_source_asmb(P, f, loop, 0, t->a[1], ++breg);
DBG_c("; call %d %d ASSIGN\n", reg, breg);
PN_ASM2(OP_CALL, reg, breg);
} else {
potion_source_asmb(P, f, loop, 0, t->a[1], breg);
@@ -620,9 +623,11 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
}
#undef LOAD_ARG
if (t->part == AST_MSG) {
DBG_c("; call %d %d MSG\n", reg, breg);
PN_ASM2(OP_CALL, reg, breg);
} else
if (PN_S(t,1) != PN_NIL) {
DBG_c("; call %d %d !MSG\n", reg, breg);
PN_ASM2(OP_CALL, reg, breg);
PN_OP_AT(f->asmb, jmp).b = (PN_OP_LEN(f->asmb) - jmp) - 1;
} else {
@@ -638,6 +643,7 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
breg++;
PN_BLOCK(breg, PN_S(t,2), PN_NIL);
}
DBG_c("; call %d %d\n", reg, breg);
PN_ASM2(OP_CALL, reg, breg);
}
}
View
@@ -96,6 +96,39 @@ int potion_sig_arity(Potion *P, PN sig) {
}
}
///\return sig tuple at index, zero-based
PN potion_sig_at(Potion *P, PN sig, int index) {
PN result = PN_NIL;
if (PN_IS_TUPLE(sig)) {
int count = -1;
struct PNTuple * volatile t = (struct PNTuple *)potion_fwd(sig);
if (t->len > 0) {
PN_SIZE i;
for (i = 0; i < t->len; i++) {
PN v = (PN)t->set[i];
if (PN_IS_STR(v)) count++;
if (PN_IS_NUM(v) && v == PN_NUM(':') && PN_IS_STR((PN)t->set[i+1])) count--;
if (count == index) {
result = potion_tuple_new(P, v);
if (i+1 < t->len && PN_IS_NUM((PN)t->set[i+1])) {
PN typ = (PN)t->set[i+1];
result = potion_tuple_push(P, result, typ);
if (i+2 < t->len && typ == PN_NUM(':'))
result = potion_tuple_push(P, result, (PN)t->set[i+2]);
}
return result;
}
}
}
return result;
}
else if (sig == PN_NIL)
return result;
else {
potion_fatal("wrong sig type for sig_at");
}
}
PN potion_no_call(Potion *P, PN cl, PN self) {
return self;
}
View
@@ -745,6 +745,7 @@ PN potion_srand(Potion *, PN, PN, PN);
PN potion_rand(Potion *, PN, PN);
PN potion_num_rand(Potion *, PN, PN);
PN potion_real(Potion *, double);
PN potion_sig_at(Potion *, PN, int);
int potion_sig_arity(Potion *, PN);
PN potion_closure_arity(Potion *, PN, PN);
void potion_define_global(Potion *, PN, PN);
View
@@ -604,6 +604,7 @@ void potion_x86_testjmp(Potion *P, struct PNProto * volatile f, PNAsm * volatile
void potion_x86_notjmp(Potion *P, struct PNProto * volatile f, PNAsm * volatile *asmp, PN_SIZE pos, PNJumps *jmps, size_t *offs, int *jmpc) {
PN_OP op = PN_OP_AT(f->asmb, pos);
DBG_t("; notjmp %d => %d\n", op.a, op.b);
X86_MOV_RBP(0x8B, op.a); // mov -A(%rbp) %rax
X86_PRE(); ASM(0x83); ASM(0xF8); ASM(PN_FALSE); // cmp FALSE %rax
ASM(0x74); ASM(X86C(4, 5)); // je +5
@@ -614,9 +615,10 @@ void potion_x86_notjmp(Potion *P, struct PNProto * volatile f, PNAsm * volatile
void potion_x86_named(Potion *P, struct PNProto * volatile f, PNAsm * volatile *asmp, PN_SIZE pos, long start) {
PN_OP op = PN_OP_AT(f->asmb, pos);
X86_ARGO(start - 3, 0);
X86_ARGO(op.a, 1);
X86_ARGO(op.b - 1, 2);
DBG_t("; named %d %d\n", op.a, op.b);
X86_ARGO(start - 3, 0); //P
X86_ARGO(op.a, 1); //cl
X86_ARGO(op.b - 1, 2); //name
X86_PRE(); ASM(0xB8); ASMN(potion_sig_find); // mov &potion_sig_find %rax
ASM(0xFF); ASM(0xD0); // callq %eax
ASM(0x85); ASM(0xC0); // test %eax %eax
@@ -676,12 +678,27 @@ void potion_x86_call(Potion *P, struct PNProto * volatile f, PNAsm * volatile *a
// (Potion *, CL) as the first argument
X86_ARGO(start - 3, 0);
X86_ARGO(op.a, 1);
{
if ((argc < f->arity) && f->arity) { // fill in defaults backwards
DBG_c("jit: defaults argc=%d sig=%s\n", argc, AS_STR(f->sig));
DBG_t("; call %d[1] ", op.a);
// arity from protos[op.a], not f
if (!PN_IS_EMPTY(f->protos) && op.a < PN_TUPLE_LEN(f->protos)) {
vPN(Proto) c = (vPN(Proto)) PN_TUPLE_AT(f->protos, op.a);
if ((argc < c->arity) && c->arity) { // fill in defaults
int j = c->arity + 1; //2: [0,1],3,2
while (j >= argc+1) { //3>=2, 2>=2
PN sig = potion_sig_at(P, c->sig, j-2);
if (sig) {
DBG_t(":=%s[%d] ", AS_STR(PN_TUPLE_AT(sig, 2)), j);
//todo: asm fill absolute at j, or push defaults also to stack.
X86_ARGO(PN_TUPLE_AT(sig, 2), j--); // fill default value
}
}
}
while (--argc >= 0) X86_ARGO(op.a + argc + 1, argc + 2);
}
while (--argc >= 0) {
DBG_t("%d[%d] ", op.a + argc + 1, argc + 2);
X86_ARGO(op.a + argc + 1, argc + 2);
}
DBG_t("\n");
ASM(0xFF); ASM(0xD0); // [b] callq *%rax
X86_PRE(); ASM(0x89); ASM(0x45); ASM(RBP(op.a)); /* mov %rbp(A) %rax */
}
View
@@ -153,26 +153,30 @@ PN_F potion_jit_proto(Potion *P, PN proto) {
PN_SIZE pos;
PNJumps jmps[JUMPS_MAX]; size_t offs[JUMPS_MAX]; int jmpc = 0, jmpi = 0;
vPN(Proto) f = (struct PNProto *)proto;
int upc = PN_TUPLE_LEN(f->upvals);
long upc = PN_TUPLE_LEN(f->upvals);
PNAsm * volatile asmb = potion_asm_new(P);
u8 *fn;
PNTarget *target = &P->target;
target->setup(P, f, &asmb);
DBG_t("-- run-time --\n");
// calculate needed stackspace. nested protos may need more.
if (PN_TUPLE_LEN(f->protos) > 0) {
PN_SIZE j;
vPN(Tuple) tp = (vPN(Tuple)) potion_fwd(f->protos);
DBG_vt("; %d subprotos\n", tp->len);
for (j=0; j < tp->len; j++) {
PN proto2 = (PN)tp->set[j];
vPN(Proto) f2 = (struct PNProto *)proto2;
int p2args;
long p2args;
f2->arity = potion_sig_arity(P, f2->sig);
p2args = 3 + f2->arity;
if (f2->jit == NULL)
potion_jit_proto(P, proto2);
if (p2args > protoargs)
if (p2args > protoargs) {
DBG_vt("; extend stack from %ld to %ld\n", protoargs, p2args);
protoargs = p2args;
}
}
}
@@ -198,6 +202,7 @@ PN_F potion_jit_proto(Potion *P, PN proto) {
}
}
}
DBG_t("; %ld locals, %ld regs, %ld upc, sig=%s\n", argx, regs, upc, AS_STR(f->sig));
f->arity = argx;
// if CL passed in with upvals, load them

0 comments on commit 66853ae

Please sign in to comment.