2 Commits

Author SHA1 Message Date
John Alanbrook
bcd6e641a5 initial try 2026-01-27 19:17:44 -06:00
John Alanbrook
2857581271 cleanup 2026-01-27 10:42:49 -06:00
4 changed files with 1347 additions and 336 deletions

View File

@@ -9,6 +9,8 @@
CELL_SHOP = $(HOME)/.cell
CELL_CORE_PACKAGE = $(CELL_SHOP)/packages/core
maker: install
makecell:
cell pack core -o cell
cp cell /opt/homebrew/bin/

View File

@@ -53,6 +53,7 @@ FMT(atom_u16)
FMT(atom_label_u8)
FMT(atom_label_u16)
FMT(label_u16)
FMT(key)
#undef FMT
#endif /* FMT */
@@ -122,14 +123,14 @@ DEF( put_ref_value, 1, 3, 0, none)
DEF( define_var, 6, 0, 0, atom_u8)
DEF(check_define_var, 6, 0, 0, atom_u8)
DEF( define_func, 6, 1, 0, atom_u8)
DEF( get_field, 5, 1, 1, atom)
DEF( get_field2, 5, 1, 2, atom)
DEF( put_field, 5, 2, 0, atom)
DEF( get_field, 5, 1, 1, key)
DEF( get_field2, 5, 1, 2, key)
DEF( put_field, 5, 2, 0, key)
DEF( get_array_el, 1, 2, 1, none)
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */
DEF( put_array_el, 1, 3, 0, none)
DEF( define_field, 5, 2, 1, atom)
DEF( define_field, 5, 2, 1, key)
DEF( set_name, 5, 1, 1, atom)
DEF(set_name_computed, 1, 2, 2, none)
DEF(define_array_el, 1, 3, 2, none)

File diff suppressed because it is too large Load Diff

View File

@@ -45,13 +45,52 @@ extern "C" {
#define __js_printf_like(a, b)
#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
typedef struct JSRuntime JSRuntime;
typedef struct JSContext JSContext;
typedef struct JSRuntime JSRuntime; // the entire VM
typedef struct JSContext JSContext; // Each actor - has its own GC
typedef struct JSClass JSClass;
typedef uint32_t JSClassID;
typedef uint32_t JSAtom;
typedef uint32_t mist_key;
/* KeyId: property key encoding for the Misty object system.
High 3 bits encode the key kind, low 29 bits are the payload. */
typedef uint32_t KeyId;
enum {
K_EMPTY = 0, /* reserved: empty slot marker */
K_TOMB = 1, /* reserved: tombstone marker */
K_TEXT = 2, /* text key (payload = stone text intern id) */
K_SYM = 3, /* symbol key (payload = symbol id) */
K_REC = 4 /* record key (payload = rec_key_id) */
};
#define KEY_KIND_SHIFT 29u
#define KEY_KIND_MASK (7u << KEY_KIND_SHIFT)
#define KEY_PAYLOAD_MASK ((1u << KEY_KIND_SHIFT) - 1u)
static inline uint32_t key_kind(KeyId k) { return (k >> KEY_KIND_SHIFT); }
static inline uint32_t key_payload(KeyId k) { return (k & KEY_PAYLOAD_MASK); }
static inline int key_is_text(KeyId k) { return key_kind(k) == K_TEXT; }
static inline int key_is_rec(KeyId k) { return key_kind(k) == K_REC; }
static inline KeyId key_text(uint32_t payload) { return (K_TEXT << KEY_KIND_SHIFT) | payload; }
static inline KeyId key_rec(uint32_t payload) { return (K_REC << KEY_KIND_SHIFT) | payload; }
#if INTPTR_MAX >= INT64_MAX
#define JS_PTR64
@@ -64,14 +103,14 @@ typedef uint32_t JSAtom;
#define JS_NAN_BOXING
#endif
#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
#define JS_LIMB_BITS 64
#else
#define JS_LIMB_BITS 32
#endif
/*
Mist tags:
0: false
1: true
2: null
4: object
*/
#define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS
enum {
/* all tags with a reference count are negative */
JS_TAG_FIRST = -10, /* first negative tag */
@@ -80,7 +119,6 @@ enum {
JS_TAG_STRING_ROPE = -7,
JS_TAG_ARRAY = -6, /* intrinsic array type */
JS_TAG_FUNCTION = -5, /* intrinsic function type */
JS_TAG_MODULE = -3, /* used internally */
JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
JS_TAG_OBJECT = -1,
@@ -90,7 +128,6 @@ enum {
JS_TAG_UNINITIALIZED = 4,
JS_TAG_CATCH_OFFSET = 5,
JS_TAG_EXCEPTION = 6,
JS_TAG_SHORT_BIG_INT = 7,
JS_TAG_FLOAT64 = 8,
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
};
@@ -116,7 +153,6 @@ typedef const struct __JSValue *JSValueConst;
#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_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_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
@@ -145,7 +181,6 @@ typedef uint64_t JSValue;
#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
#define JS_VALUE_GET_INT(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_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
@@ -208,11 +243,6 @@ typedef union JSValueUnion {
int32_t int32;
double float64;
void *ptr;
#if JS_SHORT_BIG_INT_BITS == 32
int32_t short_big_int;
#else
int64_t short_big_int;
#endif
} JSValueUnion;
typedef struct JSValue {
@@ -228,7 +258,6 @@ typedef struct JSValue {
#define JS_VALUE_GET_INT(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_SHORT_BIG_INT(v) ((v).u.short_big_int)
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
@@ -298,7 +327,7 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
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 JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);
typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *data);
typedef struct JSMallocState {
size_t malloc_count;
@@ -613,7 +642,6 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
JS_BOOL JS_StrictEq(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_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
@@ -623,7 +651,6 @@ static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
}
int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom);
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);
/* return an exception if 'val' is a Number */
@@ -665,23 +692,25 @@ static js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_
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
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_SetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop, JSValue val);
JSValue JS_GetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key);
int JS_SetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key, JSValue val);
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
// Must be an array
JSValue JS_GetPropertyNumber(JSContext *ctx, JSValueConst 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, JSValueConst this_obj, uint32_t idx);
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 */
#define JS_GPN_STRING_MASK (1 << 0)
#define JS_GPN_SYMBOL_MASK (1 << 1)
@@ -788,9 +817,6 @@ typedef union JSCFunctionType {
JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
const char *name,
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,
int length)