-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpy_compile.py
More file actions
27 lines (24 loc) · 870 Bytes
/
py_compile.py
File metadata and controls
27 lines (24 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from yapypy.extended_python.emit_impl import *
from os.path import splitext
from Redy.Tools.PathLib import Path
_non_ctx: Context = Context.__new__(Context)
def py_compile(node, filename='<unknown>', is_entrypoint=False):
if isinstance(node, Tag):
ctx = _non_ctx.enter_new(node.tag)
ctx.bc.filename = filename
ctx.bc.name = '__main__' if is_entrypoint else splitext(
Path(filename).relative())[0]
try:
py_emit(node.it, ctx)
except SyntaxError as exc:
exc.filename = filename
raise exc
return ctx.bc.to_code()
# try:
# return ctx.bc.to_code()
# except Exception as e:
# dump_bytecode(ctx.bc)
# raise e
else:
tag = to_tagged_ast(node)
return py_compile(tag, filename, is_entrypoint=is_entrypoint)