Add i64 support

Stack slots, locals and globals were already 8 bytes wide, so i64 is mostly
64-bit encodings of the existing i32 ops: constants, comparisons, arithmetic,
bitwise, shifts/rotates, div/rem (with zero and overflow traps), wrap/extend,
sign-extension ops, i64 loads/stores (incl. narrow forms) and 64-bit globals.
Adds examples/i64.wat, which self-checks and exits 0 on success.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-21 09:49:28 +00:00
1 parent 05488c9783
commit 4c4fa91dc9
6 files changed
+294 -126

No files matched your search

+15 -8
View File
@@ -6,28 +6,28 @@ priv struct Asm {
///|
fn Asm::new() -> Asm {
{ code: [] }
{ code: [], }
}
///|
fn Asm::here(self : Asm) -> Int {
fn Asm::here(self : Asm) -> Int32 {
self.code.length()
}
///|
fn Asm::b(self : Asm, x : Int) -> Unit {
fn Asm::b(self : Asm, x : Int32) -> Unit {
self.code.push((x & 0xFF).to_byte())
}
///|
fn Asm::bs(self : Asm, xs : Array[Int]) -> Unit {
fn Asm::bs(self : Asm, xs : Array[Int32]) -> Unit {
for x in xs {
self.b(x)
}
}
///|
fn Asm::i32(self : Asm, x : Int) -> Unit {
fn Asm::i32(self : Asm, x : Int32) -> Unit {
self.b(x)
self.b(x >> 8)
self.b(x >> 16)
@@ -36,7 +36,7 @@ fn Asm::i32(self : Asm, x : Int) -> Unit {
///|
/// Emit opcode bytes followed by a rel32 placeholder; returns the placeholder's position.
fn Asm::rel(self : Asm, op : Array[Int]) -> Int {
fn Asm::rel(self : Asm, op : Array[Int32]) -> Int32 {
self.bs(op)
let at = self.here()
self.i32(0)
@@ -45,7 +45,7 @@ fn Asm::rel(self : Asm, op : Array[Int]) -> Int {
///|
/// Point the rel32 placeholder at `at` to `target`.
fn Asm::patch(self : Asm, at : Int, target : Int) -> Unit {
fn Asm::patch(self : Asm, at : Int32, target : Int32) -> Unit {
let v = target - (at + 4)
self.code[at] = (v & 0xFF).to_byte()
self.code[at + 1] = ((v >> 8) & 0xFF).to_byte()
@@ -54,6 +54,13 @@ fn Asm::patch(self : Asm, at : Int, target : Int) -> Unit {
}
///|
fn Asm::patch_here(self : Asm, at : Int) -> Unit {
fn Asm::patch_here(self : Asm, at : Int32) -> Unit {
self.patch(at, self.here())
}
///|
fn Asm::i64(self : Asm, x : Int64) -> Unit {
for k in 0..<8 {
self.b((x >> (8 * k)).to_int())
}
}