fix build
This commit is contained in:
parent
07bb4a0f6b
commit
046fa0adad
|
@ -38,10 +38,9 @@ extern "C" {
|
||||||
#include "picrin/kvec.h"
|
#include "picrin/kvec.h"
|
||||||
#include "picrin/khash.h"
|
#include "picrin/khash.h"
|
||||||
|
|
||||||
#include "picrin/value.h"
|
|
||||||
|
|
||||||
typedef struct pic_state pic_state;
|
typedef struct pic_state pic_state;
|
||||||
|
|
||||||
|
#include "picrin/value.h"
|
||||||
#include "picrin/irep.h"
|
#include "picrin/irep.h"
|
||||||
#include "picrin/file.h"
|
#include "picrin/file.h"
|
||||||
#include "picrin/read.h"
|
#include "picrin/read.h"
|
||||||
|
|
|
@ -583,43 +583,86 @@ pic_eqv_p(pic_value x, pic_value y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
#if PIC_ENABLE_FLOAT
|
||||||
# define pic_aop(pic, a, b, op, name, guard) \
|
# define pic_define_aop(name, op, guard) \
|
||||||
((pic_int_p(a) && pic_int_p(b)) ? \
|
PIC_INLINE pic_value \
|
||||||
((INT_MIN <= (double)pic_int(a) op (double)pic_int(b) && (double)pic_int(a) op (double)pic_int(b) <= INT_MAX && guard) \
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
? pic_int_value((int)((double)pic_int(a) op (double)pic_int(b))) \
|
{ \
|
||||||
: pic_float_value((double)pic_int(a) op (double)pic_int(b))) \
|
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
: (pic_float_p(a) && pic_float_p(b)) ? pic_float_value(pic_float(a) op pic_float(b)) \
|
double f; \
|
||||||
: (pic_int_p(a) && pic_float_p(b)) ? pic_float_value(pic_int(a) op pic_float(b)) \
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
: (pic_float_p(a) && pic_int_p(b)) ? pic_float_value(pic_float(a) op pic_int(b)) \
|
f = (double)pic_int(a) op (double)pic_int(b); \
|
||||||
: (pic_errorf(pic, name ": non-number operand given"), 0))
|
return (INT_MIN <= f && f <= INT_MAX && guard) \
|
||||||
|
? pic_int_value((int)f) \
|
||||||
|
: pic_float_value(f); \
|
||||||
|
} else if (pic_float_p(a) && pic_float_p(b)) { \
|
||||||
|
return pic_float_value(pic_float(a) op pic_float(b)); \
|
||||||
|
} else if (pic_int_p(a) && pic_float_p(b)) { \
|
||||||
|
return pic_float_value(pic_int(a) op pic_float(b)); \
|
||||||
|
} else if (pic_float_p(a) && pic_int_p(b)) { \
|
||||||
|
return pic_float_value(pic_float(a) op pic_int(b)); \
|
||||||
|
} else { \
|
||||||
|
pic_errorf(pic, #name ": non-number operand given"); \
|
||||||
|
} \
|
||||||
|
PIC_UNREACHABLE(); \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
# define pic_aop(pic, a, b, op, name) \
|
# define pic_define_aop(name, op) \
|
||||||
((pic_int_p(a) && pic_int_p(b)) \
|
PIC_INLINE pic_value \
|
||||||
? pic_int_value(pic_int(a) op pic_int(b)) \
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
: (pic_errorf(pic, name ": non-number operand given"), 0))
|
{ \
|
||||||
|
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
|
double f; \
|
||||||
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
|
return pic_int_value(pic_int(a) op pic_int(b)); \
|
||||||
|
} else { \
|
||||||
|
pic_errorf(pic, #name ": non-number operand given"); \
|
||||||
|
} \
|
||||||
|
PIC_UNREACHABLE(); \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define pic_add(pic, a, b) pic_aop(pic, a, b, +, "+", true)
|
pic_define_aop(pic_add, +, true)
|
||||||
#define pic_sub(pic, a, b) pic_aop(pic, a, b, -, "-", true)
|
pic_define_aop(pic_sub, -, true)
|
||||||
#define pic_mul(pic, a, b) pic_aop(pic, a, b, *, "*", true)
|
pic_define_aop(pic_mul, *, true)
|
||||||
#define pic_div(pic, a, b) pic_aop(pic, a, b, /, "/", (double)pic_int(a) / (double)pic_int(b) == round((double)pic_int(a) / (double)pic_int(b)))
|
pic_define_aop(pic_div, /, f == round(f))
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
#if PIC_ENABLE_FLOAT
|
||||||
# define pic_cmp(pic, a, b, op, name) \
|
# define pic_define_cmp(name, op) \
|
||||||
((pic_int_p(a) && pic_int_p(b)) ? pic_int(a) op pic_int(b) \
|
PIC_INLINE bool \
|
||||||
: (pic_float_p(a) && pic_float_p(b)) ? pic_float(a) op pic_float(b) \
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
: (pic_int_p(a) && pic_float_p(b)) ? pic_int(a) op pic_float(b) \
|
{ \
|
||||||
: (pic_float_p(a) && pic_int_p(b)) ? pic_float(a) op pic_int(b) \
|
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
: (pic_errorf(pic, name ": non-number operand given"), 0))
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
|
return pic_int(a) op pic_int(b); \
|
||||||
|
} else if (pic_float_p(a) && pic_float_p(b)) { \
|
||||||
|
return pic_float(a) op pic_float(b); \
|
||||||
|
} else if (pic_int_p(a) && pic_float_p(b)) { \
|
||||||
|
return pic_int(a) op pic_float(b); \
|
||||||
|
} else if (pic_float_p(a) && pic_int_p(b)) { \
|
||||||
|
return pic_float(a) op pic_int(b); \
|
||||||
|
} else { \
|
||||||
|
pic_errorf(pic, #name ": non-number operand given"); \
|
||||||
|
} \
|
||||||
|
PIC_UNREACHABLE(); \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
# define pic_cmp(pic, a, b, op, name) \
|
# define pic_define_cmp(name, op) \
|
||||||
((pic_int_p(a) && pic_int_p(b)) ? pic_int(a) op pic_int(b) \
|
PIC_INLINE bool \
|
||||||
: (pic_errorf(pic, name ": non-number operand given"), 0))
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
|
{ \
|
||||||
|
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
|
return pic_int(a) op pic_int(b); \
|
||||||
|
} else { \
|
||||||
|
pic_errorf(pic, #name ": non-number operand given"); \
|
||||||
|
} \
|
||||||
|
PIC_UNREACHABLE(); \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define pic_eq(pic, a, b) pic_cmp(pic, a, b, ==, "=")
|
pic_define_cmp(pic_eq, ==)
|
||||||
#define pic_le(pic, a, b) pic_cmp(pic, a, b, <=, "<=")
|
pic_define_cmp(pic_lt, <)
|
||||||
#define pic_lt(pic, a, b) pic_cmp(pic, a, b, <, "<")
|
pic_define_cmp(pic_le, <=)
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue