From 40a4e2ead4ac09b277606fef6aec75b22e2a04a6 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 07:59:57 +0900 Subject: [PATCH 01/10] remove make-error-object --- extlib/benz/error.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 1386ab63..927ad2ec 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -212,22 +212,6 @@ pic_error_error(pic_state *pic) pic_error(pic, str, pic_list_by_array(pic, argc, argv)); } -static pic_value -pic_error_make_error_object(pic_state *pic) -{ - struct pic_error *e; - pic_sym *type; - pic_str *msg; - size_t argc; - pic_value *argv; - - pic_get_args(pic, "ms*", &type, &msg, &argc, &argv); - - e = pic_make_error(pic, type, pic_str_cstr(pic, msg), pic_list_by_array(pic, argc, argv)); - - return pic_obj_value(e); -} - static pic_value pic_error_error_object_p(pic_state *pic) { @@ -275,7 +259,6 @@ pic_init_error(pic_state *pic) pic_defun(pic, "raise", pic_error_raise); pic_defun(pic, "raise-continuable", pic_error_raise_continuable); pic_defun(pic, "error", pic_error_error); - pic_defun(pic, "make-error-object", pic_error_make_error_object); pic_defun(pic, "error-object?", pic_error_error_object_p); pic_defun(pic, "error-object-message", pic_error_error_object_message); pic_defun(pic, "error-object-irritants", pic_error_error_object_irritants); From e944183e9914205577e09fe1eb43b7f10f7ab943 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:05:46 +0900 Subject: [PATCH 02/10] pic_obj_alloc_unsafe should be private --- extlib/benz/include/picrin.h | 1 - 1 file changed, 1 deletion(-) diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index b94b0903..ad7bf419 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -144,7 +144,6 @@ void *pic_malloc(pic_state *, size_t); void *pic_realloc(pic_state *, void *, size_t); void *pic_calloc(pic_state *, size_t, size_t); struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt); -struct pic_object *pic_obj_alloc_unsafe(pic_state *, size_t, enum pic_tt); void pic_free(pic_state *, void *); void pic_gc_run(pic_state *); From 81c38d8fa286feed324b6db986b44161c560a204 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:10:30 +0900 Subject: [PATCH 03/10] s/PICRIN_VALUE_H/PICRIN_TYPE_H/g --- extlib/benz/include/picrin/type.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extlib/benz/include/picrin/type.h b/extlib/benz/include/picrin/type.h index e055430f..c5d5f4da 100644 --- a/extlib/benz/include/picrin/type.h +++ b/extlib/benz/include/picrin/type.h @@ -2,8 +2,8 @@ * See Copyright Notice in picrin.h */ -#ifndef PICRIN_VALUE_H -#define PICRIN_VALUE_H +#ifndef PICRIN_TYPE_H +#define PICRIN_TYPE_H #if defined(__cplusplus) extern "C" { From 71d1d4837d49935d45f3749373c670272bb789ad Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:16:04 +0900 Subject: [PATCH 04/10] pic_intern_cstr -> pic_intern --- contrib/20.r7rs/src/file.c | 2 +- extlib/benz/attr.c | 4 ++-- extlib/benz/debug.c | 2 +- extlib/benz/error.c | 2 +- extlib/benz/include/picrin.h | 4 ++-- extlib/benz/macro.c | 2 +- extlib/benz/port.c | 2 +- extlib/benz/proc.c | 6 +++--- extlib/benz/read.c | 6 +++--- extlib/benz/record.c | 4 ++-- extlib/benz/state.c | 10 +++++----- extlib/benz/symbol.c | 8 ++++---- extlib/benz/vm.c | 12 ++++++------ 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/contrib/20.r7rs/src/file.c b/contrib/20.r7rs/src/file.c index dd94803c..9aeae3d4 100644 --- a/contrib/20.r7rs/src/file.c +++ b/contrib/20.r7rs/src/file.c @@ -11,7 +11,7 @@ file_error(pic_state *pic, const char *msg) { struct pic_error *e; - e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value()); + e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value()); pic_raise(pic, pic_obj_value(e)); } diff --git a/extlib/benz/attr.c b/extlib/benz/attr.c index 3e0bb192..ca11fa07 100644 --- a/extlib/benz/attr.c +++ b/extlib/benz/attr.c @@ -22,13 +22,13 @@ pic_attr(pic_state *pic, pic_value obj) pic_value pic_attr_ref(pic_state *pic, pic_value obj, const char *key) { - return pic_dict_ref(pic, pic_attr(pic, obj), pic_intern_cstr(pic, key)); + return pic_dict_ref(pic, pic_attr(pic, obj), pic_intern(pic, key)); } void pic_attr_set(pic_state *pic, pic_value obj, const char *key, pic_value v) { - pic_dict_set(pic, pic_attr(pic, obj), pic_intern_cstr(pic, key), v); + pic_dict_set(pic, pic_attr(pic, obj), pic_intern(pic, key), v); } static pic_value diff --git a/extlib/benz/debug.c b/extlib/benz/debug.c index 040b12a8..7d682f0f 100644 --- a/extlib/benz/debug.c +++ b/extlib/benz/debug.c @@ -45,7 +45,7 @@ pic_print_backtrace(pic_state *pic, xFILE *file) pic_value elem, it; e = pic_error_ptr(pic->err); - if (e->type != pic_intern_cstr(pic, "")) { + if (e->type != pic_intern(pic, "")) { pic_fwrite(pic, pic_obj_value(e->type), file); xfprintf(pic, file, " "); } diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 927ad2ec..67a7cdc0 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -158,7 +158,7 @@ pic_error(pic_state *pic, const char *msg, pic_value irrs) { struct pic_error *e; - e = pic_make_error(pic, pic_intern_cstr(pic, ""), msg, irrs); + e = pic_make_error(pic, pic_intern(pic, ""), msg, irrs); pic_raise(pic, pic_obj_value(e)); } diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index ad7bf419..ada531fd 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -172,8 +172,8 @@ bool pic_eq_p(pic_value, pic_value); bool pic_eqv_p(pic_value, pic_value); bool pic_equal_p(pic_state *, pic_value, pic_value); -pic_sym *pic_intern(pic_state *, pic_str *); -pic_sym *pic_intern_cstr(pic_state *, const char *); +pic_sym *pic_intern(pic_state *, const char *); +pic_sym *pic_intern_str(pic_state *, pic_str *); const char *pic_symbol_name(pic_state *, pic_sym *); pic_value pic_read(pic_state *, struct pic_port *); diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index cac07fd5..8bca193f 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -56,7 +56,7 @@ pic_uniq(pic_state *pic, pic_value var) str = pic_format(pic, "%s.%d", pic_symbol_name(pic, pic_var_name(pic, var)), pic->ucnt++); - return pic_intern(pic, str); + return pic_intern_str(pic, str); } pic_sym * diff --git a/extlib/benz/port.c b/extlib/benz/port.c index 337d0ecd..9b4b605d 100644 --- a/extlib/benz/port.c +++ b/extlib/benz/port.c @@ -103,7 +103,7 @@ file_error(pic_state *pic, const char *msg) { struct pic_error *e; - e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value()); + e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value()); pic_raise(pic, pic_obj_value(e)); } diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index 4c00885b..d7a5bca1 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -42,19 +42,19 @@ pic_proc_env(pic_state *pic, struct pic_proc *proc) bool pic_proc_env_has(pic_state *pic, struct pic_proc *proc, const char *key) { - return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key)); + return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern(pic, key)); } pic_value pic_proc_env_ref(pic_state *pic, struct pic_proc *proc, const char *key) { - return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key)); + return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern(pic, key)); } void pic_proc_env_set(pic_state *pic, struct pic_proc *proc, const char *key, pic_value val) { - pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key), val); + pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern(pic, key), val); } static pic_value diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 77cce237..09278225 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -14,7 +14,7 @@ read_error(pic_state *pic, const char *msg) { struct pic_error *e; - e = pic_make_error(pic, pic_intern_cstr(pic, "read"), msg, pic_nil_value()); + e = pic_make_error(pic, pic_intern(pic, "read"), msg, pic_nil_value()); pic_raise(pic, pic_obj_value(e)); } @@ -216,7 +216,7 @@ read_symbol(pic_state *pic, struct pic_port *port, int c) buf[len] = 0; } - sym = pic_intern_cstr(pic, buf); + sym = pic_intern(pic, buf); pic_free(pic, buf); return pic_obj_value(sym); @@ -537,7 +537,7 @@ read_pipe(pic_state *pic, struct pic_port *port, int c) } buf[cnt] = '\0'; - sym = pic_intern_cstr(pic, buf); + sym = pic_intern(pic, buf); pic_free(pic, buf); return pic_obj_value(sym); diff --git a/extlib/benz/record.c b/extlib/benz/record.c index dfa21908..db14159e 100644 --- a/extlib/benz/record.c +++ b/extlib/benz/record.c @@ -15,7 +15,7 @@ pic_make_record(pic_state *pic, pic_value rectype) rec = (struct pic_record *)pic_obj_alloc(pic, sizeof(struct pic_record), PIC_TT_RECORD); rec->data = data; - pic_record_set(pic, rec, pic_intern_cstr(pic, "@@type"), rectype); + pic_record_set(pic, rec, pic_intern(pic, "@@type"), rectype); return rec; } @@ -23,7 +23,7 @@ pic_make_record(pic_state *pic, pic_value rectype) pic_value pic_record_type(pic_state *pic, struct pic_record *rec) { - return pic_record_ref(pic, rec, pic_intern_cstr(pic, "@@type")); + return pic_record_ref(pic, rec, pic_intern(pic, "@@type")); } pic_value diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 2fb447a3..8e03f6c4 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -15,7 +15,7 @@ pic_set_argv(pic_state *pic, int argc, char *argv[], char **envp) void pic_add_feature(pic_state *pic, const char *feature) { - pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features); + pic_push(pic, pic_obj_value(pic_intern(pic, feature)), pic->features); } void pic_init_undef(pic_state *); @@ -113,10 +113,10 @@ pic_features(pic_state *pic) #define DONE pic_gc_arena_restore(pic, ai); #define define_builtin_syntax(uid, name) \ - pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern_cstr(pic, name), uid) + pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern(pic, name), uid) #define VM(uid, name) \ - pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern_cstr(pic, name), uid) + pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern(pic, name), uid) #define VM3(name) \ pic->c##name = pic_vm_gref_slot(pic, pic->u##name); @@ -343,7 +343,7 @@ pic_open(pic_allocf allocf, void *userdata) ai = pic_gc_arena_preserve(pic); -#define S(slot,name) pic->slot = pic_intern_cstr(pic, name) +#define S(slot,name) pic->slot = pic_intern(pic, name) S(sQUOTE, "quote"); S(sQUASIQUOTE, "quasiquote"); @@ -364,7 +364,7 @@ pic_open(pic_allocf allocf, void *userdata) pic_gc_arena_restore(pic, ai); -#define U(slot,name) pic->slot = pic_uniq(pic, pic_obj_value(pic_intern_cstr(pic, name))) +#define U(slot,name) pic->slot = pic_uniq(pic, pic_obj_value(pic_intern(pic, name))) U(uDEFINE, "define"); U(uLAMBDA, "lambda"); diff --git a/extlib/benz/symbol.c b/extlib/benz/symbol.c index ba5fb47c..5dec1035 100644 --- a/extlib/benz/symbol.c +++ b/extlib/benz/symbol.c @@ -7,13 +7,13 @@ KHASH_DEFINE(s, const char *, pic_sym *, kh_str_hash_func, kh_str_hash_equal) pic_sym * -pic_intern(pic_state *pic, pic_str *str) +pic_intern_str(pic_state *pic, pic_str *str) { - return pic_intern_cstr(pic, pic_str_cstr(pic, str)); + return pic_intern(pic, pic_str_cstr(pic, str)); } pic_sym * -pic_intern_cstr(pic_state *pic, const char *cstr) +pic_intern(pic_state *pic, const char *cstr) { khash_t(s) *h = &pic->syms; pic_sym *sym; @@ -93,7 +93,7 @@ pic_symbol_string_to_symbol(pic_state *pic) pic_get_args(pic, "s", &str); - return pic_obj_value(pic_intern(pic, str)); + return pic_obj_value(pic_intern_str(pic, str)); } void diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index dd719d24..b47849f0 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -1113,7 +1113,7 @@ pic_define_(pic_state *pic, const char *name, pic_value val) { pic_sym *sym, *uid; - sym = pic_intern_cstr(pic, name); + sym = pic_intern(pic, name); if ((uid = pic_find_variable(pic, pic->lib->env, pic_obj_value(sym))) == NULL) { uid = pic_add_variable(pic, pic->lib->env, pic_obj_value(sym)); @@ -1130,7 +1130,7 @@ void pic_define(pic_state *pic, const char *name, pic_value val) { pic_define_(pic, name, val); - pic_export(pic, pic_intern_cstr(pic, name)); + pic_export(pic, pic_intern(pic, name)); } void @@ -1143,7 +1143,7 @@ void pic_defun(pic_state *pic, const char *name, pic_func_t cfunc) { pic_defun_(pic, name, cfunc); - pic_export(pic, pic_intern_cstr(pic, name)); + pic_export(pic, pic_intern(pic, name)); } void @@ -1156,7 +1156,7 @@ void pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *conv) { pic_defvar_(pic, name, init, conv); - pic_export(pic, pic_intern_cstr(pic, name)); + pic_export(pic, pic_intern(pic, name)); } pic_value @@ -1164,7 +1164,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name) { pic_sym *sym, *uid; - sym = pic_intern_cstr(pic, name); + sym = pic_intern(pic, name); if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) { pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); @@ -1178,7 +1178,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val) { pic_sym *sym, *uid; - sym = pic_intern_cstr(pic, name); + sym = pic_intern(pic, name); if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) { pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); From 5c2cbb9e55c307bdbd675477c44c21c642021c68 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:20:07 +0900 Subject: [PATCH 05/10] pic_load_port -> pic_load --- contrib/20.r7rs/src/load.c | 19 ++++++------------- extlib/benz/include/picrin.h | 2 +- extlib/benz/load.c | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/contrib/20.r7rs/src/load.c b/contrib/20.r7rs/src/load.c index f0d65b6e..15cc6cae 100644 --- a/contrib/20.r7rs/src/load.c +++ b/contrib/20.r7rs/src/load.c @@ -4,27 +4,20 @@ #include "picrin.h" -void -pic_load(pic_state *pic, const char *filename) -{ - struct pic_port *port; - - port = pic_open_file(pic, filename, PIC_PORT_IN | PIC_PORT_TEXT); - - pic_load_port(pic, port); - - pic_close_port(pic, port); -} - static pic_value pic_load_load(pic_state *pic) { pic_value envid; char *fn; + struct pic_port *port; pic_get_args(pic, "z|o", &fn, &envid); - pic_load(pic, fn); + port = pic_open_file(pic, fn, PIC_PORT_IN | PIC_PORT_TEXT); + + pic_load(pic, port); + + pic_close_port(pic, port); return pic_undef_value(); } diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index ada531fd..51c15ee8 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -179,7 +179,7 @@ const char *pic_symbol_name(pic_state *, pic_sym *); pic_value pic_read(pic_state *, struct pic_port *); pic_value pic_read_cstr(pic_state *, const char *); -void pic_load_port(pic_state *, struct pic_port *); +void pic_load(pic_state *, struct pic_port *); void pic_load_cstr(pic_state *, const char *); void pic_define(pic_state *, const char *, pic_value); diff --git a/extlib/benz/load.c b/extlib/benz/load.c index cd609afe..32e6f152 100644 --- a/extlib/benz/load.c +++ b/extlib/benz/load.c @@ -5,7 +5,7 @@ #include "picrin.h" void -pic_load_port(pic_state *pic, struct pic_port *port) +pic_load(pic_state *pic, struct pic_port *port) { pic_value form; size_t ai = pic_gc_arena_preserve(pic); @@ -23,7 +23,7 @@ pic_load_cstr(pic_state *pic, const char *src) struct pic_port *port = pic_open_input_string(pic, src); pic_try { - pic_load_port(pic, port); + pic_load(pic, port); } pic_catch { pic_close_port(pic, port); From 42ec53d73f1f3a8d20ac08bddda0fc3d2e8940c1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:22:19 +0900 Subject: [PATCH 06/10] remove pic_errmsg --- extlib/benz/error.c | 16 ---------------- extlib/benz/include/picrin.h | 3 +-- extlib/benz/include/picrin/irep.h | 1 + 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 67a7cdc0..c50fc85d 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -47,22 +47,6 @@ pic_errorf(pic_state *pic, const char *fmt, ...) pic_error(pic, msg, irrs); } -const char * -pic_errmsg(pic_state *pic) -{ - pic_str *str; - - assert(! pic_invalid_p(pic->err)); - - if (! pic_error_p(pic->err)) { - str = pic_format(pic, "~s", pic->err); - } else { - str = pic_error_ptr(pic->err)->msg; - } - - return pic_str_cstr(pic, str); -} - pic_value pic_native_exception_handler(pic_state *pic) { diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 51c15ee8..67b6f091 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -208,7 +208,6 @@ pic_value pic_apply5(pic_state *, struct pic_proc *, pic_value, pic_value, pic_v pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, size_t, pic_value *); pic_value pic_apply_trampoline_list(pic_state *, struct pic_proc *, pic_value); pic_value pic_eval(pic_state *, pic_value, struct pic_env *); -struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_env *); struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *); @@ -232,9 +231,9 @@ void pic_export(pic_state *, pic_sym *); PIC_NORETURN void pic_panic(pic_state *, const char *); PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); void pic_warnf(pic_state *, const char *, ...); -const char *pic_errmsg(pic_state *); pic_str *pic_get_backtrace(pic_state *); void pic_print_backtrace(pic_state *, xFILE *); + struct pic_dict *pic_attr(pic_state *, pic_value); pic_value pic_attr_ref(pic_state *, pic_value, const char *); void pic_attr_set(pic_state *, pic_value, const char *, pic_value); diff --git a/extlib/benz/include/picrin/irep.h b/extlib/benz/include/picrin/irep.h index aa230848..246a84e2 100644 --- a/extlib/benz/include/picrin/irep.h +++ b/extlib/benz/include/picrin/irep.h @@ -35,6 +35,7 @@ pic_sym *pic_resolve(pic_state *, pic_value, struct pic_env *); pic_value pic_expand(pic_state *, pic_value, struct pic_env *); pic_value pic_analyze(pic_state *, pic_value); struct pic_irep *pic_codegen(pic_state *, pic_value); +struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_env *); #if defined(__cplusplus) } From 5c5066bfa0835893ab0eeaf3c6f58084602f0a69 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:24:06 +0900 Subject: [PATCH 07/10] Revert "add box type" This reverts commit d53f0cf9e47003e6eb8cdcb73bdf33840f0f0bab. --- extlib/benz/gc.c | 9 ------ extlib/benz/include/picrin.h | 1 - extlib/benz/include/picrin/box.h | 53 ------------------------------- extlib/benz/include/picrin/type.h | 5 +-- 4 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 extlib/benz/include/picrin/box.h diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 878c500e..4651ff35 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -487,12 +487,6 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) } break; } - case PIC_TT_BOX: { - struct pic_box *box = (struct pic_box *)obj; - - gc_mark(pic, box->value); - break; - } case PIC_TT_NIL: case PIC_TT_BOOL: #if PIC_ENABLE_FLOAT @@ -739,9 +733,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) case PIC_TT_CP: { break; } - case PIC_TT_BOX: { - break; - } case PIC_TT_NIL: case PIC_TT_BOOL: #if PIC_ENABLE_FLOAT diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 67b6f091..82429713 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -269,7 +269,6 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *); #include "picrin/symbol.h" #include "picrin/vector.h" #include "picrin/reg.h" -#include "picrin/box.h" #if defined(__cplusplus) } diff --git a/extlib/benz/include/picrin/box.h b/extlib/benz/include/picrin/box.h deleted file mode 100644 index edce0f0d..00000000 --- a/extlib/benz/include/picrin/box.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_BOX_H -#define PICRIN_BOX_H - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_box { - PIC_OBJECT_HEADER - pic_value value; -}; - -#define pic_box_p(v) (pic_type(v) == PIC_TT_BOX) -#define pic_box_ptr(o) ((struct pic_box *)pic_ptr(o)) - -PIC_INLINE pic_value -pic_box(pic_state *pic, pic_value value) -{ - struct pic_box *box; - - box = (struct pic_box *)pic_obj_alloc(pic, sizeof(struct pic_box), PIC_TT_BOX); - box->value = value; - - return pic_obj_value(box); -} - -PIC_INLINE pic_value -pic_unbox(pic_state *pic, pic_value box) -{ - if (! pic_box_p(box)) { - pic_errorf(pic, "box required"); - } - return pic_box_ptr(box)->value; -} - -PIC_INLINE void -pic_set_box(pic_state *pic, pic_value box, pic_value value) -{ - if (! pic_box_p(box)) { - pic_errorf(pic, "box required"); - } - pic_box_ptr(box)->value = value; -} - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/extlib/benz/include/picrin/type.h b/extlib/benz/include/picrin/type.h index c5d5f4da..e824d9b1 100644 --- a/extlib/benz/include/picrin/type.h +++ b/extlib/benz/include/picrin/type.h @@ -163,11 +163,10 @@ enum pic_tt { PIC_TT_DATA, PIC_TT_DICT, PIC_TT_REG, - PIC_TT_BOX, PIC_TT_RECORD, PIC_TT_CXT, PIC_TT_IREP, - PIC_TT_CP, + PIC_TT_CP }; #define PIC_OBJECT_HEADER \ @@ -338,8 +337,6 @@ pic_type_repr(enum pic_tt tt) return "reg"; case PIC_TT_RECORD: return "record"; - case PIC_TT_BOX: - return "box"; case PIC_TT_CP: return "checkpoint"; } From cbe5e81b2836bfeeb8b2c58d0f7ad63b42dfaa3f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 08:28:21 +0900 Subject: [PATCH 08/10] remove pic_make_vec_from_list --- extlib/benz/include/picrin/vector.h | 3 +-- extlib/benz/read.c | 12 ++++++++++-- extlib/benz/vector.c | 16 ---------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/extlib/benz/include/picrin/vector.h b/extlib/benz/include/picrin/vector.h index 514ecb4b..2d845308 100644 --- a/extlib/benz/include/picrin/vector.h +++ b/extlib/benz/include/picrin/vector.h @@ -18,8 +18,7 @@ struct pic_vector { #define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR) #define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o)) -struct pic_vector *pic_make_vec(pic_state *, size_t); -struct pic_vector *pic_make_vec_from_list(pic_state *, pic_value); +pic_vec *pic_make_vec(pic_state *, size_t); #if defined(__cplusplus) } diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 09278225..3c13fd03 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -643,11 +643,19 @@ read_pair(pic_state *pic, struct pic_port *port, int c) static pic_value read_vector(pic_state *pic, struct pic_port *port, int c) { - pic_value list; + pic_value list, it, elem; + pic_vec *vec; + size_t i = 0; list = read(pic, port, c); - return pic_obj_value(pic_make_vec_from_list(pic, list)); + vec = pic_make_vec(pic, pic_length(pic, list)); + + pic_for_each (elem, list, it) { + vec->data[i++] = elem; + } + + return pic_obj_value(vec); } static pic_value diff --git a/extlib/benz/vector.c b/extlib/benz/vector.c index c3b914c1..a270ad69 100644 --- a/extlib/benz/vector.c +++ b/extlib/benz/vector.c @@ -19,22 +19,6 @@ pic_make_vec(pic_state *pic, size_t len) return vec; } -struct pic_vector * -pic_make_vec_from_list(pic_state *pic, pic_value data) -{ - struct pic_vector *vec; - size_t len, i; - - len = pic_length(pic, data); - - vec = pic_make_vec(pic, len); - for (i = 0; i < len; ++i) { - vec->data[i] = pic_car(pic, data); - data = pic_cdr(pic, data); - } - return vec; -} - static pic_value pic_vec_vector_p(pic_state *pic) { From 5635661b3c8cc77d6f98b5fd8f0eced036d4eeb5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 09:03:32 +0900 Subject: [PATCH 09/10] remove pic_make_str_fill --- contrib/20.r7rs/src/mutable-string.c | 5 ++++- extlib/benz/include/picrin/string.h | 1 - extlib/benz/string.c | 30 ++++++++++------------------ 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/contrib/20.r7rs/src/mutable-string.c b/contrib/20.r7rs/src/mutable-string.c index 85db9be0..01887976 100644 --- a/contrib/20.r7rs/src/mutable-string.c +++ b/contrib/20.r7rs/src/mutable-string.c @@ -4,13 +4,16 @@ void pic_str_set(pic_state *pic, pic_str *str, size_t i, char c) { pic_str *x, *y, *z, *tmp; + char buf[1]; if (pic_str_len(str) <= i) { pic_errorf(pic, "index out of range %d", i); } + buf[0] = c; + x = pic_str_sub(pic, str, 0, i); - y = pic_make_str_fill(pic, 1, c); + y = pic_make_str(pic, buf, 1); z = pic_str_sub(pic, str, i + 1, pic_str_len(str)); tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z)); diff --git a/extlib/benz/include/picrin/string.h b/extlib/benz/include/picrin/string.h index 2728e97b..b7448783 100644 --- a/extlib/benz/include/picrin/string.h +++ b/extlib/benz/include/picrin/string.h @@ -22,7 +22,6 @@ void pic_rope_decref(pic_state *, struct pic_rope *); pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t); pic_str *pic_make_str_cstr(pic_state *, const char *); -pic_str *pic_make_str_fill(pic_state *, size_t, char); char pic_str_ref(pic_state *, pic_str *, size_t); size_t pic_str_len(pic_str *); diff --git a/extlib/benz/string.c b/extlib/benz/string.c index 9d1060c3..cc4a0519 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -240,25 +240,6 @@ pic_make_str_cstr(pic_state *pic, const char *cstr) return pic_make_str(pic, cstr, strlen(cstr)); } -pic_str * -pic_make_str_fill(pic_state *pic, size_t len, char fill) -{ - size_t i; - char *buf = pic_malloc(pic, len); - pic_str *str; - - for (i = 0; i < len; ++i) { - buf[i] = fill; - } - buf[i] = '\0'; - - str = pic_make_str(pic, buf, len); - - pic_free(pic, buf); - - return str; -} - size_t pic_str_len(pic_str *str) { @@ -474,7 +455,16 @@ pic_str_make_string(pic_state *pic) pic_get_args(pic, "k|c", &len, &c); - return pic_obj_value(pic_make_str_fill(pic, len, c)); + { + size_t i; + char buf[len]; + + for (i = 0; i < len; ++i) { + buf[i] = c; + } + + return pic_obj_value(pic_make_str(pic, buf, len)); + } } static pic_value From 072a32601fbb121212f933a1d8c966ce41af954c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 10:02:01 +0900 Subject: [PATCH 10/10] don't use VLA --- extlib/benz/string.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/extlib/benz/string.c b/extlib/benz/string.c index cc4a0519..f94dfd50 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -452,19 +452,18 @@ pic_str_make_string(pic_state *pic) { size_t len; char c = ' '; + char *buf; + pic_value ret; pic_get_args(pic, "k|c", &len, &c); - { - size_t i; - char buf[len]; + buf = pic_malloc(pic, len); + memset(buf, c, len); - for (i = 0; i < len; ++i) { - buf[i] = c; - } + ret = pic_obj_value(pic_make_str(pic, buf, len)); - return pic_obj_value(pic_make_str(pic, buf, len)); - } + pic_free(pic, buf); + return ret; } static pic_value