Skip to content

Commit 13e412e

Browse files
committed
[interp] support ntype.CompareTo ()
1 parent a576a79 commit 13e412e

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎mono/mini/builtin-types.cs‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,28 @@ static int test_0_nint_cmp_large_val ()
248248
return 0;
249249
}
250250

251+
static int test_0_nint_compareto ()
252+
{
253+
if (((nint) 0).CompareTo ((nint) 0) != 0)
254+
return 1;
255+
if (((nint) 0).CompareTo ((nint) 1) != -1)
256+
return 2;
257+
if (((nint) 1).CompareTo ((nint) 0) != 1)
258+
return 3;
259+
260+
if (((nint) 0).CompareTo ((object)(nint) 0) != 0)
261+
return 4;
262+
if (((nint) 0).CompareTo ((object)(nint) 1) != -1)
263+
return 5;
264+
if (((nint) 1).CompareTo ((object)(nint) 0) != 1)
265+
return 6;
266+
267+
if (((nint) 1).CompareTo (null) != 1)
268+
return 7;
269+
270+
return 0;
271+
}
272+
251273
// static int test_0_nint_call_boxed_equals ()
252274
// {
253275
// object x = new nint (10);
@@ -610,6 +632,28 @@ static int test_0_nuint_cmp_large_val ()
610632
return 0;
611633
}
612634

635+
static int test_0_nuint_compareto ()
636+
{
637+
if (((nuint) 0).CompareTo ((nuint) 0) != 0)
638+
return 1;
639+
if (((nuint) 0).CompareTo ((nuint) 1) != -1)
640+
return 2;
641+
if (((nuint) 1).CompareTo ((nuint) 0) != 1)
642+
return 3;
643+
644+
if (((nuint) 0).CompareTo ((object)(nuint) 0) != 0)
645+
return 4;
646+
if (((nuint) 0).CompareTo ((object)(nuint) 1) != -1)
647+
return 5;
648+
if (((nuint) 1).CompareTo ((object)(nuint) 0) != 1)
649+
return 6;
650+
651+
if (((nuint) 1).CompareTo (null) != 1)
652+
return 7;
653+
654+
return 0;
655+
}
656+
613657
// static int test_0_nuint_call_boxed_equals ()
614658
// {
615659
// object x = new nuint (10);
@@ -965,6 +1009,28 @@ static int test_0_nfloat_isnan ()
9651009
return nfloat.IsNaN (x) ? 0 : 1;
9661010
}
9671011

1012+
static int test_0_nfloat_compareto ()
1013+
{
1014+
if (((nfloat) 0).CompareTo ((nfloat) 0) != 0)
1015+
return 1;
1016+
if (((nfloat) 0).CompareTo ((nfloat) 1) != -1)
1017+
return 2;
1018+
if (((nfloat) 1).CompareTo ((nfloat) 0) != 1)
1019+
return 3;
1020+
1021+
if (((nfloat) 0).CompareTo ((object)(nfloat) 0) != 0)
1022+
return 4;
1023+
if (((nfloat) 0).CompareTo ((object)(nfloat) 1) != -1)
1024+
return 5;
1025+
if (((nfloat) 1).CompareTo ((object)(nfloat) 0) != 1)
1026+
return 6;
1027+
1028+
if (((nfloat) 1).CompareTo (null) != 1)
1029+
return 7;
1030+
1031+
return 0;
1032+
}
1033+
9681034
// static int test_0_nfloat_call_boxed_equals ()
9691035
// {
9701036
// object x = new nfloat (10f);

‎mono/mini/interp/transform.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,16 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoMeth
10511051
SET_TYPE (td->sp - 1, stack_type [mt], magic_class);
10521052
td->ip += 5;
10531053
return TRUE;
1054+
} else if (!strcmp ("CompareTo", tm)) {
1055+
MonoType *arg = csignature->params [0];
1056+
1057+
/* on 'System.n*::CompareTo (System.n*)' variant we need to push managed
1058+
* pointer instead of value */
1059+
if (arg->type == MONO_TYPE_VALUETYPE)
1060+
emit_store_value_as_local (td, arg);
1061+
1062+
/* emit call to managed conversion method */
1063+
return FALSE;
10541064
} else if (!strcmp (".cctor", tm)) {
10551065
/* white list */
10561066
return FALSE;

0 commit comments

Comments
 (0)