diff --git a/include/picrin.h b/include/picrin.h index 65eaed6c..320315e5 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -54,10 +54,6 @@ void pic_close(pic_state *); void pic_get_args(pic_state *, const char *, ...); void pic_defun(pic_state *, const char *, pic_func_t); -pic_value pic_cons(pic_state *, pic_value, pic_value); -pic_value pic_car(pic_state *, pic_value); -pic_value pic_cdr(pic_state *, pic_value); - bool pic_eq_p(pic_state *, pic_value, pic_value); pic_value pic_intern_cstr(pic_state *, const char *); diff --git a/include/picrin/pair.h b/include/picrin/pair.h new file mode 100644 index 00000000..53cabfc9 --- /dev/null +++ b/include/picrin/pair.h @@ -0,0 +1,12 @@ +#ifndef PAIR_H__ +#define PAIR_H__ + +pic_value pic_cons(pic_state *, pic_value, pic_value); +pic_value pic_car(pic_state *, pic_value); +pic_value pic_cdr(pic_state *, pic_value); + +pic_value pic_list(pic_state *, size_t, ...); + +pic_value pic_assq(pic_state *, pic_value key, pic_value assoc); + +#endif diff --git a/src/pair.c b/src/pair.c index 18d6839e..d2a4003f 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1,4 +1,5 @@ #include "picrin.h" +#include "picrin/pair.h" pic_value pic_cons(pic_state *pic, pic_value car, pic_value cdr) @@ -31,3 +32,21 @@ pic_cdr(pic_state *pic, pic_value obj) return pair->cdr; } + +pic_value +pic_assq(pic_state *pic, pic_value key, pic_value assoc) +{ + pic_value cell; + + enter: + + if (pic_nil_p(assoc)) + return assoc; + + cell = pic_car(pic, assoc); + if (pic_eq_p(pic, key, pic_car(pic, cell))) + return cell; + + assoc = pic_cdr(pic, assoc); + goto enter; +} diff --git a/src/parse.y b/src/parse.y index ca4ca611..8aaf0207 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3,6 +3,7 @@ #include #include "picrin.h" +#include "picrin/pair.h" #define YYERROR_VERBOSE 1 diff --git a/src/time.c b/src/time.c index 3de5c44b..12f79f3d 100644 --- a/src/time.c +++ b/src/time.c @@ -1,5 +1,4 @@ #include -#include #include "picrin.h" diff --git a/src/vm.c b/src/vm.c index ee8513d5..e74b98e0 100644 --- a/src/vm.c +++ b/src/vm.c @@ -5,24 +5,7 @@ #include "picrin.h" #include "picrin/irep.h" #include "picrin/proc.h" - -static pic_value -pic_assq(pic_state *pic, pic_value key, pic_value assoc) -{ - pic_value cell; - - enter: - - if (pic_nil_p(assoc)) - return assoc; - - cell = pic_car(pic, assoc); - if (pic_eq_p(pic, key, pic_car(pic, cell))) - return cell; - - assoc = pic_cdr(pic, assoc); - goto enter; -} +#include "picrin/pair.h" static bool env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, int *depth, int *idx)