Skip to content

Commit

Permalink
Merge branch 'master' into Branch_lights_matchopcodechange
Browse files Browse the repository at this point in the history
  • Loading branch information
lightszero authored Jan 14, 2020
2 parents b92a83a + 88eb342 commit dda641a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,23 @@ private bool TryInsertMethod(NeoModule outModule, Mono.Cecil.MethodDefinition me
}
}
}
private int _ConvertCgt(ILMethod method, OpCode src, NeoMethod to)
{
var code = to.body_Codes.Last().Value;
if (code.code == VM.OpCode.PUSHNULL)
{
//remove last code
to.body_Codes.Remove(code.addr);
this.addr = code.addr;
_Convert1by1(VM.OpCode.ISNULL, src, to);
_Convert1by1(VM.OpCode.NOT, src, to);
}
else
{
_Convert1by1(VM.OpCode.GT, src, to);
}
return 0;
}
private int _ConvertCeq(ILMethod method, OpCode src, NeoMethod to)
{
var code = to.body_Codes.Last().Value;
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ private int ConvertCode(ILMethod method, OpCode src, NeoMethod to)
break;
case CodeEx.Cgt:
case CodeEx.Cgt_Un:
_Convert1by1(VM.OpCode.GT, src, to);
skipcount = _ConvertCgt(method, src, to);

break;
case CodeEx.Ceq:
skipcount = _ConvertCeq(method, src, to);
Expand Down
10 changes: 10 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_NULL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public static bool EqualNullB(byte[] value)
return value == null;
}

public static bool EqualNotNullA(byte[] value)
{
return null != value;
}

public static bool EqualNotNullB(byte[] value)
{
return value != null;
}

public static string NullCoalescing(string code)
{
string myname = code?.Substring(1, 2);
Expand Down
40 changes: 40 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,45 @@ public void EqualNull()
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.ToBoolean());
}

[TestMethod]
public void EqualNotNull()
{
// True

testengine.Reset();
var result = testengine.ExecuteTestCaseStandard("equalNotNullA", StackItem.Null);
var item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.ToBoolean());

// False

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("equalNotNullA", new Integer(1));
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsTrue(item.ToBoolean());

// True

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("equalNotNullB", StackItem.Null);
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.ToBoolean());

// False

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("equalNotNullB", new Integer(1));
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsTrue(item.ToBoolean());
}
}
}

0 comments on commit dda641a

Please sign in to comment.