adjust stack pointer to the next to the initial position after calling function
This commit is contained in:
parent
213177eb10
commit
85a766a242
18
src/cont.c
18
src/cont.c
|
@ -181,13 +181,13 @@ pic_values(pic_state *pic, size_t c, ...)
|
|||
va_start(ap, c);
|
||||
|
||||
for (i = 0; i < c; ++i) {
|
||||
*pic->sp++ = va_arg(ap, pic_value);
|
||||
pic->sp[i] = va_arg(ap, pic_value);
|
||||
}
|
||||
pic->ci->retc = c;
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return c == 0 ? pic_none_value() : pic->sp[-c];
|
||||
return c == 0 ? pic_none_value() : pic->sp[0];
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
@ -196,26 +196,26 @@ pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv)
|
|||
size_t i;
|
||||
|
||||
for (i = 0; i < argc; ++i) {
|
||||
*pic->sp++ = argv[i];
|
||||
pic->sp[i] = argv[i];
|
||||
}
|
||||
pic->ci->retc = argc;
|
||||
|
||||
return argc == 0 ? pic_none_value() : pic->sp[-argc];
|
||||
return argc == 0 ? pic_none_value() : pic->sp[0];
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_values_by_list(pic_state *pic, pic_value list)
|
||||
{
|
||||
pic_value v;
|
||||
size_t c;
|
||||
size_t i;
|
||||
|
||||
c = pic_length(pic, list);
|
||||
i = 0;
|
||||
pic_for_each (v, list) {
|
||||
*pic->sp++ = v;
|
||||
pic->sp[i++] = v;
|
||||
}
|
||||
pic->ci->retc = c;
|
||||
pic->ci->retc = i;
|
||||
|
||||
return pic_nil_p(list) ? pic_none_value() : pic->sp[-c];
|
||||
return pic_nil_p(list) ? pic_none_value() : pic->sp[0];
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
11
src/vm.c
11
src/vm.c
|
@ -572,10 +572,8 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
if (pic_proc_cfunc_p(x)) {
|
||||
|
||||
/* invoke! */
|
||||
v = proc->u.cfunc(pic);
|
||||
if (ci->retc == 1 && pic->sp == ci->fp + c.u.i) {
|
||||
PUSH(v);
|
||||
}
|
||||
pic->sp[0] = proc->u.cfunc(pic);
|
||||
pic->sp += ci->retc;
|
||||
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
goto L_RET;
|
||||
|
@ -656,11 +654,14 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
L_RET:
|
||||
retc = pic->ci->retc;
|
||||
retv = pic->sp - retc;
|
||||
if (retc == 0) {
|
||||
pic->ci->fp[0] = retv[0]; /* copy at least once */
|
||||
}
|
||||
for (i = 0; i < retc; ++i) {
|
||||
pic->ci->fp[i] = retv[i];
|
||||
}
|
||||
ci = POPCI();
|
||||
pic->sp = ci->fp + retc;
|
||||
pic->sp = ci->fp + 1; /* advance only one! */
|
||||
pic->ip = ci->ip;
|
||||
|
||||
NEXT;
|
||||
|
|
Loading…
Reference in New Issue