52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
try:
|
|
import mpycross
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
import os
|
|
|
|
HERE = __file__.rsplit("/", 1)[0] or "."
|
|
|
|
# A subset of things in run-tests.py:emitter_tests_to_skip: ones that actually cause errors while compiling
|
|
blacklist = {
|
|
"exception_chain.py",
|
|
"try_reraise2.py",
|
|
"try_finally_return2.py",
|
|
"gen_yield_from_close.py",
|
|
"try_reraise.py",
|
|
}
|
|
|
|
|
|
def run_dir(testdir, pfx="", emit_arch="host", emit_opt="EMIT_OPT_BYTECODE"):
|
|
for leaf in sorted(os.listdir(testdir)):
|
|
if leaf in blacklist:
|
|
continue
|
|
if not leaf.endswith(".py"):
|
|
continue
|
|
if not leaf.startswith(pfx):
|
|
continue
|
|
with open(f"{testdir}/{leaf}", "r") as f:
|
|
content = f.read()
|
|
print(f"Compiling {leaf} with {emit_arch} {emit_opt}")
|
|
compiled = mpycross.compile(
|
|
content, leaf, emit_arch=emit_arch, emit_opt=getattr(mpycross, emit_opt)
|
|
)
|
|
# This is likely to be fragile
|
|
# print(f"got {len(compiled)} bytes of mpy file")
|
|
|
|
|
|
def run_one_arch(arch):
|
|
try:
|
|
mpycross.compile("3+3", "<arch-support-test>", emit_arch=arch)
|
|
except ValueError as e:
|
|
if e.value == "Invalid emit_arch":
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
run_dir(f"{HERE}/../../micropython", "viper_", emit_arch=arch)
|
|
run_dir(f"{HERE}/../../basics", emit_arch=arch, emit_opt="EMIT_OPT_NATIVE_PYTHON")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_dir(f"{HERE}/../../basics", emit_opt="EMIT_OPT_BYTECODE")
|