cleanup
This commit is contained in:
327
source/quickjs.c
327
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -45,10 +45,25 @@ extern "C" {
|
|||||||
#define __js_printf_like(a, b)
|
#define __js_printf_like(a, b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// #define BINARY32 // 32 bit word type (float)
|
||||||
|
// #define BINARY64 // 64 bit word type (double)
|
||||||
|
// #define DEC64 // 64 bit word type (dec)
|
||||||
|
|
||||||
|
/*
|
||||||
|
NaN boxing is used, always. A value is the length of the word.
|
||||||
|
Half: 10 bits
|
||||||
|
Float: 23 bits
|
||||||
|
Double: 52 bits
|
||||||
|
Dec64: 56 bits
|
||||||
|
|
||||||
|
On double builds, 48 bits
|
||||||
|
On Dec64, max
|
||||||
|
*/
|
||||||
|
|
||||||
#define JS_BOOL int
|
#define JS_BOOL int
|
||||||
|
|
||||||
typedef struct JSRuntime JSRuntime;
|
typedef struct JSRuntime JSRuntime; // the entire VM
|
||||||
typedef struct JSContext JSContext;
|
typedef struct JSContext JSContext; // Each actor - has its own GC
|
||||||
typedef struct JSClass JSClass;
|
typedef struct JSClass JSClass;
|
||||||
typedef uint32_t JSClassID;
|
typedef uint32_t JSClassID;
|
||||||
typedef uint32_t JSAtom;
|
typedef uint32_t JSAtom;
|
||||||
@@ -64,14 +79,14 @@ typedef uint32_t JSAtom;
|
|||||||
#define JS_NAN_BOXING
|
#define JS_NAN_BOXING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
|
/*
|
||||||
#define JS_LIMB_BITS 64
|
Mist tags:
|
||||||
#else
|
0: false
|
||||||
#define JS_LIMB_BITS 32
|
1: true
|
||||||
#endif
|
2: null
|
||||||
|
4: object
|
||||||
|
*/
|
||||||
|
|
||||||
#define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/* all tags with a reference count are negative */
|
/* all tags with a reference count are negative */
|
||||||
JS_TAG_FIRST = -10, /* first negative tag */
|
JS_TAG_FIRST = -10, /* first negative tag */
|
||||||
@@ -80,7 +95,6 @@ enum {
|
|||||||
JS_TAG_STRING_ROPE = -7,
|
JS_TAG_STRING_ROPE = -7,
|
||||||
JS_TAG_ARRAY = -6, /* intrinsic array type */
|
JS_TAG_ARRAY = -6, /* intrinsic array type */
|
||||||
JS_TAG_FUNCTION = -5, /* intrinsic function type */
|
JS_TAG_FUNCTION = -5, /* intrinsic function type */
|
||||||
JS_TAG_MODULE = -3, /* used internally */
|
|
||||||
JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
|
JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
|
||||||
JS_TAG_OBJECT = -1,
|
JS_TAG_OBJECT = -1,
|
||||||
|
|
||||||
@@ -90,7 +104,6 @@ enum {
|
|||||||
JS_TAG_UNINITIALIZED = 4,
|
JS_TAG_UNINITIALIZED = 4,
|
||||||
JS_TAG_CATCH_OFFSET = 5,
|
JS_TAG_CATCH_OFFSET = 5,
|
||||||
JS_TAG_EXCEPTION = 6,
|
JS_TAG_EXCEPTION = 6,
|
||||||
JS_TAG_SHORT_BIG_INT = 7,
|
|
||||||
JS_TAG_FLOAT64 = 8,
|
JS_TAG_FLOAT64 = 8,
|
||||||
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
|
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
|
||||||
};
|
};
|
||||||
@@ -116,7 +129,6 @@ typedef const struct __JSValue *JSValueConst;
|
|||||||
#define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)
|
#define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)
|
||||||
#define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)
|
#define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)
|
||||||
#define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)
|
#define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)
|
||||||
#define JS_VALUE_GET_SHORT_BIG_INT(v) JS_VALUE_GET_INT(v)
|
|
||||||
#define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)
|
#define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)
|
||||||
|
|
||||||
#define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
|
#define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
|
||||||
@@ -145,7 +157,6 @@ typedef uint64_t JSValue;
|
|||||||
#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
|
#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
|
||||||
#define JS_VALUE_GET_INT(v) (int)(v)
|
#define JS_VALUE_GET_INT(v) (int)(v)
|
||||||
#define JS_VALUE_GET_BOOL(v) (int)(v)
|
#define JS_VALUE_GET_BOOL(v) (int)(v)
|
||||||
#define JS_VALUE_GET_SHORT_BIG_INT(v) (int)(v)
|
|
||||||
#define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)
|
#define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)
|
||||||
|
|
||||||
#define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
|
#define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
|
||||||
@@ -208,11 +219,6 @@ typedef union JSValueUnion {
|
|||||||
int32_t int32;
|
int32_t int32;
|
||||||
double float64;
|
double float64;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
#if JS_SHORT_BIG_INT_BITS == 32
|
|
||||||
int32_t short_big_int;
|
|
||||||
#else
|
|
||||||
int64_t short_big_int;
|
|
||||||
#endif
|
|
||||||
} JSValueUnion;
|
} JSValueUnion;
|
||||||
|
|
||||||
typedef struct JSValue {
|
typedef struct JSValue {
|
||||||
@@ -228,7 +234,6 @@ typedef struct JSValue {
|
|||||||
#define JS_VALUE_GET_INT(v) ((v).u.int32)
|
#define JS_VALUE_GET_INT(v) ((v).u.int32)
|
||||||
#define JS_VALUE_GET_BOOL(v) ((v).u.int32)
|
#define JS_VALUE_GET_BOOL(v) ((v).u.int32)
|
||||||
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
|
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
|
||||||
#define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int)
|
|
||||||
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
|
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
|
||||||
|
|
||||||
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
|
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
|
||||||
@@ -298,7 +303,6 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
|||||||
|
|
||||||
typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
||||||
typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
|
typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
|
||||||
typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);
|
|
||||||
|
|
||||||
typedef struct JSMallocState {
|
typedef struct JSMallocState {
|
||||||
size_t malloc_count;
|
size_t malloc_count;
|
||||||
@@ -613,7 +617,6 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
|
|||||||
|
|
||||||
JS_BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
|
JS_BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
|
||||||
JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
|
JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
|
||||||
JS_BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
|
|
||||||
|
|
||||||
int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
|
int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
|
||||||
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
|
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
|
||||||
@@ -623,7 +626,6 @@ static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
|
|||||||
}
|
}
|
||||||
int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom);
|
int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom);
|
||||||
int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
||||||
int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val);
|
|
||||||
int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);
|
int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);
|
||||||
/* return an exception if 'val' is a Number */
|
/* return an exception if 'val' is a Number */
|
||||||
|
|
||||||
@@ -665,22 +667,18 @@ static js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_
|
|||||||
return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);
|
return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generic
|
||||||
|
JSValue JS_GetPropertyV(JSContext *js, JSValue obj, JSValue prop);
|
||||||
|
JSValue JS_SetPropertyV(JSContext *js, JSValue obj, JSValue prop, JSValue val);
|
||||||
|
|
||||||
// For records
|
// For records
|
||||||
JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop);
|
JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop);
|
||||||
int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop, JSValue val);
|
int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop, JSValue val);
|
||||||
int JS_SetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop, JSValue val);
|
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
|
||||||
JSValue JS_GetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key);
|
|
||||||
int JS_SetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key, JSValue val);
|
|
||||||
|
|
||||||
// Must be an array
|
// Must be an array
|
||||||
JSValue JS_GetPropertyNumber(JSContext *ctx, JSValueConst this_obj, int idx);
|
JSValue JS_GetPropertyNumber(JSContext *ctx, JSValueConst this_obj, int idx);
|
||||||
JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx);
|
JSValue JS_SetPropertyNumber(JSContext *ctx, JSValue obj, int idx, JSValue val);
|
||||||
int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx, JSValue val);
|
|
||||||
int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj, int64_t idx, JSValue val);
|
|
||||||
|
|
||||||
int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
|
|
||||||
int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop);
|
|
||||||
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
|
|
||||||
|
|
||||||
/* Get Own Property Names flags */
|
/* Get Own Property Names flags */
|
||||||
#define JS_GPN_STRING_MASK (1 << 0)
|
#define JS_GPN_STRING_MASK (1 << 0)
|
||||||
@@ -788,9 +786,6 @@ typedef union JSCFunctionType {
|
|||||||
JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
|
JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
|
||||||
const char *name,
|
const char *name,
|
||||||
int length, JSCFunctionEnum cproto, int magic);
|
int length, JSCFunctionEnum cproto, int magic);
|
||||||
JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
|
|
||||||
int length, int magic, int data_len,
|
|
||||||
JSValueConst *data);
|
|
||||||
|
|
||||||
static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,
|
static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,
|
||||||
int length)
|
int length)
|
||||||
|
|||||||
Reference in New Issue
Block a user