From d49e25a5b44da52e121b749fce9b824cb9c8e29c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 21 Feb 2016 19:53:31 +0900 Subject: [PATCH] remove opcode.h --- extlib/benz/eval.c | 2 +- extlib/benz/include/picrin/private/irep.h | 42 ---- extlib/benz/include/picrin/private/opcode.h | 215 -------------------- extlib/benz/include/picrin/private/state.h | 2 +- extlib/benz/include/picrin/private/vm.h | 85 ++++++++ extlib/benz/proc.c | 8 +- 6 files changed, 92 insertions(+), 262 deletions(-) delete mode 100644 extlib/benz/include/picrin/private/irep.h delete mode 100644 extlib/benz/include/picrin/private/opcode.h create mode 100644 extlib/benz/include/picrin/private/vm.h diff --git a/extlib/benz/eval.c b/extlib/benz/eval.c index 148fbc04..f1b334c7 100644 --- a/extlib/benz/eval.c +++ b/extlib/benz/eval.c @@ -5,7 +5,7 @@ #include "picrin.h" #include "picrin/extra.h" #include "picrin/private/object.h" -#include "picrin/private/opcode.h" +#include "picrin/private/vm.h" #include "picrin/private/state.h" #define EQ(sym, lit) (strcmp(pic_str(pic, pic_sym_name(pic, sym)), lit) == 0) diff --git a/extlib/benz/include/picrin/private/irep.h b/extlib/benz/include/picrin/private/irep.h deleted file mode 100644 index fff6c249..00000000 --- a/extlib/benz/include/picrin/private/irep.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_IREP_H -#define PICRIN_IREP_H - -#if defined(__cplusplus) -extern "C" { -#endif - -typedef struct { - int insn; - int a; - int b; -} pic_code; - -struct pic_list { - struct pic_list *prev, *next; -}; - -struct pic_irep { - struct pic_list list; - unsigned refc; - int argc, localc, capturec; - bool varg; - pic_code *code; - struct pic_irep **irep; - int *ints; - double *nums; - struct pic_object **pool; - size_t ncode, nirep, nints, nnums, npool; -}; - -void pic_irep_incref(pic_state *, struct pic_irep *); -void pic_irep_decref(pic_state *, struct pic_irep *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/extlib/benz/include/picrin/private/opcode.h b/extlib/benz/include/picrin/private/opcode.h deleted file mode 100644 index e27a4a12..00000000 --- a/extlib/benz/include/picrin/private/opcode.h +++ /dev/null @@ -1,215 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_OPCODE_H -#define PICRIN_OPCODE_H - -#if defined(__cplusplus) -extern "C" { -#endif - -enum pic_opcode { - OP_NOP, - OP_POP, - OP_PUSHUNDEF, - OP_PUSHNIL, - OP_PUSHTRUE, - OP_PUSHFALSE, - OP_PUSHINT, - OP_PUSHFLOAT, - OP_PUSHCHAR, - OP_PUSHEOF, - OP_PUSHCONST, - OP_GREF, - OP_GSET, - OP_LREF, - OP_LSET, - OP_CREF, - OP_CSET, - OP_JMP, - OP_JMPIF, - OP_NOT, - OP_CALL, - OP_TAILCALL, - OP_RET, - OP_LAMBDA, - OP_CONS, - OP_CAR, - OP_CDR, - OP_NILP, - OP_SYMBOLP, - OP_PAIRP, - OP_ADD, - OP_SUB, - OP_MUL, - OP_DIV, - OP_EQ, - OP_LT, - OP_LE, - OP_GT, - OP_GE, - OP_STOP -}; - -#define PIC_INIT_CODE_I(code, op, ival) do { \ - code.insn = op; \ - code.a = ival; \ - } while (0) - -#if DEBUG - -PIC_INLINE void -pic_dump_code(pic_code c) -{ - switch (c.insn) { - case OP_NOP: - puts("OP_NOP"); - break; - case OP_POP: - puts("OP_POP"); - break; - case OP_PUSHUNDEF: - puts("OP_PUSHUNDEF"); - break; - case OP_PUSHNIL: - puts("OP_PUSHNIL"); - break; - case OP_PUSHTRUE: - puts("OP_PUSHTRUE"); - break; - case OP_PUSHFALSE: - puts("OP_PUSHFALSE"); - break; - case OP_PUSHINT: - printf("OP_PUSHINT\t%d\n", c.a); - break; - case OP_PUSHFLOAT: - printf("OP_PUSHFLAOT\t%d\n", c.a); - break; - case OP_PUSHCHAR: - printf("OP_PUSHCHAR\t%c\n", c.a); - break; - case OP_PUSHEOF: - puts("OP_PUSHEOF"); - break; - case OP_PUSHCONST: - printf("OP_PUSHCONST\t%d\n", c.a); - break; - case OP_GREF: - printf("OP_GREF\t%i\n", c.a); - break; - case OP_GSET: - printf("OP_GSET\t%i\n", c.a); - break; - case OP_LREF: - printf("OP_LREF\t%d\n", c.a); - break; - case OP_LSET: - printf("OP_LSET\t%d\n", c.a); - break; - case OP_CREF: - printf("OP_CREF\t%d\t%d\n", c.a, c.b); - break; - case OP_CSET: - printf("OP_CSET\t%d\t%d\n", c.a, c.b); - break; - case OP_JMP: - printf("OP_JMP\t%x\n", c.a); - break; - case OP_JMPIF: - printf("OP_JMPIF\t%x\n", c.a); - break; - case OP_NOT: - puts("OP_NOT"); - break; - case OP_CALL: - printf("OP_CALL\t%d\n", c.a); - break; - case OP_TAILCALL: - printf("OP_TAILCALL\t%d\n", c.a); - break; - case OP_RET: - puts("OP_RET"); - break; - case OP_LAMBDA: - printf("OP_LAMBDA\t%d\n", c.a); - break; - case OP_CONS: - puts("OP_CONS"); - break; - case OP_CAR: - puts("OP_CAR"); - break; - case OP_NILP: - puts("OP_NILP"); - break; - case OP_SYMBOLP: - puts("OP_SYMBOLP"); - break; - case OP_PAIRP: - puts("OP_PAIRP"); - break; - case OP_CDR: - puts("OP_CDR"); - break; - case OP_ADD: - puts("OP_ADD"); - break; - case OP_SUB: - puts("OP_SUB"); - break; - case OP_MUL: - puts("OP_MUL"); - break; - case OP_DIV: - puts("OP_DIV"); - break; - case OP_EQ: - puts("OP_EQ"); - break; - case OP_LT: - puts("OP_LT"); - break; - case OP_LE: - puts("OP_LE"); - break; - case OP_GT: - puts("OP_GT"); - break; - case OP_GE: - puts("OP_GE"); - break; - case OP_STOP: - puts("OP_STOP"); - break; - } -} - -PIC_INLINE void -pic_dump_irep(struct pic_irep *irep) -{ - size_t i; - - printf("## irep %p\n", (void *)irep); - printf("# argc = %d\n", irep->argc); - printf("# localc = %d\n", irep->localc); - printf("# capturec = %d\n", irep->capturec); - - for (i = 0; i < irep->ncode; ++i) { - printf("%02x: ", i); - pic_dump_code(irep->u.s.code[i]); - } - - for (i = 0; i < irep->nirep; ++i) { - pic_dump_irep(irep->u.s.irep[i].i); - } -} - -#endif - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/extlib/benz/include/picrin/private/state.h b/extlib/benz/include/picrin/private/state.h index a2b859a0..cf11b4d1 100644 --- a/extlib/benz/include/picrin/private/state.h +++ b/extlib/benz/include/picrin/private/state.h @@ -12,7 +12,7 @@ extern "C" { #include "picrin/private/khash.h" #include "picrin/private/file.h" -#include "picrin/private/irep.h" +#include "picrin/private/vm.h" #include "picrin/private/gc.h" struct pic_lib { diff --git a/extlib/benz/include/picrin/private/vm.h b/extlib/benz/include/picrin/private/vm.h new file mode 100644 index 00000000..068b7299 --- /dev/null +++ b/extlib/benz/include/picrin/private/vm.h @@ -0,0 +1,85 @@ +/** + * See Copyright Notice in picrin.h + */ + +#ifndef PICRIN_VM_H +#define PICRIN_VM_H + +#if defined(__cplusplus) +extern "C" { +#endif + +enum { + OP_NOP, + OP_POP, + OP_PUSHUNDEF, + OP_PUSHNIL, + OP_PUSHTRUE, + OP_PUSHFALSE, + OP_PUSHINT, + OP_PUSHFLOAT, + OP_PUSHCHAR, + OP_PUSHEOF, + OP_PUSHCONST, + OP_GREF, + OP_GSET, + OP_LREF, + OP_LSET, + OP_CREF, + OP_CSET, + OP_JMP, + OP_JMPIF, + OP_NOT, + OP_CALL, + OP_TAILCALL, + OP_RET, + OP_LAMBDA, + OP_CONS, + OP_CAR, + OP_CDR, + OP_NILP, + OP_SYMBOLP, + OP_PAIRP, + OP_ADD, + OP_SUB, + OP_MUL, + OP_DIV, + OP_EQ, + OP_LT, + OP_LE, + OP_GT, + OP_GE, + OP_STOP +}; + +struct code { + int insn; + int a; + int b; +} + +struct list_head { + struct list_head *prev, *next; +}; + +struct irep { + struct list_head list; + unsigned refc; + int argc, localc, capturec; + bool varg; + struct code *code; + struct irep **irep; + int *ints; + double *nums; + struct object **pool; + size_t ncode, nirep, nints, nnums, npool; +}; + +void pic_irep_incref(pic_state *, struct irep *); +void pic_irep_decref(pic_state *, struct irep *); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index 3028bc67..59c44fe7 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -5,7 +5,7 @@ #include "picrin.h" #include "picrin/extra.h" #include "picrin/private/object.h" -#include "picrin/private/opcode.h" +#include "picrin/private/vm.h" #include "picrin/private/state.h" #define MIN(x,y) ((x) < (y) ? (x) : (y)) @@ -856,8 +856,10 @@ pic_applyk(pic_state *pic, pic_value proc, int argc, pic_value *args) pic_callinfo *ci; int i; - PIC_INIT_CODE_I(pic->iseq[0], OP_NOP, 0); - PIC_INIT_CODE_I(pic->iseq[1], OP_TAILCALL, -1); + pic->iseq[0].insn = OP_NOP; + pic->iseq[0].a = 0; + pic->iseq[1].insn = OP_TAILCALL; + pic->iseq[1].a = -1; *pic->sp++ = proc;