Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Rename local global opcodes #503

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 26 additions & 12 deletions lib/wabt.js

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions misc/arc-templates/arc_wat/src/module.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,92 @@
(param $buffer i32) (param $rows i32) (param $cols i32) (param $frameCount i32) (param $fps i32) (param $isFirst i32)
(local $colorStart i32) (local $frame i32) (local $frameSize i32) (local $i i32)

get_local $rows
get_local $cols
local.get $rows
local.get $cols
i32.mul
set_local $frameSize
local.set $frameSize

i32.const 0
set_local $frame
local.set $frame

block $frames_end loop $frames
get_local $frame
get_local $frameCount
local.get $frame
local.get $frameCount
i32.ge_s
br_if $frames_end

(; Fill frame with solid color ;)
get_local $frame
local.get $frame
i32.const 8
i32.rem_u
i32.const 3
i32.mul
get_global $colors
global.get $colors
i32.add
set_local $colorStart
local.set $colorStart

i32.const 0
set_local $i
local.set $i
block $frame_end loop $frame
get_local $i
get_local $frameSize
local.get $i
local.get $frameSize
i32.ge_s
br_if $frame_end

get_local $buffer
get_local $colorStart
local.get $buffer
local.get $colorStart
i32.load8_u
i32.store8

get_local $buffer
get_local $colorStart
local.get $buffer
local.get $colorStart
i32.load8_u offset=1
i32.store8 offset=1

get_local $buffer
get_local $colorStart
local.get $buffer
local.get $colorStart
i32.load8_u offset=2
i32.store8 offset=2

get_local $buffer
local.get $buffer
i32.const 3
i32.add
set_local $buffer
local.set $buffer

get_local $i
local.get $i
i32.const 1
i32.add
set_local $i
local.set $i
br $frame
end end

get_local $frame
local.get $frame
i32.const 1
i32.add
set_local $frame
local.set $frame
br $frames
end end
)

(; Very simplistic allocation/deallocation functions ;)
(func (export "alloc") (param $size i32) (result i32)
get_global $allocated
global.get $allocated
if unreachable end
i32.const 1
set_global $allocated
get_global $memoryStarts
global.set $allocated
global.get $memoryStarts
)
(func (export "free") (param $p i32)
get_global $allocated
global.get $allocated
i32.const 1
i32.xor
if unreachable end
get_local $p
get_global $memoryStarts
local.get $p
global.get $memoryStarts
i32.ne
if unreachable end
i32.const 0
set_global $allocated
global.set $allocated
)

(memory (export "memory") 1024)
Expand Down
20 changes: 10 additions & 10 deletions src/languages/wat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export function getWatCompletionItems() {
{ label: "f32.store", documentation: "(no conversion) store 4 bytes", kind: keyword, insertText: "f32.store" },
{ label: "f64.store", documentation: "(no conversion) store 8 bytes", kind: keyword, insertText: "f64.store" },

{ label: "get_local", documentation: "read the current value of a local variable", kind: keyword, insertText: "get_local" },
{ label: "set_local", documentation: "set the current value of a local variable", kind: keyword, insertText: "set_local" },
{ label: "tee_local", documentation: "like `set_local`, but also returns the set value", kind: keyword, insertText: "tee_local" },
{ label: "local.get", documentation: "read the current value of a local variable", kind: keyword, insertText: "local.get" },
{ label: "local.set", documentation: "set the current value of a local variable", kind: keyword, insertText: "local.set" },
{ label: "local.tee", documentation: "like `local.set`, but also returns the set value", kind: keyword, insertText: "local.tee" },

{ label: "get_global", documentation: "get the current value of a global variable", kind: keyword, insertText: "get_global" },
{ label: "set_global", documentation: "set the current value of a global variable", kind: keyword, insertText: "set_global" },
{ label: "global.get", documentation: "get the current value of a global variable", kind: keyword, insertText: "global.get" },
{ label: "global.set", documentation: "set the current value of a global variable", kind: keyword, insertText: "global.set" },

{ label: "nop", documentation: "no operation, no effect", kind: keyword, insertText: "nop" },
{ label: "block", documentation: "the beginning of a block construct, a sequence of instructions with a label at the end", kind: keyword, insertText: "block" },
Expand Down Expand Up @@ -377,11 +377,11 @@ const MonarchDefinitions = {
"f64.convert_u/i64",
"f64.reinterpret/i64",

"get_local",
"set_local",
"tee_local",
"get_global",
"set_global",
"local.get",
"local.set",
"local.tee",
"global.get",
"global.set",

"drop",
"select",
Expand Down
1 change: 1 addition & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function loadWabt() {
if (typeof wabt === "undefined") {
(self as any).global = self; // Wabt installs itself on the global object.
importScripts("../lib/wabt.js");
wabt!.ready;
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/languages/wat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ describe("Tests for Wat", () => {
{ label: "i64.store", documentation: "(no conversion) store 8 bytes", kind: keyword, insertText: "i64.store" },
{ label: "f32.store", documentation: "(no conversion) store 4 bytes", kind: keyword, insertText: "f32.store" },
{ label: "f64.store", documentation: "(no conversion) store 8 bytes", kind: keyword, insertText: "f64.store" },
{ label: "get_local", documentation: "read the current value of a local variable", kind: keyword, insertText: "get_local" },
{ label: "set_local", documentation: "set the current value of a local variable", kind: keyword, insertText: "set_local" },
{ label: "tee_local", documentation: "like `set_local`, but also returns the set value", kind: keyword, insertText: "tee_local" },
{ label: "get_global", documentation: "get the current value of a global variable", kind: keyword, insertText: "get_global" },
{ label: "set_global", documentation: "set the current value of a global variable", kind: keyword, insertText: "set_global" },
{ label: "local.get", documentation: "read the current value of a local variable", kind: keyword, insertText: "local.get" },
{ label: "local.set", documentation: "set the current value of a local variable", kind: keyword, insertText: "local.set" },
{ label: "local.tee", documentation: "like `local.set`, but also returns the set value", kind: keyword, insertText: "local.tee" },
{ label: "global.get", documentation: "get the current value of a global variable", kind: keyword, insertText: "global.get" },
{ label: "global.set", documentation: "set the current value of a global variable", kind: keyword, insertText: "global.set" },
{ label: "nop", documentation: "no operation, no effect", kind: keyword, insertText: "nop" },
{ label: "block", documentation: "the beginning of a block construct, a sequence of instructions with a label at the end", kind: keyword, insertText: "block" },
{ label: "loop", documentation: "a block with a label at the beginning which may be used to form loops", kind: keyword, insertText: "loop" },
Expand Down Expand Up @@ -380,11 +380,11 @@ describe("Tests for Wat", () => {
"f64.convert_u/i32",
"f64.convert_u/i64",
"f64.reinterpret/i64",
"get_local",
"set_local",
"tee_local",
"get_global",
"set_global",
"local.get",
"local.set",
"local.tee",
"global.get",
"global.set",
"drop",
"select",
"memory.size",
Expand Down