1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 07:33:01 +00:00

Rename to janet

This commit is contained in:
Calvin Rose
2018-09-05 22:18:42 -04:00
parent 285f2d7ea9
commit c8ef2a0d88
69 changed files with 6199 additions and 6259 deletions

View File

@@ -20,141 +20,141 @@
* IN THE SOFTWARE.
*/
#include <dst/dst.h>
#include <janet/janet.h>
#ifdef DST_NANBOX
#ifdef JANET_NANBOX
void *dst_nanbox_to_pointer(Dst x) {
void *janet_nanbox_to_pointer(Janet x) {
/* We need to do this shift to keep the higher bits of the pointer
* the same as bit 47 as required by the x86 architecture. We may save
* an instruction if we do x.u64 & DST_NANBOX_POINTERBITS, but this 0s
* an instruction if we do x.u64 & JANET_NANBOX_POINTERBITS, but this 0s
* the high bits, and may make the pointer non-canocial on x86. If we switch
* to 47 bit pointers (which is what userspace uses on Windows, we can use
* the single mask rather than two shifts. */
#if defined (DST_NANBOX_47) || defined (DST_32)
x.i64 &= DST_NANBOX_POINTERBITS;
#if defined (JANET_NANBOX_47) || defined (JANET_32)
x.i64 &= JANET_NANBOX_POINTERBITS;
#else
x.i64 = (x.i64 << 16) >> 16;
#endif
return (void *)x.i64;
}
Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask) {
Dst ret;
Janet janet_nanbox_from_pointer(void *p, uint64_t tagmask) {
Janet ret;
ret.u64 = (int64_t)p;
#if defined (DST_NANBOX_47) || defined (DST_32)
#if defined (JANET_NANBOX_47) || defined (JANET_32)
#else
ret.u64 &= DST_NANBOX_POINTERBITS;
ret.u64 &= JANET_NANBOX_POINTERBITS;
#endif
ret.u64 |= tagmask;
return ret;
}
Dst dst_nanbox_from_cpointer(const void *p, uint64_t tagmask) {
Dst ret;
Janet janet_nanbox_from_cpointer(const void *p, uint64_t tagmask) {
Janet ret;
ret.u64 = (int64_t)p;
#if defined (DST_NANBOX_47) || defined (DST_32)
#if defined (JANET_NANBOX_47) || defined (JANET_32)
#else
ret.u64 &= DST_NANBOX_POINTERBITS;
ret.u64 &= JANET_NANBOX_POINTERBITS;
#endif
ret.u64 |= tagmask;
return ret;
}
Dst dst_nanbox_from_double(double d) {
Dst ret;
Janet janet_nanbox_from_double(double d) {
Janet ret;
ret.real = d;
/* Normalize NaNs */
if (d != d)
ret.u64 = dst_nanbox_tag(DST_REAL);
ret.u64 = janet_nanbox_tag(JANET_REAL);
return ret;
}
Dst dst_nanbox_from_bits(uint64_t bits) {
Dst ret;
Janet janet_nanbox_from_bits(uint64_t bits) {
Janet ret;
ret.u64 = bits;
return ret;
}
void *dst_nanbox_memalloc_empty(int32_t count) {
void *janet_nanbox_memalloc_empty(int32_t count) {
int32_t i;
void *mem = malloc(count * sizeof(DstKV));
DstKV *mmem = (DstKV *)mem;
void *mem = malloc(count * sizeof(JanetKV));
JanetKV *mmem = (JanetKV *)mem;
for (i = 0; i < count; i++) {
DstKV *kv = mmem + i;
kv->key = dst_wrap_nil();
kv->value = dst_wrap_nil();
JanetKV *kv = mmem + i;
kv->key = janet_wrap_nil();
kv->value = janet_wrap_nil();
}
return mem;
}
void dst_nanbox_memempty(DstKV *mem, int32_t count) {
void janet_nanbox_memempty(JanetKV *mem, int32_t count) {
int32_t i;
for (i = 0; i < count; i++) {
mem[i].key = dst_wrap_nil();
mem[i].value = dst_wrap_nil();
mem[i].key = janet_wrap_nil();
mem[i].value = janet_wrap_nil();
}
}
#else
/* Wrapper functions wrap a data type that is used from C into a
* dst value, which can then be used in dst internal functions. Use
* janet value, which can then be used in janet internal functions. Use
* these functions sparingly, as these function will let the programmer
* leak memory, where as the stack based API ensures that all values can
* be collected by the garbage collector. */
Dst dst_wrap_nil() {
Dst y;
y.type = DST_NIL;
Janet janet_wrap_nil() {
Janet y;
y.type = JANET_NIL;
y.as.u64 = 0;
return y;
}
Dst dst_wrap_true(void) {
Dst y;
y.type = DST_TRUE;
Janet janet_wrap_true(void) {
Janet y;
y.type = JANET_TRUE;
y.as.u64 = 0;
return y;
}
Dst dst_wrap_false(void) {
Dst y;
y.type = DST_FALSE;
Janet janet_wrap_false(void) {
Janet y;
y.type = JANET_FALSE;
y.as.u64 = 0;
return y;
}
Dst dst_wrap_boolean(int x) {
Dst y;
y.type = x ? DST_TRUE : DST_FALSE;
Janet janet_wrap_boolean(int x) {
Janet y;
y.type = x ? JANET_TRUE : JANET_FALSE;
y.as.u64 = 0;
return y;
}
#define DST_WRAP_DEFINE(NAME, TYPE, DTYPE, UM)\
Dst dst_wrap_##NAME(TYPE x) {\
Dst y;\
#define JANET_WRAP_DEFINE(NAME, TYPE, DTYPE, UM)\
Janet janet_wrap_##NAME(TYPE x) {\
Janet y;\
y.type = DTYPE;\
y.as.u64 = 0; /* zero other bits in case of 32 bit integer */ \
y.as.UM = x;\
return y;\
}
DST_WRAP_DEFINE(real, double, DST_REAL, real)
DST_WRAP_DEFINE(integer, int32_t, DST_INTEGER, integer)
DST_WRAP_DEFINE(string, const uint8_t *, DST_STRING, cpointer)
DST_WRAP_DEFINE(symbol, const uint8_t *, DST_SYMBOL, cpointer)
DST_WRAP_DEFINE(array, DstArray *, DST_ARRAY, pointer)
DST_WRAP_DEFINE(tuple, const Dst *, DST_TUPLE, cpointer)
DST_WRAP_DEFINE(struct, const DstKV *, DST_STRUCT, cpointer)
DST_WRAP_DEFINE(fiber, DstFiber *, DST_FIBER, pointer)
DST_WRAP_DEFINE(buffer, DstBuffer *, DST_BUFFER, pointer)
DST_WRAP_DEFINE(function, DstFunction *, DST_FUNCTION, pointer)
DST_WRAP_DEFINE(cfunction, DstCFunction, DST_CFUNCTION, pointer)
DST_WRAP_DEFINE(table, DstTable *, DST_TABLE, pointer)
DST_WRAP_DEFINE(abstract, void *, DST_ABSTRACT, pointer)
JANET_WRAP_DEFINE(real, double, JANET_REAL, real)
JANET_WRAP_DEFINE(integer, int32_t, JANET_INTEGER, integer)
JANET_WRAP_DEFINE(string, const uint8_t *, JANET_STRING, cpointer)
JANET_WRAP_DEFINE(symbol, const uint8_t *, JANET_SYMBOL, cpointer)
JANET_WRAP_DEFINE(array, JanetArray *, JANET_ARRAY, pointer)
JANET_WRAP_DEFINE(tuple, const Janet *, JANET_TUPLE, cpointer)
JANET_WRAP_DEFINE(struct, const JanetKV *, JANET_STRUCT, cpointer)
JANET_WRAP_DEFINE(fiber, JanetFiber *, JANET_FIBER, pointer)
JANET_WRAP_DEFINE(buffer, JanetBuffer *, JANET_BUFFER, pointer)
JANET_WRAP_DEFINE(function, JanetFunction *, JANET_FUNCTION, pointer)
JANET_WRAP_DEFINE(cfunction, JanetCFunction, JANET_CFUNCTION, pointer)
JANET_WRAP_DEFINE(table, JanetTable *, JANET_TABLE, pointer)
JANET_WRAP_DEFINE(abstract, void *, JANET_ABSTRACT, pointer)
#undef DST_WRAP_DEFINE
#undef JANET_WRAP_DEFINE
#endif