define stack operation macros POP and PUSH

This commit is contained in:
Yuichi Nishiwaki 2013-10-13 17:27:44 +09:00
parent f0541e0f6b
commit 8b859d4dbc
1 changed files with 14 additions and 11 deletions

View File

@ -181,6 +181,9 @@ pic_codegen(pic_state *pic, pic_value obj, struct pic_env *env)
#define JUMP break #define JUMP break
#define VM_LOOP_END } } #define VM_LOOP_END } }
#define PUSH(v) (*++sp = (v))
#define POP() (*sp--)
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)
{ {
@ -192,37 +195,37 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
VM_LOOP { VM_LOOP {
CASE(OP_PUSHNIL) { CASE(OP_PUSHNIL) {
*++sp = pic_nil_value(); PUSH(pic_nil_value());
NEXT; NEXT;
} }
CASE(OP_PUSHI) { CASE(OP_PUSHI) {
*++sp = pic_int_value(pc->u.i); PUSH(pic_int_value(pc->u.i));
NEXT; NEXT;
} }
CASE(OP_PUSHUNDEF) { CASE(OP_PUSHUNDEF) {
*++sp = pic_undef_value(); PUSH(pic_undef_value());
NEXT; NEXT;
} }
CASE(OP_GREF) { CASE(OP_GREF) {
*++sp = pc->u.gvar->cdr; PUSH(pc->u.gvar->cdr);
NEXT; NEXT;
} }
CASE(OP_GSET) { CASE(OP_GSET) {
pc->u.gvar->cdr = *sp--; pc->u.gvar->cdr = POP();
NEXT; NEXT;
} }
CASE(OP_CONS) { CASE(OP_CONS) {
pic_value a, b; pic_value a, b;
a = *sp--; a = POP();
b = *sp--; b = POP();
*++sp = pic_cons(pic, a, b); PUSH(pic_cons(pic, a, b));
NEXT; NEXT;
} }
CASE(OP_ADD) { CASE(OP_ADD) {
pic_value a, b; pic_value a, b;
a = *sp--; a = POP();
b = *sp--; b = POP();
*++sp = pic_int_value(pic_int(a) + pic_int(b)); PUSH(pic_int_value(pic_int(a) + pic_int(b)));
NEXT; NEXT;
} }
CASE(OP_STOP) { CASE(OP_STOP) {