MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

optimize array literal handling

use js_mkprop_fast
improve loop block scope handling for function declarations

+34 -16
+2 -1
.gitignore
··· 1 1 .env 2 2 .nova 3 + .maid 3 4 .cache 4 5 .github/artifacts 5 6 ··· 9 10 10 11 /build 11 12 /traces 13 + /todo/* 12 14 13 15 /src/pkg/.zig-cache 14 16 /src/strip/target ··· 25 27 26 28 ant.txt 27 29 zoo.sh 28 - todo.txt 29 30 AGENTS.md 30 31 31 32 node_modules
+4
maidfile.toml
··· 2 2 path = "build" 3 3 script = "meson compile" 4 4 5 + [tasks.build.cache] 6 + path = "src" 7 + target = ["build/ant"] 8 + 5 9 [tasks.strip] 6 10 path = "build" 7 11 script = "strip ant"
+28 -15
src/ant.c
··· 7321 7321 if (!is_spread) { 7322 7322 char idxstr[16]; 7323 7323 size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)idx); 7324 - jsval_t key = js_mkstr(js, idxstr, idxlen); 7325 - jsval_t res = setprop(js, arr, key, resolved); 7324 + jsval_t res = js_mkprop_fast(js, arr, idxstr, idxlen, resolved); 7326 7325 if (is_err(res)) return res; 7327 - idx++; 7328 - goto next_elem; 7326 + idx++; goto next_elem; 7329 7327 } 7330 7328 7331 7329 uint8_t t = vtype(resolved); ··· 7336 7334 for (jsoff_t i = 0; i < slen; i++) { 7337 7335 char idxstr[16]; 7338 7336 size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)idx); 7339 - jsval_t key = js_mkstr(js, idxstr, idxlen); 7340 7337 jsval_t ch = js_mkstr(js, (char *)&js->mem[soff + i], 1); 7341 - setprop(js, arr, key, ch); 7338 + js_mkprop_fast(js, arr, idxstr, idxlen, ch); 7342 7339 idx++; 7343 7340 } 7344 7341 goto next_elem; ··· 7347 7344 jsoff_t len = js_arr_len(js, resolved); 7348 7345 for (jsoff_t i = 0; i < len; i++) { 7349 7346 char src_idx[16], dst_idx[16]; 7350 - snprintf(src_idx, sizeof(src_idx), "%u", (unsigned)i); 7351 - snprintf(dst_idx, sizeof(dst_idx), "%u", (unsigned)idx); 7352 - jsval_t key = js_mkstr(js, src_idx, strlen(src_idx)); 7353 - jsoff_t prop_off = lkp(js, resolved, (char *)&js->mem[(jsoff_t)vdata(key) + sizeof(jsoff_t)], strlen(src_idx)); 7347 + size_t src_len = uint_to_str(src_idx, sizeof(src_idx), (unsigned)i); 7348 + size_t dst_len = uint_to_str(dst_idx, sizeof(dst_idx), (unsigned)idx); 7349 + jsoff_t prop_off = lkp(js, resolved, src_idx, src_len); 7354 7350 jsval_t elem = (prop_off != 0) ? resolveprop(js, mkval(T_PROP, prop_off)) : js_mkundef(); 7355 - setprop(js, arr, js_mkstr(js, dst_idx, strlen(dst_idx)), elem); 7351 + js_mkprop_fast(js, arr, dst_idx, dst_len, elem); 7356 7352 idx++; 7357 7353 } 7358 7354 ··· 7363 7359 7364 7360 EXPECT(TOK_RBRACKET); 7365 7361 if (exe) { 7366 - jsval_t len_key = js_mkstr(js, "length", 6); 7367 - jsval_t len_val = tov((double)idx); 7368 - jsval_t res = setprop(js, arr, len_key, len_val); 7362 + jsval_t res = js_mkprop_fast(js, arr, "length", 6, tov((double)idx)); 7369 7363 if (is_err(res)) return res; 7370 7364 arr = mkval(T_ARR, vdata(arr)); 7371 7365 } ··· 9678 9672 typedef struct { 9679 9673 bool is_block; 9680 9674 bool needs_scope; 9675 + bool has_func_decl; 9676 + bool has_func_decl_checked; 9681 9677 jsval_t loop_scope; 9682 9678 } loop_block_ctx_t; 9683 9679 9684 9680 static void loop_block_init(struct js *js, loop_block_ctx_t *ctx) { 9685 9681 ctx->is_block = (lookahead(js) == TOK_LBRACE); 9686 9682 ctx->needs_scope = false; 9683 + ctx->has_func_decl = false; 9684 + ctx->has_func_decl_checked = false; 9687 9685 ctx->loop_scope = js_mkundef(); 9688 9686 9689 9687 if (ctx->is_block && !(js->flags & F_NOEXEC)) { ··· 9706 9704 static inline jsval_t loop_block_exec(struct js *js, loop_block_ctx_t *ctx) { 9707 9705 if (ctx->is_block) { 9708 9706 next(js); 9709 - return js_block(js, false); 9707 + 9708 + if (!ctx->has_func_decl_checked) { 9709 + ctx->has_func_decl = code_has_function_decl( 9710 + js->code + js->pos, 9711 + js->clen - js->pos 9712 + ); 9713 + ctx->has_func_decl_checked = true; 9714 + } 9715 + 9716 + bool saved_skip = js->skip_func_hoist; 9717 + if (!ctx->has_func_decl) js->skip_func_hoist = true; 9718 + 9719 + jsval_t result = js_block(js, false); 9720 + js->skip_func_hoist = saved_skip; 9721 + 9722 + return result; 9710 9723 } 9711 9724 9712 9725 return js_block_or_stmt(js);