mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Update number representation so that wrapping numbers isn't
doesn't need to check for NaNs. Change ordering of types.
This commit is contained in:
parent
ca9c017ec4
commit
d724c5b959
@ -61,12 +61,12 @@ const char *mr_strings[] = {
|
||||
|
||||
/* Lead bytes in marshaling protocol */
|
||||
enum {
|
||||
LB_NIL = 200,
|
||||
LB_REAL = 200,
|
||||
LB_NIL,
|
||||
LB_FALSE,
|
||||
LB_TRUE,
|
||||
LB_FIBER,
|
||||
LB_INTEGER,
|
||||
LB_REAL,
|
||||
LB_STRING,
|
||||
LB_SYMBOL,
|
||||
LB_ARRAY,
|
||||
|
@ -229,7 +229,7 @@ static double convert(
|
||||
|
||||
/* Short circuit zero and huge numbers */
|
||||
if (mant->n == 0 && mant->first_digit == 0)
|
||||
return 0.0;
|
||||
return negative ? -0.0 : 0.0;
|
||||
if (exponent > 1023)
|
||||
return negative ? -INFINITY : INFINITY;
|
||||
|
||||
|
@ -35,11 +35,11 @@ const char janet_base64[65] =
|
||||
/* The JANET value types in order. These types can be used as
|
||||
* mnemonics instead of a bit pattern for type checking */
|
||||
const char *const janet_type_names[15] = {
|
||||
":number",
|
||||
":nil",
|
||||
":boolean",
|
||||
":boolean",
|
||||
":fiber",
|
||||
":number",
|
||||
":string",
|
||||
":symbol",
|
||||
":array",
|
||||
|
@ -35,6 +35,8 @@ int32_t janet_tablen(int32_t n);
|
||||
void janet_buffer_push_types(JanetBuffer *buffer, int types);
|
||||
const JanetKV *janet_dict_find(const JanetKV *buckets, int32_t cap, Janet key);
|
||||
Janet janet_dict_get(const JanetKV *buckets, int32_t cap, Janet key);
|
||||
void janet_memempty(JanetKV *mem, int32_t count);
|
||||
void *janet_memalloc_empty(int32_t count);
|
||||
const void *janet_strbinsearch(
|
||||
const void *tab,
|
||||
size_t tabcount,
|
||||
|
@ -22,6 +22,26 @@
|
||||
|
||||
#include <janet/janet.h>
|
||||
|
||||
void *janet_memalloc_empty(int32_t count) {
|
||||
int32_t i;
|
||||
void *mem = malloc(count * sizeof(JanetKV));
|
||||
JanetKV *mmem = (JanetKV *)mem;
|
||||
for (i = 0; i < count; i++) {
|
||||
JanetKV *kv = mmem + i;
|
||||
kv->key = janet_wrap_nil();
|
||||
kv->value = janet_wrap_nil();
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
void janet_memempty(JanetKV *mem, int32_t count) {
|
||||
int32_t i;
|
||||
for (i = 0; i < count; i++) {
|
||||
mem[i].key = janet_wrap_nil();
|
||||
mem[i].value = janet_wrap_nil();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JANET_NANBOX_64
|
||||
|
||||
void *janet_nanbox_to_pointer(Janet x) {
|
||||
@ -46,9 +66,6 @@ Janet janet_nanbox_from_cpointer(const void *p, uint64_t tagmask) {
|
||||
Janet janet_nanbox_from_double(double d) {
|
||||
Janet ret;
|
||||
ret.number = d;
|
||||
/* Normalize NaNs */
|
||||
if (d != d)
|
||||
ret.u64 = janet_nanbox_tag(JANET_NUMBER);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -58,26 +75,6 @@ Janet janet_nanbox_from_bits(uint64_t bits) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *janet_nanbox_memalloc_empty(int32_t count) {
|
||||
int32_t i;
|
||||
void *mem = malloc(count * sizeof(JanetKV));
|
||||
JanetKV *mmem = (JanetKV *)mem;
|
||||
for (i = 0; i < count; i++) {
|
||||
JanetKV *kv = mmem + i;
|
||||
kv->key = janet_wrap_nil();
|
||||
kv->value = janet_wrap_nil();
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
void janet_nanbox_memempty(JanetKV *mem, int32_t count) {
|
||||
int32_t i;
|
||||
for (i = 0; i < count; i++) {
|
||||
mem[i].key = janet_wrap_nil();
|
||||
mem[i].value = janet_wrap_nil();
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(JANET_NANBOX_32)
|
||||
|
||||
Janet janet_wrap_number(double x) {
|
||||
|
@ -274,11 +274,11 @@ typedef int (*JanetCFunction)(JanetArgs args);
|
||||
|
||||
/* Basic types for all Janet Values */
|
||||
typedef enum JanetType {
|
||||
JANET_NUMBER,
|
||||
JANET_NIL,
|
||||
JANET_FALSE,
|
||||
JANET_TRUE,
|
||||
JANET_FIBER,
|
||||
JANET_NUMBER,
|
||||
JANET_STRING,
|
||||
JANET_SYMBOL,
|
||||
JANET_ARRAY,
|
||||
@ -372,16 +372,11 @@ union Janet {
|
||||
: janet_nanbox_checkauxtype((x), (t)))
|
||||
|
||||
JANET_API void *janet_nanbox_to_pointer(Janet x);
|
||||
JANET_API void janet_nanbox_memempty(JanetKV *mem, int32_t count);
|
||||
JANET_API void *janet_nanbox_memalloc_empty(int32_t count);
|
||||
JANET_API Janet janet_nanbox_from_pointer(void *p, uint64_t tagmask);
|
||||
JANET_API Janet janet_nanbox_from_cpointer(const void *p, uint64_t tagmask);
|
||||
JANET_API Janet janet_nanbox_from_double(double d);
|
||||
JANET_API Janet janet_nanbox_from_bits(uint64_t bits);
|
||||
|
||||
#define janet_memempty(mem, len) janet_nanbox_memempty((mem), (len))
|
||||
#define janet_memalloc_empty(count) janet_nanbox_memalloc_empty(count)
|
||||
|
||||
/* Todo - check for single mask operation */
|
||||
#define janet_truthy(x) \
|
||||
(!(janet_checktype((x), JANET_NIL) || janet_checktype((x), JANET_FALSE)))
|
||||
@ -462,8 +457,6 @@ union Janet {
|
||||
#define janet_u64(x) ((x).u64)
|
||||
#define janet_type(x) (((x).tagged.type < JANET_DOUBLE_OFFSET) ? (x).tagged.type : JANET_NUMBER)
|
||||
#define janet_checktype(x, t) ((x).tagged.type == (t))
|
||||
#define janet_memempty(mem, count) memset((mem), 0, sizeof(JanetKV) * (count))
|
||||
#define janet_memalloc_empty(count) calloc((count), sizeof(JanetKV))
|
||||
#define janet_truthy(x) ((x).tagged.type != JANET_NIL && (x).tagged.type != JANET_FALSE)
|
||||
|
||||
JANET_API Janet janet_wrap_number(double x);
|
||||
@ -518,8 +511,6 @@ struct Janet {
|
||||
};
|
||||
|
||||
#define janet_u64(x) ((x).as.u64)
|
||||
#define janet_memempty(mem, count) memset((mem), 0, sizeof(JanetKV) * (count))
|
||||
#define janet_memalloc_empty(count) calloc((count), sizeof(JanetKV))
|
||||
#define janet_type(x) ((x).type)
|
||||
#define janet_checktype(x, t) ((x).type == (t))
|
||||
#define janet_truthy(x) \
|
||||
|
@ -37,9 +37,9 @@
|
||||
(assert (= 7 (% 20 13)) "modulo 1")
|
||||
(assert (= -7 (% -20 13)) "modulo 2")
|
||||
|
||||
(assert (order< nil false true
|
||||
(assert (order< 1.0 nil false true
|
||||
(fiber/new (fn [] 1))
|
||||
1.0 "hi"
|
||||
"hi"
|
||||
(quote hello)
|
||||
(array 1 2 3)
|
||||
(tuple 1 2 3)
|
||||
|
Loading…
Reference in New Issue
Block a user