redefine value constructors/destructors as inline functions
This commit is contained in:
parent
6d264f7b53
commit
3e014b0e60
2
Makefile
2
Makefile
|
@ -76,7 +76,7 @@ src/init_contrib.c:
|
|||
lib/boot.c: piclib/boot.scm
|
||||
bin/picrin-bootstrap tools/mkboot.scm < piclib/boot.scm > lib/boot.c
|
||||
|
||||
$(LIBPICRIN_OBJS) $(PICRIN_OBJS) $(CONTRIB_OBJS): lib/include/picrin.h lib/include/picrin/*.h lib/khash.h lib/value.h lib/object.h lib/state.h lib/vm.h
|
||||
$(LIBPICRIN_OBJS) $(PICRIN_OBJS) $(CONTRIB_OBJS): lib/include/picrin.h lib/include/picrin/*.h lib/khash.h lib/object.h lib/state.h lib/vm.h
|
||||
|
||||
doc: docs/*.rst docs/contrib.rst
|
||||
$(MAKE) -C docs html
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
|
|
17
lib/bool.c
17
lib/bool.c
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
#if PIC_NAN_BOXING
|
||||
|
@ -25,14 +24,14 @@ pic_eqv_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
|
|||
bool
|
||||
pic_eq_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
|
||||
{
|
||||
if (value_type(pic, x) != value_type(pic, y))
|
||||
if (pic_type(pic, x) != pic_type(pic, y))
|
||||
return false;
|
||||
|
||||
switch (value_type(pic, x)) {
|
||||
switch (pic_type(pic, x)) {
|
||||
case PIC_TYPE_NIL:
|
||||
return true;
|
||||
case PIC_TYPE_TRUE: case PIC_TYPE_FALSE:
|
||||
return value_type(pic, x) == value_type(pic, y);
|
||||
return pic_type(pic, x) == pic_type(pic, y);
|
||||
default:
|
||||
return obj_ptr(x) == obj_ptr(y);
|
||||
}
|
||||
|
@ -41,14 +40,14 @@ pic_eq_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
|
|||
bool
|
||||
pic_eqv_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
|
||||
{
|
||||
if (value_type(pic, x) != value_type(pic, y))
|
||||
if (pic_type(pic, x) != pic_type(pic, y))
|
||||
return false;
|
||||
|
||||
switch (value_type(pic, x)) {
|
||||
switch (pic_type(pic, x)) {
|
||||
case PIC_TYPE_NIL:
|
||||
return true;
|
||||
case PIC_TYPE_TRUE: case PIC_TYPE_FALSE:
|
||||
return value_type(pic, x) == value_type(pic, y);
|
||||
return pic_type(pic, x) == pic_type(pic, y);
|
||||
case PIC_TYPE_FLOAT:
|
||||
return pic_float(pic, x) == pic_float(pic, y);
|
||||
case PIC_TYPE_INT:
|
||||
|
@ -89,11 +88,11 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m)
|
|||
if (pic_eqv_p(pic, x, y)) {
|
||||
return true;
|
||||
}
|
||||
if (value_type(pic, x) != value_type(pic, y)) {
|
||||
if (pic_type(pic, x) != pic_type(pic, y)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (value_type(pic, x)) {
|
||||
switch (pic_type(pic, x)) {
|
||||
case PIC_TYPE_ID: {
|
||||
struct identifier *id1, *id2;
|
||||
pic_value s1, s2;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
static pic_value
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
bool
|
||||
pic_data_p(pic_state *pic, pic_value obj, const pic_data_type *type)
|
||||
{
|
||||
if (value_type(pic, obj) != PIC_TYPE_DATA) {
|
||||
if (pic_type(pic, obj) != PIC_TYPE_DATA) {
|
||||
return false;
|
||||
}
|
||||
return type == NULL || pic_data_ptr(pic, obj)->type == type;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
KHASH_DEFINE(dict, symbol *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
#include "vm.h"
|
||||
|
@ -173,7 +172,7 @@ expand_defmacro(pic_state *pic, pic_value expr, pic_value env)
|
|||
static pic_value
|
||||
expand_node(pic_state *pic, pic_value expr, pic_value env, pic_value deferred)
|
||||
{
|
||||
switch (value_type(pic, expr)) {
|
||||
switch (pic_type(pic, expr)) {
|
||||
case PIC_TYPE_ID:
|
||||
case PIC_TYPE_SYMBOL: {
|
||||
return expand_var(pic, expr, env, deferred);
|
||||
|
@ -498,7 +497,7 @@ analyze_call(pic_state *pic, analyze_scope *scope, pic_value obj)
|
|||
static pic_value
|
||||
analyze_node(pic_state *pic, analyze_scope *scope, pic_value obj)
|
||||
{
|
||||
switch (value_type(pic, obj)) {
|
||||
switch (pic_type(pic, obj)) {
|
||||
case PIC_TYPE_SYMBOL: {
|
||||
return analyze_var(pic, scope, obj);
|
||||
}
|
||||
|
@ -947,7 +946,7 @@ codegen_quote(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos)
|
|||
int pidx;
|
||||
|
||||
obj = pic_list_ref(pic, obj, 1);
|
||||
switch (value_type(pic, obj)) {
|
||||
switch (pic_type(pic, obj)) {
|
||||
case PIC_TYPE_UNDEF:
|
||||
emit_n(pic, cxt, OP_PUSHUNDEF);
|
||||
break;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
#undef EOF
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
struct writer_control {
|
||||
|
@ -170,7 +169,7 @@ traverse(pic_state *pic, pic_value obj, struct writer_control *p)
|
|||
return;
|
||||
}
|
||||
|
||||
switch (value_type(pic, obj)) {
|
||||
switch (pic_type(pic, obj)) {
|
||||
case PIC_TYPE_PAIR:
|
||||
case PIC_TYPE_VECTOR:
|
||||
case PIC_TYPE_DICT: {
|
||||
|
@ -413,7 +412,7 @@ write_dict(pic_state *pic, pic_value dict, pic_value port, struct writer_control
|
|||
static const char *
|
||||
typename(pic_state *pic, pic_value obj)
|
||||
{
|
||||
switch (value_type(pic, obj)) {
|
||||
switch (pic_type(pic, obj)) {
|
||||
case PIC_TYPE_NIL:
|
||||
return "null";
|
||||
case PIC_TYPE_TRUE:
|
||||
|
@ -486,7 +485,7 @@ write_core(pic_state *pic, pic_value obj, pic_value port, struct writer_control
|
|||
pic_weak_set(pic, labels, obj, pic_int_value(pic, i));
|
||||
}
|
||||
|
||||
switch (value_type(pic, obj)) {
|
||||
switch (pic_type(pic, obj)) {
|
||||
case PIC_TYPE_UNDEF:
|
||||
pic_fprintf(pic, port, "#undefined");
|
||||
break;
|
||||
|
|
1
lib/gc.c
1
lib/gc.c
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -89,24 +89,14 @@ bool pic_equal_p(pic_state *, pic_value, pic_value);
|
|||
* number, boolean, character, string, bytevector, and userdata
|
||||
*/
|
||||
|
||||
#include "picrin/value.h" /* inline definitions */
|
||||
|
||||
typedef struct {
|
||||
const char *type_name;
|
||||
void (*dtor)(pic_state *, void *);
|
||||
void (*mark)(pic_state *, void *, void (*)(pic_state *, pic_value));
|
||||
} pic_data_type;
|
||||
|
||||
typedef struct {
|
||||
int (*read)(pic_state *, void *, char *, int);
|
||||
int (*write)(pic_state *, void *, const char *, int);
|
||||
long (*seek)(pic_state *, void *, long, int);
|
||||
int (*close)(pic_state *, void *);
|
||||
} pic_port_type;
|
||||
|
||||
typedef pic_value (*pic_func_t)(pic_state *);
|
||||
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
bool pic_undef_p(pic_state *, pic_value); /* deprecated */
|
||||
bool pic_int_p(pic_state *, pic_value);
|
||||
bool pic_float_p(pic_state *, pic_value);
|
||||
|
@ -241,6 +231,7 @@ pic_value pic_sym_name(pic_state *, pic_value sym);
|
|||
* procedure
|
||||
*/
|
||||
|
||||
typedef pic_value (*pic_func_t)(pic_state *);
|
||||
bool pic_proc_p(pic_state *, pic_value);
|
||||
pic_value pic_lambda(pic_state *, pic_func_t f, int n, ...);
|
||||
pic_value pic_vlambda(pic_state *, pic_func_t f, int n, va_list);
|
||||
|
@ -257,6 +248,13 @@ pic_value pic_applyk(pic_state *, pic_value proc, int n, pic_value *argv);
|
|||
* port
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int (*read)(pic_state *, void *, char *, int);
|
||||
int (*write)(pic_state *, void *, const char *, int);
|
||||
long (*seek)(pic_state *, void *, long, int);
|
||||
int (*close)(pic_state *, void *);
|
||||
} pic_port_type;
|
||||
|
||||
#define PIC_SEEK_CUR 0
|
||||
#define PIC_SEEK_END 1
|
||||
#define PIC_SEEK_SET 2
|
||||
|
@ -303,6 +301,7 @@ PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...);
|
|||
PIC_NORETURN void pic_raise(pic_state *, pic_value v);
|
||||
pic_value pic_make_error(pic_state *, const char *type, const char *msg, pic_value irrs); /* deprecated */
|
||||
pic_value pic_get_backtrace(pic_state *); /* deprecated */
|
||||
void pic_warnf(pic_state *pic, const char *fmt, ...); /* deprecated */
|
||||
#define pic_try pic_try_(PIC_GENSYM(cont), PIC_GENSYM(jmp))
|
||||
#define pic_try_(cont, jmp) \
|
||||
do { \
|
||||
|
|
|
@ -9,58 +9,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define pic_int pic_int_inline
|
||||
#define pic_float pic_float_inline
|
||||
#define pic_char pic_char_inline
|
||||
#define pic_int_value pic_int_value_inline
|
||||
#define pic_float_value pic_float_value_inline
|
||||
#define pic_char_value pic_char_value_inline
|
||||
#define obj_value obj_value_inline /* TODO */
|
||||
#define pic_nil_value pic_nil_value_inline
|
||||
#define pic_eof_object pic_eof_object_inline
|
||||
#define pic_true_value pic_true_value_inline
|
||||
#define pic_false_value pic_false_value_inline
|
||||
#define pic_undef_value pic_undef_value_inline
|
||||
#define pic_invalid_value pic_invalid_value_inline
|
||||
#define pic_bool_value pic_bool_value_inline
|
||||
#define pic_invalid_p pic_invalid_p_inline
|
||||
#define pic_float_p pic_float_p_inline
|
||||
#define pic_int_p pic_int_p_inline
|
||||
#define pic_char_p pic_char_p_inline
|
||||
#define pic_eof_p pic_eof_p_inline
|
||||
#define pic_undef_p pic_undef_p_inline
|
||||
#define pic_true_p pic_true_p_inline
|
||||
#define pic_nil_p pic_nil_p_inline
|
||||
#define pic_false_p pic_false_p_inline
|
||||
#define pic_bool_p pic_bool_p_inline
|
||||
#define pic_str_p pic_str_p_inline
|
||||
#define pic_vec_p pic_vec_p_inline
|
||||
#define pic_blob_p pic_blob_p_inline
|
||||
#define pic_error_p pic_error_p_inline
|
||||
#define pic_id_p pic_id_p_inline
|
||||
#define pic_dict_p pic_dict_p_inline
|
||||
#define pic_weak_p pic_weak_p_inline
|
||||
#define pic_env_p pic_env_p_inline
|
||||
#define pic_rec_p pic_rec_p_inline
|
||||
#define pic_sym_p pic_sym_p_inline
|
||||
#define pic_pair_p pic_pair_p_inline
|
||||
#define pic_cp_p pic_cp_p_inline
|
||||
#define pic_func_p pic_func_p_inline
|
||||
#define pic_irep_p pic_irep_p_inline
|
||||
#define pic_proc_p pic_proc_p_inline
|
||||
#endif
|
||||
|
||||
/* #ifndef INLINE */
|
||||
/* # if GENERATE_EXTERNAL_DEFINITION */
|
||||
/* # define INLINE PIC_EXTERN_INLINE */
|
||||
/* # else */
|
||||
/* # define INLINE PIC_INLINE */
|
||||
/* # endif */
|
||||
/* #endif */
|
||||
|
||||
#define INLINE PIC_STATIC_INLINE
|
||||
|
||||
enum {
|
||||
PIC_TYPE_INVALID = 1,
|
||||
PIC_TYPE_FLOAT = 2,
|
||||
|
@ -92,12 +40,10 @@ enum {
|
|||
PIC_TYPE_IREP = 33
|
||||
};
|
||||
|
||||
PIC_STATIC_INLINE int obj_tt(void *); /* defined in object.h */
|
||||
|
||||
#if !PIC_NAN_BOXING
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
make_value(int type)
|
||||
pic_make_value(int type)
|
||||
{
|
||||
pic_value v;
|
||||
v.type = type;
|
||||
|
@ -105,70 +51,50 @@ make_value(int type)
|
|||
return v;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE struct object *
|
||||
obj_ptr(pic_value v)
|
||||
{
|
||||
return (struct object *)(v.u.data);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE bool
|
||||
obj_p(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.type > PIC_IVAL_END;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
obj_value(void *ptr)
|
||||
{
|
||||
pic_value v = make_value(obj_tt(ptr));
|
||||
v.u.data = ptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE int
|
||||
value_type(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
pic_type(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return (int)(v.type);
|
||||
}
|
||||
|
||||
INLINE int
|
||||
PIC_STATIC_INLINE int
|
||||
pic_int(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.u.i;
|
||||
}
|
||||
|
||||
INLINE double
|
||||
PIC_STATIC_INLINE double
|
||||
pic_float(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.u.f;
|
||||
}
|
||||
|
||||
INLINE char
|
||||
PIC_STATIC_INLINE char
|
||||
pic_char(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.u.c;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_int_value(pic_state *PIC_UNUSED(pic), int i)
|
||||
{
|
||||
pic_value v = make_value(PIC_TYPE_INT);
|
||||
pic_value v = pic_make_value(PIC_TYPE_INT);
|
||||
v.u.i = i;
|
||||
return v;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_float_value(pic_state *PIC_UNUSED(pic), double f)
|
||||
{
|
||||
pic_value v = make_value(PIC_TYPE_FLOAT);
|
||||
pic_value v = pic_make_value(PIC_TYPE_FLOAT);
|
||||
v.u.f = f;
|
||||
return v;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_char_value(pic_state *PIC_UNUSED(pic), char c)
|
||||
{
|
||||
pic_value v = make_value(PIC_TYPE_CHAR);
|
||||
pic_value v = pic_make_value(PIC_TYPE_CHAR);
|
||||
v.u.c = c;
|
||||
return v;
|
||||
}
|
||||
|
@ -184,40 +110,20 @@ pic_char_value(pic_state *PIC_UNUSED(pic), char c)
|
|||
*/
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
make_value(int type)
|
||||
pic_make_value(int type)
|
||||
{
|
||||
pic_value v;
|
||||
v.v = 0xfff0000000000000ul | ((uint64_t)(type) << 46);
|
||||
return v;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE struct object *
|
||||
obj_ptr(pic_value v)
|
||||
{
|
||||
return (struct object *)((0x3ffffffffffful & v.v) << 2);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE bool
|
||||
obj_p(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.v > ((0x3ffC0ul + (0x3f & PIC_IVAL_END)) << 46);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
obj_value(void *ptr)
|
||||
{
|
||||
pic_value v = make_value(obj_tt(ptr));
|
||||
v.v |= 0x3ffffffffffful & ((uint64_t)ptr >> 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE int
|
||||
value_type(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
pic_type(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return 0xfff0000000000000ul >= v.v ? PIC_TYPE_FLOAT : ((v.v >> 46) & 0x3f);
|
||||
}
|
||||
|
||||
INLINE int
|
||||
PIC_STATIC_INLINE int
|
||||
pic_int(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
union { int i; unsigned u; } u;
|
||||
|
@ -225,7 +131,7 @@ pic_int(pic_state *PIC_UNUSED(pic), pic_value v)
|
|||
return u.i;
|
||||
}
|
||||
|
||||
INLINE double
|
||||
PIC_STATIC_INLINE double
|
||||
pic_float(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
union { double f; uint64_t i; } u;
|
||||
|
@ -233,21 +139,21 @@ pic_float(pic_state *PIC_UNUSED(pic), pic_value v)
|
|||
return u.f;
|
||||
}
|
||||
|
||||
INLINE char
|
||||
PIC_STATIC_INLINE char
|
||||
pic_char(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.v & 0xfffffffful;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_int_value(pic_state *PIC_UNUSED(pic), int i)
|
||||
{
|
||||
pic_value v = make_value(PIC_TYPE_INT);
|
||||
pic_value v = pic_make_value(PIC_TYPE_INT);
|
||||
v.v |= (unsigned)i;
|
||||
return v;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_float_value(pic_state *PIC_UNUSED(pic), double f)
|
||||
{
|
||||
union { double f; uint64_t i; } u;
|
||||
|
@ -262,19 +168,19 @@ pic_float_value(pic_state *PIC_UNUSED(pic), double f)
|
|||
return v;
|
||||
}
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_char_value(pic_state *PIC_UNUSED(pic), char c)
|
||||
{
|
||||
pic_value v = make_value(PIC_TYPE_CHAR);
|
||||
pic_value v = pic_make_value(PIC_TYPE_CHAR);
|
||||
v.v |= (unsigned char)c;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* NAN_BOXING end */
|
||||
|
||||
#define DEFVAL(name, type) \
|
||||
INLINE pic_value name(pic_state *PIC_UNUSED(pic)) { \
|
||||
return make_value(type); \
|
||||
#define DEFVAL(name, type) \
|
||||
PIC_STATIC_INLINE pic_value name(pic_state *PIC_UNUSED(pic)) { \
|
||||
return pic_make_value(type); \
|
||||
}
|
||||
|
||||
DEFVAL(pic_nil_value, PIC_TYPE_NIL)
|
||||
|
@ -284,15 +190,15 @@ DEFVAL(pic_false_value, PIC_TYPE_FALSE)
|
|||
DEFVAL(pic_undef_value, PIC_TYPE_UNDEF)
|
||||
DEFVAL(pic_invalid_value, PIC_TYPE_INVALID)
|
||||
|
||||
INLINE pic_value
|
||||
PIC_STATIC_INLINE pic_value
|
||||
pic_bool_value(pic_state *PIC_UNUSED(pic), bool b)
|
||||
{
|
||||
return make_value(b ? PIC_TYPE_TRUE : PIC_TYPE_FALSE);
|
||||
return pic_make_value(b ? PIC_TYPE_TRUE : PIC_TYPE_FALSE);
|
||||
}
|
||||
|
||||
#define DEFPRED(name, type) \
|
||||
INLINE bool name(pic_state *pic, pic_value obj) { \
|
||||
return value_type(pic, obj) == type; \
|
||||
#define DEFPRED(name, type) \
|
||||
PIC_STATIC_INLINE bool name(pic_state *pic, pic_value obj) { \
|
||||
return pic_type(pic, obj) == type; \
|
||||
}
|
||||
|
||||
DEFPRED(pic_invalid_p, PIC_TYPE_INVALID)
|
||||
|
@ -318,22 +224,22 @@ DEFPRED(pic_cp_p, PIC_TYPE_CP)
|
|||
DEFPRED(pic_func_p, PIC_TYPE_FUNC)
|
||||
DEFPRED(pic_irep_p, PIC_TYPE_IREP)
|
||||
|
||||
INLINE bool
|
||||
PIC_STATIC_INLINE bool
|
||||
pic_bool_p(pic_state *pic, pic_value obj)
|
||||
{
|
||||
return pic_true_p(pic, obj) || pic_false_p(pic, obj);
|
||||
}
|
||||
|
||||
INLINE bool
|
||||
PIC_STATIC_INLINE bool
|
||||
pic_proc_p(pic_state *pic, pic_value o)
|
||||
{
|
||||
return pic_func_p(pic, o) || pic_irep_p(pic, o);
|
||||
}
|
||||
|
||||
INLINE bool
|
||||
PIC_STATIC_INLINE bool
|
||||
pic_id_p(pic_state *pic, pic_value o)
|
||||
{
|
||||
return value_type(pic, o) == PIC_TYPE_ID || pic_sym_p(pic, o);
|
||||
return pic_type(pic, o) == PIC_TYPE_ID || pic_sym_p(pic, o);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
static pic_value
|
||||
|
|
48
lib/object.h
48
lib/object.h
|
@ -188,12 +188,56 @@ struct checkpoint {
|
|||
if (tolen - at < e - s) pic_error(pic, "invalid range", 0); \
|
||||
} while (0)
|
||||
|
||||
PIC_STATIC_INLINE struct object *obj_ptr(pic_value); /* defined in value.h */
|
||||
|
||||
PIC_STATIC_INLINE int obj_tt(void *ptr) {
|
||||
return ((struct basic *)ptr)->tt;
|
||||
}
|
||||
|
||||
#if !PIC_NAN_BOXING
|
||||
|
||||
PIC_STATIC_INLINE struct object *
|
||||
obj_ptr(pic_value v)
|
||||
{
|
||||
return (struct object *)(v.u.data);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE bool
|
||||
obj_p(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.type > PIC_IVAL_END;
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
obj_value(void *ptr)
|
||||
{
|
||||
pic_value v = pic_make_value(obj_tt(ptr));
|
||||
v.u.data = ptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
#else /* NAN_BOXING */
|
||||
|
||||
PIC_STATIC_INLINE struct object *
|
||||
obj_ptr(pic_value v)
|
||||
{
|
||||
return (struct object *)((0x3ffffffffffful & v.v) << 2);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE bool
|
||||
obj_p(pic_state *PIC_UNUSED(pic), pic_value v)
|
||||
{
|
||||
return v.v > ((0x3ffC0ul + (0x3f & PIC_IVAL_END)) << 46);
|
||||
}
|
||||
|
||||
PIC_STATIC_INLINE pic_value
|
||||
obj_value(void *ptr)
|
||||
{
|
||||
pic_value v = pic_make_value(obj_tt(ptr));
|
||||
v.v |= 0x3ffffffffffful & ((uint64_t)ptr >> 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* NAN_BOXING */
|
||||
|
||||
#define DEFPTR(name,type) \
|
||||
PIC_STATIC_INLINE type *name(pic_state *PIC_UNUSED(pic), pic_value o) { \
|
||||
return (type *) obj_ptr(o); \
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
@ -14,7 +13,7 @@
|
|||
bool
|
||||
pic_port_p(pic_state *pic, pic_value obj, const pic_port_type *type)
|
||||
{
|
||||
if (value_type(pic, obj) != PIC_TYPE_PORT) {
|
||||
if (pic_type(pic, obj) != PIC_TYPE_PORT) {
|
||||
return false;
|
||||
}
|
||||
return type == NULL || pic_port_ptr(pic, obj)->file.vtable == type;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
#include "vm.h"
|
||||
|
@ -189,7 +188,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
e = (c == c2 ? va_arg(ap, bool *) : &dummy); \
|
||||
\
|
||||
v = GET_ARG(pic, i); \
|
||||
switch (value_type(pic, v)) { \
|
||||
switch (pic_type(pic, v)) { \
|
||||
case PIC_TYPE_FLOAT: \
|
||||
*n = pic_float(pic, v); \
|
||||
*e = false; \
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
struct rope {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "value.h"
|
||||
#include "object.h"
|
||||
|
||||
KHASH_DEFINE(weak, struct object *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal)
|
||||
|
|
Loading…
Reference in New Issue