From 205ca796260849a0984ccf542de2b2b87cb52878 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 10 Feb 2016 01:38:05 +0900 Subject: [PATCH] remove pic->argc/argv/envp --- contrib/20.r7rs/src/system.c | 12 ++++-- extlib/benz/include/picrin.h | 4 -- extlib/benz/state.c | 71 +++++++++++++++--------------------- src/main.c | 9 ++++- 4 files changed, 45 insertions(+), 51 deletions(-) diff --git a/contrib/20.r7rs/src/system.c b/contrib/20.r7rs/src/system.c index 63f6f0a4..7cda6527 100644 --- a/contrib/20.r7rs/src/system.c +++ b/contrib/20.r7rs/src/system.c @@ -6,6 +6,10 @@ #include "picrin.h" +extern int picrin_argc; +extern char **picrin_argv; +extern char **picrin_envp; + static pic_value pic_system_cmdline(pic_state *pic) { @@ -14,10 +18,10 @@ pic_system_cmdline(pic_state *pic) pic_get_args(pic, ""); - for (i = 0; i < pic->argc; ++i) { + for (i = 0; i < picrin_argc; ++i) { size_t ai = pic_gc_arena_preserve(pic); - v = pic_cons(pic, pic_obj_value(pic_make_cstr(pic, pic->argv[i])), v); + v = pic_cons(pic, pic_obj_value(pic_make_cstr(pic, picrin_argv[i])), v); pic_gc_arena_restore(pic, ai); } @@ -96,11 +100,11 @@ pic_system_getenvs(pic_state *pic) pic_get_args(pic, ""); - if (! pic->envp) { + if (! picrin_envp) { return pic_nil_value(); } - for (envp = pic->envp; *envp; ++envp) { + for (envp = picrin_envp; *envp; ++envp) { pic_str *key, *val; int i; diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 47942e6d..6e44db8c 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -69,9 +69,6 @@ typedef struct { typedef void *(*pic_allocf)(void *, void *, size_t); struct pic_state { - int argc; - char **argv, **envp; - pic_allocf allocf; void *userdata; @@ -151,7 +148,6 @@ void pic_gc_arena_restore(pic_state *, size_t); void *pic_default_allocf(void *, 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 4dfb287c..6661a221 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -4,43 +4,6 @@ #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) -{ - pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features); -} - -void pic_init_bool(pic_state *); -void pic_init_pair(pic_state *); -void pic_init_port(pic_state *); -void pic_init_number(pic_state *); -void pic_init_proc(pic_state *); -void pic_init_symbol(pic_state *); -void pic_init_vector(pic_state *); -void pic_init_blob(pic_state *); -void pic_init_cont(pic_state *); -void pic_init_char(pic_state *); -void pic_init_error(pic_state *); -void pic_init_str(pic_state *); -void pic_init_var(pic_state *); -void pic_init_write(pic_state *); -void pic_init_read(pic_state *); -void pic_init_dict(pic_state *); -void pic_init_record(pic_state *); -void pic_init_eval(pic_state *); -void pic_init_lib(pic_state *); -void pic_init_reg(pic_state *); - -extern const char pic_boot[][80]; - static void pic_init_features(pic_state *pic) { @@ -99,6 +62,12 @@ pic_init_features(pic_state *pic) #endif } +void +pic_add_feature(pic_state *pic, const char *feature) +{ + pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features); +} + static pic_value pic_features(pic_state *pic) { @@ -120,6 +89,29 @@ pic_features(pic_state *pic) pic_put_identifier(pic, (pic_id *)sym, sym, pic->lib->env); \ } while (0) +void pic_init_bool(pic_state *); +void pic_init_pair(pic_state *); +void pic_init_port(pic_state *); +void pic_init_number(pic_state *); +void pic_init_proc(pic_state *); +void pic_init_symbol(pic_state *); +void pic_init_vector(pic_state *); +void pic_init_blob(pic_state *); +void pic_init_cont(pic_state *); +void pic_init_char(pic_state *); +void pic_init_error(pic_state *); +void pic_init_str(pic_state *); +void pic_init_var(pic_state *); +void pic_init_write(pic_state *); +void pic_init_read(pic_state *); +void pic_init_dict(pic_state *); +void pic_init_record(pic_state *); +void pic_init_eval(pic_state *); +void pic_init_lib(pic_state *); +void pic_init_reg(pic_state *); + +extern const char pic_boot[][80]; + static void pic_init_core(pic_state *pic) { @@ -223,11 +215,6 @@ pic_open(pic_allocf allocf, void *userdata) /* root block */ pic->cp = NULL; - /* command line */ - pic->argc = 0; - pic->argv = NULL; - pic->envp = NULL; - /* prepare VM stack */ pic->stbase = pic->sp = allocf(userdata, NULL, PIC_STACK_SIZE * sizeof(pic_value)); pic->stend = pic->stbase + PIC_STACK_SIZE; diff --git a/src/main.c b/src/main.c index 6eb5498f..fa67bdad 100644 --- a/src/main.c +++ b/src/main.c @@ -34,6 +34,10 @@ pic_init_picrin(pic_state *pic) pic_load_piclib(pic); } +int picrin_argc; +char **picrin_argv; +char **picrin_envp; + int main(int argc, char *argv[], char **envp) { @@ -42,7 +46,10 @@ main(int argc, char *argv[], char **envp) int status; pic = pic_open(pic_default_allocf, NULL); - pic_set_argv(pic, argc, argv, envp); + + picrin_argc = argc; + picrin_argv = argv; + picrin_envp = envp; pic_try { pic_init_picrin(pic);