change pic_open interface
This commit is contained in:
parent
8587fe6dfc
commit
33dfe2b5cc
|
@ -19,7 +19,7 @@ main(int argc, char *argv[])
|
||||||
pic_state *pic;
|
pic_state *pic;
|
||||||
pic_value expr;
|
pic_value expr;
|
||||||
|
|
||||||
pic = pic_open(argc, argv, NULL);
|
pic = pic_open(pic_default_allocf, NULL);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("> ");
|
printf("> ");
|
||||||
|
@ -61,7 +61,7 @@ pic_value factorial(pic_state *pic) {
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
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 */
|
pic_defun(pic, "fact", factorial); /* define fact procedure */
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ struct pic_state {
|
||||||
char **argv, **envp;
|
char **argv, **envp;
|
||||||
|
|
||||||
pic_allocf allocf;
|
pic_allocf allocf;
|
||||||
|
void *userdata;
|
||||||
|
|
||||||
pic_checkpoint *cp;
|
pic_checkpoint *cp;
|
||||||
struct pic_cont *cc;
|
struct pic_cont *cc;
|
||||||
|
@ -169,9 +170,10 @@ void pic_gc_arena_restore(pic_state *, size_t);
|
||||||
pic_gc_arena_restore(pic, ai); \
|
pic_gc_arena_restore(pic, ai); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
pic_state *pic_open(int argc, char *argv[], char **envp, pic_allocf);
|
|
||||||
void *pic_default_allocf(void *, size_t);
|
void *pic_default_allocf(void *, size_t);
|
||||||
|
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 *);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,14 @@
|
||||||
|
|
||||||
#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
|
void
|
||||||
pic_add_feature(pic_state *pic, const char *feature)
|
pic_add_feature(pic_state *pic, const char *feature)
|
||||||
{
|
{
|
||||||
|
@ -152,7 +160,7 @@ pic_init_core(pic_state *pic)
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_state *
|
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);
|
struct pic_port *pic_make_standard_port(pic_state *, xFILE *, short);
|
||||||
char t;
|
char t;
|
||||||
|
@ -169,6 +177,9 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
|
||||||
/* allocator */
|
/* allocator */
|
||||||
pic->allocf = allocf;
|
pic->allocf = allocf;
|
||||||
|
|
||||||
|
/* user data */
|
||||||
|
pic->userdata = userdata;
|
||||||
|
|
||||||
/* turn off GC */
|
/* turn off GC */
|
||||||
pic->gc_enable = false;
|
pic->gc_enable = false;
|
||||||
|
|
||||||
|
@ -180,9 +191,9 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
|
||||||
pic->cp = NULL;
|
pic->cp = NULL;
|
||||||
|
|
||||||
/* command line */
|
/* command line */
|
||||||
pic->argc = argc;
|
pic->argc = 0;
|
||||||
pic->argv = argv;
|
pic->argv = NULL;
|
||||||
pic->envp = envp;
|
pic->envp = NULL;
|
||||||
|
|
||||||
/* prepare VM stack */
|
/* prepare VM stack */
|
||||||
pic->stbase = pic->sp = allocf(NULL, PIC_STACK_SIZE * sizeof(pic_value));
|
pic->stbase = pic->sp = allocf(NULL, PIC_STACK_SIZE * sizeof(pic_value));
|
||||||
|
|
|
@ -41,7 +41,8 @@ main(int argc, char *argv[], char **envp)
|
||||||
struct pic_lib *PICRIN_MAIN;
|
struct pic_lib *PICRIN_MAIN;
|
||||||
int status = 0;
|
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);
|
pic_init_picrin(pic);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue