simplifications
This commit is contained in:
@@ -55,13 +55,13 @@ enum mist_obj_type {
|
||||
OBJ_FORWARD = 7
|
||||
};
|
||||
|
||||
typedef uint64_t JSValue;
|
||||
|
||||
#define OBJHDR_S_BIT 3u
|
||||
#define OBJHDR_P_BIT 4u
|
||||
#define OBJHDR_A_BIT 5u
|
||||
#define OBJHDR_R_BIT 7u
|
||||
|
||||
|
||||
#define OBJHDR_FLAG(bit) ((objhdr_t)1ull << (bit))
|
||||
#define OBJHDR_S_MASK OBJHDR_FLAG (OBJHDR_S_BIT)
|
||||
#define OBJHDR_P_MASK OBJHDR_FLAG (OBJHDR_P_BIT)
|
||||
@@ -115,39 +115,24 @@ struct JSGCRef;
|
||||
|
||||
============================================================ */
|
||||
|
||||
#if INTPTR_MAX >= INT64_MAX
|
||||
#define JS_PTR64
|
||||
#define JS_PTR64_DEF(a) a
|
||||
typedef uint64_t JSValue;
|
||||
#define JSW 8
|
||||
#else
|
||||
typedef uint32_t JSValue;
|
||||
#define JSW 4
|
||||
#define JS_PTR64_DEF(a)
|
||||
#endif
|
||||
|
||||
#define JSValue JSValue
|
||||
|
||||
/* JSValueConst is just JSValue (const is not needed in value semantics) */
|
||||
typedef JSValue JSValueConst;
|
||||
|
||||
#define JSW 8
|
||||
|
||||
/* LSB-based tags */
|
||||
enum {
|
||||
/* Primary tags (low bits) */
|
||||
JS_TAG_INT = 0, /* LSB = 0 */
|
||||
JS_TAG_PTR = 1, /* LSB = 01 */
|
||||
#ifdef JS_PTR64
|
||||
JS_TAG_SHORT_FLOAT = 5, /* LSB = 101 */
|
||||
#endif
|
||||
JS_TAG_SPECIAL = 3, /* LSB = 11 */
|
||||
|
||||
/* Special subtypes (5 bits: xxxx11) */
|
||||
JS_TAG_BOOL = 0x03, /* 00011 */
|
||||
JS_TAG_NULL = 0x07, /* 00111 */
|
||||
JS_TAG_EXCEPTION = 0x0F, /* 01111 */
|
||||
JS_TAG_UNINITIALIZED = 0x17, /* 10111 */
|
||||
JS_TAG_STRING_IMM = 0x1B, /* 11011 - immediate ASCII (up to 7 chars) */
|
||||
JS_TAG_CATCH_OFFSET = 0x1F, /* 11111 */
|
||||
JS_TAG_STRING_IMM = 0x0B, /* 01011 - immediate ASCII (up to 7 chars) */
|
||||
};
|
||||
|
||||
/* Compatibility tag aliases for external code */
|
||||
@@ -180,16 +165,10 @@ void JS_DeleteGCRef(JSContext *ctx, JSGCRef *ref);
|
||||
/* Get primary tag (low 2-3 bits) */
|
||||
static inline int
|
||||
JS_VALUE_GET_TAG (JSValue v) {
|
||||
#ifdef JS_PTR64
|
||||
if ((v & 1) == 0) return JS_TAG_INT;
|
||||
if ((v & 7) == JS_TAG_SHORT_FLOAT) return JS_TAG_SHORT_FLOAT;
|
||||
if ((v & 3) == JS_TAG_PTR) return JS_TAG_PTR;
|
||||
return (int)(v & 0x1F); /* special tag */
|
||||
#else
|
||||
if ((v & 1) == 0) return JS_TAG_INT;
|
||||
if ((v & 3) == JS_TAG_PTR) return JS_TAG_PTR;
|
||||
return (int)(v & 0x1F);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG (v)
|
||||
@@ -220,7 +199,6 @@ static inline JSValue _JS_MkVal (int tag, int32_t val) {
|
||||
Out of range → JS_NULL
|
||||
============================================================ */
|
||||
|
||||
#ifdef JS_PTR64
|
||||
static inline JSValue
|
||||
__JS_NewFloat64 (JSContext *ctx, double d) {
|
||||
union {
|
||||
@@ -280,17 +258,6 @@ static inline double JS_VALUE_GET_FLOAT64 (JSValue v) {
|
||||
#define JS_TAG_IS_FLOAT64(tag) ((tag) == JS_TAG_SHORT_FLOAT)
|
||||
#define JS_NAN JS_MKVAL (JS_TAG_NULL, 0)
|
||||
|
||||
#else /* 32-bit: no short float, use boxed double */
|
||||
|
||||
static inline JSValue __JS_NewFloat64 (JSContext *ctx,
|
||||
double d); /* forward decl */
|
||||
static inline double JS_VALUE_GET_FLOAT64 (JSValue v);
|
||||
|
||||
#define JS_TAG_IS_FLOAT64(tag) (0)
|
||||
#define JS_NAN JS_MKVAL (JS_TAG_NULL, 0)
|
||||
|
||||
#endif /* JS_PTR64 */
|
||||
|
||||
/* ============================================================
|
||||
Type Checks
|
||||
============================================================ */
|
||||
@@ -299,14 +266,10 @@ static inline JS_BOOL JS_IsInt (JSValue v) { return (v & 1) == 0; }
|
||||
static inline JS_BOOL JS_IsPtr (JSValue v) { return (v & 7) == JS_TAG_PTR; }
|
||||
static inline JS_BOOL JS_IsSpecial (JSValue v) { return (v & 3) == JS_TAG_SPECIAL; }
|
||||
|
||||
|
||||
|
||||
#ifdef JS_PTR64
|
||||
static inline JS_BOOL
|
||||
JS_IsShortFloat (JSValue v) {
|
||||
return (v & 7) == JS_TAG_SHORT_FLOAT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define JS_VALUE_IS_BOTH_INT(v1, v2) (((v1) & 1) == 0 && ((v2) & 1) == 0)
|
||||
#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) \
|
||||
@@ -320,7 +283,6 @@ JS_IsShortFloat (JSValue v) {
|
||||
#define JS_FALSE ((JSValue)JS_TAG_BOOL)
|
||||
#define JS_TRUE ((JSValue)(JS_TAG_BOOL | (1 << 5)))
|
||||
#define JS_EXCEPTION ((JSValue)JS_TAG_EXCEPTION)
|
||||
#define JS_UNINITIALIZED ((JSValue)JS_TAG_UNINITIALIZED)
|
||||
|
||||
/* flags for object properties - simplified model:
|
||||
- No per-property writable/configurable (use stone() for immutability)
|
||||
@@ -433,11 +395,6 @@ JS_NewInt32 (JSContext *ctx, int32_t val) {
|
||||
return JS_MKVAL (JS_TAG_INT, val);
|
||||
}
|
||||
|
||||
static inline JSValue
|
||||
JS_NewCatchOffset (JSContext *ctx, int32_t val) {
|
||||
return JS_MKVAL (JS_TAG_CATCH_OFFSET, val);
|
||||
}
|
||||
|
||||
static inline JSValue
|
||||
JS_NewInt64 (JSContext *ctx, int64_t val) {
|
||||
JSValue v;
|
||||
@@ -495,10 +452,6 @@ static inline JS_BOOL JS_IsException (JSValue v) {
|
||||
return (JS_VALUE_GET_TAG (v) == JS_TAG_EXCEPTION);
|
||||
}
|
||||
|
||||
static inline JS_BOOL JS_IsUninitialized (JSValue v) {
|
||||
return (JS_VALUE_GET_TAG (v) == JS_TAG_UNINITIALIZED);
|
||||
}
|
||||
|
||||
/* Immediate String Helpers */
|
||||
#define MIST_ASCII_MAX_LEN 7
|
||||
|
||||
@@ -512,13 +465,11 @@ MIST_GetImmediateASCIILen (JSValue v) {
|
||||
return (int)((v >> 5) & 0x7);
|
||||
}
|
||||
|
||||
static inline int
|
||||
MIST_GetImmediateASCIIChar (JSValue v, int idx) {
|
||||
static inline int MIST_GetImmediateASCIIChar (JSValue v, int idx) {
|
||||
return (int)((v >> (8 + idx * 8)) & 0xFF);
|
||||
}
|
||||
|
||||
static inline JSValue
|
||||
MIST_TryNewImmediateASCII (const char *str, size_t len) {
|
||||
static inline JSValue MIST_TryNewImmediateASCII (const char *str, size_t len) {
|
||||
if (len > MIST_ASCII_MAX_LEN) return JS_NULL;
|
||||
JSValue v = (JSValue)JS_TAG_STRING_IMM | ((JSValue)len << 5);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@@ -529,20 +480,10 @@ MIST_TryNewImmediateASCII (const char *str, size_t len) {
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline JS_BOOL JS_IsInteger (JSValue v) {
|
||||
return JS_VALUE_GET_TAG (v) == JS_TAG_INT;
|
||||
}
|
||||
|
||||
static inline JS_BOOL JS_IsObject (JSValue v) {
|
||||
return JS_IsPtr (v);
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsArray(JSValue v);
|
||||
JS_BOOL JS_IsRecord(JSValue v);
|
||||
#define JS_IsObject JS_IsRecord
|
||||
JS_BOOL JS_IsFunction(JSValue v);
|
||||
JS_BOOL JS_IsCode(JSValue v);
|
||||
JS_BOOL JS_IsForwarded(JSValue v);
|
||||
JS_BOOL JS_IsFrame(JSValue v);
|
||||
JS_BOOL JS_IsBlob(JSValue v);
|
||||
JS_BOOL JS_IsText(JSValue v);
|
||||
static JS_BOOL JS_IsStone(JSValue v);
|
||||
@@ -565,6 +506,7 @@ JSValue __js_printf_like (2, 3)
|
||||
JS_ThrowInternalError (JSContext *ctx, const char *fmt, ...);
|
||||
JSValue JS_ThrowOutOfMemory (JSContext *ctx);
|
||||
|
||||
// TODO: rename this to just "eq"
|
||||
JS_BOOL JS_StrictEq (JSContext *ctx, JSValue op1, JSValue op2);
|
||||
|
||||
int JS_ToBool (JSContext *ctx, JSValue val); /* return -1 for JS_EXCEPTION */
|
||||
@@ -599,7 +541,6 @@ JSValue JS_NewObject (JSContext *ctx);
|
||||
JSValue JS_NewArray (JSContext *ctx);
|
||||
JSValue JS_NewArrayLen (JSContext *ctx, uint32_t len);
|
||||
|
||||
/* GC-safe push: takes pointer to array, updates it if array grows */
|
||||
int JS_ArrayPush (JSContext *ctx, JSValue *arr_ptr, JSValue val);
|
||||
JSValue JS_ArrayPop (JSContext *ctx, JSValue obj);
|
||||
|
||||
@@ -664,24 +605,17 @@ void JS_PrintTextLn (JSContext *ctx, JSValue val);
|
||||
void JS_PrintFormatted (JSContext *ctx, const char *fmt, int count, JSValue *values);
|
||||
|
||||
JSValue JS_GetProperty (JSContext *ctx, JSValue this_obj, JSValue prop);
|
||||
int JS_SetProperty (JSContext *ctx, JSValue this_obj, JSValue prop, JSValue val);
|
||||
|
||||
// For records
|
||||
JSValue JS_GetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop);
|
||||
int JS_SetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop, JSValue val);
|
||||
|
||||
// Set property on the global object
|
||||
int JS_SetGlobalStr (JSContext *ctx, const char *prop, JSValue val);
|
||||
int JS_SetProperty (JSContext *ctx, JSValue this_obj, JSValue prop, JSValue val);
|
||||
JSValue JS_GetPrototype (JSContext *ctx, JSValue val);
|
||||
|
||||
// Must be an array
|
||||
JSValue JS_GetPropertyNumber (JSContext *ctx, JSValue this_obj, int idx);
|
||||
JSValue JS_SetPropertyNumber (JSContext *ctx, JSValue obj, int idx, JSValue val);
|
||||
|
||||
// Indexed property access (works with arrays and objects)
|
||||
JSValue JS_GetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx);
|
||||
int JS_SetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx, JSValue val);
|
||||
int JS_SetPropertyInt64 (JSContext *ctx, JSValue this_obj, int64_t idx, JSValue val);
|
||||
JSValue JS_GetPrototype (JSContext *ctx, JSValue val);
|
||||
|
||||
/* Get property keys as array of text */
|
||||
JSValue JS_GetOwnPropertyNames (JSContext *ctx, JSValue obj);
|
||||
@@ -706,13 +640,6 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj,
|
||||
typedef int JSInterruptHandler (JSRuntime *rt, void *opaque);
|
||||
void JS_SetInterruptHandler (JSContext *ctx, JSInterruptHandler *cb,
|
||||
void *opaque);
|
||||
/* select which debug info is stripped from the compiled code */
|
||||
#define JS_STRIP_SOURCE (1 << 0) /* strip source code */
|
||||
#define JS_STRIP_DEBUG \
|
||||
(1 << 1) /* strip all debug info including source code */
|
||||
void JS_SetStripInfo (JSRuntime *rt, int flags);
|
||||
int JS_GetStripInfo (JSRuntime *rt);
|
||||
|
||||
|
||||
/* C function definition */
|
||||
typedef enum JSCFunctionEnum {
|
||||
|
||||
Reference in New Issue
Block a user