From da4a4fd4490660ef02b19ab74d89da1de1ec27ed Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 25 Jun 2014 15:39:04 +0900 Subject: [PATCH] api changes of reader/parser --- include/picrin.h | 5 +++-- src/codegen.c | 2 +- src/state.c | 4 ++-- tools/main.c | 22 +++++++++++----------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index 8522ef5b..0e673dca 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -152,7 +152,8 @@ bool pic_interned_p(pic_state *, pic_sym); char *pic_strdup(pic_state *, const char *); char *pic_strndup(pic_state *, const char *, size_t); -pic_value pic_read(pic_state *, const char *); +pic_value pic_read(pic_state *, struct pic_port *); +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 *); @@ -180,7 +181,7 @@ struct pic_lib *pic_find_library(pic_state *, pic_value); #define pic_deflibrary_helper__(i, prev_lib, spec) \ for (int i = 0; ! i; ) \ for (struct pic_lib *prev_lib; ! i; ) \ - for ((prev_lib = pic->lib), pic_make_library(pic, pic_read(pic, spec)), pic_in_library(pic, pic_read(pic, spec)); ! i++; pic->lib = prev_lib) + for ((prev_lib = pic->lib), pic_make_library(pic, pic_read_cstr(pic, spec)), pic_in_library(pic, pic_read_cstr(pic, spec)); ! i++; pic->lib = prev_lib) void pic_import(pic_state *, pic_value); void pic_export(pic_state *, pic_sym); diff --git a/src/codegen.c b/src/codegen.c index f18062b0..d097896f 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -68,7 +68,7 @@ new_analyze_state(pic_state *pic) state->pic = pic; state->scope = NULL; - stdlib = pic_find_library(pic, pic_read(pic, "(scheme base)")); + stdlib = pic_find_library(pic, pic_read_cstr(pic, "(scheme base)")); /* native VM procedures */ register_renamed_symbol(pic, state, rCONS, stdlib, "cons"); diff --git a/src/state.c b/src/state.c index 61cd2f41..63a25254 100644 --- a/src/state.c +++ b/src/state.c @@ -119,8 +119,8 @@ pic_open(int argc, char *argv[], char **envp) pic_init_core(pic); /* set library */ - pic_make_library(pic, pic_read(pic, "(picrin user)")); - pic_in_library(pic, pic_read(pic, "(picrin user)")); + pic_make_library(pic, pic_read_cstr(pic, "(picrin user)")); + pic_in_library(pic, pic_read_cstr(pic, "(picrin user)")); return pic; } diff --git a/tools/main.c b/tools/main.c index 2d3a8cfd..83f7bd40 100644 --- a/tools/main.c +++ b/tools/main.c @@ -39,16 +39,16 @@ import_repllib(pic_state *pic) { int ai = pic_gc_arena_preserve(pic); - pic_import(pic, pic_read(pic, "(scheme base)")); - pic_import(pic, pic_read(pic, "(scheme load)")); - pic_import(pic, pic_read(pic, "(scheme process-context)")); - pic_import(pic, pic_read(pic, "(scheme write)")); - pic_import(pic, pic_read(pic, "(scheme file)")); - pic_import(pic, pic_read(pic, "(scheme inexact)")); - pic_import(pic, pic_read(pic, "(scheme cxr)")); - pic_import(pic, pic_read(pic, "(scheme lazy)")); - pic_import(pic, pic_read(pic, "(scheme time)")); - pic_import(pic, pic_read(pic, "(picrin macro)")); + pic_import(pic, pic_read_cstr(pic, "(scheme base)")); + pic_import(pic, pic_read_cstr(pic, "(scheme load)")); + pic_import(pic, pic_read_cstr(pic, "(scheme process-context)")); + pic_import(pic, pic_read_cstr(pic, "(scheme write)")); + pic_import(pic, pic_read_cstr(pic, "(scheme file)")); + pic_import(pic, pic_read_cstr(pic, "(scheme inexact)")); + pic_import(pic, pic_read_cstr(pic, "(scheme cxr)")); + pic_import(pic, pic_read_cstr(pic, "(scheme lazy)")); + pic_import(pic, pic_read_cstr(pic, "(scheme time)")); + pic_import(pic, pic_read_cstr(pic, "(picrin macro)")); #if DEBUG puts("* imported repl libraries"); @@ -289,7 +289,7 @@ main(int argc, char *argv[], char **envp) parse_opt(argc, argv); if (mode == INTERACTIVE_MODE || mode == ONE_LINER_MODE) { - import_repllib(pic); + // import_repllib(pic); } switch (mode) {