remove eval.c and load.c

This commit is contained in:
Yuichi Nishiwaki 2014-08-25 16:55:51 +09:00
parent bd2c5afb02
commit 6a1b7c372d
5 changed files with 10 additions and 133 deletions

39
eval.c
View File

@ -1,39 +0,0 @@
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
#include "picrin/macro.h"
pic_value
pic_eval(pic_state *pic, pic_value program, struct pic_lib *lib)
{
struct pic_proc *proc;
proc = pic_compile(pic, program, lib);
return pic_apply(pic, proc, pic_nil_value());
}
static pic_value
pic_eval_eval(pic_state *pic)
{
pic_value program, spec;
struct pic_lib *lib;
pic_get_args(pic, "oo", &program, &spec);
lib = pic_find_library(pic, spec);
if (lib == NULL) {
pic_errorf(pic, "no library found: ~s", spec);
}
return pic_eval(pic, program, lib);
}
void
pic_init_eval(pic_state *pic)
{
pic_deflibrary (pic, "(scheme eval)") {
pic_defun(pic, "eval", pic_eval_eval);
}
}

View File

@ -160,9 +160,6 @@ pic_value pic_read_cstr(pic_state *, const char *);
pic_list pic_parse_file(pic_state *, FILE *); /* #f for incomplete input */
pic_list pic_parse_cstr(pic_state *, const char *);
pic_value pic_load(pic_state *, const char *);
pic_value pic_load_cstr(pic_state *, const char *);
pic_value pic_apply(pic_state *, struct pic_proc *, pic_value);
pic_value pic_apply0(pic_state *, struct pic_proc *);
pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value);

4
init.c
View File

@ -54,12 +54,10 @@ void pic_init_error(pic_state *);
void pic_init_str(pic_state *);
void pic_init_macro(pic_state *);
void pic_init_var(pic_state *);
void pic_init_load(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 *);
#define DONE pic_gc_arena_restore(pic, ai);
@ -103,12 +101,10 @@ pic_init_core(pic_state *pic)
pic_init_str(pic); DONE;
pic_init_macro(pic); DONE;
pic_init_var(pic); DONE;
pic_init_load(pic); DONE;
pic_init_write(pic); DONE;
pic_init_read(pic); DONE;
pic_init_dict(pic); DONE;
pic_init_record(pic); DONE;
pic_init_eval(pic); DONE;
pic_init_lib(pic); DONE;
}
}

87
load.c
View File

@ -1,87 +0,0 @@
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
#include "picrin/pair.h"
pic_value
pic_load_cstr(pic_state *pic, const char *src)
{
size_t ai;
pic_value v, exprs;
struct pic_proc *proc;
exprs = pic_parse_cstr(pic, src);
if (pic_undef_p(exprs)) {
pic_errorf(pic, "load: read failure (%s)", pic_errmsg(pic));
}
pic_for_each (v, exprs) {
ai = pic_gc_arena_preserve(pic);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
pic_error(pic, "load: compilation failure");
}
pic_apply(pic, proc, pic_nil_value());
pic_gc_arena_restore(pic, ai);
}
return pic_none_value();
}
pic_value
pic_load(pic_state *pic, const char *fn)
{
FILE *file;
size_t ai;
pic_value v, exprs;
struct pic_proc *proc;
file = fopen(fn, "r");
if (file == NULL) {
pic_errorf(pic, "load: could not read file \"%s\"", fn);
}
exprs = pic_parse_file(pic, file);
if (pic_undef_p(exprs)) {
pic_errorf(pic, "load: read failure (%s)", pic_errmsg(pic));
}
pic_for_each (v, exprs) {
ai = pic_gc_arena_preserve(pic);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
pic_error(pic, "load: compilation failure");
}
pic_apply(pic, proc, pic_nil_value());
pic_gc_arena_restore(pic, ai);
}
return pic_none_value();
}
static pic_value
pic_load_load(pic_state *pic)
{
pic_value envid;
char *fn;
pic_get_args(pic, "z|o", &fn, &envid);
return pic_load(pic, fn);
}
void
pic_init_load(pic_state *pic)
{
pic_deflibrary (pic, "(scheme load)") {
pic_defun(pic, "load", pic_load_load);
}
}

10
vm.c
View File

@ -1055,3 +1055,13 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
return pic_car(pic, args);
}
}
pic_value
pic_eval(pic_state *pic, pic_value program, struct pic_lib *lib)
{
struct pic_proc *proc;
proc = pic_compile(pic, program, lib);
return pic_apply(pic, proc, pic_nil_value());
}