change the stack layout: to hold proc object on the stack when procedure
call is invoked
This commit is contained in:
parent
1646de5e8d
commit
c92a672e01
|
@ -10,7 +10,6 @@
|
||||||
struct pic_code;
|
struct pic_code;
|
||||||
|
|
||||||
typedef struct pic_callinfo {
|
typedef struct pic_callinfo {
|
||||||
struct pic_proc *proc;
|
|
||||||
int argc;
|
int argc;
|
||||||
struct pic_code *pc;
|
struct pic_code *pc;
|
||||||
pic_value *sp;
|
pic_value *sp;
|
||||||
|
|
6
src/gc.c
6
src/gc.c
|
@ -177,11 +177,7 @@ gc_mark_phase(pic_state *pic)
|
||||||
for (stack = pic->stbase; stack != pic->sp; ++stack) {
|
for (stack = pic->stbase; stack != pic->sp; ++stack) {
|
||||||
gc_mark(pic, *stack);
|
gc_mark(pic, *stack);
|
||||||
}
|
}
|
||||||
|
gc_mark(pic, *stack);
|
||||||
/* callinfo */
|
|
||||||
for (ci = pic->cibase; ci != pic->ci; ++ci) {
|
|
||||||
gc_mark_object(pic, (struct pic_object *)ci->proc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* arena */
|
/* arena */
|
||||||
for (i = 0; i < pic->arena_idx; ++i) {
|
for (i = 0; i < pic->arena_idx; ++i) {
|
||||||
|
|
27
src/vm.c
27
src/vm.c
|
@ -406,7 +406,7 @@ pic_gen_call(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_en
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
irep->code[irep->clen].insn = OP_CALL;
|
irep->code[irep->clen].insn = OP_CALL;
|
||||||
irep->code[irep->clen].u.i = i - 1;
|
irep->code[irep->clen].u.i = i;
|
||||||
irep->clen++;
|
irep->clen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,17 +476,16 @@ pic_codegen(pic_state *pic, pic_value obj, struct pic_env *env)
|
||||||
# define VM_LOOP_END } }
|
# define VM_LOOP_END } }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PUSH(v) (*pic->sp++ = (v))
|
#define PUSH(v) (*++pic->sp = (v))
|
||||||
#define POP() (*--pic->sp)
|
#define POP() (*pic->sp--)
|
||||||
|
|
||||||
#define PUSHCI() (pic->ci++)
|
#define PUSHCI() (++pic->ci)
|
||||||
#define POPCI() (--pic->ci)
|
#define POPCI() (pic->ci--)
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
{
|
{
|
||||||
struct pic_code *pc;
|
struct pic_code *pc;
|
||||||
pic_callinfo *ci;
|
|
||||||
pic_value val;
|
pic_value val;
|
||||||
int ai = pic_gc_arena_preserve(pic);
|
int ai = pic_gc_arena_preserve(pic);
|
||||||
|
|
||||||
|
@ -501,9 +500,11 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
|
|
||||||
pc = proc->u.irep->code;
|
pc = proc->u.irep->code;
|
||||||
|
|
||||||
ci = PUSHCI();
|
/* adjust call frame */
|
||||||
ci->proc = proc;
|
pic->sp[0] = pic_obj_value(proc);
|
||||||
ci->argc = 0;
|
pic->ci->argc = 0;
|
||||||
|
pic->ci->pc = NULL;
|
||||||
|
pic->ci->sp = NULL;
|
||||||
|
|
||||||
VM_LOOP {
|
VM_LOOP {
|
||||||
CASE(OP_PUSHNIL) {
|
CASE(OP_PUSHNIL) {
|
||||||
|
@ -531,7 +532,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
NEXT;
|
NEXT;
|
||||||
}
|
}
|
||||||
CASE(OP_LREF) {
|
CASE(OP_LREF) {
|
||||||
PUSH(pic->ci[-1].sp[pc->u.i]);
|
PUSH(pic->ci->sp[pc->u.i]);
|
||||||
NEXT;
|
NEXT;
|
||||||
}
|
}
|
||||||
CASE(OP_JMP) {
|
CASE(OP_JMP) {
|
||||||
|
@ -550,12 +551,12 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
}
|
}
|
||||||
CASE(OP_CALL) {
|
CASE(OP_CALL) {
|
||||||
pic_value c, v;
|
pic_value c, v;
|
||||||
|
pic_callinfo *ci;
|
||||||
struct pic_proc *proc;
|
struct pic_proc *proc;
|
||||||
|
|
||||||
pic_gc_protect(pic, c = POP());
|
c = pic->sp[0];
|
||||||
proc = pic_proc_ptr(c);
|
proc = pic_proc_ptr(c);
|
||||||
ci = PUSHCI();
|
ci = PUSHCI();
|
||||||
ci->proc = proc;
|
|
||||||
ci->argc = pc->u.i;
|
ci->argc = pc->u.i;
|
||||||
ci->pc = pc;
|
ci->pc = pc;
|
||||||
ci->sp = pic->sp;
|
ci->sp = pic->sp;
|
||||||
|
@ -575,6 +576,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
}
|
}
|
||||||
CASE(OP_RET) {
|
CASE(OP_RET) {
|
||||||
pic_value v;
|
pic_value v;
|
||||||
|
pic_callinfo *ci;
|
||||||
|
|
||||||
v = POP();
|
v = POP();
|
||||||
pic->sp -= ci->argc;
|
pic->sp -= ci->argc;
|
||||||
|
@ -636,7 +638,6 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
} VM_LOOP_END;
|
} VM_LOOP_END;
|
||||||
|
|
||||||
STOP:
|
STOP:
|
||||||
POPCI();
|
|
||||||
val = POP();
|
val = POP();
|
||||||
|
|
||||||
#if GC_DEBUG
|
#if GC_DEBUG
|
||||||
|
|
Loading…
Reference in New Issue