remove jsffi
This commit is contained in:
@@ -1,16 +1,3 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_MIMALLOC
|
||||
#include <mimalloc.h>
|
||||
#endif
|
||||
@@ -802,6 +789,8 @@ static int actor_interrupt_cb(JSRuntime *rt, cell_rt *crt)
|
||||
return SDL_GetAtomicInt(&shutting_down) || crt->disrupt;
|
||||
}
|
||||
|
||||
JSValue js_os_use(JSContext *js);
|
||||
|
||||
void script_startup(cell_rt *prt)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
@@ -830,17 +819,43 @@ void script_startup(cell_rt *prt)
|
||||
|
||||
JS_SetContextOpaque(js, prt);
|
||||
prt->context = js;
|
||||
ffi_load(js);
|
||||
|
||||
// Add core QOP blob to hidden
|
||||
cell_rt *crt = JS_GetContextOpaque(js);
|
||||
JS_FreeValue(js, js_blob_use(js));
|
||||
|
||||
JSValue globalThis = JS_GetGlobalObject(js);
|
||||
JSValue cell = JS_GetPropertyStr(js, globalThis, "cell");
|
||||
JSValue hidden = JS_GetPropertyStr(js, cell, "hidden");
|
||||
|
||||
JSValue cell = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js,globalThis,"cell", cell);
|
||||
|
||||
JSValue hidden_fn = JS_NewObject(js);
|
||||
|
||||
JS_SetPropertyStr(js, cell, "hidden", hidden_fn);
|
||||
JS_SetPropertyStr(js, hidden_fn, "os", js_os_use(js));
|
||||
|
||||
const char actorsym_script[] = "var sym = Symbol(`actordata`); sym;";
|
||||
|
||||
JSValue actorsym = JS_Eval(js, actorsym_script, sizeof(actorsym_script)-1, "internal", 0);
|
||||
|
||||
JS_SetPropertyStr(js, hidden_fn, "actorsym", actorsym);
|
||||
|
||||
crt->actor_sym = JS_ValueToAtom(js, actorsym);
|
||||
|
||||
if (crt->init_wota) {
|
||||
JS_SetPropertyStr(js, hidden_fn, "init", wota2value(js, crt->init_wota));
|
||||
// init wota can now be freed
|
||||
free(crt->init_wota);
|
||||
crt->init_wota = NULL;
|
||||
}
|
||||
|
||||
JSValue js_cell = JS_GetPropertyStr(js, globalThis, "cell");
|
||||
JSValue hidden = JS_GetPropertyStr(js, js_cell, "hidden");
|
||||
size_t archive_size = qop_core.data_size - qop_core.files_offset;
|
||||
JSValue blob = js_new_blob_stoned_copy(js, qop_core.data + qop_core.files_offset, archive_size);
|
||||
JS_SetPropertyStr(js, hidden, "core_qop_blob", blob);
|
||||
JS_FreeValue(js, hidden);
|
||||
JS_FreeValue(js, cell);
|
||||
JS_FreeValue(js, js_cell);
|
||||
|
||||
JS_FreeValue(js, globalThis);
|
||||
|
||||
// Find and load engine.cm from QOP archive
|
||||
@@ -864,11 +879,11 @@ void script_startup(cell_rt *prt)
|
||||
}
|
||||
data[engine_file->size] = 0;
|
||||
|
||||
prt->state = ACTOR_RUNNING;
|
||||
crt->state = ACTOR_RUNNING;
|
||||
JSValue v = JS_Eval(js, data, (size_t)engine_file->size, ENGINE, 0);
|
||||
uncaught_exception(js, v);
|
||||
prt->state = ACTOR_IDLE;
|
||||
set_actor_state(prt);
|
||||
crt->state = ACTOR_IDLE;
|
||||
set_actor_state(crt);
|
||||
}
|
||||
|
||||
int uncaught_exception(JSContext *js, JSValue v)
|
||||
@@ -1046,4 +1061,15 @@ int cell_random() {
|
||||
uint8_t buf[4];
|
||||
randombytes(buf, sizeof(buf));
|
||||
return *(int32_t *)buf;
|
||||
}
|
||||
}
|
||||
|
||||
int js2bool(JSContext *js, JSValue v) { return JS_ToBool(js,v); }
|
||||
JSValue bool2js(JSContext *js, int b) { return JS_NewBool(js,b); }
|
||||
|
||||
JSValue number2js(JSContext *js, double g) { return JS_NewFloat64(js,g); }
|
||||
double js2number(JSContext *js, JSValue v) {
|
||||
double g;
|
||||
JS_ToFloat64(js, &g, v);
|
||||
if (isnan(g)) g = 0;
|
||||
return g;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user