@@ -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 ),
@@ -2332,18 +2331,17 @@ first_pass(<<?OP_CALL_FUN2, Rest0/binary>>, MMod, MSt0, State0) ->
23322331 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
23332332 {MSt1 , Tag , Rest1 } = decode_compact_term (Rest0 , MMod , MSt0 , State0 ),
23342333 {ArgsCount , Rest2 } = decode_literal (Rest1 ),
2335- {MSt2 , Fun , Rest3 } = decode_compact_term (Rest2 , MMod , MSt1 , State0 ),
2334+ {MSt2 , Fun , Rest3 } = decode_typed_compact_term (Rest2 , MMod , MSt1 , State0 ),
23362335 ? TRACE (" OP_CALL_FUN2 ~p , ~p , ~p \n " , [Tag , ArgsCount , Fun ]),
23372336 % We ignore Tag (could be literal 0 or atom unsafe)
23382337 MSt3 = MMod :free_native_registers (MSt2 , [Tag ]),
23392338 MSt4 = MMod :decrement_reductions_and_maybe_schedule_next (MSt3 ),
2340- {MSt5 , Reg } = MMod :move_to_native_register (MSt4 , Fun ),
2341- MSt6 = verify_is_function (Reg , MMod , MSt5 ),
2342- MSt7 = MMod :call_primitive_with_cp (MSt6 , ? PRIM_CALL_FUN , [
2343- ctx , jit_state , offset , Reg , ArgsCount
2339+ {MSt5 , Reg } = verify_is_function (Fun , MMod , MSt4 ),
2340+ MSt6 = MMod :call_primitive_with_cp (MSt5 , ? PRIM_CALL_FUN , [
2341+ ctx , jit_state , offset , {free , Reg }, ArgsCount
23442342 ]),
2345- ? ASSERT_ALL_NATIVE_FREE (MSt7 ),
2346- first_pass (Rest3 , MMod , MSt7 , State0 );
2343+ ? ASSERT_ALL_NATIVE_FREE (MSt6 ),
2344+ first_pass (Rest3 , MMod , MSt6 , State0 );
23472345% 180
23482346first_pass (<<? OP_BADRECORD , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
23492347 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
@@ -3026,8 +3024,18 @@ term_is_boxed_with_tag_and_get_ptr(Label, Arg1, BoxedTag, MMod, MSt1) ->
30263024% % @param MSt0 backend state
30273025% % @return new backend state
30283026% %-----------------------------------------------------------------------------
3029- verify_is_function (Arg , MMod , MSt0 ) ->
3030- {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Arg ),
3027+ verify_is_function ({typed , Func , t_fun }, MMod , MSt0 ) ->
3028+ MMod :move_to_native_register (MSt0 , Func );
3029+ verify_is_function ({typed , Func , any }, MMod , MSt0 ) ->
3030+ verify_is_function (Func , MMod , MSt0 );
3031+ verify_is_function ({typed , Func , _Other }, MMod , MSt0 ) ->
3032+ {MSt1 , Reg } = MMod :move_to_native_register (MSt0 , Func ),
3033+ MSt2 = MMod :call_primitive_last (MSt1 , ? PRIM_RAISE_ERROR_TUPLE , [
3034+ ctx , jit_state , offset , ? BADFUN_ATOM , Reg
3035+ ]),
3036+ {MSt2 , Reg };
3037+ verify_is_function (Func , MMod , MSt0 ) ->
3038+ {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Func ),
30313039 MSt2 = MMod :if_block (MSt1 , {Reg , '&' , ? TERM_PRIMARY_MASK , '!=' , ? TERM_PRIMARY_BOXED }, fun (BSt0 ) ->
30323040 MMod :call_primitive_last (BSt0 , ? PRIM_RAISE_ERROR_TUPLE , [
30333041 ctx , jit_state , offset , ? BADFUN_ATOM , Reg
@@ -3040,7 +3048,8 @@ verify_is_function(Arg, MMod, MSt0) ->
30403048 ctx , jit_state , offset , ? BADFUN_ATOM , Reg
30413049 ])
30423050 end ),
3043- MMod :free_native_registers (MSt5 , [Reg ]).
3051+ MSt6 = MMod :free_native_registers (MSt5 , [Reg ]),
3052+ MMod :move_to_native_register (MSt6 , Func ).
30443053
30453054verify_is_binary_or_match_state (Label , Src , MMod , MSt0 ) ->
30463055 {MSt1 , Reg } = MMod :copy_to_native_register (MSt0 , Src ),
0 commit comments