merge cell
This commit is contained in:
@@ -49,12 +49,173 @@
|
||||
#include "libregexp.h"
|
||||
#include "libunicode.h"
|
||||
#include "list.h"
|
||||
#include "quickjs.h"
|
||||
#include "cell.h"
|
||||
#include "cJSON.h"
|
||||
#include "blob.h"
|
||||
#include "nota.h"
|
||||
#include "wota.h"
|
||||
|
||||
/* ============================================================
|
||||
Internal API — not for C module authors
|
||||
============================================================ */
|
||||
|
||||
/* Object header types */
|
||||
enum mist_obj_type {
|
||||
OBJ_ARRAY = 0,
|
||||
OBJ_BLOB = 1,
|
||||
OBJ_TEXT = 2,
|
||||
OBJ_RECORD = 3, // js style objects
|
||||
OBJ_FUNCTION = 4,
|
||||
OBJ_CODE = 5,
|
||||
OBJ_FRAME = 6,
|
||||
OBJ_FORWARD = 7
|
||||
};
|
||||
|
||||
/* Object header bits */
|
||||
#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)
|
||||
#define OBJHDR_A_MASK OBJHDR_FLAG (OBJHDR_A_BIT)
|
||||
#define OBJHDR_R_MASK OBJHDR_FLAG (OBJHDR_R_BIT)
|
||||
|
||||
typedef uint64_t word_t; // one actor-memory word
|
||||
typedef uint64_t objhdr_t; // header word
|
||||
typedef uint64_t objref_t; // 56-bit word address (0 = null)
|
||||
|
||||
static inline uint8_t objhdr_type (objhdr_t h) { return (uint8_t)(h & 7u); }
|
||||
static inline int objhdr_s (objhdr_t h) { return (h & OBJHDR_S_MASK) != 0; }
|
||||
|
||||
/* Word size constant */
|
||||
#define JSW 8
|
||||
|
||||
/* Runtime / Context lifecycle */
|
||||
JSRuntime *JS_NewRuntime (void);
|
||||
void JS_FreeRuntime (JSRuntime *rt);
|
||||
void JS_SetMemoryLimit (JSRuntime *rt, size_t limit);
|
||||
void JS_SetPoolSize (JSRuntime *rt, size_t initial, size_t cap);
|
||||
|
||||
JSContext *JS_NewContext (JSRuntime *rt);
|
||||
JSContext *JS_NewContextWithHeapSize (JSRuntime *rt, size_t heap_size);
|
||||
void JS_FreeContext (JSContext *s);
|
||||
void *JS_GetContextOpaque (JSContext *ctx);
|
||||
void JS_SetContextOpaque (JSContext *ctx, void *opaque);
|
||||
|
||||
typedef void (*JS_GCScanFn)(JSContext *ctx,
|
||||
uint8_t *from_base, uint8_t *from_end,
|
||||
uint8_t *to_base, uint8_t **to_free, uint8_t *to_end);
|
||||
void JS_SetGCScanExternal(JSContext *ctx, JS_GCScanFn fn);
|
||||
|
||||
void JS_SetActorSym (JSContext *ctx, JSValue sym);
|
||||
JSValue JS_GetActorSym (JSContext *ctx);
|
||||
JSRuntime *JS_GetRuntime (JSContext *ctx);
|
||||
void JS_SetMaxStackSize (JSContext *ctx, size_t stack_size);
|
||||
void JS_UpdateStackTop (JSContext *ctx);
|
||||
int JS_GetVMCallDepth(JSContext *ctx);
|
||||
void JS_SetHeapMemoryLimit(JSContext *ctx, size_t limit);
|
||||
void JS_SetPauseFlag(JSContext *ctx, int value);
|
||||
JS_BOOL JS_IsLiveObject (JSRuntime *rt, JSValue obj);
|
||||
|
||||
/* Suspended state */
|
||||
#define JS_TAG_SUSPENDED 0x13 /* 10011 - distinct special tag */
|
||||
#define JS_SUSPENDED ((JSValue)JS_TAG_SUSPENDED)
|
||||
|
||||
static inline JS_BOOL JS_IsSuspended(JSValue v) {
|
||||
return JS_VALUE_GET_TAG(v) == JS_TAG_SUSPENDED;
|
||||
}
|
||||
|
||||
#ifndef JS_DEFAULT_STACK_SIZE
|
||||
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
|
||||
#endif
|
||||
|
||||
/* Internal compile flags */
|
||||
#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)
|
||||
|
||||
/* Compilation and MachCode */
|
||||
struct cJSON;
|
||||
typedef struct MachCode MachCode;
|
||||
|
||||
void JS_FreeMachCode(MachCode *mc);
|
||||
uint8_t *JS_SerializeMachCode(MachCode *mc, size_t *out_size);
|
||||
MachCode *JS_DeserializeMachCode(const uint8_t *data, size_t size);
|
||||
struct JSCodeRegister *JS_LoadMachCode(JSContext *ctx, MachCode *mc, JSValue env);
|
||||
JSValue JS_RunMachBin(JSContext *ctx, const uint8_t *data, size_t size, JSValue env);
|
||||
JSValue JS_RunMachMcode(JSContext *ctx, const char *json_str, size_t len, JSValue env);
|
||||
void JS_DumpMachBin(JSContext *ctx, const uint8_t *data, size_t size, JSValue env);
|
||||
MachCode *mach_compile_mcode(struct cJSON *mcode_json);
|
||||
|
||||
/* Debug / Dump utilities */
|
||||
typedef struct JSMemoryUsage {
|
||||
int64_t malloc_size, malloc_limit, memory_used_size;
|
||||
int64_t malloc_count;
|
||||
int64_t memory_used_count;
|
||||
int64_t str_count, str_size;
|
||||
int64_t obj_count, obj_size;
|
||||
int64_t prop_count, prop_size;
|
||||
int64_t shape_count, shape_size;
|
||||
int64_t js_func_count, js_func_size, js_func_code_size;
|
||||
int64_t js_func_pc2line_count, js_func_pc2line_size;
|
||||
int64_t c_func_count, array_count;
|
||||
int64_t fast_array_count, fast_array_elements;
|
||||
int64_t binary_object_count, binary_object_size;
|
||||
} JSMemoryUsage;
|
||||
|
||||
void JS_ComputeMemoryUsage (JSRuntime *rt, JSMemoryUsage *s);
|
||||
void JS_DumpMemoryUsage (FILE *fp, const JSMemoryUsage *s, JSRuntime *rt);
|
||||
|
||||
typedef struct {
|
||||
JS_BOOL show_hidden : 8;
|
||||
JS_BOOL raw_dump : 8;
|
||||
uint32_t max_depth;
|
||||
uint32_t max_string_length;
|
||||
uint32_t max_item_count;
|
||||
} JSPrintValueOptions;
|
||||
|
||||
typedef void JSPrintValueWrite (void *opaque, const char *buf, size_t len);
|
||||
|
||||
void JS_PrintValueSetDefaultOptions (JSPrintValueOptions *options);
|
||||
void JS_PrintValueRT (JSRuntime *rt, JSPrintValueWrite *write_func,
|
||||
void *write_opaque, JSValue val,
|
||||
const JSPrintValueOptions *options);
|
||||
void JS_PrintValue (JSContext *ctx, JSPrintValueWrite *write_func,
|
||||
void *write_opaque, JSValue val,
|
||||
const JSPrintValueOptions *options);
|
||||
|
||||
void js_debug_info (JSContext *js, JSValue fn, js_debug *dbg);
|
||||
|
||||
uint32_t js_debugger_stack_depth (JSContext *ctx);
|
||||
JSValue js_debugger_backtrace_fns (JSContext *ctx);
|
||||
JSValue js_debugger_closure_variables (JSContext *ctx, JSValue fn);
|
||||
JSValue js_debugger_local_variables (JSContext *ctx, int stack_index);
|
||||
void js_debugger_set_closure_variable (JSContext *js, JSValue fn,
|
||||
JSValue var_name, JSValue val);
|
||||
JSValue js_debugger_build_backtrace (JSContext *ctx);
|
||||
JSValue js_debugger_fn_info (JSContext *ctx, JSValue fn);
|
||||
JSValue js_debugger_fn_bytecode (JSContext *js, JSValue fn);
|
||||
void *js_debugger_val_address (JSContext *js, JSValue val);
|
||||
|
||||
/* Stack trace */
|
||||
JSValue JS_GetStack (JSContext *ctx);
|
||||
void JS_CrashPrintStack(JSContext *ctx);
|
||||
|
||||
/* Serialization (internal) */
|
||||
JSValue wota2value(JSContext *js, void *v);
|
||||
void *value2wota(JSContext *js, JSValue v, JSValue replacer, size_t *bytes);
|
||||
JSValue nota2value(JSContext *js, void *nota);
|
||||
void *value2nota(JSContext *js, JSValue v);
|
||||
|
||||
/* Internal module init (called during context init) */
|
||||
JSValue js_core_blob_use(JSContext *js);
|
||||
JSValue js_core_json_use(JSContext *js);
|
||||
|
||||
/* ============================================================
|
||||
End internal API declarations
|
||||
============================================================ */
|
||||
|
||||
void *js_malloc (JSContext *ctx, size_t size);
|
||||
void *js_mallocz (JSContext *ctx, size_t size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user