From bf421743a529ba75a10d530895d74d59f5e9583e Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 11 Dec 2025 14:42:30 -0600 Subject: [PATCH] fix scheduler --- build.ce | 2 +- build.cm | 10 +--- install.ce | 8 ++- pack.ce | 2 +- playdate/display_playdate.c | 12 ++-- playdate/gfx_playdate.c | 48 +++++++-------- playdate/json_playdate.c | 10 ++-- playdate/lua_playdate.c | 14 ++--- playdate/network_playdate.c | 24 ++++---- playdate/scoreboards_playdate.c | 30 +++++----- playdate/sound_playdate.c | 68 +++++++++++----------- playdate/sprite_playdate.c | 52 ++++++++--------- playdate/sys_playdate.c | 18 +++--- shop.cm | 13 ++++- source/qjs_blob.c | 2 +- source/scheduler.c | 100 +++++++++++++++++--------------- toolchains.cm | 6 ++ 17 files changed, 217 insertions(+), 202 deletions(-) diff --git a/build.ce b/build.ce index 8a378ea4..59f38ec7 100644 --- a/build.ce +++ b/build.ce @@ -12,7 +12,7 @@ var fd = use('fd') var target = null var target_package = null -var buildtype = 'release' +var buildtype = 'debug' for (var i = 0; i < args.length; i++) { if (args[i] == '-t' || args[i] == '--target') { diff --git a/build.cm b/build.cm index 9b992841..b104776c 100644 --- a/build.cm +++ b/build.cm @@ -177,7 +177,7 @@ Build.compile_file = function(pkg, file, target, buildtype = 'release') { // Build all C files for a package // Returns array of object file paths -Build.build_package = function(pkg, target, exclude_main, buildtype = 'release') { +Build.build_package = function(pkg, target = Build.detect_host_target(), exclude_main, buildtype = 'release') { var c_files = pkg_tools.get_c_files(pkg, target, exclude_main) var objects = [] @@ -195,9 +195,7 @@ Build.build_package = function(pkg, target, exclude_main, buildtype = 'release') // Build a dynamic library for a package // Output goes to .cell/lib/. // Dynamic libraries do NOT link against core; undefined symbols are resolved at dlopen time -Build.build_dynamic = function(pkg, target, buildtype = 'release') { - target = target || Build.detect_host_target() - +Build.build_dynamic = function(pkg, target = Build.detect_host_target(), buildtype = 'release') { var objects = Build.build_package(pkg, target, true, buildtype) // exclude main.c if (objects.length == 0) { @@ -287,9 +285,7 @@ Build.build_dynamic = function(pkg, target, buildtype = 'release') { // Build a static binary from multiple packages // packages: array of package names // output: output binary path -Build.build_static = function(packages, target, output, buildtype = 'release') { - target = target || Build.detect_host_target() - +Build.build_static = function(packages, target = Build.detect_host_target(), output, buildtype = 'release') { var all_objects = [] var all_ldflags = [] var seen_flags = {} diff --git a/install.ce b/install.ce index 8cfba93e..bd669fc6 100644 --- a/install.ce +++ b/install.ce @@ -2,6 +2,7 @@ // Does not modify the current project's cell.toml var shop = use('shop') +var build = use('build') if (args.length < 1) { log.console("Usage: cell install ") @@ -14,17 +15,18 @@ var locator = args[0] log.console("Installing " + locator + "...") if (!shop.update(locator)) { log.console("Failed to install " + locator) - $_.exit(1) + $_.stop() + return } var deps = shop.list_packages(locator) for (var dep of deps) { log.console("Installing dependency " + dep) shop.update(dep) - shop.build_package(dep) + build.build_package(dep) } -shop.build_package(locator) +build.build_package(locator) log.console("Installed " + locator) $_.stop() diff --git a/pack.ce b/pack.ce index 20780ca7..7ea213d3 100644 --- a/pack.ce +++ b/pack.ce @@ -12,7 +12,7 @@ var pkg_tools = use('package') var target = null var output_name = 'app' var target_package = null -var buildtype = 'release' +var buildtype = 'debug' if (args.length < 1) { log.error('Usage: cell pack [options]') diff --git a/playdate/display_playdate.c b/playdate/display_playdate.c index 5ad15a70..ef7e8ec3 100644 --- a/playdate/display_playdate.c +++ b/playdate/display_playdate.c @@ -20,7 +20,7 @@ JSC_CCALL(display_setRefreshRate, if (!pd_display) return JS_ThrowInternalError(js, "display not initialized"); float rate = (float)js2number(js, argv[0]); pd_display->setRefreshRate(rate); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(display_getRefreshRate, @@ -37,14 +37,14 @@ JSC_CCALL(display_setInverted, if (!pd_display) return JS_ThrowInternalError(js, "display not initialized"); int flag = JS_ToBool(js, argv[0]); pd_display->setInverted(flag); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(display_setScale, if (!pd_display) return JS_ThrowInternalError(js, "display not initialized"); unsigned int scale = (unsigned int)js2number(js, argv[0]); pd_display->setScale(scale); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(display_setMosaic, @@ -52,7 +52,7 @@ JSC_CCALL(display_setMosaic, unsigned int x = (unsigned int)js2number(js, argv[0]); unsigned int y = (unsigned int)js2number(js, argv[1]); pd_display->setMosaic(x, y); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(display_setFlipped, @@ -60,7 +60,7 @@ JSC_CCALL(display_setFlipped, int x = JS_ToBool(js, argv[0]); int y = JS_ToBool(js, argv[1]); pd_display->setFlipped(x, y); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(display_setOffset, @@ -68,7 +68,7 @@ JSC_CCALL(display_setOffset, int x = (int)js2number(js, argv[0]); int y = (int)js2number(js, argv[1]); pd_display->setOffset(x, y); - return JS_UNDEFINED; + return JS_NULL; ) static const JSCFunctionListEntry js_display_funcs[] = { diff --git a/playdate/gfx_playdate.c b/playdate/gfx_playdate.c index 69a0444c..daae9410 100644 --- a/playdate/gfx_playdate.c +++ b/playdate/gfx_playdate.c @@ -30,14 +30,14 @@ JSC_CCALL(gfx_clear, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); LCDColor color = (LCDColor)js2number(js, argv[0]); pd_gfx->clear(color); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setBackgroundColor, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); LCDSolidColor color = (LCDSolidColor)(int)js2number(js, argv[0]); pd_gfx->setBackgroundColor(color); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setDrawMode, @@ -50,38 +50,38 @@ JSC_CCALL(gfx_setDrawMode, JSC_CCALL(gfx_setDrawOffset, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setDrawOffset((int)js2number(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setClipRect, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setClipRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), (int)js2number(js, argv[3])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_clearClipRect, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->clearClipRect(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setLineCapStyle, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setLineCapStyle((LCDLineCapStyle)(int)js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setFont, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setFont(js2font(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setTextTracking, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setTextTracking((int)js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_getTextTracking, @@ -92,13 +92,13 @@ JSC_CCALL(gfx_getTextTracking, JSC_CCALL(gfx_pushContext, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->pushContext(argc > 0 ? js2bitmap(js, argv[0]) : NULL); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_popContext, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->popContext(); - return JS_UNDEFINED; + return JS_NULL; ) // --- Drawing Primitives --- @@ -109,7 +109,7 @@ JSC_CCALL(gfx_drawBitmap, if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap"); pd_gfx->drawBitmap(bmp, (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), argc > 3 ? (LCDBitmapFlip)(int)js2number(js, argv[3]) : kBitmapUnflipped); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_drawLine, @@ -117,7 +117,7 @@ JSC_CCALL(gfx_drawLine, pd_gfx->drawLine((int)js2number(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (int)js2number(js, argv[4]), (LCDColor)js2number(js, argv[5])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_drawRect, @@ -125,7 +125,7 @@ JSC_CCALL(gfx_drawRect, pd_gfx->drawRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (LCDColor)js2number(js, argv[4])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_fillRect, @@ -133,7 +133,7 @@ JSC_CCALL(gfx_fillRect, pd_gfx->fillRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (LCDColor)js2number(js, argv[4])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_fillTriangle, @@ -142,7 +142,7 @@ JSC_CCALL(gfx_fillTriangle, (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (int)js2number(js, argv[4]), (int)js2number(js, argv[5]), (LCDColor)js2number(js, argv[6])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_drawEllipse, @@ -151,7 +151,7 @@ JSC_CCALL(gfx_drawEllipse, (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (int)js2number(js, argv[4]), (float)js2number(js, argv[5]), (float)js2number(js, argv[6]), (LCDColor)js2number(js, argv[7])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_fillEllipse, @@ -160,7 +160,7 @@ JSC_CCALL(gfx_fillEllipse, (int)js2number(js, argv[2]), (int)js2number(js, argv[3]), (float)js2number(js, argv[4]), (float)js2number(js, argv[5]), (LCDColor)js2number(js, argv[6])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(gfx_drawText, @@ -176,7 +176,7 @@ JSC_CCALL(gfx_drawScaledBitmap, if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap"); pd_gfx->drawScaledBitmap(bmp, (int)js2number(js, argv[1]), (int)js2number(js, argv[2]), (float)js2number(js, argv[3]), (float)js2number(js, argv[4])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_drawRotatedBitmap, @@ -187,14 +187,14 @@ JSC_CCALL(gfx_drawRotatedBitmap, (float)js2number(js, argv[3]), (float)js2number(js, argv[4]), (float)js2number(js, argv[5]), (float)js2number(js, argv[6]), (float)js2number(js, argv[7])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_setPixel, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->setPixel((int)js2number(js, argv[0]), (int)js2number(js, argv[1]), (LCDColor)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) // --- Bitmap Functions --- @@ -211,7 +211,7 @@ JSC_CCALL(gfx_freeBitmap, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); LCDBitmap *bmp = js2bitmap(js, argv[0]); if (bmp) pd_gfx->freeBitmap(bmp); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(gfx_loadBitmap, @@ -235,7 +235,7 @@ JSC_CCALL(gfx_clearBitmap, LCDBitmap *bmp = js2bitmap(js, argv[0]); if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap"); pd_gfx->clearBitmap(bmp, argc > 1 ? (LCDColor)js2number(js, argv[1]) : kColorWhite); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_getBitmapData, @@ -279,13 +279,13 @@ JSC_SCALL(gfx_getTextWidth, JSC_CCALL(gfx_display, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->display(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_markUpdatedRows, if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized"); pd_gfx->markUpdatedRows((int)js2number(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(gfx_copyFrameBufferBitmap, diff --git a/playdate/json_playdate.c b/playdate/json_playdate.c index 4c0d933e..40b26c53 100644 --- a/playdate/json_playdate.c +++ b/playdate/json_playdate.c @@ -57,10 +57,10 @@ static void json_decode_table_value(json_decoder *decoder, const char *key, json if (ctx->stack_depth > 1) { jsval = ctx->stack[ctx->stack_depth - 1]; } else { - jsval = JS_UNDEFINED; + jsval = JS_NULL; } break; - default: jsval = JS_UNDEFINED; break; + default: jsval = JS_NULL; break; } JS_SetPropertyStr(ctx->js, container, key, jsval); } @@ -77,7 +77,7 @@ static void json_decode_array_value(json_decoder *decoder, int pos, json_value v case kJSONInteger: jsval = JS_NewInt32(ctx->js, value.data.intval); break; case kJSONFloat: jsval = JS_NewFloat64(ctx->js, value.data.floatval); break; case kJSONString: jsval = JS_NewString(ctx->js, value.data.stringval); break; - default: jsval = JS_UNDEFINED; break; + default: jsval = JS_NULL; break; } JS_SetPropertyUint32(ctx->js, container, pos, jsval); } @@ -136,7 +136,7 @@ static void encode_js_array(json_encoder *enc, JSContext *js, JSValue arr) { } static void encode_js_value(json_encoder *enc, JSContext *js, JSValue val) { - if (JS_IsNull(val) || JS_IsUndefined(val)) { + if (JS_IsNull(val)) { enc->writeNull(enc); } else if (JS_IsBool(val)) { if (JS_ToBool(js, val)) enc->writeTrue(enc); @@ -163,7 +163,7 @@ static void encode_js_value(json_encoder *enc, JSContext *js, JSValue val) { JSC_SCALL(json_decodeString, if (!pd_json) return JS_ThrowInternalError(js, "json not initialized"); - JsonDecodeCtx ctx = { js, JS_UNDEFINED, {}, 0 }; + JsonDecodeCtx ctx = { js, JS_NULL, {}, 0 }; json_decoder decoder = {0}; decoder.decodeError = json_decode_error; decoder.willDecodeSublist = json_decode_will_sublist; diff --git a/playdate/lua_playdate.c b/playdate/lua_playdate.c index 822d3069..8186722c 100644 --- a/playdate/lua_playdate.c +++ b/playdate/lua_playdate.c @@ -11,13 +11,13 @@ JSC_CCALL(lua_stop, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->stop(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(lua_start, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->start(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(lua_getArgCount, @@ -73,25 +73,25 @@ JSC_CCALL(lua_getArgBytes, JSC_CCALL(lua_pushNil, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->pushNil(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(lua_pushBool, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->pushBool(JS_ToBool(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(lua_pushInt, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->pushInt((int)js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(lua_pushFloat, if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized"); pd_lua->pushFloat((float)js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(lua_pushString, @@ -105,7 +105,7 @@ JSC_CCALL(lua_pushBytes, const char *data = js_get_blob_data(js, &len, argv[0]); if (data == (void*)-1) return JS_EXCEPTION; pd_lua->pushBytes(data, len); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(lua_callFunction, diff --git a/playdate/network_playdate.c b/playdate/network_playdate.c index 9be72642..394d8dfb 100644 --- a/playdate/network_playdate.c +++ b/playdate/network_playdate.c @@ -30,7 +30,7 @@ JSC_CCALL(network_setEnabled, if (!pd_network) return JS_ThrowInternalError(js, "network not initialized"); // Note: callback not implemented for simplicity pd_network->setEnabled(JS_ToBool(js, argv[0]), NULL); - return JS_UNDEFINED; + return JS_NULL; ) // --- HTTP Functions --- @@ -54,25 +54,25 @@ JSC_CCALL(http_release, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); HTTPConnection *conn = js2http(js, argv[0]); if (conn) pd_network->http->release(conn); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(http_setConnectTimeout, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->setConnectTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(http_setKeepAlive, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->setKeepAlive(js2http(js, argv[0]), JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(http_setByteRange, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->setByteRange(js2http(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(http_get, @@ -126,13 +126,13 @@ JSC_CCALL(http_getBytesAvailable, JSC_CCALL(http_setReadTimeout, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->setReadTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(http_setReadBufferSize, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->setReadBufferSize(js2http(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(http_read, @@ -154,7 +154,7 @@ JSC_CCALL(http_read, JSC_CCALL(http_close, if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized"); pd_network->http->close(js2http(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) // --- TCP Functions --- @@ -178,7 +178,7 @@ JSC_CCALL(tcp_release, if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized"); TCPConnection *conn = js2tcp(js, argv[0]); if (conn) pd_network->tcp->release(conn); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(tcp_getError, @@ -189,7 +189,7 @@ JSC_CCALL(tcp_getError, JSC_CCALL(tcp_setConnectTimeout, if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized"); pd_network->tcp->setConnectTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(tcp_close, @@ -200,13 +200,13 @@ JSC_CCALL(tcp_close, JSC_CCALL(tcp_setReadTimeout, if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized"); pd_network->tcp->setReadTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(tcp_setReadBufferSize, if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized"); pd_network->tcp->setReadBufferSize(js2tcp(js, argv[0]), (int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(tcp_getBytesAvailable, diff --git a/playdate/scoreboards_playdate.c b/playdate/scoreboards_playdate.c index 411a2b23..6fb99196 100644 --- a/playdate/scoreboards_playdate.c +++ b/playdate/scoreboards_playdate.c @@ -10,10 +10,10 @@ // A more robust implementation would use promises or callback registration. static JSContext *g_scoreboard_js = NULL; -static JSValue g_add_score_callback = JS_UNDEFINED; -static JSValue g_personal_best_callback = JS_UNDEFINED; -static JSValue g_boards_list_callback = JS_UNDEFINED; -static JSValue g_scores_callback = JS_UNDEFINED; +static JSValue g_add_score_callback = JS_NULL; +static JSValue g_personal_best_callback = JS_NULL; +static JSValue g_boards_list_callback = JS_NULL; +static JSValue g_scores_callback = JS_NULL; static JSValue score_to_js(JSContext *js, PDScore *score) { if (!score) return JS_NULL; @@ -25,29 +25,29 @@ static JSValue score_to_js(JSContext *js, PDScore *score) { } static void add_score_cb(PDScore *score, const char *errorMessage) { - if (!g_scoreboard_js || JS_IsUndefined(g_add_score_callback)) return; + if (!g_scoreboard_js || JS_IsNull(g_add_score_callback)) return; JSValue args[2]; args[0] = score_to_js(g_scoreboard_js, score); args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL; - JSValue ret = JS_Call(g_scoreboard_js, g_add_score_callback, JS_UNDEFINED, 2, args); + JSValue ret = JS_Call(g_scoreboard_js, g_add_score_callback, JS_NULL, 2, args); JS_FreeValue(g_scoreboard_js, ret); JS_FreeValue(g_scoreboard_js, args[0]); JS_FreeValue(g_scoreboard_js, args[1]); } static void personal_best_cb(PDScore *score, const char *errorMessage) { - if (!g_scoreboard_js || JS_IsUndefined(g_personal_best_callback)) return; + if (!g_scoreboard_js || JS_IsNull(g_personal_best_callback)) return; JSValue args[2]; args[0] = score_to_js(g_scoreboard_js, score); args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL; - JSValue ret = JS_Call(g_scoreboard_js, g_personal_best_callback, JS_UNDEFINED, 2, args); + JSValue ret = JS_Call(g_scoreboard_js, g_personal_best_callback, JS_NULL, 2, args); JS_FreeValue(g_scoreboard_js, ret); JS_FreeValue(g_scoreboard_js, args[0]); JS_FreeValue(g_scoreboard_js, args[1]); } static void boards_list_cb(PDBoardsList *boards, const char *errorMessage) { - if (!g_scoreboard_js || JS_IsUndefined(g_boards_list_callback)) return; + if (!g_scoreboard_js || JS_IsNull(g_boards_list_callback)) return; JSValue args[2]; if (boards) { JSValue arr = JS_NewArray(g_scoreboard_js); @@ -64,14 +64,14 @@ static void boards_list_cb(PDBoardsList *boards, const char *errorMessage) { args[0] = JS_NULL; } args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL; - JSValue ret = JS_Call(g_scoreboard_js, g_boards_list_callback, JS_UNDEFINED, 2, args); + JSValue ret = JS_Call(g_scoreboard_js, g_boards_list_callback, JS_NULL, 2, args); JS_FreeValue(g_scoreboard_js, ret); JS_FreeValue(g_scoreboard_js, args[0]); JS_FreeValue(g_scoreboard_js, args[1]); } static void scores_cb(PDScoresList *scores, const char *errorMessage) { - if (!g_scoreboard_js || JS_IsUndefined(g_scores_callback)) return; + if (!g_scoreboard_js || JS_IsNull(g_scores_callback)) return; JSValue args[2]; if (scores) { JSValue obj = JS_NewObject(g_scoreboard_js); @@ -91,7 +91,7 @@ static void scores_cb(PDScoresList *scores, const char *errorMessage) { args[0] = JS_NULL; } args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL; - JSValue ret = JS_Call(g_scoreboard_js, g_scores_callback, JS_UNDEFINED, 2, args); + JSValue ret = JS_Call(g_scoreboard_js, g_scores_callback, JS_NULL, 2, args); JS_FreeValue(g_scoreboard_js, ret); JS_FreeValue(g_scoreboard_js, args[0]); JS_FreeValue(g_scoreboard_js, args[1]); @@ -124,7 +124,7 @@ JSC_CCALL(scoreboards_freeScore, if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized"); // Note: PDScore from callbacks is managed by Playdate, this is for user-allocated scores // In practice, JS doesn't allocate PDScore directly, so this is a no-op wrapper - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(scoreboards_getScoreboards, @@ -140,7 +140,7 @@ JSC_CCALL(scoreboards_getScoreboards, JSC_CCALL(scoreboards_freeBoardsList, if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized"); // Managed by Playdate after callback - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(scoreboards_getScores, @@ -156,7 +156,7 @@ JSC_SCALL(scoreboards_getScores, JSC_CCALL(scoreboards_freeScoresList, if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized"); // Managed by Playdate after callback - return JS_UNDEFINED; + return JS_NULL; ) static const JSCFunctionListEntry js_scoreboards_funcs[] = { diff --git a/playdate/sound_playdate.c b/playdate/sound_playdate.c index 4abd8973..445269ad 100644 --- a/playdate/sound_playdate.c +++ b/playdate/sound_playdate.c @@ -47,7 +47,7 @@ JSC_CCALL(sound_removeChannel, JSC_CCALL(sound_setOutputsActive, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->setOutputsActive(JS_ToBool(js, argv[0]), JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_getError, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -65,7 +65,7 @@ JSC_CCALL(sound_freeFilePlayer, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); FilePlayer *p = js2fileplayer(js, argv[0]); if (p) pd_sound->fileplayer->freePlayer(p); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(sound_loadIntoFilePlayer, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -85,17 +85,17 @@ JSC_CCALL(sound_filePlayerIsPlaying, JSC_CCALL(sound_filePlayerPause, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->pause(js2fileplayer(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerStop, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->stop(js2fileplayer(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerSetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setVolume(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerGetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -112,7 +112,7 @@ JSC_CCALL(sound_filePlayerGetLength, JSC_CCALL(sound_filePlayerSetOffset, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setOffset(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerGetOffset, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -121,7 +121,7 @@ JSC_CCALL(sound_filePlayerGetOffset, JSC_CCALL(sound_filePlayerSetRate, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setRate(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerGetRate, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -130,7 +130,7 @@ JSC_CCALL(sound_filePlayerGetRate, JSC_CCALL(sound_filePlayerSetLoopRange, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setLoopRange(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerDidUnderrun, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -139,12 +139,12 @@ JSC_CCALL(sound_filePlayerDidUnderrun, JSC_CCALL(sound_filePlayerSetStopOnUnderrun, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setStopOnUnderrun(js2fileplayer(js, argv[0]), JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_filePlayerSetBufferLength, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->fileplayer->setBufferLength(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) // --- Sample --- @@ -157,7 +157,7 @@ JSC_CCALL(sound_freeSample, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); AudioSample *s = js2sample(js, argv[0]); if (s) pd_sound->sample->freeSample(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_getSampleLength, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -179,12 +179,12 @@ JSC_CCALL(sound_freeSamplePlayer, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); SamplePlayer *p = js2sampleplayer(js, argv[0]); if (p) pd_sound->sampleplayer->freePlayer(p); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerSetSample, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setSample(js2sampleplayer(js, argv[0]), js2sample(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerPlay, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -200,12 +200,12 @@ JSC_CCALL(sound_samplePlayerIsPlaying, JSC_CCALL(sound_samplePlayerStop, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->stop(js2sampleplayer(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerSetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setVolume(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerGetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -222,7 +222,7 @@ JSC_CCALL(sound_samplePlayerGetLength, JSC_CCALL(sound_samplePlayerSetOffset, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setOffset(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerGetOffset, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -231,7 +231,7 @@ JSC_CCALL(sound_samplePlayerGetOffset, JSC_CCALL(sound_samplePlayerSetRate, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setRate(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerGetRate, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -240,12 +240,12 @@ JSC_CCALL(sound_samplePlayerGetRate, JSC_CCALL(sound_samplePlayerSetPlayRange, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setPlayRange(js2sampleplayer(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_samplePlayerSetPaused, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->sampleplayer->setPaused(js2sampleplayer(js, argv[0]), JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) // --- Synth --- @@ -258,37 +258,37 @@ JSC_CCALL(sound_freeSynth, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); PDSynth *s = js2synth(js, argv[0]); if (s) pd_sound->synth->freeSynth(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetWaveform, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setWaveform(js2synth(js, argv[0]), (SoundWaveform)(int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetAttackTime, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setAttackTime(js2synth(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetDecayTime, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setDecayTime(js2synth(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetSustainLevel, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setSustainLevel(js2synth(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetReleaseTime, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setReleaseTime(js2synth(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetTranspose, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setTranspose(js2synth(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthPlayNote, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -298,7 +298,7 @@ JSC_CCALL(sound_synthPlayNote, float len = argc > 3 ? (float)js2number(js, argv[3]) : -1.0f; uint32_t when = argc > 4 ? (uint32_t)js2number(js, argv[4]) : 0; pd_sound->synth->playNote(s, freq, vel, len, when); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthPlayMIDINote, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -308,22 +308,22 @@ JSC_CCALL(sound_synthPlayMIDINote, float len = argc > 3 ? (float)js2number(js, argv[3]) : -1.0f; uint32_t when = argc > 4 ? (uint32_t)js2number(js, argv[4]) : 0; pd_sound->synth->playMIDINote(s, note, vel, len, when); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthNoteOff, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->noteOff(js2synth(js, argv[0]), argc > 1 ? (uint32_t)js2number(js, argv[1]) : 0); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthStop, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->stop(js2synth(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthSetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->synth->setVolume(js2synth(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_synthGetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -356,12 +356,12 @@ JSC_CCALL(sound_freeChannel, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); SoundChannel *ch = js2channel(js, argv[0]); if (ch) pd_sound->channel->freeChannel(ch); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_channelSetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->channel->setVolume(js2channel(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sound_channelGetVolume, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); @@ -370,7 +370,7 @@ JSC_CCALL(sound_channelGetVolume, JSC_CCALL(sound_channelSetPan, if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized"); pd_sound->channel->setPan(js2channel(js, argv[0]), (float)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) static const JSCFunctionListEntry js_sound_funcs[] = { diff --git a/playdate/sprite_playdate.c b/playdate/sprite_playdate.c index 787a5127..1d6606e0 100644 --- a/playdate/sprite_playdate.c +++ b/playdate/sprite_playdate.c @@ -23,19 +23,19 @@ static LCDBitmap* js2bitmap(JSContext *js, JSValueConst val) { JSC_CCALL(sprite_setAlwaysRedraw, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); pd_sprite->setAlwaysRedraw(JS_ToBool(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_drawSprites, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); pd_sprite->drawSprites(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_updateAndDrawSprites, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); pd_sprite->updateAndDrawSprites(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_newSprite, @@ -49,7 +49,7 @@ JSC_CCALL(sprite_freeSprite, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); LCDSprite *s = js2sprite(js, argv[0]); if (s) pd_sprite->freeSprite(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_copy, @@ -65,7 +65,7 @@ JSC_CCALL(sprite_addSprite, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->addSprite(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_removeSprite, @@ -73,13 +73,13 @@ JSC_CCALL(sprite_removeSprite, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->removeSprite(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_removeAllSprites, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); pd_sprite->removeAllSprites(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getSpriteCount, @@ -94,7 +94,7 @@ JSC_CCALL(sprite_setBounds, PDRect bounds = { (float)js2number(js, argv[1]), (float)js2number(js, argv[2]), (float)js2number(js, argv[3]), (float)js2number(js, argv[4]) }; pd_sprite->setBounds(s, bounds); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getBounds, @@ -115,7 +115,7 @@ JSC_CCALL(sprite_moveTo, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->moveTo(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_moveBy, @@ -123,7 +123,7 @@ JSC_CCALL(sprite_moveBy, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->moveBy(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setImage, @@ -133,7 +133,7 @@ JSC_CCALL(sprite_setImage, if (!s) return JS_ThrowTypeError(js, "invalid sprite"); LCDBitmapFlip flip = argc > 2 ? (LCDBitmapFlip)(int)js2number(js, argv[2]) : kBitmapUnflipped; pd_sprite->setImage(s, img, flip); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getImage, @@ -149,7 +149,7 @@ JSC_CCALL(sprite_setSize, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setSize(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setZIndex, @@ -157,7 +157,7 @@ JSC_CCALL(sprite_setZIndex, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setZIndex(s, (int16_t)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getZIndex, @@ -172,7 +172,7 @@ JSC_CCALL(sprite_setDrawMode, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setDrawMode(s, (LCDBitmapDrawMode)(int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setImageFlip, @@ -180,7 +180,7 @@ JSC_CCALL(sprite_setImageFlip, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setImageFlip(s, (LCDBitmapFlip)(int)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getImageFlip, @@ -195,7 +195,7 @@ JSC_CCALL(sprite_setVisible, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setVisible(s, JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_isVisible, @@ -210,7 +210,7 @@ JSC_CCALL(sprite_setOpaque, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setOpaque(s, JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_markDirty, @@ -218,7 +218,7 @@ JSC_CCALL(sprite_markDirty, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->markDirty(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setTag, @@ -226,7 +226,7 @@ JSC_CCALL(sprite_setTag, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setTag(s, (uint8_t)js2number(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getTag, @@ -241,7 +241,7 @@ JSC_CCALL(sprite_setIgnoresDrawOffset, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setIgnoresDrawOffset(s, JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getPosition, @@ -261,7 +261,7 @@ JSC_CCALL(sprite_setCenter, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setCenter(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getCenter, @@ -281,7 +281,7 @@ JSC_CCALL(sprite_getCenter, JSC_CCALL(sprite_resetCollisionWorld, if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized"); pd_sprite->resetCollisionWorld(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setCollideRect, @@ -291,7 +291,7 @@ JSC_CCALL(sprite_setCollideRect, PDRect rect = { (float)js2number(js, argv[1]), (float)js2number(js, argv[2]), (float)js2number(js, argv[3]), (float)js2number(js, argv[4]) }; pd_sprite->setCollideRect(s, rect); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_getCollideRect, @@ -312,7 +312,7 @@ JSC_CCALL(sprite_clearCollideRect, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->clearCollideRect(s); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_setCollisionsEnabled, @@ -320,7 +320,7 @@ JSC_CCALL(sprite_setCollisionsEnabled, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setCollisionsEnabled(s, JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_collisionsEnabled, @@ -335,7 +335,7 @@ JSC_CCALL(sprite_setUpdatesEnabled, LCDSprite *s = js2sprite(js, argv[0]); if (!s) return JS_ThrowTypeError(js, "invalid sprite"); pd_sprite->setUpdatesEnabled(s, JS_ToBool(js, argv[1])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sprite_updatesEnabled, diff --git a/playdate/sys_playdate.c b/playdate/sys_playdate.c index ceb1df7e..66d6468b 100644 --- a/playdate/sys_playdate.c +++ b/playdate/sys_playdate.c @@ -14,7 +14,7 @@ JSC_CCALL(sys_logToConsole, pd_sys->logToConsole("%s", str); JS_FreeCString(js, str); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_error, @@ -24,7 +24,7 @@ JSC_CCALL(sys_error, pd_sys->error("%s", str); JS_FreeCString(js, str); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_getLanguage, @@ -53,7 +53,7 @@ JSC_CCALL(sys_drawFPS, int x = (int)js2number(js, argv[0]); int y = (int)js2number(js, argv[1]); pd_sys->drawFPS(x, y); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_getButtonState, @@ -71,7 +71,7 @@ JSC_CCALL(sys_setPeripheralsEnabled, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); PDPeripherals mask = (PDPeripherals)(int)js2number(js, argv[0]); pd_sys->setPeripheralsEnabled(mask); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_getAccelerometer, @@ -115,7 +115,7 @@ JSC_CCALL(sys_getFlipped, JSC_CCALL(sys_setAutoLockDisabled, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); pd_sys->setAutoLockDisabled(JS_ToBool(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_getReduceFlashing, @@ -131,7 +131,7 @@ JSC_CCALL(sys_getElapsedTime, JSC_CCALL(sys_resetElapsedTime, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); pd_sys->resetElapsedTime(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_getBatteryPercentage, @@ -185,13 +185,13 @@ JSC_CCALL(sys_convertDateTimeToEpoch, JSC_CCALL(sys_clearICache, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); pd_sys->clearICache(); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sys_delay, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); pd_sys->delay((uint32_t)js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; ) JSC_SCALL(sys_restartGame, @@ -224,7 +224,7 @@ JSC_CCALL(sys_getSystemInfo, JSC_CCALL(sys_removeAllMenuItems, if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized"); pd_sys->removeAllMenuItems(); - return JS_UNDEFINED; + return JS_NULL; ) static const JSCFunctionListEntry js_sys_funcs[] = { diff --git a/shop.cm b/shop.cm index ef6fed3a..6c3bf97a 100644 --- a/shop.cm +++ b/shop.cm @@ -320,7 +320,8 @@ function resolve_mod_fn(path, pkg) { } // Compile name is just for debug/stack traces - var compile_name = pkg ? pkg + ':' + path : 'local:' + path +// var compile_name = pkg ? pkg + ':' + path : 'local:' + path + var compile_name = path var fn = js.compile(compile_name, script) @@ -622,7 +623,9 @@ function get_package_abs_dir(package) // Returns null for local packages or if fetch fails function fetch_remote_hash(pkg) { var api_url = Shop.get_api_url(pkg) + if (!api_url) return null + try { var resp = http.fetch(api_url) @@ -766,14 +769,18 @@ Shop.update = function(pkg) { var lock_entry = lock[pkg] var info = Shop.resolve_package_info(pkg) -log.console(`checking ${pkg}`) + log.console(`checking ${pkg}`) + if (info == 'local') return { updated: time.number() } - var local_commit = lock_entry.commit + var local_commit = lock_entry ? lock_entry.commit : null var remote_commit = fetch_remote_hash(pkg) + log.console(`local commit: ${local_commit}`) + log.console(`remote commit: ${remote_commit}`) + if (local_commit == remote_commit) return null diff --git a/source/qjs_blob.c b/source/qjs_blob.c index ca79aa9f..de020da2 100644 --- a/source/qjs_blob.c +++ b/source/qjs_blob.c @@ -10,7 +10,7 @@ // Free function for blob void blob_free(JSRuntime *rt, blob *b) { -// blob_destroy(b); + blob_destroy(b); } // Use QJSCLASS macro to generate class boilerplate diff --git a/source/scheduler.c b/source/scheduler.c index 253a550b..d10ed445 100644 --- a/source/scheduler.c +++ b/source/scheduler.c @@ -139,55 +139,59 @@ int heap_pop(timer_node *out) { } void *timer_thread_func(void *arg) { - while (1) { - pthread_mutex_lock(&engine.lock); - - if (engine.shutting_down) { - pthread_mutex_unlock(&engine.lock); - return NULL; - } - - if (arrlen(timer_heap) == 0) { - pthread_cond_wait(&engine.timer_cond, &engine.lock); - } else { - uint64_t now = cell_ns(); - if (timer_heap[0].execute_at_ns <= now) { - // --- TIMER FIRED --- - timer_node t; - heap_pop(&t); - pthread_mutex_unlock(&engine.lock); - - if (t.type == TIMER_NATIVE_REMOVE) { - // Execute native remove callback - actor_remove_cb(t.actor, t.timer_id, 0); - } else { - // Inject event into Actor - pthread_mutex_lock(t.actor->msg_mutex); - int idx = hmgeti(t.actor->timers, t.timer_id); - if (idx != -1) { - JSValue cb = t.actor->timers[idx].value; - hmdel(t.actor->timers, t.timer_id); - actor_clock(t.actor, cb); - JS_FreeValue(t.actor->context, cb); - } - pthread_mutex_unlock(t.actor->msg_mutex); - } - - // Loop immediately to check for other expired timers - continue; - } else { - // --- WAIT FOR DEADLINE --- - struct timespec ts; - uint64_t ns = timer_heap[0].execute_at_ns; - ts.tv_sec = ns / 1000000000ULL; - ts.tv_nsec = ns % 1000000000ULL; - - pthread_cond_timedwait(&engine.timer_cond, &engine.lock, &ts); - } - } - pthread_mutex_unlock(&engine.lock); + while (1) { + pthread_mutex_lock(&engine.lock); + + if (engine.shutting_down) { + pthread_mutex_unlock(&engine.lock); + return NULL; } - return NULL; + + if (arrlen(timer_heap) == 0) { + pthread_cond_wait(&engine.timer_cond, &engine.lock); + } else { + uint64_t now = cell_ns(); + if (timer_heap[0].execute_at_ns <= now) { + // --- TIMER FIRED --- + timer_node t; + heap_pop(&t); + pthread_mutex_unlock(&engine.lock); + + if (t.type == TIMER_NATIVE_REMOVE) { + actor_remove_cb(t.actor, t.timer_id, 0); + } else { + pthread_mutex_lock(t.actor->msg_mutex); + int idx = hmgeti(t.actor->timers, t.timer_id); + if (idx != -1) { + JSValue cb = t.actor->timers[idx].value; + hmdel(t.actor->timers, t.timer_id); + actor_clock(t.actor, cb); + JS_FreeValue(t.actor->context, cb); + } + pthread_mutex_unlock(t.actor->msg_mutex); + } + + continue; + } else { + // --- WAIT FOR DEADLINE --- + struct timespec ts; + uint64_t wait_ns = timer_heap[0].execute_at_ns - now; + + // Convert relative wait time to absolute CLOCK_REALTIME + struct timespec now_real; + clock_gettime(CLOCK_REALTIME, &now_real); + + uint64_t deadline_real_ns = (uint64_t)now_real.tv_sec * 1000000000ULL + + (uint64_t)now_real.tv_nsec + wait_ns; + ts.tv_sec = deadline_real_ns / 1000000000ULL; + ts.tv_nsec = deadline_real_ns % 1000000000ULL; + + pthread_cond_timedwait(&engine.timer_cond, &engine.lock, &ts); + } + } + pthread_mutex_unlock(&engine.lock); + } + return NULL; } void *actor_runner(void *arg) { diff --git a/toolchains.cm b/toolchains.cm index d95c565c..d3e4e895 100644 --- a/toolchains.cm +++ b/toolchains.cm @@ -242,5 +242,11 @@ return { endian: 'little', c_args: [], c_link_args: [] + }, + raspberrypi: { + + }, + android: { + } } \ No newline at end of file