mirror of
https://github.com/janet-lang/janet
synced 2025-06-09 10:04:14 +00:00
Fix 32 bit platforms janet number handling.
This commit is contained in:
parent
d724c5b959
commit
fe22a8db39
@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
@ -436,3 +437,43 @@ int janet_checkint64(Janet x) {
|
|||||||
double dval = janet_unwrap_number(x);
|
double dval = janet_unwrap_number(x);
|
||||||
return janet_checkint64range(dval);
|
return janet_checkint64range(dval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Useful for inspecting values while debugging */
|
||||||
|
void janet_inspect(Janet x) {
|
||||||
|
printf("<type=%s, ", janet_type_names[janet_type(x)]);
|
||||||
|
|
||||||
|
#ifdef JANET_BIG_ENDIAN
|
||||||
|
printf("be ");
|
||||||
|
#else
|
||||||
|
printf("le ");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JANET_NANBOX_64
|
||||||
|
printf("nanbox64 raw=0x%.16" PRIx64 ", ", x.u64);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JANET_NANBOX_32
|
||||||
|
printf("nanbox32 type=0x%.8" PRIx32 ", ", x.tagged.type);
|
||||||
|
printf("payload=%" PRId32 ", ", x.tagged.payload.integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (janet_type(x)) {
|
||||||
|
case JANET_NIL:
|
||||||
|
printf("value=nil");
|
||||||
|
break;
|
||||||
|
case JANET_NUMBER:
|
||||||
|
printf("number=%.17g", janet_unwrap_number(x));
|
||||||
|
break;
|
||||||
|
case JANET_TRUE:
|
||||||
|
printf("value=true");
|
||||||
|
break;
|
||||||
|
case JANET_FALSE:
|
||||||
|
printf("value=false");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("pointer=%p", janet_unwrap_pointer(x));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(">\n");
|
||||||
|
}
|
||||||
|
@ -456,7 +456,9 @@ union Janet {
|
|||||||
|
|
||||||
#define janet_u64(x) ((x).u64)
|
#define janet_u64(x) ((x).u64)
|
||||||
#define janet_type(x) (((x).tagged.type < JANET_DOUBLE_OFFSET) ? (x).tagged.type : JANET_NUMBER)
|
#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_checktype(x, t) ((t) == JANET_NUMBER \
|
||||||
|
? (x).tagged.type >= JANET_DOUBLE_OFFSET \
|
||||||
|
: (x).tagged.type == (t))
|
||||||
#define janet_truthy(x) ((x).tagged.type != JANET_NIL && (x).tagged.type != JANET_FALSE)
|
#define janet_truthy(x) ((x).tagged.type != JANET_NIL && (x).tagged.type != JANET_FALSE)
|
||||||
|
|
||||||
JANET_API Janet janet_wrap_number(double x);
|
JANET_API Janet janet_wrap_number(double x);
|
||||||
@ -1077,6 +1079,7 @@ JANET_API int janet_getindex(Janet ds, int32_t index, Janet *out);
|
|||||||
JANET_API int janet_length(Janet x, int32_t *out);
|
JANET_API int janet_length(Janet x, int32_t *out);
|
||||||
JANET_API int janet_put(Janet ds, Janet key, Janet value);
|
JANET_API int janet_put(Janet ds, Janet key, Janet value);
|
||||||
JANET_API int janet_putindex(Janet ds, int32_t index, Janet value);
|
JANET_API int janet_putindex(Janet ds, int32_t index, Janet value);
|
||||||
|
JANET_API void janet_inspect(Janet x);
|
||||||
|
|
||||||
/* VM functions */
|
/* VM functions */
|
||||||
JANET_API int janet_init(void);
|
JANET_API int janet_init(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user