pic->cxt->ai -> pic->ai

This commit is contained in:
Yuichi Nishiwaki 2017-04-16 05:20:55 +09:00
parent 22d0a334ff
commit f4de6ee57e
7 changed files with 19 additions and 18 deletions

View File

@ -39,8 +39,6 @@ pic_prepare_try(pic_state *pic)
{ {
struct context *cxt = pic_alloca(pic, sizeof(struct context)); struct context *cxt = pic_alloca(pic, sizeof(struct context));
cxt->ai = pic->cxt->ai;
pic->cxt->ai--; /* cxt should be freed after this try ends */
cxt->pc = NULL; cxt->pc = NULL;
cxt->fp = NULL; cxt->fp = NULL;
cxt->sp = NULL; cxt->sp = NULL;

View File

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include "picrin.h" #include "picrin.h"
#include "../object.h"
#if PIC_USE_FILE #if PIC_USE_FILE

View File

@ -144,11 +144,11 @@ pic_free(pic_state *pic, void *ptr)
static void static void
gc_protect(pic_state *pic, struct object *obj) gc_protect(pic_state *pic, struct object *obj)
{ {
if (pic->cxt->ai >= pic->arena_size) { if (pic->ai >= pic->arena_size) {
pic->arena_size = pic->arena_size * 2 + 1; pic->arena_size = pic->arena_size * 2 + 1;
pic->arena = pic_realloc(pic, pic->arena, sizeof(struct object *) * pic->arena_size); pic->arena = pic_realloc(pic, pic->arena, sizeof(struct object *) * pic->arena_size);
} }
pic->arena[pic->cxt->ai++] = obj; pic->arena[pic->ai++] = obj;
} }
pic_value pic_value
@ -165,13 +165,13 @@ pic_protect(pic_state *pic, pic_value v)
size_t size_t
pic_enter(pic_state *pic) pic_enter(pic_state *pic)
{ {
return pic->cxt->ai; return pic->ai;
} }
void void
pic_leave(pic_state *pic, size_t state) pic_leave(pic_state *pic, size_t state)
{ {
pic->cxt->ai = state; pic->ai = state;
} }
void * void *
@ -332,7 +332,7 @@ gc_mark_phase(pic_state *pic)
} }
/* arena */ /* arena */
for (j = 0; j < pic->cxt->ai; ++j) { for (j = 0; j < pic->ai; ++j) {
gc_mark_object(pic, (struct object *)pic->arena[j]); gc_mark_object(pic, (struct object *)pic->arena[j]);
} }

View File

@ -297,13 +297,14 @@ pic_value pic_raise_continuable(pic_state *pic, pic_value err);
PIC_NORETURN void pic_raise(pic_state *, pic_value v); PIC_NORETURN void pic_raise(pic_state *, pic_value v);
PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...); PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...);
#define pic_try pic_try_(PIC_GENSYM(cont), PIC_GENSYM(jmp)) #define pic_try pic_try_(PIC_GENSYM(jmp))
#define pic_try_(cont, jmp) \ #define pic_try_(jmp) \
do { \ do { \
extern PIC_JMPBUF *pic_prepare_try(pic_state *); \ extern PIC_JMPBUF *pic_prepare_try(pic_state *); \
extern void pic_enter_try(pic_state *); \ extern void pic_enter_try(pic_state *); \
extern void pic_exit_try(pic_state *); \ extern void pic_exit_try(pic_state *); \
extern pic_value pic_abort_try(pic_state *); \ extern pic_value pic_abort_try(pic_state *); \
size_t pic_try_ai_ = pic_enter(pic); \
PIC_JMPBUF *jmp = pic_prepare_try(pic); \ PIC_JMPBUF *jmp = pic_prepare_try(pic); \
if (PIC_SETJMP(*jmp) == 0) { \ if (PIC_SETJMP(*jmp) == 0) { \
pic_enter_try(pic); pic_enter_try(pic);
@ -312,6 +313,8 @@ PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...);
pic_exit_try(pic); \ pic_exit_try(pic); \
} else { \ } else { \
e = pic_abort_try(pic); \ e = pic_abort_try(pic); \
pic_leave(pic, pic_try_ai_); \
pic_protect(pic, e); \
goto label; \ goto label; \
} \ } \
} while (0); \ } while (0); \

