diff --git a/include/picrin.h b/include/picrin.h index 955dac01..6683dd8e 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -77,10 +77,6 @@ void pic_close(pic_state *); int pic_get_args(pic_state *, const char *, ...); void pic_defun(pic_state *, const char *, pic_func_t); -bool pic_eq_p(pic_state *, pic_value, pic_value); -bool pic_eqv_p(pic_state *, pic_value, pic_value); -bool pic_equal_p(pic_state *, pic_value, pic_value); - pic_sym pic_intern_cstr(pic_state *, const char *); const char *pic_symbol_name(pic_state *, pic_sym); diff --git a/include/picrin/value.h b/include/picrin/value.h index d72eb4f3..06e02c92 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -26,6 +26,7 @@ enum pic_vtype { * sym : 1111111111110111 0000000000000000 SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS * char : 1111111111111000 0000000000000000 CCCCCCCCCCCCCCCC ................ */ + typedef struct { union { void *data; @@ -149,4 +150,7 @@ pic_value pic_char_value(char c); #define pic_str_p(v) (pic_type(v) == PIC_TT_STRING) #define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR) +bool pic_eq_p(pic_value, pic_value); +bool pic_eqv_p(pic_value, pic_value); + #endif diff --git a/src/bool.c b/src/bool.c index 3d319739..a5aaf294 100644 --- a/src/bool.c +++ b/src/bool.c @@ -2,22 +2,6 @@ #include "picrin.h" -bool -pic_eq_p(pic_state *pic, pic_value x, pic_value y) -{ - if (pic_type(x) != pic_type(y)) - return false; - - switch (pic_type(x)) { - case PIC_TT_NIL: - return true; - case PIC_TT_SYMBOL: - return pic_sym(x) == pic_sym(y); - default: - return false; - } -} - static pic_value pic_bool_eq_p(pic_state *pic) { @@ -25,7 +9,7 @@ pic_bool_eq_p(pic_state *pic) pic_get_args(pic, "oo", &x, &y); - return pic_bool_value(pic_eq_p(pic, x, y)); + return pic_bool_value(pic_eq_p(x, y)); } /* TODO: replace it with native opcode */ diff --git a/src/pair.c b/src/pair.c index 231912cc..922a73bb 100644 --- a/src/pair.c +++ b/src/pair.c @@ -102,7 +102,7 @@ pic_assq(pic_state *pic, pic_value key, pic_value assoc) return assoc; cell = pic_car(pic, assoc); - if (pic_eq_p(pic, key, pic_car(pic, cell))) + if (pic_eq_p(key, pic_car(pic, cell))) return cell; assoc = pic_cdr(pic, assoc); diff --git a/src/value.c b/src/value.c index c63ff683..3b76bf67 100644 --- a/src/value.c +++ b/src/value.c @@ -216,3 +216,31 @@ pic_undef_value() pic_init_value(v, PIC_VTYPE_UNDEF); return v; } + +#if PIC_NAN_BOXING + +bool +pic_eq_p(pic_value x, pic_value y) +{ + return x.u.data == y.u.data; +} + +#else + +bool +pic_eq_p(pic_value x, pic_value y) +{ + if (pic_type(x) != pic_type(y)) + return false; + + switch (pic_type(x)) { + case PIC_TT_NIL: + return true; + case PIC_TT_SYMBOL: + return pic_sym(x) == pic_sym(y); + default: + return false; + } +} + +#endif