@@ -860,7 +860,8 @@ static bool sort_kv_pairs(struct kv_pair *kv, int size, GlobalContext *global)
860860 for (int i = 1 ; i < k ; i ++ ) {
861861 term t_max = kv [max_pos ].key ;
862862 term t = kv [i ].key ;
863- TermCompareResult result = term_compare (t , t_max , global );
863+ // TODO: not sure if exact is the right choice here
864+ TermCompareResult result = term_compare (t , t_max , TermCompareExact , global );
864865 if (result == TermGreaterThan ) {
865866 max_pos = i ;
866867 } else if (UNLIKELY (result == TermCompareMemoryAllocFail )) {
@@ -2182,7 +2183,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
21822183 #ifdef IMPL_EXECUTE_LOOP
21832184 TRACE ("is_lt/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
21842185
2185- TermCompareResult result = term_compare (arg1 , arg2 , ctx -> global );
2186+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareNoOpts , ctx -> global );
21862187 if (result == TermLessThan ) {
21872188 NEXT_INSTRUCTION (next_off );
21882189 } else if (result & (TermGreaterThan | TermEquals )) {
@@ -2214,7 +2215,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
22142215 #ifdef IMPL_EXECUTE_LOOP
22152216 TRACE ("is_ge/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
22162217
2217- TermCompareResult result = term_compare (arg1 , arg2 , ctx -> global );
2218+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareNoOpts , ctx -> global );
22182219 if (result & (TermGreaterThan | TermEquals )) {
22192220 NEXT_INSTRUCTION (next_off );
22202221 } else if (result == TermLessThan ) {
@@ -2246,8 +2247,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
22462247 #ifdef IMPL_EXECUTE_LOOP
22472248 TRACE ("is_equal/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
22482249
2249- //TODO: implement this
2250- TermCompareResult result = term_compare (arg1 , arg2 , ctx -> global );
2250+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareNoOpts , ctx -> global );
22512251 if (result == TermEquals ) {
22522252 NEXT_INSTRUCTION (next_off );
22532253 } else if (result & (TermLessThan | TermGreaterThan )) {
@@ -2279,7 +2279,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
22792279 #ifdef IMPL_EXECUTE_LOOP
22802280 TRACE ("is_not_equal/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
22812281
2282- TermCompareResult result = term_compare (arg1 , arg2 , ctx -> global );
2282+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareNoOpts , ctx -> global );
22832283 if (result & (TermLessThan | TermGreaterThan )) {
22842284 NEXT_INSTRUCTION (next_off );
22852285 } else if (result == TermEquals ) {
@@ -2311,12 +2311,13 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
23112311 #ifdef IMPL_EXECUTE_LOOP
23122312 TRACE ("is_eq_exact/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
23132313
2314- // handle error
2315- //TODO: implement this
2316- if (term_exactly_equals (arg1 , arg2 , ctx -> global )) {
2314+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareExact , ctx -> global );
2315+ if (result == TermEquals ) {
23172316 NEXT_INSTRUCTION (next_off );
2318- } else {
2317+ } else if ( result & ( TermLessThan | TermGreaterThan )) {
23192318 i = POINTER_TO_II (mod -> labels [label ]);
2319+ } else {
2320+ RAISE_ERROR (OUT_OF_MEMORY_ATOM );
23202321 }
23212322 #endif
23222323
@@ -2342,12 +2343,13 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
23422343 #ifdef IMPL_EXECUTE_LOOP
23432344 TRACE ("is_not_eq_exact/2, label=%i, arg1=%lx, arg2=%lx\n" , label , arg1 , arg2 );
23442345
2345- // handle error
2346- //TODO: implement this
2347- if (!term_exactly_equals (arg1 , arg2 , ctx -> global )) {
2346+ TermCompareResult result = term_compare (arg1 , arg2 , TermCompareExact , ctx -> global );
2347+ if (result & (TermLessThan | TermGreaterThan )) {
23482348 NEXT_INSTRUCTION (next_off );
2349- } else {
2349+ } else if ( result == TermEquals ) {
23502350 i = POINTER_TO_II (mod -> labels [label ]);
2351+ } else {
2352+ RAISE_ERROR (OUT_OF_MEMORY_ATOM );
23512353 }
23522354 #endif
23532355
@@ -5414,7 +5416,8 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
54145416 } else {
54155417 term src_key = term_get_map_key (src , src_pos );
54165418 term new_key = kv [kv_pos ].key ;
5417- switch (term_compare (src_key , new_key , ctx -> global )) {
5419+ // TODO: not sure if exact is the right choice here
5420+ switch (term_compare (src_key , new_key , TermCompareExact , ctx -> global )) {
54185421 case TermLessThan : {
54195422 term src_value = term_get_map_value (src , src_pos );
54205423 term_set_map_assoc (map , j , src_key , src_value );
@@ -6573,9 +6576,12 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
65736576 DECODE_COMPACT_TERM (update_value , code , i , next_off );
65746577 #ifdef IMPL_EXECUTE_LOOP
65756578 if (reuse ) {
6576- // handle error
6577- if (term_exactly_equals (update_value , term_get_tuple_element (dst , update_ix - 1 ), ctx -> global )) {
6579+ term old_value = term_get_tuple_element (dst , update_ix - 1 );
6580+ TermCompareResult result = term_compare (update_value , old_value , TermCompareExact , ctx -> global );
6581+ if (result == TermEquals ) {
65786582 continue ;
6583+ } else if (UNLIKELY (result == TermCompareMemoryAllocFail )) {
6584+ RAISE_ERROR (OUT_OF_MEMORY_ATOM );
65796585 }
65806586 reuse = false;
65816587 }
0 commit comments