From febb07b8b2536ba4ecef03ec54f4f2b87f113f3a Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Sun, 23 Apr 2017 03:35:03 -0500 Subject: [PATCH] Stopped the extra pop on get/set global. Fixes #2. --- .../kotlin/asmble/compile/jvm/InsnReworker.kt | 5 ++-- .../resources/local-spec/multi-global.wast | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/local-spec/multi-global.wast diff --git a/src/main/kotlin/asmble/compile/jvm/InsnReworker.kt b/src/main/kotlin/asmble/compile/jvm/InsnReworker.kt index f80a6d2..03a1d95 100644 --- a/src/main/kotlin/asmble/compile/jvm/InsnReworker.kt +++ b/src/main/kotlin/asmble/compile/jvm/InsnReworker.kt @@ -196,8 +196,8 @@ open class InsnReworker { is Node.Instr.GetLocal -> PUSH_RESULT is Node.Instr.SetLocal -> POP_PARAM is Node.Instr.TeeLocal -> POP_PARAM + PUSH_RESULT - is Node.Instr.GetGlobal -> POP_THIS + PUSH_RESULT - is Node.Instr.SetGlobal -> POP_THIS + POP_PARAM + is Node.Instr.GetGlobal -> PUSH_RESULT + is Node.Instr.SetGlobal -> POP_PARAM is Node.Instr.I32Load, is Node.Instr.I64Load, is Node.Instr.F32Load, is Node.Instr.F64Load, is Node.Instr.I32Load8S, is Node.Instr.I32Load8U, is Node.Instr.I32Load16U, is Node.Instr.I32Load16S, is Node.Instr.I64Load8S, is Node.Instr.I64Load8U, is Node.Instr.I64Load16U, is Node.Instr.I64Load16S, @@ -266,7 +266,6 @@ open class InsnReworker { }.let { (count, _) -> count } companion object : InsnReworker() { - const val POP_THIS = -1 const val POP_PARAM = -1 const val PUSH_RESULT = 1 const val NOP = 0 diff --git a/src/test/resources/local-spec/multi-global.wast b/src/test/resources/local-spec/multi-global.wast new file mode 100644 index 0000000..8631f08 --- /dev/null +++ b/src/test/resources/local-spec/multi-global.wast @@ -0,0 +1,23 @@ +;; This was breaking because stack diff was wrong for get_global and set_global + +(module + (global $foo (mut i32) (i32.const 20)) + (func (export "test") (param $p i32) (result i32) + (local i32) + (get_global $foo) + (set_local 1) + (get_global $foo) + (get_local $p) + (i32.add) + (set_global $foo) + (get_global $foo) + (i32.const 15) + (i32.add) + (i32.const -16) + (i32.and) + (set_global $foo) + (get_global $foo) + ) +) + +(assert_return (invoke "test" (i32.const 7)) (i32.const 32)) \ No newline at end of file