move all contents in value.c to value.h

This commit is contained in:
Yuichi Nishiwaki 2014-01-30 21:51:26 +09:00
parent bfcf2d29e9
commit 2dd8d2746d
2 changed files with 138 additions and 141 deletions

View File

@ -140,8 +140,8 @@ struct pic_blob;
#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o))
#define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o))
enum pic_tt pic_type(pic_value);
const char *pic_type_repr(enum pic_tt);
inline enum pic_tt pic_type(pic_value);
inline const char *pic_type_repr(enum pic_tt);
inline pic_value pic_nil_value();
inline pic_value pic_true_value();
@ -175,10 +175,90 @@ inline pic_value pic_none_value();
/* obsoleted macro(s) */
#define pic_symbol_p pic_sym_p
bool pic_eq_p(pic_value, pic_value);
bool pic_eqv_p(pic_value, pic_value);
inline bool pic_eq_p(pic_value, pic_value);
inline bool pic_eqv_p(pic_value, pic_value);
inline enum pic_tt
pic_type(pic_value v)
{
switch (pic_vtype(v)) {
case PIC_VTYPE_NIL:
return PIC_TT_NIL;
case PIC_VTYPE_TRUE:
return PIC_TT_BOOL;
case PIC_VTYPE_FALSE:
return PIC_TT_BOOL;
case PIC_VTYPE_UNDEF:
return PIC_TT_UNDEF;
case PIC_VTYPE_FLOAT:
return PIC_TT_FLOAT;
case PIC_VTYPE_INT:
return PIC_TT_INT;
case PIC_VTYPE_SYMBOL:
return PIC_TT_SYMBOL;
case PIC_VTYPE_CHAR:
return PIC_TT_CHAR;
case PIC_VTYPE_EOF:
return PIC_TT_EOF;
case PIC_VTYPE_HEAP:
return ((struct pic_object *)pic_ptr(v))->tt;
}
}
inline const char *
pic_type_repr(enum pic_tt tt)
{
switch (tt) {
case PIC_TT_NIL:
return "nil";
case PIC_TT_BOOL:
return "boolean";
case PIC_TT_FLOAT:
return "float";
case PIC_TT_INT:
return "int";
case PIC_TT_SYMBOL:
return "symbol";
case PIC_TT_CHAR:
return "char";
case PIC_TT_EOF:
return "eof";
case PIC_TT_UNDEF:
return "undef";
case PIC_TT_PAIR:
return "pair";
case PIC_TT_STRING:
return "string";
case PIC_TT_VECTOR:
return "vector";
case PIC_TT_BLOB:
return "blob";
case PIC_TT_PORT:
return "port";
case PIC_TT_ERROR:
return "error";
case PIC_TT_ENV:
return "env";
case PIC_TT_CONT:
return "cont";
case PIC_TT_PROC:
return "proc";
case PIC_TT_SC:
return "sc";
case PIC_TT_SENV:
return "senv";
case PIC_TT_SYNTAX:
return "syntax";
case PIC_TT_LIB:
return "lib";
case PIC_TT_VAR:
return "var";
case PIC_TT_IREP:
return "irep";
}
}
inline pic_value
pic_nil_value()
{
@ -314,6 +394,60 @@ pic_none_value()
#endif
}
#if PIC_NAN_BOXING
inline bool
pic_eq_p(pic_value x, pic_value y)
{
return x.u.data == y.u.data;
}
inline bool
pic_eqv_p(pic_value x, pic_value y)
{
return x.u.data == y.u.data;
}
#else
inline 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 pic_ptr(x) == pic_ptr(y);
}
}
inline bool
pic_eqv_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);
case PIC_TT_FLOAT:
return pic_float(x) == pic_float(y);
case PIC_TT_INT:
return pic_int(x) == pic_int(y);
default:
return pic_ptr(x) == pic_ptr(y);
}
}
#endif
#if defined(__cplusplus)
}
#endif

View File

@ -7,140 +7,3 @@
#include "picrin.h"
enum pic_tt
pic_type(pic_value v)
{
switch (pic_vtype(v)) {
case PIC_VTYPE_NIL:
return PIC_TT_NIL;
case PIC_VTYPE_TRUE:
return PIC_TT_BOOL;
case PIC_VTYPE_FALSE:
return PIC_TT_BOOL;
case PIC_VTYPE_UNDEF:
return PIC_TT_UNDEF;
case PIC_VTYPE_FLOAT:
return PIC_TT_FLOAT;
case PIC_VTYPE_INT:
return PIC_TT_INT;
case PIC_VTYPE_SYMBOL:
return PIC_TT_SYMBOL;
case PIC_VTYPE_CHAR:
return PIC_TT_CHAR;
case PIC_VTYPE_EOF:
return PIC_TT_EOF;
case PIC_VTYPE_HEAP:
return ((struct pic_object *)pic_ptr(v))->tt;
}
/* logic flaw (suppress warnings gcc will emit) */
abort();
}
const char *
pic_type_repr(enum pic_tt tt)
{
switch (tt) {
case PIC_TT_NIL:
return "nil";
case PIC_TT_BOOL:
return "boolean";
case PIC_TT_FLOAT:
return "float";
case PIC_TT_INT:
return "int";
case PIC_TT_SYMBOL:
return "symbol";
case PIC_TT_CHAR:
return "char";
case PIC_TT_EOF:
return "eof";
case PIC_TT_UNDEF:
return "undef";
case PIC_TT_PAIR:
return "pair";
case PIC_TT_STRING:
return "string";
case PIC_TT_VECTOR:
return "vector";
case PIC_TT_BLOB:
return "blob";
case PIC_TT_PORT:
return "port";
case PIC_TT_ERROR:
return "error";
case PIC_TT_ENV:
return "env";
case PIC_TT_CONT:
return "cont";
case PIC_TT_PROC:
return "proc";
case PIC_TT_SC:
return "sc";
case PIC_TT_SENV:
return "senv";
case PIC_TT_SYNTAX:
return "syntax";
case PIC_TT_LIB:
return "lib";
case PIC_TT_VAR:
return "var";
case PIC_TT_IREP:
return "irep";
}
/* logic flaw */
abort();
}
#if PIC_NAN_BOXING
bool
pic_eq_p(pic_value x, pic_value y)
{
return x.u.data == y.u.data;
}
bool
pic_eqv_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 pic_ptr(x) == pic_ptr(y);
}
}
bool
pic_eqv_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);
case PIC_TT_FLOAT:
return pic_float(x) == pic_float(y);
case PIC_TT_INT:
return pic_int(x) == pic_int(y);
default:
return pic_ptr(x) == pic_ptr(y);
}
}
#endif