let OP_RET take an argument
This commit is contained in:
parent
16639a1764
commit
0f75a1b7cb
|
@ -1312,8 +1312,14 @@ codegen(codegen_state *state, pic_value obj)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (sym == state->sRETURN) {
|
else if (sym == state->sRETURN) {
|
||||||
codegen(state, pic_list_ref(pic, obj, 1));
|
int len = pic_length(pic, obj);
|
||||||
|
pic_value elt;
|
||||||
|
|
||||||
|
pic_for_each (elt, pic_cdr(pic, obj)) {
|
||||||
|
codegen(state, elt);
|
||||||
|
}
|
||||||
cxt->code[cxt->clen].insn = OP_RET;
|
cxt->code[cxt->clen].insn = OP_RET;
|
||||||
|
cxt->code[cxt->clen].u.i = len - 1;
|
||||||
cxt->clen++;
|
cxt->clen++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1581,7 +1587,7 @@ print_code(pic_state *pic, struct pic_code c)
|
||||||
printf("OP_TAILCALL\t%d\n", c.u.i);
|
printf("OP_TAILCALL\t%d\n", c.u.i);
|
||||||
break;
|
break;
|
||||||
case OP_RET:
|
case OP_RET:
|
||||||
puts("OP_RET");
|
printf("OP_RET\t%d\n", c.u.i);
|
||||||
break;
|
break;
|
||||||
case OP_LAMBDA:
|
case OP_LAMBDA:
|
||||||
printf("OP_LAMBDA\t%d\n", c.u.i);
|
printf("OP_LAMBDA\t%d\n", c.u.i);
|
||||||
|
|
24
src/vm.c
24
src/vm.c
|
@ -624,20 +624,23 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
||||||
CASE(OP_TAILCALL) {
|
CASE(OP_TAILCALL) {
|
||||||
int i, argc;
|
int i, argc;
|
||||||
pic_value *argv;
|
pic_value *argv;
|
||||||
|
pic_callinfo *ci;
|
||||||
|
|
||||||
argc = c.u.i;
|
argc = c.u.i;
|
||||||
argv = pic->sp - argc;
|
argv = pic->sp - argc;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic->ci->fp[i] = argv[i];
|
pic->ci->fp[i] = argv[i];
|
||||||
}
|
}
|
||||||
pic->sp = pic->ci->fp + argc;
|
ci = POPCI();
|
||||||
pic->ip = POPCI()->ip;
|
pic->sp = ci->fp + argc;
|
||||||
|
pic->ip = ci->ip;
|
||||||
|
|
||||||
/* c is not changed */
|
/* c is not changed */
|
||||||
goto L_CALL;
|
goto L_CALL;
|
||||||
}
|
}
|
||||||
CASE(OP_RET) {
|
CASE(OP_RET) {
|
||||||
pic_value v;
|
int i, retc;
|
||||||
|
pic_value *retv;
|
||||||
pic_callinfo *ci;
|
pic_callinfo *ci;
|
||||||
|
|
||||||
if (pic->err) {
|
if (pic->err) {
|
||||||
|
@ -645,13 +648,16 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
||||||
L_RAISE:
|
L_RAISE:
|
||||||
goto L_STOP;
|
goto L_STOP;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
v = POP();
|
retc = c.u.i;
|
||||||
ci = POPCI();
|
retv = pic->sp - retc;
|
||||||
pic->ip = ci->ip;
|
for (i = 0; i < retc; ++i) {
|
||||||
pic->sp = ci->fp;
|
pic->ci->fp[i] = retv[i];
|
||||||
PUSH(v);
|
|
||||||
}
|
}
|
||||||
|
ci = POPCI();
|
||||||
|
pic->sp = ci->fp + retc;
|
||||||
|
pic->ip = ci->ip;
|
||||||
|
|
||||||
NEXT;
|
NEXT;
|
||||||
}
|
}
|
||||||
CASE(OP_LAMBDA) {
|
CASE(OP_LAMBDA) {
|
||||||
|
|
Loading…
Reference in New Issue