change pic_open interface

This commit is contained in:
Yuichi Nishiwaki 2015-06-26 02:09:06 +09:00
parent 8587fe6dfc
commit 33dfe2b5cc
4 changed files with 22 additions and 8 deletions

View File

@ -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 */

View File

@ -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 *);

View File

@ -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));

View File

@ -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);