remove jsffi
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
||||
debug: FORCE
|
||||
meson setup build_dbg -Dbuildtype=debugoptimized
|
||||
meson install --only-changed -C --verbose build_dbg
|
||||
meson install --only-changed -C build_dbg
|
||||
|
||||
fast: FORCE
|
||||
meson setup build_fast
|
||||
|
||||
@@ -213,7 +213,6 @@ src += [ # core
|
||||
'qjs_blob.c',
|
||||
'monocypher.c',
|
||||
'timer.c',
|
||||
'jsffi.c',
|
||||
'cell.c',
|
||||
'wildmatch.c',
|
||||
'qjs_actor.c',
|
||||
@@ -313,7 +312,7 @@ cell = custom_target('cell',
|
||||
)
|
||||
|
||||
# Install headers for building dynamic libraries using Cell
|
||||
install_headers('source/cell.h', 'source/jsffi.h')
|
||||
install_headers('source/cell.h')
|
||||
install_headers('source/quickjs.h')
|
||||
install_headers('source/wota.h')
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
119
source/jsffi.c
119
source/jsffi.c
@@ -1,119 +0,0 @@
|
||||
#include "jsffi.h"
|
||||
#include "stb_ds.h"
|
||||
#include "string.h"
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include "HandmadeMath.h"
|
||||
#include <stdint.h>
|
||||
#include "cell.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#define JS_GETNUM(JS,VAL,I,TO,TYPE) { \
|
||||
JSValue val = JS_GetPropertyUint32(JS,VAL,I); \
|
||||
TO = js2##TYPE(JS, val); \
|
||||
JS_FreeValue(JS, val); } \
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
JSValue js_getproperty(JSContext *js, JSValue v, const char *prop)
|
||||
{
|
||||
JSValue ret = JS_GetPropertyStr(js, v, prop);
|
||||
JS_FreeValue(js,ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
JSValue make_quad_indices_buffer(JSContext *js, int quads)
|
||||
{
|
||||
cell_rt *rt = JS_GetContextOpaque(js);
|
||||
int count = quads*6;
|
||||
if (!JS_IsNull(rt->idx_buffer) && rt->idx_count >= count)
|
||||
return JS_DupValue(js,rt->idx_buffer);
|
||||
|
||||
int verts = quads*4;
|
||||
uint16_t *indices = malloc(sizeof(*indices)*count);
|
||||
for (int i = 0, v = 0; v < verts; i +=6, v += 4) {
|
||||
indices[i] = v;
|
||||
indices[i+1] = v+2;
|
||||
indices[i+2] = v+1;
|
||||
indices[i+3] = v+2;
|
||||
indices[i+4] = v+3;
|
||||
indices[i+5] = v+1;
|
||||
}
|
||||
|
||||
if (!JS_IsNull(rt->idx_buffer))
|
||||
JS_FreeValue(js,rt->idx_buffer);
|
||||
|
||||
// rt->idx_buffer = make_gpu_buffer(js,indices, sizeof(*indices)*count, JS_TYPED_ARRAY_UINT16, 1,0,1);
|
||||
rt->idx_count = count;
|
||||
return JS_DupValue(js,rt->idx_buffer);
|
||||
}
|
||||
|
||||
char *js2strdup(JSContext *js, JSValue v) {
|
||||
const char *str = JS_ToCString(js, v);
|
||||
char *ret = strdup(str);
|
||||
JS_FreeCString(js, str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
JSValue angle2js(JSContext *js,double g) {
|
||||
return number2js(js,g*HMM_RadToTurn);
|
||||
}
|
||||
|
||||
double js2angle(JSContext *js,JSValue v) {
|
||||
double n = js2number(js,v);
|
||||
return n * HMM_TurnToRad;
|
||||
}
|
||||
|
||||
JSValue js_os_use(JSContext *js);
|
||||
|
||||
void ffi_load(JSContext *js)
|
||||
{
|
||||
cell_rt *rt = JS_GetContextOpaque(js);
|
||||
JS_FreeValue(js, js_blob_use(js));
|
||||
|
||||
JSValue globalThis = JS_GetGlobalObject(js);
|
||||
|
||||
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);
|
||||
|
||||
rt->actor_sym = JS_ValueToAtom(js, actorsym);
|
||||
|
||||
if (rt->init_wota) {
|
||||
JS_SetPropertyStr(js, hidden_fn, "init", wota2value(js, rt->init_wota));
|
||||
// init wota can now be freed
|
||||
free(rt->init_wota);
|
||||
rt->init_wota = NULL;
|
||||
}
|
||||
|
||||
JS_FreeValue(js,globalThis);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef FFI_H
|
||||
#define FFI_H
|
||||
|
||||
#include "cell.h"
|
||||
|
||||
void ffi_load(JSContext *js);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user