split out spline and js
This commit is contained in:
@@ -148,7 +148,7 @@ src += [
|
|||||||
'anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c',
|
'anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c',
|
||||||
'render.c','simplex.c','spline.c', 'transform.c','prosperon.c', 'wildmatch.c',
|
'render.c','simplex.c','spline.c', 'transform.c','prosperon.c', 'wildmatch.c',
|
||||||
'sprite.c', 'rtree.c', 'qjs_nota.c', 'qjs_soloud.c', 'qjs_sdl.c', 'qjs_math.c', 'qjs_geometry.c', 'qjs_transform.c', 'qjs_sprite.c', 'qjs_io.c', 'qjs_os.c',
|
'sprite.c', 'rtree.c', 'qjs_nota.c', 'qjs_soloud.c', 'qjs_sdl.c', 'qjs_math.c', 'qjs_geometry.c', 'qjs_transform.c', 'qjs_sprite.c', 'qjs_io.c', 'qjs_os.c',
|
||||||
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c'
|
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c', 'qjs_spline.c', 'qjs_js.c'
|
||||||
]
|
]
|
||||||
# quirc src
|
# quirc src
|
||||||
src += [
|
src += [
|
||||||
|
|||||||
412
source/jsffi.c
412
source/jsffi.c
@@ -45,6 +45,8 @@
|
|||||||
#include "qjs_sdl_gpu.h"
|
#include "qjs_sdl_gpu.h"
|
||||||
#include "qjs_os.h"
|
#include "qjs_os.h"
|
||||||
#include "qjs_rtree.h"
|
#include "qjs_rtree.h"
|
||||||
|
#include "qjs_spline.h"
|
||||||
|
#include "qjs_js.h"
|
||||||
|
|
||||||
SDL_Window *global_window;
|
SDL_Window *global_window;
|
||||||
|
|
||||||
@@ -798,38 +800,6 @@ JSC_CCALL(os_make_text_buffer,
|
|||||||
arrfree(buffer);
|
arrfree(buffer);
|
||||||
)
|
)
|
||||||
|
|
||||||
JSC_CCALL(spline_catmull,
|
|
||||||
HMM_Vec2 *points = js2cpvec2arr(js,argv[0]);
|
|
||||||
float param = js2number(js,argv[1]);
|
|
||||||
HMM_Vec2 *samples = catmull_rom_ma_v2(points,param);
|
|
||||||
|
|
||||||
if (!samples)
|
|
||||||
ret = JS_UNDEFINED;
|
|
||||||
else
|
|
||||||
ret = vecarr2js(js,samples, arrlen(samples));
|
|
||||||
|
|
||||||
arrfree(points);
|
|
||||||
arrfree(samples);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(spline_bezier,
|
|
||||||
HMM_Vec2 *points = js2cpvec2arr(js,argv[0]);
|
|
||||||
float param = js2number(js,argv[1]);
|
|
||||||
HMM_Vec2 *samples = catmull_rom_ma_v2(points,param);
|
|
||||||
|
|
||||||
if (!samples)
|
|
||||||
ret = JS_UNDEFINED;
|
|
||||||
else
|
|
||||||
ret = vecarr2js(js,samples, arrlen(samples));
|
|
||||||
|
|
||||||
arrfree(samples);
|
|
||||||
arrfree(points);
|
|
||||||
)
|
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_spline_funcs[] = {
|
|
||||||
MIST_FUNC_DEF(spline, catmull, 2),
|
|
||||||
MIST_FUNC_DEF(spline, bezier, 2)
|
|
||||||
};
|
|
||||||
|
|
||||||
shader_globals camera_globals(JSContext *js, JSValue camera)
|
shader_globals camera_globals(JSContext *js, JSValue camera)
|
||||||
{
|
{
|
||||||
@@ -2011,13 +1981,6 @@ JSValue js_os_sys(JSContext *js, JSValue self, int argc, JSValue *argv)
|
|||||||
return JS_NewString(js, SDL_GetPlatform());
|
return JS_NewString(js, SDL_GetPlatform());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSC_CCALL(os_dump_atoms,
|
|
||||||
return js_dump_atoms(js);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_dump_shapes,
|
|
||||||
return js_dump_shapes(js);
|
|
||||||
)
|
|
||||||
|
|
||||||
// input: (encoded image data of jpg, png, bmp, tiff)
|
// input: (encoded image data of jpg, png, bmp, tiff)
|
||||||
JSC_CCALL(os_make_texture,
|
JSC_CCALL(os_make_texture,
|
||||||
@@ -2458,367 +2421,6 @@ JSC_CCALL(os_cull_sprites,
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
JSC_CCALL(os_on,
|
|
||||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
|
||||||
JS_FreeValue(js, rt->on_exception);
|
|
||||||
rt->on_exception = JS_DupValue(js,argv[1]);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_clean_transforms,
|
|
||||||
clean_all(js);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_totalmem, return number2js(js, SDL_GetSystemRAM()))
|
|
||||||
JSC_CCALL(os_platform, return JS_NewString(js,SDL_GetPlatform()))
|
|
||||||
JSC_CCALL(os_hostname,
|
|
||||||
char buf[256];
|
|
||||||
if (gethostname(buf,sizeof(buf)) == 0) return JS_NewString(js,buf);
|
|
||||||
return JS_NewString(js,"");
|
|
||||||
)
|
|
||||||
|
|
||||||
JSValue js_os_freemem(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
MEMORYSTATUSEX statex;
|
|
||||||
statex.dwLength = sizeof(statex);
|
|
||||||
if (!GlobalMemoryStatusEx(&statex)) return JS_ThrowInternalError(js,"GlobalMemoryStatusEx failed");
|
|
||||||
return JS_NewInt64(js,(int64_t)statex.ullAvailPhys);
|
|
||||||
#elif defined(__linux__)
|
|
||||||
struct sysinfo info;
|
|
||||||
if (sysinfo(&info) == 0)
|
|
||||||
return JS_NewInt64(js,(int64_t)info.freeram * info.mem_unit);
|
|
||||||
return JS_NewInt64(js,0);
|
|
||||||
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
||||||
// A very rough fallback using the same sysconf approach
|
|
||||||
// (macOS or *BSD typically need specialized APIs to get free mem accurately)
|
|
||||||
// This is often only "unused" pages, ignoring caches, etc.
|
|
||||||
long pages = sysconf(_SC_AVPHYS_PAGES);
|
|
||||||
long page_size = sysconf(_SC_PAGE_SIZE);
|
|
||||||
if (pages < 0 || page_size < 0) return JS_NewInt64(js,0);
|
|
||||||
return JS_NewInt64(js,(int64_t)pages * (int64_t)page_size);
|
|
||||||
#else
|
|
||||||
// Fallback: unknown
|
|
||||||
return JS_NewInt64(js,0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue js_os_arch(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
|
||||||
#if defined(__x86_64__) || defined(_M_X64)
|
|
||||||
return JS_NewString(js,"x64");
|
|
||||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
|
||||||
return JS_NewString(js,"arm64");
|
|
||||||
#elif defined(__arm__) || defined(_M_ARM)
|
|
||||||
return JS_NewString(js,"arm");
|
|
||||||
#elif defined(__i386__) || defined(_M_IX86)
|
|
||||||
return JS_NewString(js,"ia32");
|
|
||||||
#elif defined(__loongarch__) || defined(__loongarch32) || defined(__loongarch64)
|
|
||||||
return JS_NewString(js,"loong64");
|
|
||||||
#elif defined(__mips__) || defined(__mips) || defined(_M_MIPS)
|
|
||||||
// You might want to distinguish mips vs mipsel
|
|
||||||
return JS_NewString(js,"mips");
|
|
||||||
#elif defined(__ppc64__) || defined(__powerpc64__) || defined(_M_PPC)
|
|
||||||
// You might want to distinguish ppc vs ppc64, big-endian vs little-endian
|
|
||||||
return JS_NewString(js,"ppc64");
|
|
||||||
#elif defined(__riscv) && __riscv_xlen == 64
|
|
||||||
return JS_NewString(js,"riscv64");
|
|
||||||
#elif defined(__s390x__)
|
|
||||||
return JS_NewString(js,"s390x");
|
|
||||||
#else
|
|
||||||
return JS_NewString(js,"unknown");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue js_os_version(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
|
||||||
HMODULE h = GetModuleHandleA("ntdll.dll");
|
|
||||||
if (h) {
|
|
||||||
RtlGetVersionPtr fx = (RtlGetVersionPtr)GetProcAddress(h, "RtlGetVersion");
|
|
||||||
if (fx) {
|
|
||||||
RTL_OSVERSIONINFOW ver;
|
|
||||||
memset(&ver, 0, sizeof(ver));
|
|
||||||
ver.dwOSVersionInfoSize = sizeof(ver);
|
|
||||||
if (!fx(&ver)) {
|
|
||||||
char buf[128];
|
|
||||||
sprintf(buf, "%u.%u.%u",
|
|
||||||
(unsigned)ver.dwMajorVersion,
|
|
||||||
(unsigned)ver.dwMinorVersion,
|
|
||||||
(unsigned)ver.dwBuildNumber
|
|
||||||
);
|
|
||||||
return JS_NewString(js, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OSVERSIONINFOW wver;
|
|
||||||
memset(&wver, 0, sizeof(wver));
|
|
||||||
wver.dwOSVersionInfoSize = sizeof(wver);
|
|
||||||
if (GetVersionExW(&wver)) {
|
|
||||||
char buf[128];
|
|
||||||
sprintf(buf, "%u.%u.%u",
|
|
||||||
(unsigned)wver.dwMajorVersion,
|
|
||||||
(unsigned)wver.dwMinorVersion,
|
|
||||||
(unsigned)wver.dwBuildNumber
|
|
||||||
);
|
|
||||||
return JS_NewString(js, buf);
|
|
||||||
}
|
|
||||||
return JS_NewString(js, "Windows_Unknown");
|
|
||||||
#else
|
|
||||||
struct utsname info;
|
|
||||||
if (!uname(&info)) return JS_NewString(js, info.release);
|
|
||||||
return JS_NewString(js, "");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSC_CCALL(os_createprocess,
|
|
||||||
int ac = JS_ArrayLength(js,argv[0]);
|
|
||||||
const char *args[ac+1];
|
|
||||||
for (int i = 0; i < ac; i++) {
|
|
||||||
JSValue astr = JS_GetPropertyUint32(js,argv[0],i);
|
|
||||||
args[i] = JS_ToCString(js,astr);
|
|
||||||
JS_FreeValue(js,astr);
|
|
||||||
}
|
|
||||||
|
|
||||||
args[ac] = NULL;
|
|
||||||
|
|
||||||
SDL_Process *actor = SDL_CreateProcess(args, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < ac; i++)
|
|
||||||
JS_FreeCString(js,args[i]);
|
|
||||||
|
|
||||||
if (!actor)
|
|
||||||
return JS_ThrowReferenceError(js, "Unable to create process: %s\n", SDL_GetError());
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_createactor,
|
|
||||||
int margc = JS_ArrayLength(js, argv[0]);
|
|
||||||
|
|
||||||
char **margv = malloc(margc*sizeof(char*));
|
|
||||||
|
|
||||||
for (int i = 0; i < margc; i++) {
|
|
||||||
JSValue val = JS_GetPropertyUint32(js, argv[0], i);
|
|
||||||
const char *cstr = JS_ToCString(js,val);
|
|
||||||
margv[i] = strdup(cstr);
|
|
||||||
JS_FreeCString(js,cstr);
|
|
||||||
JS_FreeValue(js,val);
|
|
||||||
}
|
|
||||||
|
|
||||||
create_actor(margc, margv);
|
|
||||||
)
|
|
||||||
|
|
||||||
#include "qjs_wota.h"
|
|
||||||
|
|
||||||
JSC_CCALL(os_mailbox_push,
|
|
||||||
if (argc < 2) return JS_ThrowInternalError(js, "Need an actor and a message");
|
|
||||||
if (!JS_IsObject(argv[1])) return JS_ThrowInternalError(js, "Object to push must be an object.");
|
|
||||||
|
|
||||||
const char *id = JS_ToCString(js, argv[0]);
|
|
||||||
int exist = actor_exists(id);
|
|
||||||
JS_FreeCString(js,id);
|
|
||||||
if (!exist)
|
|
||||||
return JS_ThrowInternalError(js, "No mailbox found for given ID");
|
|
||||||
|
|
||||||
void *data = value2wota(js, argv[1], JS_UNDEFINED);
|
|
||||||
|
|
||||||
const char *err = send_message(id, data);
|
|
||||||
if (err) {
|
|
||||||
free(data);
|
|
||||||
return JS_ThrowInternalError(js, "Could not send message: %s", err);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_register_actor,
|
|
||||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
|
||||||
const char *id = JS_ToCString(js, argv[0]);
|
|
||||||
const char *err = register_actor(id, rt, JS_ToBool(js, argv[2]));
|
|
||||||
if (err) return JS_ThrowInternalError(js, "Could not register actor: %s", err);
|
|
||||||
rt->message_handle = JS_DupValue(js, argv[1]);
|
|
||||||
rt->context = js;
|
|
||||||
JS_FreeCString(js, id);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_mailbox_exist,
|
|
||||||
const char *id = JS_ToCString(js, argv[0]);
|
|
||||||
int exist = actor_exists(id);
|
|
||||||
JS_FreeCString(js, id);
|
|
||||||
|
|
||||||
return JS_NewBool(js, exist);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_unneeded,
|
|
||||||
prosperon_rt *actor = JS_GetContextOpaque(js);
|
|
||||||
SDL_LockMutex(actor->msg_mutex);
|
|
||||||
JS_FreeValue(js, actor->unneeded);
|
|
||||||
|
|
||||||
if (!JS_IsFunction(js, argv[0])) {
|
|
||||||
actor->unneeded = JS_UNDEFINED;
|
|
||||||
goto END;
|
|
||||||
}
|
|
||||||
|
|
||||||
actor->unneeded = JS_DupValue(js, argv[0]);
|
|
||||||
JS_ToFloat64(js, &actor->unneeded_secs, argv[1]);
|
|
||||||
|
|
||||||
END:
|
|
||||||
if (actor->ar) {
|
|
||||||
SDL_RemoveTimer(actor->ar);
|
|
||||||
actor->ar = 0;
|
|
||||||
}
|
|
||||||
set_actor_state(actor);
|
|
||||||
SDL_UnlockMutex(actor->msg_mutex);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_destroy,
|
|
||||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
|
||||||
rt->need_stop = 1;
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(js_dump_class, return js_get_object_class_distribution(js))
|
|
||||||
JSC_CCALL(js_dump_type_overheads, return js_get_object_type_overheads(js))
|
|
||||||
JSC_CCALL(js_dump_objects, return js_dump_objects(js))
|
|
||||||
|
|
||||||
void cycle_hook_call(JSContext *js, JSValue v)
|
|
||||||
{
|
|
||||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
|
||||||
JS_FreeValue(js,JS_Call(js, rt->cycle_fn,JS_UNDEFINED,1,&v));
|
|
||||||
}
|
|
||||||
|
|
||||||
JSC_CCALL(js_cycle_hook,
|
|
||||||
if (JS_IsUndefined(argv[0]))
|
|
||||||
js_debug_sethook(js,NULL,JS_HOOK_CYCLE);
|
|
||||||
else {
|
|
||||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
|
||||||
JS_FreeValue(js,rt->cycle_fn);
|
|
||||||
rt->cycle_fn = JS_DupValue(js,argv[0]);
|
|
||||||
js_debug_sethook(js,cycle_hook_call, JS_HOOK_CYCLE);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(js_stack_info, return js_dump_stack_info(js))
|
|
||||||
|
|
||||||
JSC_CCALL(os_mem, return js_get_memory_usage(js))
|
|
||||||
|
|
||||||
#define JSOBJ_ADD_FIELD(OBJ, STRUCT, FIELD, TYPE) \
|
|
||||||
JS_SetPropertyStr(js, OBJ, #FIELD, TYPE##2js(js,STRUCT.FIELD));\
|
|
||||||
|
|
||||||
#define JSJMEMRET(FIELD) JSOBJ_ADD_FIELD(ret, jsmem, FIELD, number)
|
|
||||||
|
|
||||||
JSC_CCALL(os_memstate,
|
|
||||||
JSMemoryUsage jsmem;
|
|
||||||
JS_FillMemoryState(JS_GetRuntime(js), &jsmem);
|
|
||||||
ret = JS_NewObject(js);
|
|
||||||
JSJMEMRET(malloc_size)
|
|
||||||
JSJMEMRET(malloc_limit)
|
|
||||||
JSJMEMRET(memory_used_size)
|
|
||||||
JSJMEMRET(gc_threshold)
|
|
||||||
JSJMEMRET(malloc_count)
|
|
||||||
JSJMEMRET(memory_used_count)
|
|
||||||
JSJMEMRET(atom_count)
|
|
||||||
JSJMEMRET(atom_size)
|
|
||||||
JSJMEMRET(str_count)
|
|
||||||
JSJMEMRET(str_size)
|
|
||||||
JSJMEMRET(obj_count)
|
|
||||||
JSJMEMRET(obj_size)
|
|
||||||
JSJMEMRET(prop_count)
|
|
||||||
JSJMEMRET(prop_size)
|
|
||||||
JSJMEMRET(shape_count)
|
|
||||||
JSJMEMRET(shape_size)
|
|
||||||
JSJMEMRET(js_func_count)
|
|
||||||
JSJMEMRET(js_func_size)
|
|
||||||
JSJMEMRET(js_func_code_size)
|
|
||||||
JSJMEMRET(js_func_pc2line_count)
|
|
||||||
JSJMEMRET(js_func_pc2line_size)
|
|
||||||
JSJMEMRET(c_func_count)
|
|
||||||
JSJMEMRET(array_count)
|
|
||||||
JSJMEMRET(fast_array_count)
|
|
||||||
JSJMEMRET(fast_array_elements)
|
|
||||||
JSJMEMRET(binary_object_count)
|
|
||||||
JSJMEMRET(binary_object_size)
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_gc, JS_RunGC(JS_GetRuntime(js)) )
|
|
||||||
|
|
||||||
JSC_SSCALL(os_eval,
|
|
||||||
ret = JS_Eval(js,str2,strlen(str2),str,JS_EVAL_TYPE_GLOBAL);
|
|
||||||
)
|
|
||||||
|
|
||||||
JSC_CCALL(os_mem_limit, JS_SetMemoryLimit(JS_GetRuntime(js), js2number(js,argv[0])))
|
|
||||||
|
|
||||||
JSC_CCALL(os_gc_threshold, JS_SetGCThreshold(JS_GetRuntime(js), js2number(js,argv[0])))
|
|
||||||
|
|
||||||
JSC_CCALL(os_max_stacksize, JS_SetMaxStackSize(JS_GetRuntime(js), js2number(js,argv[0])))
|
|
||||||
JSC_CCALL(os_rt_info, return JS_GetRTInfo(JS_GetRuntime(js),js))
|
|
||||||
|
|
||||||
JSC_CCALL(os_calc_mem,
|
|
||||||
JSMemoryUsage mu;
|
|
||||||
JS_ComputeMemoryUsage(JS_GetRuntime(js),&mu);
|
|
||||||
ret = JS_NewObject(js);
|
|
||||||
JS_SetPropertyStr(js,ret,"malloc_size",number2js(js,mu.malloc_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"malloc_limit",number2js(js,mu.malloc_limit));
|
|
||||||
JS_SetPropertyStr(js,ret,"memory_used_size",number2js(js,mu.memory_used_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"malloc_count",number2js(js,mu.malloc_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"memory_used_count",number2js(js,mu.memory_used_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"atom_count",number2js(js,mu.atom_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"atom_size",number2js(js,mu.atom_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"str_count",number2js(js,mu.str_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"str_size",number2js(js,mu.str_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"obj_count",number2js(js,mu.obj_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"obj_size",number2js(js,mu.obj_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"prop_count",number2js(js,mu.prop_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"prop_size",number2js(js,mu.prop_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"shape_count",number2js(js,mu.shape_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"shape_size",number2js(js,mu.shape_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"js_func_count",number2js(js,mu.js_func_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"js_func_size",number2js(js,mu.js_func_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"js_func_code_size",number2js(js,mu.js_func_code_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"js_func_pc2line_count",number2js(js,mu.js_func_pc2line_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"js_func_pc2line_size",number2js(js,mu.js_func_pc2line_size));
|
|
||||||
JS_SetPropertyStr(js,ret,"c_func_count",number2js(js,mu.c_func_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"array_count",number2js(js,mu.array_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"fast_array_count",number2js(js,mu.fast_array_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"fast_array_elements",number2js(js,mu.fast_array_elements));
|
|
||||||
JS_SetPropertyStr(js,ret,"binary_object_count",number2js(js,mu.binary_object_count));
|
|
||||||
JS_SetPropertyStr(js,ret,"binary_object_size",number2js(js,mu.binary_object_size));
|
|
||||||
)
|
|
||||||
/*
|
|
||||||
JSC_CCALL(os_memstate,
|
|
||||||
#ifdef _WIN32
|
|
||||||
MEMORYSTATUSEX statex;
|
|
||||||
statex.dwLength = sizeof (statex);
|
|
||||||
GlobalMemoryStatusEx (&statex);
|
|
||||||
ret = JS_NewObject(js);
|
|
||||||
JS_SetPropertyStr(js,ret,"load",number2js(js,statex.dwMemoryLoad));
|
|
||||||
JS_SetPropertyStr(js,ret,"physical",number2js(js,statex.ullTotalPhys));
|
|
||||||
JS_SetPropertyStr(js,ret,"availphysical",number2js(js,statex.ullAvailPhys));
|
|
||||||
JS_SetPropertyStr(js,ret,"pagefile",number2js(js,statex.ullTotalPageFile));
|
|
||||||
JS_SetPropertyStr(js,ret,"availpagefile",number2js(js,statex.ullAvailPageFile));
|
|
||||||
JS_SetPropertyStr(js,ret,"virtual",number2js(js,statex.ullTotalVirtual));
|
|
||||||
JS_SetPropertyStr(js,ret,"availvirtual",number2js(js,statex.ullAvailVirtual));
|
|
||||||
JS_SetPropertyStr(js,ret,"availextended",number2js(js,statex.ullAvailExtendedVirtual));
|
|
||||||
#else
|
|
||||||
ret = JS_NewObject(js);
|
|
||||||
#endif
|
|
||||||
)*/
|
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_js_funcs[] = {
|
|
||||||
MIST_FUNC_DEF(js, cycle_hook,1),
|
|
||||||
MIST_FUNC_DEF(os, dump_shapes, 0),
|
|
||||||
MIST_FUNC_DEF(os, dump_atoms,0),
|
|
||||||
MIST_FUNC_DEF(js, dump_class, 0),
|
|
||||||
MIST_FUNC_DEF(js, dump_objects, 0),
|
|
||||||
MIST_FUNC_DEF(js, dump_type_overheads, 0),
|
|
||||||
MIST_FUNC_DEF(js, stack_info, 0),
|
|
||||||
MIST_FUNC_DEF(os, calc_mem, 1),
|
|
||||||
MIST_FUNC_DEF(os, mem, 1),
|
|
||||||
MIST_FUNC_DEF(os, mem_limit, 1),
|
|
||||||
MIST_FUNC_DEF(os, gc_threshold, 1),
|
|
||||||
MIST_FUNC_DEF(os, max_stacksize, 1),
|
|
||||||
MIST_FUNC_DEF(os, memstate, 0),
|
|
||||||
MIST_FUNC_DEF(os, gc, 0),
|
|
||||||
MIST_FUNC_DEF(os, eval, 2),
|
|
||||||
MIST_FUNC_DEF(os, rt_info, 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_util_funcs[] = {
|
static const JSCFunctionListEntry js_util_funcs[] = {
|
||||||
MIST_FUNC_DEF(os, guid, 0),
|
MIST_FUNC_DEF(os, guid, 0),
|
||||||
MIST_FUNC_DEF(os, insertion_sort, 2),
|
MIST_FUNC_DEF(os, insertion_sort, 2),
|
||||||
@@ -3244,17 +2846,7 @@ JSValue js_miniz_use(JSContext *js);
|
|||||||
JSValue js_tracy_use(JSContext *js);
|
JSValue js_tracy_use(JSContext *js);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JSValue js_spline_use(JSContext *js) {
|
|
||||||
JSValue mod = JS_NewObject(js);
|
|
||||||
JS_SetPropertyFunctionList(js,mod,js_spline_funcs,countof(js_spline_funcs));
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue js_js_use(JSContext *js) {
|
|
||||||
JSValue mod = JS_NewObject(js);
|
|
||||||
JS_SetPropertyFunctionList(js,mod,js_js_funcs,countof(js_js_funcs));
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue js_graphics_use(JSContext *js) {
|
JSValue js_graphics_use(JSContext *js) {
|
||||||
JSValue mod = JS_NewObject(js);
|
JSValue mod = JS_NewObject(js);
|
||||||
|
|||||||
172
source/qjs_js.c
Normal file
172
source/qjs_js.c
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#include "qjs_js.h"
|
||||||
|
#include "qjs_macros.h"
|
||||||
|
#include "jsffi.h"
|
||||||
|
#include "prosperon.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Function implementations
|
||||||
|
|
||||||
|
JSC_CCALL(os_dump_atoms,
|
||||||
|
return js_dump_atoms(js);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(os_dump_shapes,
|
||||||
|
return js_dump_shapes(js);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(js_dump_class, return js_get_object_class_distribution(js))
|
||||||
|
JSC_CCALL(js_dump_type_overheads, return js_get_object_type_overheads(js))
|
||||||
|
JSC_CCALL(js_dump_objects, return js_dump_objects(js))
|
||||||
|
|
||||||
|
void cycle_hook_call(JSContext *js, JSValue v)
|
||||||
|
{
|
||||||
|
prosperon_rt *rt = JS_GetContextOpaque(js);
|
||||||
|
JS_FreeValue(js,JS_Call(js, rt->cycle_fn,JS_UNDEFINED,1,&v));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSC_CCALL(js_cycle_hook,
|
||||||
|
if (JS_IsUndefined(argv[0]))
|
||||||
|
js_debug_sethook(js,NULL,JS_HOOK_CYCLE);
|
||||||
|
else {
|
||||||
|
prosperon_rt *rt = JS_GetContextOpaque(js);
|
||||||
|
JS_FreeValue(js,rt->cycle_fn);
|
||||||
|
rt->cycle_fn = JS_DupValue(js,argv[0]);
|
||||||
|
js_debug_sethook(js,cycle_hook_call, JS_HOOK_CYCLE);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(js_stack_info, return js_dump_stack_info(js))
|
||||||
|
|
||||||
|
JSC_CCALL(os_mem, return js_get_memory_usage(js))
|
||||||
|
|
||||||
|
#define JSOBJ_ADD_FIELD(OBJ, STRUCT, FIELD, TYPE) \
|
||||||
|
JS_SetPropertyStr(js, OBJ, #FIELD, TYPE##2js(js,STRUCT.FIELD));\
|
||||||
|
|
||||||
|
#define JSJMEMRET(FIELD) JSOBJ_ADD_FIELD(ret, jsmem, FIELD, number)
|
||||||
|
|
||||||
|
JSC_CCALL(os_memstate,
|
||||||
|
JSMemoryUsage jsmem;
|
||||||
|
JS_FillMemoryState(JS_GetRuntime(js), &jsmem);
|
||||||
|
ret = JS_NewObject(js);
|
||||||
|
JSJMEMRET(malloc_size)
|
||||||
|
JSJMEMRET(malloc_limit)
|
||||||
|
JSJMEMRET(memory_used_size)
|
||||||
|
JSJMEMRET(gc_threshold)
|
||||||
|
JSJMEMRET(malloc_count)
|
||||||
|
JSJMEMRET(memory_used_count)
|
||||||
|
JSJMEMRET(atom_count)
|
||||||
|
JSJMEMRET(atom_size)
|
||||||
|
JSJMEMRET(str_count)
|
||||||
|
JSJMEMRET(str_size)
|
||||||
|
JSJMEMRET(obj_count)
|
||||||
|
JSJMEMRET(obj_size)
|
||||||
|
JSJMEMRET(prop_count)
|
||||||
|
JSJMEMRET(prop_size)
|
||||||
|
JSJMEMRET(shape_count)
|
||||||
|
JSJMEMRET(shape_size)
|
||||||
|
JSJMEMRET(js_func_count)
|
||||||
|
JSJMEMRET(js_func_size)
|
||||||
|
JSJMEMRET(js_func_code_size)
|
||||||
|
JSJMEMRET(js_func_pc2line_count)
|
||||||
|
JSJMEMRET(js_func_pc2line_size)
|
||||||
|
JSJMEMRET(c_func_count)
|
||||||
|
JSJMEMRET(array_count)
|
||||||
|
JSJMEMRET(fast_array_count)
|
||||||
|
JSJMEMRET(fast_array_elements)
|
||||||
|
JSJMEMRET(binary_object_count)
|
||||||
|
JSJMEMRET(binary_object_size)
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(os_gc, JS_RunGC(JS_GetRuntime(js)) )
|
||||||
|
|
||||||
|
JSC_SSCALL(os_eval,
|
||||||
|
ret = JS_Eval(js,str2,strlen(str2),str,JS_EVAL_TYPE_GLOBAL);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(os_mem_limit, JS_SetMemoryLimit(JS_GetRuntime(js), js2number(js,argv[0])))
|
||||||
|
|
||||||
|
JSC_CCALL(os_gc_threshold, JS_SetGCThreshold(JS_GetRuntime(js), js2number(js,argv[0])))
|
||||||
|
|
||||||
|
JSC_CCALL(os_max_stacksize, JS_SetMaxStackSize(JS_GetRuntime(js), js2number(js,argv[0])))
|
||||||
|
JSC_CCALL(os_rt_info, return JS_GetRTInfo(JS_GetRuntime(js),js))
|
||||||
|
|
||||||
|
JSC_CCALL(os_calc_mem,
|
||||||
|
JSMemoryUsage mu;
|
||||||
|
JS_ComputeMemoryUsage(JS_GetRuntime(js),&mu);
|
||||||
|
ret = JS_NewObject(js);
|
||||||
|
JS_SetPropertyStr(js,ret,"malloc_size",number2js(js,mu.malloc_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"malloc_limit",number2js(js,mu.malloc_limit));
|
||||||
|
JS_SetPropertyStr(js,ret,"memory_used_size",number2js(js,mu.memory_used_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"malloc_count",number2js(js,mu.malloc_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"memory_used_count",number2js(js,mu.memory_used_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"atom_count",number2js(js,mu.atom_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"atom_size",number2js(js,mu.atom_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"str_count",number2js(js,mu.str_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"str_size",number2js(js,mu.str_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"obj_count",number2js(js,mu.obj_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"obj_size",number2js(js,mu.obj_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"prop_count",number2js(js,mu.prop_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"prop_size",number2js(js,mu.prop_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"shape_count",number2js(js,mu.shape_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"shape_size",number2js(js,mu.shape_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"js_func_count",number2js(js,mu.js_func_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"js_func_size",number2js(js,mu.js_func_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"js_func_code_size",number2js(js,mu.js_func_code_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"js_func_pc2line_count",number2js(js,mu.js_func_pc2line_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"js_func_pc2line_size",number2js(js,mu.js_func_pc2line_size));
|
||||||
|
JS_SetPropertyStr(js,ret,"c_func_count",number2js(js,mu.c_func_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"array_count",number2js(js,mu.array_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"fast_array_count",number2js(js,mu.fast_array_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"fast_array_elements",number2js(js,mu.fast_array_elements));
|
||||||
|
JS_SetPropertyStr(js,ret,"binary_object_count",number2js(js,mu.binary_object_count));
|
||||||
|
JS_SetPropertyStr(js,ret,"binary_object_size",number2js(js,mu.binary_object_size));
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
JSC_CCALL(os_memstate,
|
||||||
|
#ifdef _WIN32
|
||||||
|
MEMORYSTATUSEX statex;
|
||||||
|
statex.dwLength = sizeof (statex);
|
||||||
|
GlobalMemoryStatusEx (&statex);
|
||||||
|
ret = JS_NewObject(js);
|
||||||
|
JS_SetPropertyStr(js,ret,"load",number2js(js,statex.dwMemoryLoad));
|
||||||
|
JS_SetPropertyStr(js,ret,"physical",number2js(js,statex.ullTotalPhys));
|
||||||
|
JS_SetPropertyStr(js,ret,"availphysical",number2js(js,statex.ullAvailPhys));
|
||||||
|
JS_SetPropertyStr(js,ret,"pagefile",number2js(js,statex.ullTotalPageFile));
|
||||||
|
JS_SetPropertyStr(js,ret,"availpagefile",number2js(js,statex.ullAvailPageFile));
|
||||||
|
JS_SetPropertyStr(js,ret,"virtual",number2js(js,statex.ullTotalVirtual));
|
||||||
|
JS_SetPropertyStr(js,ret,"availvirtual",number2js(js,statex.ullAvailVirtual));
|
||||||
|
JS_SetPropertyStr(js,ret,"availextended",number2js(js,statex.ullAvailExtendedVirtual));
|
||||||
|
#else
|
||||||
|
ret = JS_NewObject(js);
|
||||||
|
#endif
|
||||||
|
)*/
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_js_funcs[] = {
|
||||||
|
MIST_FUNC_DEF(js, cycle_hook,1),
|
||||||
|
MIST_FUNC_DEF(os, dump_shapes, 0),
|
||||||
|
MIST_FUNC_DEF(os, dump_atoms,0),
|
||||||
|
MIST_FUNC_DEF(js, dump_class, 0),
|
||||||
|
MIST_FUNC_DEF(js, dump_objects, 0),
|
||||||
|
MIST_FUNC_DEF(js, dump_type_overheads, 0),
|
||||||
|
MIST_FUNC_DEF(js, stack_info, 0),
|
||||||
|
MIST_FUNC_DEF(os, calc_mem, 0),
|
||||||
|
MIST_FUNC_DEF(os, mem, 0),
|
||||||
|
MIST_FUNC_DEF(os, mem_limit, 1),
|
||||||
|
MIST_FUNC_DEF(os, gc_threshold, 1),
|
||||||
|
MIST_FUNC_DEF(os, max_stacksize, 1),
|
||||||
|
MIST_FUNC_DEF(os, memstate, 0),
|
||||||
|
MIST_FUNC_DEF(os, gc, 0),
|
||||||
|
MIST_FUNC_DEF(os, eval, 2),
|
||||||
|
MIST_FUNC_DEF(os, rt_info, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
JSValue js_js_use(JSContext *js) {
|
||||||
|
JSValue mod = JS_NewObject(js);
|
||||||
|
JS_SetPropertyFunctionList(js,mod,js_js_funcs,countof(js_js_funcs));
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
8
source/qjs_js.h
Normal file
8
source/qjs_js.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef QJS_JS_H
|
||||||
|
#define QJS_JS_H
|
||||||
|
|
||||||
|
#include <quickjs.h>
|
||||||
|
|
||||||
|
JSValue js_js_use(JSContext *ctx);
|
||||||
|
|
||||||
|
#endif
|
||||||
65
source/qjs_spline.c
Normal file
65
source/qjs_spline.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include "qjs_spline.h"
|
||||||
|
#include "qjs_macros.h"
|
||||||
|
#include "jsffi.h"
|
||||||
|
#include "spline.h"
|
||||||
|
#include "HandmadeMath.h"
|
||||||
|
#include "stb_ds.h"
|
||||||
|
|
||||||
|
// Helper functions - these are duplicated from jsffi.c as they're used there too
|
||||||
|
static HMM_Vec2 *js2cpvec2arr(JSContext *js, JSValue v) {
|
||||||
|
HMM_Vec2 *arr = NULL;
|
||||||
|
int n = JS_ArrayLength(js, v);
|
||||||
|
arrsetlen(arr, n);
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
arr[i] = js2vec2(js, JS_GetPropertyUint32(js, v, i));
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue vecarr2js(JSContext *js, HMM_Vec2 *points, int n) {
|
||||||
|
JSValue array = JS_NewArray(js);
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
JS_SetPropertyUint32(js, array, i, vec22js(js, points[i]));
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSC_CCALL(spline_catmull,
|
||||||
|
HMM_Vec2 *points = js2cpvec2arr(js, argv[0]);
|
||||||
|
float param = js2number(js, argv[1]);
|
||||||
|
HMM_Vec2 *samples = catmull_rom_ma_v2(points, param);
|
||||||
|
|
||||||
|
if (!samples)
|
||||||
|
ret = JS_UNDEFINED;
|
||||||
|
else
|
||||||
|
ret = vecarr2js(js, samples, arrlen(samples));
|
||||||
|
|
||||||
|
arrfree(points);
|
||||||
|
arrfree(samples);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(spline_bezier,
|
||||||
|
HMM_Vec2 *points = js2cpvec2arr(js, argv[0]);
|
||||||
|
float param = js2number(js, argv[1]);
|
||||||
|
HMM_Vec2 *samples = bezier_cb_ma_v2(points, param);
|
||||||
|
|
||||||
|
if (!samples)
|
||||||
|
ret = JS_UNDEFINED;
|
||||||
|
else
|
||||||
|
ret = vecarr2js(js, samples, arrlen(samples));
|
||||||
|
|
||||||
|
arrfree(samples);
|
||||||
|
arrfree(points);
|
||||||
|
)
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_spline_funcs[] = {
|
||||||
|
MIST_FUNC_DEF(spline, catmull, 2),
|
||||||
|
MIST_FUNC_DEF(spline, bezier, 2)
|
||||||
|
};
|
||||||
|
|
||||||
|
JSValue js_spline_use(JSContext *js) {
|
||||||
|
JSValue mod = JS_NewObject(js);
|
||||||
|
JS_SetPropertyFunctionList(js, mod, js_spline_funcs, countof(js_spline_funcs));
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
8
source/qjs_spline.h
Normal file
8
source/qjs_spline.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef QJS_SPLINE_H
|
||||||
|
#define QJS_SPLINE_H
|
||||||
|
|
||||||
|
#include <quickjs.h>
|
||||||
|
|
||||||
|
JSValue js_spline_use(JSContext *ctx);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user