remove pic->argc/argv/envp

This commit is contained in:
Yuichi Nishiwaki 2016-02-10 01:38:05 +09:00
parent f91678aa82
commit 205ca79626
4 changed files with 45 additions and 51 deletions

View File

@ -6,6 +6,10 @@
#include "picrin.h" #include "picrin.h"
extern int picrin_argc;
extern char **picrin_argv;
extern char **picrin_envp;
static pic_value static pic_value
pic_system_cmdline(pic_state *pic) pic_system_cmdline(pic_state *pic)
{ {
@ -14,10 +18,10 @@ pic_system_cmdline(pic_state *pic)
pic_get_args(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); 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); pic_gc_arena_restore(pic, ai);
} }
@ -96,11 +100,11 @@ pic_system_getenvs(pic_state *pic)
pic_get_args(pic, ""); pic_get_args(pic, "");
if (! pic->envp) { if (! picrin_envp) {
return pic_nil_value(); return pic_nil_value();
} }
for (envp = pic->envp; *envp; ++envp) { for (envp = picrin_envp; *envp; ++envp) {
pic_str *key, *val; pic_str *key, *val;
int i; int i;

View File

@ -69,9 +69,6 @@ typedef struct {
typedef void *(*pic_allocf)(void *, void *, size_t); typedef void *(*pic_allocf)(void *, void *, size_t);
struct pic_state { struct pic_state {
int argc;
char **argv, **envp;
pic_allocf allocf; pic_allocf allocf;
void *userdata; void *userdata;
@ -151,7 +148,6 @@ void pic_gc_arena_restore(pic_state *, size_t);
void *pic_default_allocf(void *, void *, size_t); void *pic_default_allocf(void *, void *, size_t);
pic_state *pic_open(pic_allocf, void *); pic_state *pic_open(pic_allocf, void *);
void pic_close(pic_state *); 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 *); void pic_add_feature(pic_state *, const char *);

View File

@ -4,43 +4,6 @@
#include "picrin.h" #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 static void
pic_init_features(pic_state *pic) pic_init_features(pic_state *pic)
{ {
@ -99,6 +62,12 @@ pic_init_features(pic_state *pic)
#endif #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 static pic_value
pic_features(pic_state *pic) 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); \ pic_put_identifier(pic, (pic_id *)sym, sym, pic->lib->env); \
} while (0) } 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 static void
pic_init_core(pic_state *pic) pic_init_core(pic_state *pic)
{ {
@ -223,11 +215,6 @@ pic_open(pic_allocf allocf, void *userdata)
/* root block */ /* root block */
pic->cp = NULL; pic->cp = NULL;
/* command line */
pic->argc = 0;
pic->argv = NULL;
pic->envp = NULL;
/* prepare VM stack */ /* prepare VM stack */
pic->stbase = pic->sp = allocf(userdata, NULL, PIC_STACK_SIZE * sizeof(pic_value)); pic->stbase = pic->sp = allocf(userdata, NULL, PIC_STACK_SIZE * sizeof(pic_value));
pic->stend = pic->stbase + PIC_STACK_SIZE; pic->stend = pic->stbase + PIC_STACK_SIZE;

View File

@ -34,6 +34,10 @@ pic_init_picrin(pic_state *pic)
pic_load_piclib(pic); pic_load_piclib(pic);
} }
int picrin_argc;
char **picrin_argv;
char **picrin_envp;
int int
main(int argc, char *argv[], char **envp) main(int argc, char *argv[], char **envp)
{ {
@ -42,7 +46,10 @@ main(int argc, char *argv[], char **envp)
int status; int status;
pic = pic_open(pic_default_allocf, NULL); 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_try {
pic_init_picrin(pic); pic_init_picrin(pic);