MVP #1

Merged
jbwdevries merged 73 commits from idea_crc32 into master 2022-08-21 12:59:21 +00:00
5 changed files with 35 additions and 5 deletions
Showing only changes of commit 473cd0b626 - Show all commits

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.wasm
*.wat

View File

@ -1,5 +1,5 @@
%.wat: %.py compile.py %.wat: %.py compile.py
python3.8 compile.py $< > $@ python3.8 compile.py $< $@
%.wasm: %.wat %.wasm: %.wat
wat2wasm $^ -o $@ wat2wasm $^ -o $@

4
README.md Normal file
View File

@ -0,0 +1,4 @@
webasm (python)
===============
You will need wat2wasm from github.com/WebAssembly/wabt in your path.

View File

@ -52,6 +52,28 @@ class Visitor(ast.NodeVisitor):
)) ))
def visit_FunctionDef(self, node): def visit_FunctionDef(self, node):
if node.decorator_list:
# TODO: Support normal decorators
assert 1 == len(node.decorator_list)
call = node.decorator_list[0]
assert 'external' == call.func.id
assert 1 == len(call.args)
assert isinstance(call.args[0].value, str)
import_ = Import(
call.args[0].value,
node.name,
node.name,
)
import_.params = [
arg.annotation.id
for arg in node.args.args
]
self.imports.append(import_)
return
func = Function( func = Function(
node.name, node.name,
) )
@ -116,7 +138,7 @@ class Visitor(ast.NodeVisitor):
def err(msg: str) -> None: def err(msg: str) -> None:
sys.stderr.write('{}\n'.format(msg)) sys.stderr.write('{}\n'.format(msg))
def main(source: str) -> int: def main(source: str, sink: str) -> int:
with open(source, 'r') as fil: with open(source, 'r') as fil:
code = fil.read() code = fil.read()
@ -125,7 +147,8 @@ def main(source: str) -> int:
visitor = Visitor() visitor = Visitor()
visitor.visit(res) visitor.visit(res)
print(visitor.generate()) with open(sink, 'w') as fil:
fil.write(visitor.generate())
return 0 return 0

5
log.py
View File

@ -1,5 +1,6 @@
from console import log as log @external('console')
"log(i32)" def log(msg: i32) -> None:
...
def logIt(): def logIt():
log(13 + 13 * 123) log(13 + 13 * 123)