eq? predicate supports nan-boxing
This commit is contained in:
parent
57f4492c4e
commit
27dc840118
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
18
src/bool.c
18
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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
28
src/value.c
28
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
|
||||
|
|
Loading…
Reference in New Issue