From 502e570e867cd505f9a84d71fe89596829d92bf6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 26 Dec 2015 03:17:26 +0800 Subject: [PATCH] compiler: embed host exception constructors as such (fixes #204). --- artiq/compiler/embedding.py | 5 ++++- artiq/compiler/testbench/embedding.py | 8 ++++++++ lit-test/test/embedding/error_attr_absent.py | 2 +- lit-test/test/embedding/error_attr_absent_suggest.py | 2 +- lit-test/test/embedding/error_attr_conflict.py | 2 +- lit-test/test/embedding/error_attr_unify.py | 2 +- lit-test/test/embedding/error_name_absent_suggest.py | 2 +- lit-test/test/embedding/error_rpc_annot_return.py | 2 +- lit-test/test/embedding/error_rpc_default_unify.py | 2 +- lit-test/test/embedding/error_syscall_annot.py | 2 +- .../test/embedding/error_syscall_annot_return.py | 2 +- lit-test/test/embedding/error_syscall_arg.py | 2 +- lit-test/test/embedding/error_syscall_default_arg.py | 2 +- lit-test/test/embedding/error_syscall_return.py | 2 +- lit-test/test/embedding/exception.py | 12 ++++++++++++ 15 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 lit-test/test/embedding/exception.py diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 2f673943a..bef22567d 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -124,7 +124,10 @@ class ASTSynthesizer: OrderedDict()) instance_type.attributes['__objectid__'] = builtins.TInt32() - constructor_type = types.TConstructor(instance_type) + if issubclass(typ, BaseException): + constructor_type = types.TExceptionConstructor(instance_type) + else: + constructor_type = types.TConstructor(instance_type) constructor_type.attributes['__objectid__'] = builtins.TInt32() instance_type.constructor = constructor_type diff --git a/artiq/compiler/testbench/embedding.py b/artiq/compiler/testbench/embedding.py index abe5f2fd3..d51e3ca99 100644 --- a/artiq/compiler/testbench/embedding.py +++ b/artiq/compiler/testbench/embedding.py @@ -6,6 +6,12 @@ from artiq.master.worker_db import DeviceManager from artiq.coredevice.core import Core, CompileError def main(): + if len(sys.argv) > 1 and sys.argv[1] == "+diag": + del sys.argv[1] + diag = True + else: + diag = False + if len(sys.argv) > 1 and sys.argv[1] == "+compile": del sys.argv[1] compile_only = True @@ -30,6 +36,8 @@ def main(): core.comm.clear_log() except CompileError as error: print("\n".join(error.__cause__.diagnostic.render(only_line=True))) + if not diag: + exit(1) if __name__ == "__main__": main() diff --git a/lit-test/test/embedding/error_attr_absent.py b/lit-test/test/embedding/error_attr_absent.py index 296ed860a..b39b0049b 100644 --- a/lit-test/test/embedding/error_attr_absent.py +++ b/lit-test/test/embedding/error_attr_absent.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_attr_absent_suggest.py b/lit-test/test/embedding/error_attr_absent_suggest.py index f6b90a338..b705a881f 100644 --- a/lit-test/test/embedding/error_attr_absent_suggest.py +++ b/lit-test/test/embedding/error_attr_absent_suggest.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_attr_conflict.py b/lit-test/test/embedding/error_attr_conflict.py index a5c960d5c..307272d4c 100644 --- a/lit-test/test/embedding/error_attr_conflict.py +++ b/lit-test/test/embedding/error_attr_conflict.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_attr_unify.py b/lit-test/test/embedding/error_attr_unify.py index e891ec73b..4659d62be 100644 --- a/lit-test/test/embedding/error_attr_unify.py +++ b/lit-test/test/embedding/error_attr_unify.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_name_absent_suggest.py b/lit-test/test/embedding/error_name_absent_suggest.py index 76b6af313..28df3056f 100644 --- a/lit-test/test/embedding/error_name_absent_suggest.py +++ b/lit-test/test/embedding/error_name_absent_suggest.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_rpc_annot_return.py b/lit-test/test/embedding/error_rpc_annot_return.py index 063ac6c28..0a092f287 100644 --- a/lit-test/test/embedding/error_rpc_annot_return.py +++ b/lit-test/test/embedding/error_rpc_annot_return.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_rpc_default_unify.py b/lit-test/test/embedding/error_rpc_default_unify.py index 9cb483628..92da137b7 100644 --- a/lit-test/test/embedding/error_rpc_default_unify.py +++ b/lit-test/test/embedding/error_rpc_default_unify.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_syscall_annot.py b/lit-test/test/embedding/error_syscall_annot.py index cbb5aab22..9cc1aeda5 100644 --- a/lit-test/test/embedding/error_syscall_annot.py +++ b/lit-test/test/embedding/error_syscall_annot.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_syscall_annot_return.py b/lit-test/test/embedding/error_syscall_annot_return.py index 20f1d4ac5..36bde42b9 100644 --- a/lit-test/test/embedding/error_syscall_annot_return.py +++ b/lit-test/test/embedding/error_syscall_annot_return.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_syscall_arg.py b/lit-test/test/embedding/error_syscall_arg.py index b944cc0e9..da1862650 100644 --- a/lit-test/test/embedding/error_syscall_arg.py +++ b/lit-test/test/embedding/error_syscall_arg.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_syscall_default_arg.py b/lit-test/test/embedding/error_syscall_default_arg.py index df025ff19..ce556cb23 100644 --- a/lit-test/test/embedding/error_syscall_default_arg.py +++ b/lit-test/test/embedding/error_syscall_default_arg.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/error_syscall_return.py b/lit-test/test/embedding/error_syscall_return.py index c82db063d..de38b02a5 100644 --- a/lit-test/test/embedding/error_syscall_return.py +++ b/lit-test/test/embedding/error_syscall_return.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.embedding %s >%t +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s >%t # RUN: OutputCheck %s --file-to-check=%t from artiq.language.core import * diff --git a/lit-test/test/embedding/exception.py b/lit-test/test/embedding/exception.py new file mode 100644 index 000000000..0a0830de4 --- /dev/null +++ b/lit-test/test/embedding/exception.py @@ -0,0 +1,12 @@ +# RUN: %python -m artiq.compiler.testbench.embedding %s + +from artiq.language.core import * +from artiq.language.types import * +from artiq.coredevice.exceptions import RTIOUnderflow + +@kernel +def entrypoint(): + try: + pass + except RTIOUnderflow: + pass