From 2039d11e19c93876872f6328c3d150b1bf3faedf Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Sat, 20 Aug 2022 18:14:28 +0200 Subject: [PATCH] Some repo cleanup --- Makefile | 2 +- README.md | 68 +++++++++++++++++++++++++++----- tests/integration/helpers.py | 38 ------------------ tests/integration/test_helper.py | 2 +- 4 files changed, 60 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 8f4d045..ad186c2 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ examples: venv/.done $(subst .py,.wasm,$(wildcard examples/*.py)) $(subst .py,.w venv/bin/python3 -m http.server --directory examples test: venv/.done - WAT2WASM=$(WAT2WASM) venv/bin/pytest tests $(TEST_FLAGS) + venv/bin/pytest tests $(TEST_FLAGS) lint: venv/.done venv/bin/pylint phasm diff --git a/README.md b/README.md index 5ab49f7..047e911 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,67 @@ phasm Elevator pitch -------------- -A language that looks like Python, handles like Haskell, and compiles to -WebAssembly. +A programming language, that looks like Python, handles like Haskell, +and compiles directly to WebAssembly. -Naming ------- +Name origin +----------- - p from python - ha from Haskell - asm from WebAssembly -You will need wat2wasm from github.com/WebAssembly/wabt in your path. +Example +------- +For more examples, see the examples directory. +```py +def helper(n: u64, a: u64, b: u64) -> u64: + if n < 1: + return a + b -Ideas -===== -- https://github.com/wasmerio/wasmer-python -- https://github.com/diekmann/wasm-fizzbuzz -- https://blog.scottlogic.com/2018/04/26/webassembly-by-hand.html + return helper(n - 1, a + b, a) + +@exported +def fib(n: u64) -> u64: + if n == 0: + return 0 + + if n == 1: + return 1 + + return helper(n - 1, 0, 1) +``` + +Gotcha's +-------- +- When importing and exporting unsigned values to WebAssembly, they will become + signed, as WebAssembly has no native unsigned type. You may need to cast + or reinterpret them. + +Contributing +------------ +At this time, I'm mostly looking for use cases for WebAssembly, other than to +compile existing C code and running them in the browser. The goal of WebAssembly +is to enable high-performance applications on web pages[5]. Though most people +seem to use it to have existing code run in the browser. + +If you have a situation where WebAssembly would be useful for it's speed, I'm +interested to see what you want to use it for. + +Also, if you are trying out Phasm, and you're running into a limitation, I'm +interested in a minimal test case that shows what you want to achieve and how +Phasm currently fails you. + +Additional required tools +------------------------- +At the moment, the compiler outputs WebAssembly text format. To actually +get a binary, you will need the wat2wasm tool[6]. + . + +References +---------- +[1] https://www.python.org/ +[2] https://www.haskell.org/ +[3] https://webassembly.org/ +[4] https://www.w3.org/TR/wasm-core-1/ +[5] https://en.wikipedia.org/w/index.php?title=WebAssembly&oldid=1103639883 +[6] https://github.com/WebAssembly/wabt diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 2858472..ca4c8a7 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -1,49 +1,11 @@ -import io -import os -import subprocess import sys -from tempfile import NamedTemporaryFile - -import pywasm - -import wasm3 - -import wasmer -import wasmer_compiler_cranelift - -import wasmtime - from phasm.codestyle import phasm_render -from phasm.compiler import phasm_compile -from phasm.parser import phasm_parse from . import runners DASHES = '-' * 16 -def wat2wasm(code_wat): - path = os.environ.get('WAT2WASM', 'wat2wasm') - - with NamedTemporaryFile('w+t') as input_fp: - input_fp.write(code_wat) - input_fp.flush() - - with NamedTemporaryFile('w+b') as output_fp: - subprocess.run( - [ - path, - input_fp.name, - '-o', - output_fp.name, - ], - check=True, - ) - - output_fp.seek(0) - - return output_fp.read() - class SuiteResult: def __init__(self): self.returned_value = None diff --git a/tests/integration/test_helper.py b/tests/integration/test_helper.py index 387eb5a..cb44021 100644 --- a/tests/integration/test_helper.py +++ b/tests/integration/test_helper.py @@ -5,7 +5,7 @@ import pytest from pywasm import binary from pywasm import Runtime -from .helpers import wat2wasm +from wasmer import wat2wasm def run(code_wat): code_wasm = wat2wasm(code_wat)