Skip to content

Commit

Permalink
Fix negate operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlich committed Jun 17, 2024
1 parent af25abf commit 3fb759a
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,27 @@ public Void builtinStaticMethod(BuiltinMethodSymbol method, TypeID returnType, C
case SHORT_INVERT:
javaWriter.invertShort();
break;

case FLOAT_NEG:
javaWriter.fNeg();
break;
case DOUBLE_NEG:
javaWriter.dNeg();
break;
case INT_NEG:
javaWriter.iNeg();
break;
case LONG_NEG:
javaWriter.lNeg();
break;
case SBYTE_NEG:
javaWriter.iNeg();
javaWriter.i2b();
break;
case SHORT_NEG:
javaWriter.iNeg();
javaWriter.i2s();
break;
case INT_TO_BYTE:
case USIZE_TO_BYTE:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error: 4:CALL_NO_VALID_METHOD

var i = 42 as byte;
println(-i);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: double
#output: 42.0
#output: double
#output: -42.0
#output: double
#output: 42.0

var i = 42 as double;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: float
#output: 42.0
#output: float
#output: -42.0
#output: float
#output: 42.0

var i = 42 as float;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: int
#output: 42
#output: int
#output: -42
#output: int
#output: 42

var i = 42 as int;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: long
#output: 42
#output: long
#output: -42
#output: long
#output: 42

var i = 42 as long;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: sbyte
#output: 42
#output: sbyte
#output: -42
#output: sbyte
#output: 42

var i = 42 as sbyte;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#output: short
#output: 42
#output: short
#output: -42
#output: short
#output: 42

var i = 42 as short;
var negated = -i;
var negatedAgain = -negated;

println(typeof(i));
println(i);

println(typeof(negated));
println(negated);

println(typeof(negatedAgain));
println(negatedAgain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error: 4:CALL_NO_VALID_METHOD

var i = 42 as uint;
println(-i);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error: 4:CALL_NO_VALID_METHOD

var i = 42 as ulong;
println(-i);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error: 4:CALL_NO_VALID_METHOD

var i = 42 as ushort;
println(-i);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error: 4:CALL_NO_VALID_METHOD

var i = 42 as usize;
println(-i);

0 comments on commit 3fb759a

Please sign in to comment.