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.

make local capture lighter

+28 -18
+3 -3
include/silver/glue.h
··· 85 85 ); 86 86 87 87 ant_value_t jit_helper_closure( 88 - sv_vm_t *vm, ant_t *js, 89 - sv_closure_t *parent_closure, ant_value_t this_val, 90 - ant_value_t *slots, int slot_count, uint32_t const_idx 88 + sv_vm_t *vm, ant_t *js, sv_closure_t *parent_closure, 89 + ant_value_t this_val, ant_value_t *slots, 90 + int slot_base, int slot_count, uint32_t const_idx 91 91 ); 92 92 93 93 ant_value_t jit_helper_bailout_resume(
+4 -4
src/silver/glue.c
··· 205 205 } 206 206 207 207 ant_value_t jit_helper_closure( 208 - sv_vm_t *vm, ant_t *js, 209 - sv_closure_t *parent_closure, ant_value_t this_val, 210 - ant_value_t *slots, int slot_count, uint32_t const_idx 208 + sv_vm_t *vm, ant_t *js, sv_closure_t *parent_closure, 209 + ant_value_t this_val, ant_value_t *slots, 210 + int slot_base, int slot_count, uint32_t const_idx 211 211 ) { 212 212 sv_func_t *parent_func = parent_closure->func; 213 213 sv_func_t *child = (sv_func_t *)(uintptr_t)vdata(parent_func->constants[const_idx]); ··· 231 231 continue; 232 232 } 233 233 234 - int idx = (int)desc->index; 234 + int idx = (int)desc->index - slot_base; 235 235 if (!slots || idx < 0 || idx >= slot_count) { 236 236 closure->upvalues[i] = jit_make_undef_upvalue(); 237 237 continue;
+21 -11
src/silver/swarm.c
··· 353 353 static void mir_emit_close_captured_slots( 354 354 MIR_context_t ctx, MIR_item_t fn, 355 355 MIR_item_t close_upval_proto, MIR_item_t imp_close_upval, 356 - MIR_reg_t r_vm, MIR_reg_t r_slotbuf, 357 - int captured_slot_count 356 + MIR_reg_t r_vm, MIR_reg_t r_slots, 357 + int slot_count 358 358 ) { 359 - if (captured_slot_count <= 0) return; 359 + if (slot_count <= 0) return; 360 360 MIR_append_insn(ctx, fn, 361 361 MIR_new_call_insn(ctx, 6, 362 362 MIR_new_ref_op(ctx, close_upval_proto), 363 363 MIR_new_ref_op(ctx, imp_close_upval), 364 364 MIR_new_reg_op(ctx, r_vm), 365 365 MIR_new_uint_op(ctx, 0), 366 - MIR_new_reg_op(ctx, r_slotbuf), 367 - MIR_new_int_op(ctx, captured_slot_count))); 366 + MIR_new_reg_op(ctx, r_slots), 367 + MIR_new_int_op(ctx, slot_count))); 368 368 } 369 369 370 370 static inline void mir_emit_self_tail( ··· 2022 2022 2023 2023 MIR_type_t cl_ret = MIR_JSVAL; 2024 2024 MIR_item_t closure_proto = MIR_new_proto(ctx, "closure_proto", 2025 - 1, &cl_ret, 7, 2025 + 1, &cl_ret, 8, 2026 2026 MIR_T_I64, "vm", 2027 2027 MIR_T_I64, "js", 2028 2028 MIR_T_P, "parent", 2029 2029 MIR_JSVAL, "this_val", 2030 2030 MIR_T_P, "slots", 2031 + MIR_T_I32, "slot_base", 2031 2032 MIR_T_I32, "slot_count", 2032 2033 MIR_T_I32, "const_idx"); 2033 2034 ··· 2367 2368 for (int i = 0; i < n_locals; i++) 2368 2369 if (captured_locals[i]) { has_captures = true; break; } 2369 2370 } 2370 - bool has_captured_slots = has_captured_params || has_captures; 2371 + bool has_captured_slots = has_captured_params; 2371 2372 int captured_slot_count = param_count + n_locals; 2372 2373 2373 2374 if (has_captured_params && needs_bailout) { ··· 2393 2394 MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)))); 2394 2395 } else mir_load_imm(ctx, jit_func, r_slotbuf, 0); 2395 2396 2396 - bool needs_lbuf = needs_bailout || feat.needs_close_upval || has_captured_slots; 2397 + bool needs_lbuf = needs_bailout || feat.needs_close_upval || has_captures || has_captured_slots; 2397 2398 MIR_reg_t r_lbuf = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, "lbuf"); 2398 2399 if (has_captured_slots && n_locals > 0) { 2399 2400 MIR_append_insn(ctx, jit_func, ··· 4937 4938 mir_emit_close_captured_slots(ctx, jit_func, 4938 4939 close_upval_proto, imp_close_upval, 4939 4940 r_vm, r_slotbuf, captured_slot_count); 4941 + else if (has_captures) 4942 + mir_emit_close_captured_slots(ctx, jit_func, 4943 + close_upval_proto, imp_close_upval, 4944 + r_vm, r_lbuf, n_locals); 4940 4945 MIR_append_insn(ctx, jit_func, 4941 4946 MIR_new_ret_insn(ctx, 1, MIR_new_reg_op(ctx, ret_val))); 4942 4947 break; ··· 4947 4952 mir_emit_close_captured_slots(ctx, jit_func, 4948 4953 close_upval_proto, imp_close_upval, 4949 4954 r_vm, r_slotbuf, captured_slot_count); 4955 + else if (has_captures) 4956 + mir_emit_close_captured_slots(ctx, jit_func, 4957 + close_upval_proto, imp_close_upval, 4958 + r_vm, r_lbuf, n_locals); 4950 4959 MIR_append_insn(ctx, jit_func, 4951 4960 MIR_new_ret_insn(ctx, 1, 4952 4961 MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)))); ··· 7083 7092 MIR_new_reg_op(ctx, local_regs[i]))); 7084 7093 } 7085 7094 MIR_append_insn(ctx, jit_func, 7086 - MIR_new_call_insn(ctx, 10, 7095 + MIR_new_call_insn(ctx, 11, 7087 7096 MIR_new_ref_op(ctx, closure_proto), 7088 7097 MIR_new_ref_op(ctx, imp_closure), 7089 7098 MIR_new_reg_op(ctx, dst), ··· 7091 7100 MIR_new_reg_op(ctx, r_js), 7092 7101 MIR_new_reg_op(ctx, r_closure), 7093 7102 MIR_new_reg_op(ctx, r_this), 7094 - MIR_new_reg_op(ctx, r_slotbuf), 7095 - MIR_new_int_op(ctx, captured_slot_count), 7103 + MIR_new_reg_op(ctx, has_captured_slots ? r_slotbuf : r_lbuf), 7104 + MIR_new_int_op(ctx, has_captured_slots ? 0 : param_count), 7105 + MIR_new_int_op(ctx, has_captured_slots ? captured_slot_count : n_locals), 7096 7106 MIR_new_uint_op(ctx, (uint64_t)idx))); 7097 7107 break; 7098 7108 }