diff --git a/Makefile b/Makefile index c0b5d5b..45522bb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,4 @@ -WABT_DIR := /home/johan/sources/github.com/WebAssembly/wabt - -WAT2WASM := $(WABT_DIR)/bin/wat2wasm -WASM2C := $(WABT_DIR)/bin/wasm2c +WAT2WASM := venv/bin/python wat2wasm.py %.wat: %.py $(shell find phasm -name '*.py') venv/.done venv/bin/python -m phasm $< $@ @@ -15,12 +12,6 @@ WASM2C := $(WABT_DIR)/bin/wasm2c %.wasm: %.wat $(WAT2WASM) $^ -o $@ -%.c: %.wasm - $(WASM2C) $^ -o $@ - -# %.exe: %.c -# cc $^ -o $@ -I $(WABT_DIR)/wasm2c - examples: venv/.done $(subst .py,.wasm,$(wildcard examples/*.py)) $(subst .py,.wat.html,$(wildcard examples/*.py)) $(subst .py,.py.html,$(wildcard examples/*.py)) venv/bin/python3 -m http.server --directory examples @@ -31,7 +22,7 @@ lint: venv/.done venv/bin/ruff check phasm tests typecheck: venv/.done - venv/bin/mypy --strict phasm tests/integration/helpers.py tests/integration/runners.py + venv/bin/mypy --strict phasm wat2wasm.py tests/integration/helpers.py tests/integration/runners.py venv/.done: requirements.txt python3.12 -m venv venv diff --git a/stubs/pywasm/__init__.pyi b/stubs/pywasm/__init__.pyi deleted file mode 100644 index 4d94109..0000000 --- a/stubs/pywasm/__init__.pyi +++ /dev/null @@ -1,14 +0,0 @@ -from typing import Any, Dict, List, Optional, Union - -from . import binary -from . import option -from . import execution - -class Runtime: - store: execution.Store - - def __init__(self, module: binary.Module, imps: Optional[Dict[str, Any]] = None, opts: Optional[option.Option] = None): - ... - - def exec(self, name: str, args: List[Union[int, float]]) -> Any: - ... diff --git a/stubs/pywasm/binary.pyi b/stubs/pywasm/binary.pyi deleted file mode 100644 index 3af65a0..0000000 --- a/stubs/pywasm/binary.pyi +++ /dev/null @@ -1,6 +0,0 @@ -from typing import BinaryIO - -class Module: - @classmethod - def from_reader(cls, reader: BinaryIO) -> 'Module': - ... diff --git a/stubs/pywasm/execution.pyi b/stubs/pywasm/execution.pyi deleted file mode 100644 index 54db4fb..0000000 --- a/stubs/pywasm/execution.pyi +++ /dev/null @@ -1,10 +0,0 @@ -from typing import List - -class Result: - ... - -class MemoryInstance: - data: bytearray - -class Store: - memory_list: List[MemoryInstance] diff --git a/stubs/pywasm/option.pyi b/stubs/pywasm/option.pyi deleted file mode 100644 index fd461ee..0000000 --- a/stubs/pywasm/option.pyi +++ /dev/null @@ -1,2 +0,0 @@ -class Option: - ... diff --git a/stubs/wasm3.pyi b/stubs/wasm3.pyi deleted file mode 100644 index 216412c..0000000 --- a/stubs/wasm3.pyi +++ /dev/null @@ -1,23 +0,0 @@ -from typing import Any, Callable - -class Module: - ... - -class Runtime: - ... - - def load(self, wasm_bin: Module) -> None: - ... - - def get_memory(self, memid: int) -> memoryview: - ... - - def find_function(self, name: str) -> Callable[[Any], Any]: - ... - -class Environment: - def new_runtime(self, mem_size: int) -> Runtime: - ... - - def parse_module(self, wasm_bin: bytes) -> Module: - ... diff --git a/stubs/wasmer.pyi b/stubs/wasmer.pyi deleted file mode 100644 index 535fa99..0000000 --- a/stubs/wasmer.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from typing import Any, Dict, Callable, Union - -def wat2wasm(inp: str) -> bytes: - ... - -class Store: - ... - -class Function: - def __init__(self, store: Store, func: Callable[[Any], Any]) -> None: - ... - -class Module: - def __init__(self, store: Store, wasm: bytes) -> None: - ... - -class Uint8Array: - def __getitem__(self, index: Union[int, slice]) -> int: - ... - - def __setitem__(self, idx: int, value: int) -> None: - ... - -class Memory: - def uint8_view(self, offset: int = 0) -> Uint8Array: - ... - -class Exports: - ... - -class ImportObject: - def register(self, region: str, values: Dict[str, Function]) -> None: - ... - -class Instance: - exports: Exports - - def __init__(self, module: Module, imports: ImportObject) -> None: - ... diff --git a/wat2wasm.py b/wat2wasm.py new file mode 100644 index 0000000..c410012 --- /dev/null +++ b/wat2wasm.py @@ -0,0 +1,11 @@ +import sys + +from wasmtime import wat2wasm + +def main(_prog: str, inp: str, _dash_o: str, out: str) -> None: + with open(inp, 'rb') as inp_obj: + with open(out, 'wb') as out_obj: + out_obj.write(wat2wasm(inp_obj.read())) + +if __name__ == '__main__': + main(*sys.argv)