From 1ac5b6458c54a7a7fd7773c714b6cdd22c9a4894 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 7 Dec 2013 07:04:26 -0800 Subject: [PATCH] add pic_null_syntactic_env and pic_minimal_syntactic_env --- include/picrin/macro.h | 2 ++ src/macro.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/picrin/macro.h b/include/picrin/macro.h index ef51c85c..0a01e00d 100644 --- a/include/picrin/macro.h +++ b/include/picrin/macro.h @@ -46,6 +46,8 @@ struct pic_sc { #define pic_senv(v) ((struct pic_senv *)pic_ptr(v)) #define pic_senv_p(v) (pic_type(v) == PIC_TT_SENV) +struct pic_senv *pic_null_syntactic_env(pic_state *pic); +struct pic_senv *pic_minimal_syntactic_env(pic_state *pic); struct pic_senv *pic_core_syntactic_env(pic_state *pic); struct pic_syntax *pic_syntax_new(pic_state *, int kind, pic_sym sym); diff --git a/src/macro.c b/src/macro.c index b64a263f..7dddcf60 100644 --- a/src/macro.c +++ b/src/macro.c @@ -31,7 +31,7 @@ new_uniq_sym(pic_state *pic, pic_sym base) } struct pic_senv * -pic_core_syntactic_env(pic_state *pic) +pic_null_syntactic_env(pic_state *pic) { struct pic_senv *senv; @@ -42,12 +42,32 @@ pic_core_syntactic_env(pic_state *pic) senv->xlen = 0; senv->xcapa = PIC_MACROS_SIZE; + return senv; +} + #define register_core_syntax(pic,senv,kind,name) do { \ senv->stx[senv->xlen] = pic_syntax_new(pic, kind, pic_intern_cstr(pic, name)); \ xh_put(senv->tbl, name, ~senv->xlen); \ senv->xlen++; \ } while (0) +struct pic_senv * +pic_minimal_syntactic_env(pic_state *pic) +{ + struct pic_senv *senv = pic_null_syntactic_env(pic); + + register_core_syntax(pic, senv, PIC_STX_DEFLIBRARY, "define-library"); + register_core_syntax(pic, senv, PIC_STX_IMPORT, "import"); + register_core_syntax(pic, senv, PIC_STX_EXPORT, "export"); + + return senv; +} + +struct pic_senv * +pic_core_syntactic_env(pic_state *pic) +{ + struct pic_senv *senv = pic_null_syntactic_env(pic); + register_core_syntax(pic, senv, PIC_STX_DEFINE, "define"); register_core_syntax(pic, senv, PIC_STX_SET, "set!"); register_core_syntax(pic, senv, PIC_STX_QUOTE, "quote"); @@ -63,6 +83,8 @@ pic_core_syntactic_env(pic_state *pic) return senv; } +#undef register_core_syntax + static struct pic_senv * new_global_senv(pic_state *pic) {