diff --git a/README.md b/README.md index 233222e..24bdc56 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Status of the project * Public API of the Compiler ### Partially Finished -* Binary format file writer (130 of 201 byte code instructions) -* Text format file writer (130 of 201 byte code instructions) +* Binary format file writer (134 of 201 byte code instructions) +* Text format file writer (134 of 201 byte code instructions) ### Open Features * Exception handling - required the next version of WebAssembly diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index c50fb0f..df3b412 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -336,6 +336,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; } break; + case neg: + switch( valueType ) { + case f32: + op = F32_NEG; + break; + case f64: + op = F64_NEG; + break; + } + break; case mul: switch( valueType ) { case i32: diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java index 1d1c7d5..264cc7d 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java @@ -548,6 +548,20 @@ public abstract class ModuleWriter implements Closeable { case 115: // drem //TODO can be implemented with a helper function like: (a - (long)(a / b) * (double)b) throw new WasmException( "Modulo/Remainder for floating numbers is not supported in WASM. Use int or long data types." + op, sourceFile, lineNumber ); + case 116: // ineg + writeConstInt( -1 ); + writeNumericOperator( NumericOperator.mul, ValueType.i32 ); + break; + case 117: // lneg + writeConstLong( -1 ); + writeNumericOperator( NumericOperator.mul, ValueType.i64 ); + break; + case 118: // fneg + writeNumericOperator( NumericOperator.neg, ValueType.f32 ); + break; + case 119: // dneg + writeNumericOperator( NumericOperator.neg, ValueType.f64 ); + break; case 120: // ishl writeNumericOperator( NumericOperator.shl, ValueType.i32 ); break; diff --git a/src/de/inetsoftware/jwebassembly/module/NumericOperator.java b/src/de/inetsoftware/jwebassembly/module/NumericOperator.java index 3c61a69..ff6f7c9 100644 --- a/src/de/inetsoftware/jwebassembly/module/NumericOperator.java +++ b/src/de/inetsoftware/jwebassembly/module/NumericOperator.java @@ -21,6 +21,7 @@ package de.inetsoftware.jwebassembly.module; public enum NumericOperator { add, sub, + neg, mul, div, rem, diff --git a/test/de/inetsoftware/jwebassembly/runtime/MathOperations.java b/test/de/inetsoftware/jwebassembly/runtime/MathOperations.java index 94e23e7..da2617f 100644 --- a/test/de/inetsoftware/jwebassembly/runtime/MathOperations.java +++ b/test/de/inetsoftware/jwebassembly/runtime/MathOperations.java @@ -90,6 +90,7 @@ public class MathOperations extends AbstractBaseTest { static int addInt( int a, int b ) { int c = 1234567; int e = -1; + e = -e; double d = -1234567; int i = 1; long l = 2; @@ -101,7 +102,8 @@ public class MathOperations extends AbstractBaseTest { @Export static int addLong() { long a = 1L; - long b = 3L; + long b = -3L; + b = -b; return (int)(a + b); } @@ -110,6 +112,7 @@ public class MathOperations extends AbstractBaseTest { float c = -1; float e = 1.25F; double d = 1234; + e = -e; int i = 1; long l = 2; float f = 3; @@ -121,6 +124,7 @@ public class MathOperations extends AbstractBaseTest { double c = -1; double d = 1234; double e = 1.25; + e = -e; int i = 1; long l = 2; float f = 3;