From b3aaee6e3a3e673f03bb6187e19059bc18077ccb Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 1 Apr 2017 17:32:36 +0900 Subject: [PATCH] tear off contexts when invoking a continuation --- lib/cont.c | 2 ++ lib/state.h | 2 ++ lib/vm.h | 80 ++++++++++++++++++++++++++--------------------------- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/cont.c b/lib/cont.c index 17e02a34..d728aa43 100644 --- a/lib/cont.c +++ b/lib/cont.c @@ -44,6 +44,8 @@ pic_save_point(pic_state *pic, struct cont *cont, PIC_JMPBUF *jmp) void pic_load_point(pic_state *pic, struct cont *cont) { + pic_vm_tear_off(pic); + /* load runtime context */ pic->sp = pic->stbase + cont->sp_offset; pic->ci = pic->cibase + cont->ci_offset; diff --git a/lib/state.h b/lib/state.h index 2f97b256..b6ba0176 100644 --- a/lib/state.h +++ b/lib/state.h @@ -74,6 +74,8 @@ void pic_heap_close(pic_state *, struct heap *); pic_value pic_global_ref(pic_state *pic, pic_value uid); void pic_global_set(pic_state *pic, pic_value uid, pic_value value); +void pic_vm_tear_off(pic_state *pic); + #if defined(__cplusplus) } #endif diff --git a/lib/vm.h b/lib/vm.h index d8440d2e..6bc6835a 100644 --- a/lib/vm.h +++ b/lib/vm.h @@ -10,46 +10,46 @@ 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 + OP_NOP = 0, + OP_POP = 1, + OP_PUSHUNDEF = 2, + OP_PUSHNIL = 3, + OP_PUSHTRUE = 4, + OP_PUSHFALSE = 5, + OP_PUSHINT = 6, + OP_PUSHFLOAT = 7, + OP_PUSHCHAR = 8, + OP_PUSHEOF = 9, + OP_PUSHCONST = 10, + OP_GREF = 11, + OP_GSET = 12, + OP_LREF = 13, + OP_LSET = 14, + OP_CREF = 15, + OP_CSET = 16, + OP_JMP = 17, + OP_JMPIF = 18, + OP_NOT = 19, + OP_CALL = 20, + OP_TAILCALL = 21, + OP_RET = 22, + OP_LAMBDA = 23, + OP_CONS = 24, + OP_CAR = 25, + OP_CDR = 26, + OP_NILP = 27, + OP_SYMBOLP = 28, + OP_PAIRP = 29, + OP_ADD = 30, + OP_SUB = 31, + OP_MUL = 32, + OP_DIV = 33, + OP_EQ = 34, + OP_LT = 35, + OP_LE = 36, + OP_GT = 37, + OP_GE = 38, + OP_STOP = 39 }; #if defined(__cplusplus)