View File

@ -360,7 +360,7 @@ pic_value
pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv) pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
{ {
struct context cxt; struct context cxt;
size_t arena_base = pic->cxt->ai; size_t arena_base = pic->ai;
#define MKCALL(argc) (cxt.tmpcode[0] = OP_CALL, cxt.tmpcode[1] = (argc), cxt.tmpcode) #define MKCALL(argc) (cxt.tmpcode[0] = OP_CALL, cxt.tmpcode[1] = (argc), cxt.tmpcode)
@ -376,15 +376,14 @@ pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
} }
cxt.fp = NULL; cxt.fp = NULL;
cxt.irep = NULL; cxt.irep = NULL;
cxt.ai = pic->cxt->ai;
cxt.prev = pic->cxt; cxt.prev = pic->cxt;
pic->cxt = &cxt; pic->cxt = &cxt;
if (PIC_SETJMP(cxt.jmp) != 0) { #define SAVE (pic->ai = arena_base)
/* pass */
}
#define SAVE (cxt.ai = arena_base) if (PIC_SETJMP(cxt.jmp) != 0) {
SAVE;
}
#define A (cxt.pc[1]) #define A (cxt.pc[1])
#define B (cxt.pc[2]) #define B (cxt.pc[2])

View File

@ -171,7 +171,6 @@ pic_open(pic_allocf allocf, void *userdata)
pic->userdata = userdata; pic->userdata = userdata;
/* context */ /* context */
pic->default_cxt.ai = 0;
pic->default_cxt.pc = NULL; pic->default_cxt.pc = NULL;
pic->default_cxt.fp = NULL; pic->default_cxt.fp = NULL;
pic->default_cxt.sp = NULL; pic->default_cxt.sp = NULL;
@ -182,6 +181,7 @@ pic_open(pic_allocf allocf, void *userdata)
/* arena */ /* arena */
pic->arena = allocf(userdata, NULL, PIC_ARENA_SIZE * sizeof(struct object *)); pic->arena = allocf(userdata, NULL, PIC_ARENA_SIZE * sizeof(struct object *));
pic->arena_size = PIC_ARENA_SIZE; pic->arena_size = PIC_ARENA_SIZE;
pic->ai = 0;
if (! pic->arena) { if (! pic->arena) {
goto EXIT_ARENA; goto EXIT_ARENA;
@ -250,7 +250,7 @@ pic_close(pic_state *pic)
/* clear out root objects */ /* clear out root objects */
pic->cxt = &pic->default_cxt; pic->cxt = &pic->default_cxt;
pic->cxt->ai = 0; pic->ai = 0;
pic->halt = pic_invalid_value(pic); pic->halt = pic_invalid_value(pic);
pic->globals = pic_invalid_value(pic); pic->globals = pic_invalid_value(pic);
pic->features = pic_invalid_value(pic); pic->features = pic_invalid_value(pic);

View File

@ -16,7 +16,6 @@ KHASH_DECLARE(oblist, struct string *, struct symbol *)
struct context { struct context {
PIC_JMPBUF jmp; PIC_JMPBUF jmp;
size_t ai;
/* vm */ /* vm */
const code_t *pc; const code_t *pc;
@ -35,6 +34,7 @@ struct pic_state {
struct context *cxt, default_cxt; struct context *cxt, default_cxt;
size_t ai;
pic_value dyn_env; pic_value dyn_env;
pic_value features; /* list of symbols */ pic_value features; /* list of symbols */