Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the remaining assertion tests #29

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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--) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhelx I think we should reverse the order here, and the tests are confirming.

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