New partly working cell model

This commit is contained in:
2026-10-07 16:41:33 +00:00
parent 44498b32a9
commit 2b612d19ed
14 changed files with 981 additions and 1902 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ bool __any_is_string(any_t a) { return a.kind == JSRT_KIND_STRING; }
bool __any_is_object(any_t a) { return a.kind == JSRT_KIND_OBJECT; }
bool __any_is_function(any_t a) {
return a.kind == JSRT_KIND_OBJECT && jsrt_fn_sites[((jsrt_header *)a.as.o)->site];
return a.kind == JSRT_KIND_OBJECT && jsrt_fn_cells[((jsrt_header *)a.as.o)->cell];
}
// ── any: abstract operations ──
+7 -13
View File
@@ -12,23 +12,18 @@ typedef struct { char _; } null_t;
// A string: UTF-16 code units, as JS counts them
typedef struct jsrt_string *string_t;
// The start of every object: the site that created it, which tells its shape
// The start of every object: the number of its cell, which tells its struct
// and, for a fn, its code
typedef struct { uint32_t site; } jsrt_header;
typedef struct { uint32_t cell; } jsrt_header;
// The sites below 3 are tags. An object of a value shape is a struct, not a
// pointer, so its header tells if it is undefined, null or absent instead
#define JSRT_SITE_UNDEFINED 0
#define JSRT_SITE_NULL 1
#define JSRT_SITE_ABSENT 2
// A pointer to an object or a string can also be one of these. NULL is null
// A pointer to an object or a string can also be one of these. NULL is null.
// They are told apart by their address only
extern jsrt_header jsrt_undefined_cell, jsrt_absent_cell;
#define JSRT_UNDEFINED ((void *)&jsrt_undefined_cell)
#define JSRT_ABSENT ((void *)&jsrt_absent_cell) // a field that an object lacks
// Whether the objects of each site are fns, by site. The emitted C defines it
extern const bool jsrt_fn_sites[];
// Whether the objects of each cell are fns, by cell. The emitted C defines it
extern const bool jsrt_fn_cells[];
// A new heap cell of `size` bytes, all zero
void *jsrt_alloc(size_t size);
@@ -48,8 +43,7 @@ void *jsrt_some(void *p);
#include <stdio.h>
#include <stdlib.h>
jsrt_header jsrt_undefined_cell = { JSRT_SITE_UNDEFINED };
jsrt_header jsrt_absent_cell = { JSRT_SITE_ABSENT };
jsrt_header jsrt_undefined_cell, jsrt_absent_cell;
void *jsrt_alloc(size_t size) {
void *p = calloc(1, size);