@@ -949,13 +949,12 @@ first_pass(<<?OP_CALL_FUN, Rest0/binary>>, MMod, MSt0, State0) ->
949949 ? TRACE (" OP_CALL_FUN ~p \n " , [ArgsCount ]),
950950 MSt1 = MMod :decrement_reductions_and_maybe_schedule_next (MSt0 ),
951951 {MSt2 , FuncReg } = read_any_xreg (ArgsCount , MMod , MSt1 ),
952- {MSt3 , Reg } = MMod :move_to_native_register (MSt2 , FuncReg ),
953- MSt4 = verify_is_function (Reg , MMod , MSt3 ),
954- MSt5 = MMod :call_primitive_with_cp (MSt4 , ? PRIM_CALL_FUN , [
955- ctx , jit_state , offset , Reg , ArgsCount
952+ {MSt3 , Reg } = verify_is_function (FuncReg , MMod , MSt2 ),
953+ MSt4 = MMod :call_primitive_with_cp (MSt3 , ? PRIM_CALL_FUN , [
954+ ctx , jit_state , offset , {free , Reg }, ArgsCount
956955 ]),
957- ? ASSERT_ALL_NATIVE_FREE (MSt5 ),
958- first_pass (Rest1 , MMod , MSt5 , State0 );
956+ ? ASSERT_ALL_NATIVE_FREE (MSt4 ),
957+ first_pass (Rest1 , MMod , MSt4 , State0 );
959958% 77
960959first_pass (<<? OP_IS_FUNCTION , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
961960 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
@@ -2322,18 +2321,17 @@ first_pass(<<?OP_CALL_FUN2, Rest0/binary>>, MMod, MSt0, State0) ->
23222321 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
23232322 {MSt1 , Tag , Rest1 } = decode_compact_term (Rest0 , MMod , MSt0 , State0 ),
23242323 {ArgsCount , Rest2 } = decode_literal (Rest1 ),
2325- {MSt2 , Fun , Rest3 } = decode_compact_term (Rest2 , MMod , MSt1 , State0 ),
2324+ {MSt2 , Fun , Rest3 } = decode_typed_compact_term (Rest2 , MMod , MSt1 , State0 ),
23262325 ? TRACE (" OP_CALL_FUN2 ~p , ~p , ~p \n " , [Tag , ArgsCount , Fun ]),
23272326 % We ignore Tag (could be literal 0 or atom unsafe)
23282327 MSt3 = MMod :free_native_registers (MSt2 , [Tag ]),
23292328 MSt4 = MMod :decrement_reductions_and_maybe_schedule_next (MSt3 ),
2330- {MSt5 , Reg } = MMod :move_to_native_register (MSt4 , Fun ),
2331- MSt6 = verify_is_function (Reg , MMod , MSt5 ),
2332- MSt7 = MMod :call_primitive_with_cp (MSt6 , ? PRIM_CALL_FUN , [
2333- ctx , jit_state , offset , Reg , ArgsCount
2329+ {MSt5 , Reg } = verify_is_function (Fun , MMod , MSt4 ),
2330+ MSt6 = MMod :call_primitive_with_cp (MSt5 , ? PRIM_CALL_FUN , [
2331+ ctx , jit_state , offset , {free , Reg }, ArgsCount
23342332 ]),
2335- ? ASSERT_ALL_NATIVE_FREE (MSt7 ),
2336- first_pass (Rest3 , MMod , MSt7 , State0 );
2333+ ? ASSERT_ALL_NATIVE_FREE (MSt6 ),
2334+ first_pass (Rest3 , MMod , MSt6 , State0 );
23372335% 180
23382336first_pass (<<? OP_BADRECORD , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
23392337 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
@@ -3016,8 +3014,18 @@ term_is_boxed_with_tag_and_get_ptr(Label, Arg1, BoxedTag, MMod, MSt1) ->
30163014% % @param MSt0 backend state
30173015% % @return new backend state
30183016% %-----------------------------------------------------------------------------
3019- verify_is_function (Arg , MMod , MSt0 ) ->
3020- {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Arg ),
3017+ verify_is_function ({typed , Func , t_fun }, MMod , MSt0 ) ->
3018+ MMod :move_to_native_register (MSt0 , Func );
3019+ verify_is_function ({typed , Func , any }, MMod , MSt0 ) ->
3020+ verify_is_function (Func , MMod , MSt0 );
3021+ verify_is_function ({typed , Func , _Other }, MMod , MSt0 ) ->
3022+ {MSt1 , Reg } = MMod :move_to_native_register (MSt0 , Func ),
3023+ MSt2 = MMod :call_primitive_last (MSt1 , ? PRIM_RAISE_ERROR_TUPLE , [
3024+ ctx , jit_state , offset , ? BADFUN_ATOM , Reg
3025+ ]),
3026+ {MSt2 , Reg };
3027+ verify_is_function (Func , MMod , MSt0 ) ->
3028+ {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Func ),
30213029 MSt2 = MMod :if_block (MSt1 , {Reg , '&' , ? TERM_PRIMARY_MASK , '!=' , ? TERM_PRIMARY_BOXED }, fun (BSt0 ) ->
30223030 MMod :call_primitive_last (BSt0 , ? PRIM_RAISE_ERROR_TUPLE , [
30233031 ctx , jit_state , offset , ? BADFUN_ATOM , Reg
@@ -3030,7 +3038,8 @@ verify_is_function(Arg, MMod, MSt0) ->
30303038 ctx , jit_state , offset , ? BADFUN_ATOM , Reg
30313039 ])
30323040 end ),
3033- MMod :free_native_registers (MSt5 , [Reg ]).
3041+ MSt6 = MMod :free_native_registers (MSt5 , [Reg ]),
3042+ MMod :move_to_native_register (MSt6 , Func ).
30343043
30353044verify_is_binary_or_match_state (Label , Src , MMod , MSt0 ) ->
30363045 {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Src ),
0 commit comments