Skip to content

Commit

Permalink
Fix the remaining assertion tests (#29)
Browse files Browse the repository at this point in the history
* Fix the remaining assertion tests

* finishing up

* fmt
  • Loading branch information
andreaTP authored Oct 12, 2023
1 parent f7d8534 commit dd45718
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
11 changes: 0 additions & 11 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@
address.wast</wastToProcess>
<excludedTests>
<!-- Assertion failures -->
SpecV1LocalGetTest.test18,
SpecV1LocalSetTest.test18,
SpecV1LocalTeeTest.test6,
SpecV1LocalTeeTest.test7,
SpecV1LocalTeeTest.test44,
SpecV1MemoryTest.test25,
SpecV1NopTest.test40,
SpecV1NopTest.test41,
SpecV1NopTest.test42,
SpecV1NopTest.test43,
SpecV1NopTest.test44,
<!-- Errors -->
SpecV1LocalTeeTest.test31,
SpecV1LocalTeeTest.test32,
Expand Down
35 changes: 26 additions & 9 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Machine.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ void eval(List<Instruction> code) throws ChicoryException {
var instruction = code.get(frame.pc++);
var opcode = instruction.getOpcode();
var operands = instruction.getOperands();
// System.out.println("func="+frame.funcId + "@"+frame.pc + ": " + instruction + "
// stack="+this.stack);
// System.out.println(
// "func="
// + frame.funcId
// + "@"
// + frame.pc
// + ": "
// + instruction
// + "stack="
// + this.stack);
switch (opcode) {
case UNREACHABLE:
throw new TrapException("Trapped on unreachable instruction", callStack);
Expand Down Expand Up @@ -1030,25 +1037,29 @@ void eval(List<Instruction> code) throws ChicoryException {
case F64_CONVERT_I64_U:
{
var tos = this.stack.pop();
this.stack.push(Value.i64(tos.asLong()));
this.stack.push(
Value.fromDouble(Long.valueOf(tos.asLong()).doubleValue()));
break;
}
case F64_CONVERT_I32_U:
{
var tos = this.stack.pop();
this.stack.push(Value.i32(tos.asUInt()));
this.stack.push(
Value.fromDouble(Long.valueOf(tos.asUInt()).doubleValue()));
break;
}
case F64_CONVERT_I32_S:
{
var tos = this.stack.pop();
this.stack.push(Value.i32(tos.asInt()));
this.stack.push(
Value.fromDouble(Long.valueOf(tos.asInt()).doubleValue()));
break;
}
case F64_PROMOTE_F32:
{
var tos = this.stack.pop();
this.stack.push(Value.f64(tos.asUInt()));
this.stack.push(
Value.fromDouble(Float.valueOf(tos.asFloat()).doubleValue()));
break;
}
case F64_REINTERPRET_I64:
Expand All @@ -1057,6 +1068,12 @@ void eval(List<Instruction> code) throws ChicoryException {
this.stack.push(Value.i64(tos.asLong()));
break;
}
case I64_TRUNC_F64_S:
{
var tos = this.stack.pop();
this.stack.push(Value.i64(Double.valueOf(tos.asDouble()).longValue()));
break;
}
default:
throw new RuntimeException(
"Machine doesn't recognize Instruction " + instruction);
Expand Down Expand Up @@ -1088,13 +1105,13 @@ public void printStackTrace() {
Value[] extractArgsForParams(ValueType[] params) {
if (params == null) return new Value[] {};
var args = new Value[params.length];
for (var i = 0; i < params.length; i++) {
for (var i = params.length; i > 0; i--) {
var p = this.stack.pop();
var t = params[i];
var t = params[i - 1];
if (p.getType() != t) {
throw new RuntimeException("Type error when extracting args.");
}
args[i] = p;
args[i - 1] = p;
}
return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public void shouldConsoleLogWithString() {
var printer = new Printer("Hello, World!");
var func =
new HostFunction(
(Memory memory, Value... args) -> {
var offset = args[0].asInt();
var len = args[1].asInt();
(Memory memory, Value... args) -> { // decompiled is: console_log(13, 0);
var len = args[0].asInt();
var offset = args[1].asInt();
var message = memory.getString(offset, len);
printer.println(message);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public long asUInt() {

// TODO memoize these
public long asLong() {
return ByteBuffer.wrap(this.data).getLong();
return new BigInteger(this.data).longValue();
}

public BigInteger asULong() {
Expand Down

0 comments on commit dd45718

Please sign in to comment.