Skip to content

Commit

Permalink
allow simplepy to pass and return
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Sep 4, 2017
1 parent 5c86808 commit 3e47f27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions simplepy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
py = """
if 4 > 5:
print(0)
elif 4 > 5:
print(1)
else:
print(2)
"""

m = simplepy2wasm(py)
Expand Down
8 changes: 8 additions & 0 deletions simplepy/simplepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,20 @@ def _compile_expr(node, ctx, push_stack):
ctx.instructions.append(i)
ctx.pop_block('while')

elif isinstance(node, ast.Pass):
pass

elif isinstance(node, ast.Continue):
ctx.instructions.append(('br', ctx.get_block_level()))

elif isinstance(node, ast.Break):
ctx.instructions.append(('br', ctx.get_block_level() + 1))

elif isinstance(node, ast.Return):
assert node.value is not None
_compile_expr(node.value, ctx, True)
ctx.instructions.append(('return', ))

elif isinstance(node, ast.Call):
if not isinstance(node.func, ast.Name):
raise SyntaxError('Only support simple function names')
Expand Down

0 comments on commit 3e47f27

Please sign in to comment.