do not pop sp in pic_get_args; OP_CALL takes care of stack unwinding

This commit is contained in:
Yuichi Nishiwaki 2013-10-16 09:19:43 +09:00
parent 910f370482
commit 36b455d9c2
1 changed files with 7 additions and 7 deletions

View File

@ -71,7 +71,7 @@ void
pic_get_args(pic_state *pic, const char *format, ...) pic_get_args(pic_state *pic, const char *format, ...)
{ {
char c; char c;
int i = 0; int i = -1;
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -82,8 +82,8 @@ pic_get_args(pic_state *pic, const char *format, ...)
pic_value *p; pic_value *p;
p = va_arg(ap, pic_value*); p = va_arg(ap, pic_value*);
*p = *--pic->sp; *p = pic->sp[i];
i++; i--;
} }
break; break;
case 'f': case 'f':
@ -91,8 +91,8 @@ pic_get_args(pic_state *pic, const char *format, ...)
double *f; double *f;
f = va_arg(ap, double *); f = va_arg(ap, double *);
*f = pic_float(*--pic->sp); *f = pic_float(pic->sp[i]);
i++; i--;
} }
break; break;
} }
@ -355,7 +355,6 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_value c; pic_value c;
struct pic_proc *proc; struct pic_proc *proc;
pic_callinfo *ci; pic_callinfo *ci;
int ai = pic_gc_arena_preserve(pic);
pic_gc_protect(pic, c = POP()); pic_gc_protect(pic, c = POP());
proc = pic_proc_ptr(c); proc = pic_proc_ptr(c);
@ -363,8 +362,9 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
ci->proc = proc; ci->proc = proc;
ci->argc = pc->u.i; ci->argc = pc->u.i;
PUSH(proc->u.cfunc(pic)); PUSH(proc->u.cfunc(pic));
pic_gc_arena_restore(pic, ai); pic->sp -= ci->argc;
POPCI(); POPCI();
pic_gc_arena_restore(pic, ai);
NEXT; NEXT;
} }
CASE(OP_CONS) { CASE(OP_CONS) {