From 659447b1abca505b9bce0eeb1fea4ca1162fcb94 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 4 Mar 2024 07:38:45 +0900 Subject: Hello, World! --- src/Execution/Runtime.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index e43a23a..d66e01b 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -698,9 +698,19 @@ final readonly class Runtime } $this->stack->pushI64($trailingZeros); } elseif ($instr instanceof Instrs\Numeric\I64DivS) { - throw new \RuntimeException("I64DivS: not implemented"); + $c2 = $this->stack->popI64(); + $c1 = $this->stack->popI64(); + if ($c2 === 0) { + throw new TrapException("i64.div_s: divide by zero"); + } + $this->stack->pushI64(intdiv($c1, $c2)); } elseif ($instr instanceof Instrs\Numeric\I64DivU) { - throw new \RuntimeException("I64DivU: not implemented"); + $c2 = $this->stack->popI64(); + $c1 = $this->stack->popI64(); + if ($c2 === 0) { + throw new TrapException("i64.div_u: divide by zero"); + } + $this->stack->pushI64(intdiv($c1, $c2)); } elseif ($instr instanceof Instrs\Numeric\I64Eq) { $c2 = $this->stack->popI64(); $c1 = $this->stack->popI64(); @@ -800,7 +810,10 @@ final readonly class Runtime } elseif ($instr instanceof Instrs\Numeric\I64RemU) { throw new \RuntimeException("I64RemU: not implemented"); } elseif ($instr instanceof Instrs\Numeric\I64RotL) { - throw new \RuntimeException("I64RotL: not implemented"); + $i2 = $this->stack->popI64(); + $i1 = $this->stack->popI64(); + $k = $i2 % 64; + $this->stack->pushI64(($i1 << $k) | ($i1 >> (64 - $k))); } elseif ($instr instanceof Instrs\Numeric\I64RotR) { throw new \RuntimeException("I64RotR: not implemented"); } elseif ($instr instanceof Instrs\Numeric\I64Shl) { @@ -1150,10 +1163,8 @@ final readonly class Runtime // foreach ($instrs as $instr) { // echo " " . $instr::opName() . "\n"; // } - if ($f->debugName === "wasm: 2695") { - // push dummy - $this->stack->pushI32(0); - } + // WORKAROUND: + $this->stack->pushI32(0); } } $this->deactivateLabel($n); -- cgit v1.2.3-70-g09d2