cleanups [skip-ci]
This commit is contained in:
parent
547576de00
commit
473cd0b626
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.wasm
|
||||||
|
*.wat
|
||||||
2
Makefile
2
Makefile
@ -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
4
README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
webasm (python)
|
||||||
|
===============
|
||||||
|
|
||||||
|
You will need wat2wasm from github.com/WebAssembly/wabt in your path.
|
||||||
27
compile.py
27
compile.py
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user