Skip to content

Commit

Permalink
[interp] support ntype.CompareTo ()
Browse files Browse the repository at this point in the history
  • Loading branch information
lewurm committed Oct 5, 2018
1 parent a576a79 commit 13e412e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
66 changes: 66 additions & 0 deletions mono/mini/builtin-types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,28 @@ static int test_0_nint_cmp_large_val ()
return 0;
}

static int test_0_nint_compareto ()
{
if (((nint) 0).CompareTo ((nint) 0) != 0)
return 1;
if (((nint) 0).CompareTo ((nint) 1) != -1)
return 2;
if (((nint) 1).CompareTo ((nint) 0) != 1)
return 3;

if (((nint) 0).CompareTo ((object)(nint) 0) != 0)
return 4;
if (((nint) 0).CompareTo ((object)(nint) 1) != -1)
return 5;
if (((nint) 1).CompareTo ((object)(nint) 0) != 1)
return 6;

if (((nint) 1).CompareTo (null) != 1)
return 7;

return 0;
}

// static int test_0_nint_call_boxed_equals ()
// {
// object x = new nint (10);
Expand Down Expand Up @@ -610,6 +632,28 @@ static int test_0_nuint_cmp_large_val ()
return 0;
}

static int test_0_nuint_compareto ()
{
if (((nuint) 0).CompareTo ((nuint) 0) != 0)
return 1;
if (((nuint) 0).CompareTo ((nuint) 1) != -1)
return 2;
if (((nuint) 1).CompareTo ((nuint) 0) != 1)
return 3;

if (((nuint) 0).CompareTo ((object)(nuint) 0) != 0)
return 4;
if (((nuint) 0).CompareTo ((object)(nuint) 1) != -1)
return 5;
if (((nuint) 1).CompareTo ((object)(nuint) 0) != 1)
return 6;

if (((nuint) 1).CompareTo (null) != 1)
return 7;

return 0;
}

// static int test_0_nuint_call_boxed_equals ()
// {
// object x = new nuint (10);
Expand Down Expand Up @@ -965,6 +1009,28 @@ static int test_0_nfloat_isnan ()
return nfloat.IsNaN (x) ? 0 : 1;
}

static int test_0_nfloat_compareto ()
{
if (((nfloat) 0).CompareTo ((nfloat) 0) != 0)
return 1;
if (((nfloat) 0).CompareTo ((nfloat) 1) != -1)
return 2;
if (((nfloat) 1).CompareTo ((nfloat) 0) != 1)
return 3;

if (((nfloat) 0).CompareTo ((object)(nfloat) 0) != 0)
return 4;
if (((nfloat) 0).CompareTo ((object)(nfloat) 1) != -1)
return 5;
if (((nfloat) 1).CompareTo ((object)(nfloat) 0) != 1)
return 6;

if (((nfloat) 1).CompareTo (null) != 1)
return 7;

return 0;
}

// static int test_0_nfloat_call_boxed_equals ()
// {
// object x = new nfloat (10f);
Expand Down
10 changes: 10 additions & 0 deletions mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,16 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoMeth
SET_TYPE (td->sp - 1, stack_type [mt], magic_class);
td->ip += 5;
return TRUE;
} else if (!strcmp ("CompareTo", tm)) {
MonoType *arg = csignature->params [0];

/* on 'System.n*::CompareTo (System.n*)' variant we need to push managed
* pointer instead of value */
if (arg->type == MONO_TYPE_VALUETYPE)
emit_store_value_as_local (td, arg);

/* emit call to managed conversion method */
return FALSE;
} else if (!strcmp (".cctor", tm)) {
/* white list */
return FALSE;
Expand Down

0 comments on commit 13e412e

Please sign in to comment.