From 33dfe2b5ccdee2a1ad94d5dac09c4b808b808380 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 26 Jun 2015 02:09:06 +0900 Subject: [PATCH] change pic_open interface --- extlib/benz/README.md | 4 ++-- extlib/benz/include/picrin.h | 4 +++- extlib/benz/state.c | 19 +++++++++++++++---- src/main.c | 3 ++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/extlib/benz/README.md b/extlib/benz/README.md index 81722f44..67c7a32d 100644 --- a/extlib/benz/README.md +++ b/extlib/benz/README.md @@ -19,7 +19,7 @@ main(int argc, char *argv[]) pic_state *pic; pic_value expr; - pic = pic_open(argc, argv, NULL); + pic = pic_open(pic_default_allocf, NULL); while (1) { printf("> "); @@ -61,7 +61,7 @@ pic_value factorial(pic_state *pic) { int main(int argc, char *argv[]) { - pic_state *pic = pic_open(argc, argv, NULL); + pic_state *pic = pic_open(pic_default_allocf, NULL); pic_defun(pic, "fact", factorial); /* define fact procedure */ diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index e19ced8b..7479ab60 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -74,6 +74,7 @@ struct pic_state { char **argv, **envp; pic_allocf allocf; + void *userdata; pic_checkpoint *cp; struct pic_cont *cc; @@ -169,9 +170,10 @@ void pic_gc_arena_restore(pic_state *, size_t); pic_gc_arena_restore(pic, ai); \ } while (0) -pic_state *pic_open(int argc, char *argv[], char **envp, pic_allocf); void *pic_default_allocf(void *, size_t); +pic_state *pic_open(pic_allocf, void *); void pic_close(pic_state *); +void pic_set_argv(pic_state *, int argc, char *argv[], char **envp); void pic_add_feature(pic_state *, const char *); diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 6c4fe6b8..7a419911 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -4,6 +4,14 @@ #include "picrin.h" +void +pic_set_argv(pic_state *pic, int argc, char *argv[], char **envp) +{ + pic->argc = argc; + pic->argv = argv; + pic->envp = envp; +} + void pic_add_feature(pic_state *pic, const char *feature) { @@ -152,7 +160,7 @@ pic_init_core(pic_state *pic) } pic_state * -pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) +pic_open(pic_allocf allocf, void *userdata) { struct pic_port *pic_make_standard_port(pic_state *, xFILE *, short); char t; @@ -169,6 +177,9 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) /* allocator */ pic->allocf = allocf; + /* user data */ + pic->userdata = userdata; + /* turn off GC */ pic->gc_enable = false; @@ -180,9 +191,9 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) pic->cp = NULL; /* command line */ - pic->argc = argc; - pic->argv = argv; - pic->envp = envp; + pic->argc = 0; + pic->argv = NULL; + pic->envp = NULL; /* prepare VM stack */ pic->stbase = pic->sp = allocf(NULL, PIC_STACK_SIZE * sizeof(pic_value)); diff --git a/src/main.c b/src/main.c index a4a330ef..5de70fdd 100644 --- a/src/main.c +++ b/src/main.c @@ -41,7 +41,8 @@ main(int argc, char *argv[], char **envp) struct pic_lib *PICRIN_MAIN; int status = 0; - pic = pic_open(argc, argv, envp, pic_default_allocf); + pic = pic_open(pic_default_allocf, NULL); + pic_set_argv(pic, argc, argv, envp); pic_init_picrin(pic);