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.

bring OP_SPECIAL(1..3) to jit support

- super_val
- this_val
- import metadata

+269 -54
+10 -3
include/silver/engine.h
··· 878 878 fn->call_count = SV_JIT_THRESHOLD - SV_JIT_RECOMPILE_DELAY; 879 879 } 880 880 881 - typedef ant_value_t (*sv_jit_func_t) 882 - (sv_vm_t *, ant_value_t, ant_value_t *, int, sv_closure_t *); 881 + typedef ant_value_t (*sv_jit_func_t)( 882 + sv_vm_t *, 883 + ant_value_t, 884 + ant_value_t, 885 + ant_value_t, 886 + ant_value_t *, 887 + int, sv_closure_t * 888 + ); 883 889 884 890 ant_value_t sv_jit_try_compile_and_call(sv_vm_t *vm, ant_t *js, 885 891 sv_closure_t *closure, ant_value_t callee_func, ··· 1075 1081 if (fn->jit_code) { 1076 1082 sv_jit_enter(js); 1077 1083 ant_value_t result = ((sv_jit_func_t)fn->jit_code)( 1078 - vm, ctx->this_val, ctx->args, ctx->argc, closure 1084 + vm, ctx->this_val, js->new_target, 1085 + ctx->super_val, ctx->args, ctx->argc, closure 1079 1086 ); 1080 1087 sv_jit_leave(js); 1081 1088 if (sv_is_jit_bailout(result)) {
+8
include/silver/glue.h
··· 67 67 ant_value_t *args, int argc 68 68 ); 69 69 70 + ant_value_t jit_helper_call_method( 71 + sv_vm_t *vm, ant_t *js, 72 + ant_value_t func, ant_value_t this_val, 73 + ant_value_t *args, int argc, 74 + ant_value_t super_val, ant_value_t new_target, 75 + ant_value_t *out_this 76 + ); 77 + 70 78 ant_value_t jit_helper_apply( 71 79 sv_vm_t *vm, ant_t *js, 72 80 ant_value_t func, ant_value_t this_val,
+21 -12
src/silver/compiler.c
··· 737 737 } 738 738 739 739 static void emit_get_var(sv_compiler_t *c, const char *name, uint32_t len) { 740 + bool is_super = is_ident_str(name, len, "super", 5); 741 + 742 + if (is_super && c->super_local >= 0) { 743 + emit_get_local(c, c->super_local); 744 + return; 745 + } 746 + 747 + if (is_super && c->is_arrow) { 748 + int super_upval = resolve_super_upvalue(c); 749 + if (super_upval != -1) { 750 + emit_op(c, OP_GET_UPVAL); 751 + emit_u16(c, (uint16_t)super_upval); 752 + return; 753 + }} 754 + 740 755 int local = resolve_local(c, name, len); 741 756 if (local != -1) { 742 757 if (c->with_depth > 0) { ··· 767 782 } 768 783 return; 769 784 } 785 + 770 786 int upval = resolve_upvalue(c, name, len); 771 787 if (upval != -1) { 772 788 if (c->with_depth > 0) { ··· 777 793 emit_u16(c, (uint16_t)upval); 778 794 return; 779 795 } 796 + 780 797 if (is_ident_str(name, len, "arguments", 9)) { 781 798 if (has_implicit_arguments_obj(c)) { 782 799 if (c->strict_args_local >= 0) { ··· 796 813 } 797 814 } 798 815 } 799 - if (c->is_arrow && is_ident_str(name, len, "super", 5)) { 800 - int super_upval = resolve_super_upvalue(c); 801 - if (super_upval != -1) { 802 - emit_op(c, OP_GET_UPVAL); 803 - emit_u16(c, (uint16_t)super_upval); 804 - return; 805 - } 806 - } 816 + 807 817 if (has_module_import_binding(c) && is_ident_str(name, len, "import", 6)) { 808 818 emit_get_module_import_binding(c); 809 819 return; 810 820 } 811 - if (c->with_depth > 0) 812 - emit_with_get(c, name, len, WITH_FB_GLOBAL, 0); 813 - else 814 - emit_atom_op(c, OP_GET_GLOBAL, name, len); 821 + 822 + if (c->with_depth > 0) emit_with_get(c, name, len, WITH_FB_GLOBAL, 0); 823 + else emit_atom_op(c, OP_GET_GLOBAL, name, len); 815 824 } 816 825 817 826 static void emit_set_var(sv_compiler_t *c, const char *name, uint32_t len, bool keep) {
+7 -2
src/silver/engine.c
··· 683 683 if (caller_frame && caller_ip) caller_frame->ip = caller_ip + 3; 684 684 sv_jit_enter(js); 685 685 ant_value_t jit_result = ((sv_jit_func_t)callee->jit_code)( 686 - vm, jit_this, call_args, call_argc, closure); 686 + vm, jit_this, js_mkundef(), closure->super_val, 687 + call_args, call_argc, closure 688 + ); 687 689 sv_jit_leave(js); 688 690 if (sv_is_jit_bailout(jit_result)) { 689 691 sv_jit_on_bailout(callee); ··· 709 711 callee->jit_code = (void *)jit_fn; 710 712 if (caller_frame && caller_ip) caller_frame->ip = caller_ip + 3; 711 713 sv_jit_enter(js); 712 - ant_value_t jit_result = jit_fn(vm, jit_this, call_args, call_argc, closure); 714 + ant_value_t jit_result = jit_fn( 715 + vm, jit_this, js_mkundef(), closure->super_val, 716 + call_args, call_argc, closure 717 + ); 713 718 sv_jit_leave(js); 714 719 if (sv_is_jit_bailout(jit_result)) { 715 720 sv_jit_on_bailout(callee);
+26
src/silver/glue.c
··· 131 131 return sv_vm_call(vm, js, func, this_val, args, argc, NULL, false); 132 132 } 133 133 134 + ant_value_t jit_helper_call_method( 135 + sv_vm_t *vm, ant_t *js, 136 + ant_value_t func, ant_value_t this_val, 137 + ant_value_t *args, int argc, 138 + ant_value_t super_val, ant_value_t new_target, 139 + ant_value_t *out_this 140 + ) { 141 + bool is_super_call = (vtype(super_val) != T_UNDEF && func == super_val); 142 + ant_value_t call_this = this_val; 143 + 144 + if (is_super_call) js->new_target = new_target; 145 + 146 + ant_value_t super_this = call_this; 147 + ant_value_t result = sv_vm_call( 148 + vm, js, func, call_this, args, argc, 149 + is_super_call ? &super_this : NULL, is_super_call 150 + ); 151 + 152 + if (out_this) { 153 + if (is_super_call && !is_err(result)) *out_this = is_object_type(result) ? result : super_this; 154 + else *out_this = call_this; 155 + } 156 + 157 + return result; 158 + } 159 + 134 160 ant_value_t jit_helper_apply( 135 161 sv_vm_t *vm, ant_t *js, 136 162 ant_value_t func, ant_value_t this_val,
+197 -37
src/silver/swarm.c
··· 59 59 LOAD_EXT(jit_helper_gt); 60 60 LOAD_EXT(jit_helper_ge); 61 61 LOAD_EXT(jit_helper_call); 62 + LOAD_EXT(jit_helper_call_method); 62 63 LOAD_EXT(jit_helper_apply); 63 64 LOAD_EXT(jit_helper_rest); 64 65 LOAD_EXT(jit_helper_special_obj); ··· 1051 1052 case OP_JMP_TRUE8: case OP_JMP_FALSE8: 1052 1053 case OP_JMP_TRUE_PEEK: case OP_JMP_FALSE_PEEK: 1053 1054 case OP_RETURN: case OP_RETURN_UNDEF: 1054 - break; 1055 1055 case OP_GET_FIELD: case OP_GET_FIELD2: case OP_GET_GLOBAL: 1056 - break; 1057 1056 case OP_SPECIAL_OBJ: 1058 - // TODO: RE_ENABLE once SPECIAL_OBJ semantics match the interpreter in JIT. 1059 - return false; 1060 1057 case OP_NOP: case OP_LINE_NUM: case OP_COL_NUM: case OP_LABEL: 1061 1058 break; 1062 1059 default: ··· 1132 1129 MIR_item_t helper2_proto, MIR_item_t imp_seq, 1133 1130 MIR_item_t imp_sne, MIR_item_t imp_eq, MIR_item_t imp_ne, 1134 1131 MIR_item_t gf_proto, MIR_item_t imp_get_field, 1135 - MIR_item_t gg_proto, MIR_item_t imp_gg 1132 + MIR_item_t gg_proto, MIR_item_t imp_gg, 1133 + MIR_item_t special_obj_proto, MIR_item_t imp_special_obj 1136 1134 ) { 1137 1135 int inl_max_stack = callee->max_stack > 0 ? callee->max_stack : 4; 1138 1136 MIR_reg_t inl_vs[inl_max_stack]; ··· 1804 1802 MIR_new_insn(ctx, MIR_JMP, MIR_new_label_op(ctx, join))); 1805 1803 break; 1806 1804 1807 - case OP_SPECIAL_OBJ: 1808 - mir_load_imm(ctx, jit_func, inl_vs[isp++], mkval(T_UNDEF, 0)); 1805 + case OP_SPECIAL_OBJ: { 1806 + uint8_t which = sv_get_u8(ip + 1); 1807 + MIR_reg_t dst = inl_vs[isp++]; 1808 + if (which == 1) { 1809 + mir_load_imm(ctx, jit_func, dst, mkval(T_UNDEF, 0)); 1810 + } else if (which == 2) { 1811 + MIR_append_insn(ctx, jit_func, 1812 + MIR_new_insn(ctx, MIR_MOV, 1813 + MIR_new_reg_op(ctx, dst), 1814 + MIR_new_mem_op(ctx, MIR_T_I64, 1815 + (MIR_disp_t)offsetof(sv_closure_t, super_val), 1816 + r_inl_closure, 0, 1))); 1817 + } else if (which == 3) { 1818 + MIR_append_insn(ctx, jit_func, 1819 + MIR_new_call_insn(ctx, 6, 1820 + MIR_new_ref_op(ctx, special_obj_proto), 1821 + MIR_new_ref_op(ctx, imp_special_obj), 1822 + MIR_new_reg_op(ctx, dst), 1823 + MIR_new_reg_op(ctx, r_vm), 1824 + MIR_new_reg_op(ctx, r_js), 1825 + MIR_new_int_op(ctx, (int64_t)which))); 1826 + } else { 1827 + mir_load_imm(ctx, jit_func, dst, mkval(T_UNDEF, 0)); 1828 + } 1809 1829 break; 1830 + } 1810 1831 1811 1832 case OP_NOP: case OP_LINE_NUM: case OP_COL_NUM: case OP_LABEL: 1812 1833 break; ··· 1979 2000 case OP_STR_ALC_SNAPSHOT: 1980 2001 case OP_TO_PROPKEY: 1981 2002 case OP_RETURN: case OP_RETURN_UNDEF: 2003 + case OP_SPECIAL_OBJ: 1982 2004 case OP_SET_NAME: 1983 2005 case OP_TRY_PUSH: case OP_TRY_POP: 1984 2006 case OP_THROW: case OP_THROW_ERROR: ··· 1993 2015 if (vtype(cv) != T_CFUNC) return false; 1994 2016 break; 1995 2017 } 1996 - case OP_SPECIAL_OBJ: 1997 - // TODO: RE_ENABLE once SPECIAL_OBJ semantics match the interpreter in JIT. 1998 - if (sv_jit_warn_unlikely) 1999 - fprintf(stderr, "jit: ineligible op SPECIAL_OBJ(%d) in %s\n", 2000 - sv_get_u8(ip + 1), 2001 - func->name ? func->name : "<anonymous>"); 2002 - eligible = false; 2003 - break; 2004 2018 default: 2005 2019 if (sv_jit_warn_unlikely) 2006 2020 fprintf(stderr, "jit: ineligible op %s in %s\n", ··· 2041 2055 2042 2056 MIR_item_t self_proto = MIR_new_proto(ctx, "jit_proto", 2043 2057 1, &ret_type, 2044 - 5, 2058 + 7, 2045 2059 MIR_T_I64, "vm", 2046 2060 MIR_JSVAL, "this_val", 2061 + MIR_JSVAL, "new_target", 2062 + MIR_JSVAL, "super_val", 2047 2063 MIR_T_P, "args", 2048 2064 MIR_T_I32, "argc", 2049 2065 MIR_T_P, "closure"); ··· 2067 2083 MIR_T_P, "args", 2068 2084 MIR_T_I32, "argc"); 2069 2085 2086 + MIR_type_t call_method_ret = MIR_JSVAL; 2087 + MIR_item_t call_method_proto = MIR_new_proto(ctx, "callm_proto", 2088 + 1, &call_method_ret, 2089 + 9, 2090 + MIR_T_I64, "vm", 2091 + MIR_T_I64, "js", 2092 + MIR_JSVAL, "func", 2093 + MIR_JSVAL, "this_val", 2094 + MIR_T_P, "args", 2095 + MIR_T_I32, "argc", 2096 + MIR_JSVAL, "super_val", 2097 + MIR_JSVAL, "new_target", 2098 + MIR_T_P, "out_this"); 2099 + 2070 2100 MIR_type_t gg_ret = MIR_JSVAL; 2071 2101 MIR_item_t gg_proto = MIR_new_proto(ctx, "gg_proto", 2072 2102 1, &gg_ret, 4, ··· 2350 2380 MIR_item_t imp_gt = MIR_new_import(ctx, "jit_helper_gt"); 2351 2381 MIR_item_t imp_ge = MIR_new_import(ctx, "jit_helper_ge"); 2352 2382 MIR_item_t imp_call = MIR_new_import(ctx, "jit_helper_call"); 2383 + MIR_item_t imp_call_method = MIR_new_import(ctx, "jit_helper_call_method"); 2353 2384 MIR_item_t imp_apply = MIR_new_import(ctx, "jit_helper_apply"); 2354 2385 MIR_item_t imp_rest = MIR_new_import(ctx, "jit_helper_rest"); 2355 2386 MIR_item_t imp_special_obj = MIR_new_import(ctx, "jit_helper_special_obj"); ··· 2401 2432 2402 2433 MIR_item_t jit_func = MIR_new_func(ctx, fname, 2403 2434 1, &ret_type, 2404 - 5, 2435 + 7, 2405 2436 MIR_T_I64, "vm", 2406 2437 MIR_JSVAL, "this_val", 2438 + MIR_JSVAL, "new_target", 2439 + MIR_JSVAL, "super_val", 2407 2440 MIR_T_P, "args", 2408 2441 MIR_T_I32, "argc", 2409 2442 MIR_T_P, "closure"); 2410 2443 2411 2444 MIR_reg_t r_vm = MIR_reg(ctx, "vm", jit_func->u.func); 2412 2445 MIR_reg_t r_this = MIR_reg(ctx, "this_val", jit_func->u.func); 2446 + MIR_reg_t r_new_target = MIR_reg(ctx, "new_target", jit_func->u.func); 2447 + MIR_reg_t r_super_val = MIR_reg(ctx, "super_val", jit_func->u.func); 2413 2448 MIR_reg_t r_args = MIR_reg(ctx, "args", jit_func->u.func); 2414 2449 MIR_reg_t r_argc = MIR_reg(ctx, "argc", jit_func->u.func); 2415 2450 MIR_reg_t r_closure = MIR_reg(ctx, "closure", jit_func->u.func); 2451 + 2452 + MIR_reg_t r_this_curr = MIR_new_func_reg(ctx, jit_func->u.func, MIR_JSVAL, "this_curr"); 2453 + MIR_append_insn(ctx, jit_func, 2454 + MIR_new_insn(ctx, MIR_MOV, 2455 + MIR_new_reg_op(ctx, r_this_curr), 2456 + MIR_new_reg_op(ctx, r_this))); 2416 2457 2417 2458 MIR_reg_t r_js = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, "js_ptr"); 2418 2459 MIR_append_insn(ctx, jit_func, ··· 2845 2886 MIR_append_insn(ctx, jit_func, 2846 2887 MIR_new_insn(ctx, MIR_MOV, 2847 2888 MIR_new_reg_op(ctx, dst), 2848 - MIR_new_reg_op(ctx, r_this))); 2889 + MIR_new_reg_op(ctx, r_this_curr))); 2849 2890 break; 2850 2891 } 2851 2892 ··· 4711 4752 } 4712 4753 4713 4754 mir_emit_resolve_call_this(ctx, jit_func, r_inl_this, r_inl_cl, 4714 - r_this, r_inl_flags, r_inl_bound); 4755 + r_this_curr, r_inl_flags, r_inl_bound); 4715 4756 4716 4757 bool inlined = jit_emit_inline_body( 4717 4758 ctx, jit_func, inline_callee, ··· 4722 4763 r_vm, r_js, 4723 4764 helper2_proto, imp_seq, imp_sne, imp_eq, imp_ne, 4724 4765 gf_proto, imp_get_field, 4725 - gg_proto, imp_gg); 4766 + gg_proto, imp_gg, 4767 + special_obj_proto, imp_special_obj); 4726 4768 4727 4769 if (inlined) { 4728 4770 MIR_append_insn(ctx, jit_func, inl_slow); ··· 4764 4806 4765 4807 int cn = call_n++; 4766 4808 4767 - char rn_arr[32], rn_this[32], rn_ccl[32], rn_cfn[32], rn_jptr[32]; 4809 + char rn_arr[32], rn_this[32], rn_ccl[32], rn_cfn[32], rn_jptr[32], rn_csup[32], rn_out_this[32]; 4768 4810 snprintf(rn_arr, sizeof(rn_arr), "arg_arr%d", cn); 4769 4811 snprintf(rn_this, sizeof(rn_this), "call_this%d", cn); 4770 4812 snprintf(rn_ccl, sizeof(rn_ccl), "callee_cl%d", cn); 4771 4813 snprintf(rn_cfn, sizeof(rn_cfn), "callee_func%d", cn); 4772 4814 snprintf(rn_jptr, sizeof(rn_jptr), "jit_ptr%d", cn); 4815 + snprintf(rn_csup, sizeof(rn_csup), "callee_super%d", cn); 4816 + snprintf(rn_out_this, sizeof(rn_out_this), "call_out_this%d", cn); 4773 4817 4774 4818 MIR_reg_t r_arg_arr = r_args_buf; 4775 4819 ··· 4802 4846 break; 4803 4847 } 4804 4848 MIR_append_insn(ctx, jit_func, 4805 - MIR_new_call_insn(ctx, 8, 4849 + MIR_new_call_insn(ctx, 10, 4806 4850 MIR_new_ref_op(ctx, self_proto), 4807 4851 MIR_new_ref_op(ctx, jit_func), 4808 4852 MIR_new_reg_op(ctx, r_call_res), 4809 4853 MIR_new_reg_op(ctx, r_vm), 4810 4854 MIR_new_reg_op(ctx, r_call_this), 4855 + MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)), 4856 + MIR_new_reg_op(ctx, r_super_val), 4811 4857 MIR_new_reg_op(ctx, r_arg_arr), 4812 4858 MIR_new_int_op(ctx, (int64_t)call_argc), 4813 4859 MIR_new_reg_op(ctx, r_closure))); ··· 4860 4906 break; 4861 4907 } 4862 4908 4909 + MIR_reg_t r_out_this = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, rn_out_this); 4910 + MIR_append_insn(ctx, jit_func, 4911 + MIR_new_insn(ctx, MIR_ALLOCA, 4912 + MIR_new_reg_op(ctx, r_out_this), 4913 + MIR_new_uint_op(ctx, sizeof(ant_value_t)))); 4914 + 4863 4915 MIR_label_t lbl_self_call = MIR_new_label(ctx); 4916 + MIR_label_t lbl_super_call = MIR_new_label(ctx); 4864 4917 MIR_label_t lbl_interp_call = MIR_new_label(ctx); 4865 4918 MIR_label_t lbl_call_done = MIR_new_label(ctx); 4866 4919 4920 + MIR_append_insn(ctx, jit_func, 4921 + MIR_new_insn(ctx, MIR_BEQ, 4922 + MIR_new_label_op(ctx, lbl_super_call), 4923 + MIR_new_reg_op(ctx, r_call_func), 4924 + MIR_new_reg_op(ctx, r_super_val))); 4925 + 4867 4926 MIR_reg_t r_callee_cl = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, rn_ccl); 4868 4927 mir_emit_get_closure(ctx, jit_func, r_callee_cl, r_call_func, 4869 4928 r_bool, lbl_interp_call); 4870 4929 4871 4930 MIR_reg_t r_callee_fn = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, rn_cfn); 4931 + MIR_reg_t r_callee_super = MIR_new_func_reg(ctx, jit_func->u.func, MIR_JSVAL, rn_csup); 4872 4932 MIR_append_insn(ctx, jit_func, 4873 4933 MIR_new_insn(ctx, MIR_MOV, 4874 4934 MIR_new_reg_op(ctx, r_callee_fn), 4875 4935 MIR_new_mem_op(ctx, MIR_T_P, 4876 4936 (MIR_disp_t)offsetof(sv_closure_t, func), 4877 4937 r_callee_cl, 0, 1))); 4938 + MIR_append_insn(ctx, jit_func, 4939 + MIR_new_insn(ctx, MIR_MOV, 4940 + MIR_new_reg_op(ctx, r_callee_super), 4941 + MIR_new_mem_op(ctx, MIR_T_I64, 4942 + (MIR_disp_t)offsetof(sv_closure_t, super_val), 4943 + r_callee_cl, 0, 1))); 4878 4944 mir_emit_resolve_call_this(ctx, jit_func, r_call_this, r_callee_cl, 4879 4945 r_call_this, r_bool, r_tmp2); 4880 4946 ··· 4905 4971 MIR_new_int_op(ctx, 0))); 4906 4972 4907 4973 MIR_append_insn(ctx, jit_func, 4908 - MIR_new_call_insn(ctx, 8, 4974 + MIR_new_call_insn(ctx, 10, 4909 4975 MIR_new_ref_op(ctx, self_proto), 4910 4976 MIR_new_reg_op(ctx, r_jit_ptr), 4911 4977 MIR_new_reg_op(ctx, r_call_res), 4912 4978 MIR_new_reg_op(ctx, r_vm), 4913 4979 MIR_new_reg_op(ctx, r_call_this), 4980 + MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)), 4981 + MIR_new_reg_op(ctx, r_callee_super), 4914 4982 MIR_new_reg_op(ctx, r_arg_arr), 4915 4983 MIR_new_int_op(ctx, (int64_t)call_argc), 4916 4984 MIR_new_reg_op(ctx, r_callee_cl))); ··· 4926 4994 captured_locals, r_lbuf, self_tail_entry); 4927 4995 } else { 4928 4996 MIR_append_insn(ctx, jit_func, 4929 - MIR_new_call_insn(ctx, 8, 4997 + MIR_new_call_insn(ctx, 10, 4930 4998 MIR_new_ref_op(ctx, self_proto), 4931 4999 MIR_new_ref_op(ctx, jit_func), 4932 5000 MIR_new_reg_op(ctx, r_call_res), 4933 5001 MIR_new_reg_op(ctx, r_vm), 4934 5002 MIR_new_reg_op(ctx, r_call_this), 5003 + MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)), 5004 + MIR_new_reg_op(ctx, r_super_val), 4935 5005 MIR_new_reg_op(ctx, r_arg_arr), 4936 5006 MIR_new_int_op(ctx, (int64_t)call_argc), 4937 5007 MIR_new_reg_op(ctx, r_closure))); 4938 5008 } 5009 + MIR_append_insn(ctx, jit_func, 5010 + MIR_new_insn(ctx, MIR_JMP, MIR_new_label_op(ctx, lbl_call_done))); 5011 + 5012 + MIR_append_insn(ctx, jit_func, lbl_super_call); 5013 + MIR_append_insn(ctx, jit_func, 5014 + MIR_new_insn(ctx, MIR_MOV, 5015 + MIR_new_mem_op(ctx, MIR_T_I64, 0, r_out_this, 0, 1), 5016 + MIR_new_reg_op(ctx, r_this_curr))); 5017 + MIR_append_insn(ctx, jit_func, 5018 + MIR_new_call_insn(ctx, 12, 5019 + MIR_new_ref_op(ctx, call_method_proto), 5020 + MIR_new_ref_op(ctx, imp_call_method), 5021 + MIR_new_reg_op(ctx, r_call_res), 5022 + MIR_new_reg_op(ctx, r_vm), 5023 + MIR_new_reg_op(ctx, r_js), 5024 + MIR_new_reg_op(ctx, r_call_func), 5025 + MIR_new_reg_op(ctx, r_this_curr), 5026 + MIR_new_reg_op(ctx, r_arg_arr), 5027 + MIR_new_int_op(ctx, (int64_t)call_argc), 5028 + MIR_new_reg_op(ctx, r_super_val), 5029 + MIR_new_reg_op(ctx, r_new_target), 5030 + MIR_new_reg_op(ctx, r_out_this))); 5031 + MIR_append_insn(ctx, jit_func, 5032 + MIR_new_insn(ctx, MIR_MOV, 5033 + MIR_new_reg_op(ctx, r_this_curr), 5034 + MIR_new_mem_op(ctx, MIR_T_I64, 0, r_out_this, 0, 1))); 4939 5035 MIR_append_insn(ctx, jit_func, 4940 5036 MIR_new_insn(ctx, MIR_JMP, MIR_new_label_op(ctx, lbl_call_done))); 4941 5037 ··· 5012 5108 } 5013 5109 5014 5110 case OP_SPECIAL_OBJ: { 5015 - // TODO: RE_ENABLE once SPECIAL_OBJ semantics match the interpreter in JIT. 5016 5111 uint8_t which = sv_get_u8(ip + 1); 5017 5112 MIR_reg_t dst = vstack_push(&vs); 5018 - if (which == 2 || which == 3) { 5113 + if (which == 1) { 5114 + MIR_append_insn(ctx, jit_func, 5115 + MIR_new_insn(ctx, MIR_MOV, 5116 + MIR_new_reg_op(ctx, dst), 5117 + MIR_new_reg_op(ctx, r_new_target))); 5118 + } else if (which == 2) { 5119 + MIR_append_insn(ctx, jit_func, 5120 + MIR_new_insn(ctx, MIR_MOV, 5121 + MIR_new_reg_op(ctx, dst), 5122 + MIR_new_reg_op(ctx, r_super_val))); 5123 + } else if (which == 3) { 5019 5124 MIR_append_insn(ctx, jit_func, 5020 5125 MIR_new_call_insn(ctx, 6, 5021 5126 MIR_new_ref_op(ctx, special_obj_proto), ··· 7330 7435 MIR_new_reg_op(ctx, areg))); 7331 7436 } 7332 7437 7333 - MIR_reg_t r_new_target = vstack_pop(&vs); 7334 - MIR_reg_t r_new_func = vstack_pop(&vs); 7335 - MIR_reg_t r_new_res = vstack_push(&vs); 7438 + MIR_reg_t r_ctor_target = vstack_pop(&vs); 7439 + MIR_reg_t r_new_func = vstack_pop(&vs); 7440 + MIR_reg_t r_new_res = vstack_push(&vs); 7336 7441 7337 7442 MIR_append_insn(ctx, jit_func, 7338 7443 MIR_new_call_insn(ctx, 9, ··· 7342 7447 MIR_new_reg_op(ctx, r_vm), 7343 7448 MIR_new_reg_op(ctx, r_js), 7344 7449 MIR_new_reg_op(ctx, r_new_func), 7345 - MIR_new_reg_op(ctx, r_new_target), 7450 + MIR_new_reg_op(ctx, r_ctor_target), 7346 7451 MIR_new_reg_op(ctx, r_args_buf), 7347 7452 MIR_new_int_op(ctx, (int64_t)new_argc))); 7348 7453 ··· 7393 7498 7394 7499 int cn = call_n++; 7395 7500 7396 - char rn_arr[32], rn_ccl[32], rn_cfn[32], rn_jptr[32]; 7501 + char rn_arr[32], rn_ccl[32], rn_cfn[32], rn_jptr[32], rn_sup[32], rn_out_this[32]; 7397 7502 snprintf(rn_arr, sizeof(rn_arr), "cm_arr%d", cn); 7398 7503 snprintf(rn_ccl, sizeof(rn_ccl), "cm_cl%d", cn); 7399 7504 snprintf(rn_cfn, sizeof(rn_cfn), "cm_fn%d", cn); 7400 7505 snprintf(rn_jptr, sizeof(rn_jptr), "cm_jptr%d", cn); 7506 + snprintf(rn_sup, sizeof(rn_sup), "cm_sup%d", cn); 7507 + snprintf(rn_out_this, sizeof(rn_out_this), "cm_out_this%d", cn); 7401 7508 7402 7509 MIR_reg_t r_arg_arr = r_args_buf; 7403 7510 ··· 7414 7521 MIR_reg_t r_call_func = vstack_pop(&vs); 7415 7522 MIR_reg_t r_call_this = vstack_pop(&vs); 7416 7523 MIR_reg_t r_call_res = vstack_push(&vs); 7524 + MIR_reg_t r_callee_super = MIR_new_func_reg(ctx, jit_func->u.func, MIR_JSVAL, rn_sup); 7525 + MIR_reg_t r_out_this = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, rn_out_this); 7526 + MIR_append_insn(ctx, jit_func, 7527 + MIR_new_insn(ctx, MIR_ALLOCA, 7528 + MIR_new_reg_op(ctx, r_out_this), 7529 + MIR_new_uint_op(ctx, sizeof(ant_value_t)))); 7417 7530 7418 7531 MIR_label_t lbl_cm_self = MIR_new_label(ctx); 7532 + MIR_label_t lbl_cm_super = MIR_new_label(ctx); 7419 7533 MIR_label_t lbl_cm_interp = MIR_new_label(ctx); 7420 7534 MIR_label_t lbl_cm_done = MIR_new_label(ctx); 7421 7535 7536 + MIR_append_insn(ctx, jit_func, 7537 + MIR_new_insn(ctx, MIR_BEQ, 7538 + MIR_new_label_op(ctx, lbl_cm_super), 7539 + MIR_new_reg_op(ctx, r_call_func), 7540 + MIR_new_reg_op(ctx, r_super_val))); 7541 + 7422 7542 MIR_reg_t r_callee_cl = MIR_new_func_reg(ctx, jit_func->u.func, MIR_T_I64, rn_ccl); 7423 7543 mir_emit_get_closure(ctx, jit_func, r_callee_cl, r_call_func, 7424 7544 r_bool, lbl_cm_interp); ··· 7429 7549 MIR_new_reg_op(ctx, r_callee_fn), 7430 7550 MIR_new_mem_op(ctx, MIR_T_P, 7431 7551 (MIR_disp_t)offsetof(sv_closure_t, func), 7552 + r_callee_cl, 0, 1))); 7553 + MIR_append_insn(ctx, jit_func, 7554 + MIR_new_insn(ctx, MIR_MOV, 7555 + MIR_new_reg_op(ctx, r_callee_super), 7556 + MIR_new_mem_op(ctx, MIR_T_I64, 7557 + (MIR_disp_t)offsetof(sv_closure_t, super_val), 7432 7558 r_callee_cl, 0, 1))); 7433 7559 mir_emit_resolve_call_this(ctx, jit_func, r_call_this, r_callee_cl, 7434 7560 r_call_this, r_bool, r_tmp2); ··· 7459 7585 MIR_new_int_op(ctx, 0))); 7460 7586 7461 7587 MIR_append_insn(ctx, jit_func, 7462 - MIR_new_call_insn(ctx, 8, 7588 + MIR_new_call_insn(ctx, 10, 7463 7589 MIR_new_ref_op(ctx, self_proto), 7464 7590 MIR_new_reg_op(ctx, r_jit_ptr), 7465 7591 MIR_new_reg_op(ctx, r_call_res), 7466 7592 MIR_new_reg_op(ctx, r_vm), 7467 7593 MIR_new_reg_op(ctx, r_call_this), 7594 + MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)), 7595 + MIR_new_reg_op(ctx, r_callee_super), 7468 7596 MIR_new_reg_op(ctx, r_arg_arr), 7469 7597 MIR_new_int_op(ctx, (int64_t)call_argc), 7470 7598 MIR_new_reg_op(ctx, r_callee_cl))); ··· 7473 7601 7474 7602 MIR_append_insn(ctx, jit_func, lbl_cm_self); 7475 7603 MIR_append_insn(ctx, jit_func, 7476 - MIR_new_call_insn(ctx, 8, 7604 + MIR_new_call_insn(ctx, 10, 7477 7605 MIR_new_ref_op(ctx, self_proto), 7478 7606 MIR_new_ref_op(ctx, jit_func), 7479 7607 MIR_new_reg_op(ctx, r_call_res), 7480 7608 MIR_new_reg_op(ctx, r_vm), 7481 7609 MIR_new_reg_op(ctx, r_call_this), 7610 + MIR_new_uint_op(ctx, mkval(T_UNDEF, 0)), 7611 + MIR_new_reg_op(ctx, r_super_val), 7482 7612 MIR_new_reg_op(ctx, r_arg_arr), 7483 7613 MIR_new_int_op(ctx, (int64_t)call_argc), 7484 7614 MIR_new_reg_op(ctx, r_closure))); 7615 + MIR_append_insn(ctx, jit_func, 7616 + MIR_new_insn(ctx, MIR_JMP, MIR_new_label_op(ctx, lbl_cm_done))); 7617 + 7618 + MIR_append_insn(ctx, jit_func, lbl_cm_super); 7619 + MIR_append_insn(ctx, jit_func, 7620 + MIR_new_insn(ctx, MIR_MOV, 7621 + MIR_new_mem_op(ctx, MIR_T_I64, 0, r_out_this, 0, 1), 7622 + MIR_new_reg_op(ctx, r_call_this))); 7623 + MIR_append_insn(ctx, jit_func, 7624 + MIR_new_call_insn(ctx, 12, 7625 + MIR_new_ref_op(ctx, call_method_proto), 7626 + MIR_new_ref_op(ctx, imp_call_method), 7627 + MIR_new_reg_op(ctx, r_call_res), 7628 + MIR_new_reg_op(ctx, r_vm), 7629 + MIR_new_reg_op(ctx, r_js), 7630 + MIR_new_reg_op(ctx, r_call_func), 7631 + MIR_new_reg_op(ctx, r_call_this), 7632 + MIR_new_reg_op(ctx, r_arg_arr), 7633 + MIR_new_int_op(ctx, (int64_t)call_argc), 7634 + MIR_new_reg_op(ctx, r_super_val), 7635 + MIR_new_reg_op(ctx, r_new_target), 7636 + MIR_new_reg_op(ctx, r_out_this))); 7637 + MIR_append_insn(ctx, jit_func, 7638 + MIR_new_insn(ctx, MIR_MOV, 7639 + MIR_new_reg_op(ctx, r_this_curr), 7640 + MIR_new_mem_op(ctx, MIR_T_I64, 0, r_out_this, 0, 1))); 7485 7641 MIR_append_insn(ctx, jit_func, 7486 7642 MIR_new_insn(ctx, MIR_JMP, MIR_new_label_op(ctx, lbl_cm_done))); 7487 7643 ··· 7891 8047 MIR_new_reg_op(ctx, r_vm), 7892 8048 MIR_new_reg_op(ctx, r_js), 7893 8049 MIR_new_reg_op(ctx, r_closure), 7894 - MIR_new_reg_op(ctx, r_this), 8050 + MIR_new_reg_op(ctx, r_this_curr), 7895 8051 MIR_new_reg_op(ctx, r_child_slots), 7896 8052 MIR_new_int_op(ctx, child_slot_base), 7897 8053 MIR_new_int_op(ctx, child_slot_count), ··· 7926 8082 MIR_new_reg_op(ctx, r_resume_res), 7927 8083 MIR_new_reg_op(ctx, r_vm), 7928 8084 MIR_new_reg_op(ctx, r_closure), 7929 - MIR_new_reg_op(ctx, r_this), 8085 + MIR_new_reg_op(ctx, r_this_curr), 7930 8086 MIR_new_reg_op(ctx, r_args), 7931 8087 MIR_new_reg_op(ctx, r_argc), 7932 8088 MIR_new_reg_op(ctx, r_args_buf), ··· 7996 8152 fn->jit_code = (void *)jit; 7997 8153 sv_jit_compile_callees(js, fn); 7998 8154 sv_jit_enter(js); 7999 - ant_value_t result = jit(vm, ctx->this_val, ctx->args, ctx->argc, closure); 8155 + ant_value_t result = jit( 8156 + vm, ctx->this_val, js->new_target, 8157 + ctx->super_val, ctx->args, ctx->argc, closure); 8000 8158 sv_jit_leave(js); 8001 8159 if (sv_is_jit_bailout(result)) { 8002 8160 sv_jit_on_bailout(fn); ··· 8051 8209 vm->jit_osr.lp = frame->lp; 8052 8210 8053 8211 sv_jit_enter(js); 8054 - ant_value_t result = jit(vm, frame->this, frame->bp, frame->argc, closure); 8212 + ant_value_t result = jit( 8213 + vm, frame->this, frame->new_target, frame->super_val, 8214 + frame->bp, frame->argc, closure); 8055 8215 sv_jit_leave(js); 8056 8216 8057 8217 if (sv_is_jit_bailout(result)) {