From a28c90464d57af707b644865baea307579ab09a2 Mon Sep 17 00:00:00 2001 From: "O'Keefe, Colin B" Date: Mon, 6 May 2024 15:04:40 -0700 Subject: [PATCH] Add tests for extern and extern pragma processing --- tests/bad-test-files/bad-empty-extern.quil | 4 ++-- tests/bad-test-files/bad-empty-stub.quil | 5 +++++ .../bad-pragma-extern-type-string-syntax.quil | 5 +++++ ...arg.quil => bad-stub-declaration-arg.quil} | 0 ...lti-args.quil => bad-stub-multi-args.quil} | 0 tests/extern-tests.lisp | 22 ++++++++++++++----- ...basic-extern.quil => good-basic-stub.quil} | 0 .../good-extern-declare-and-call.quil | 8 +++++++ ...-externs.quil => good-multiple-stubs.quil} | 0 9 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 tests/bad-test-files/bad-empty-stub.quil create mode 100644 tests/bad-test-files/bad-pragma-extern-type-string-syntax.quil rename tests/bad-test-files/{bad-extern-declaration-arg.quil => bad-stub-declaration-arg.quil} (100%) rename tests/bad-test-files/{bad-extern-multi-args.quil => bad-stub-multi-args.quil} (100%) rename tests/good-test-files/{good-basic-extern.quil => good-basic-stub.quil} (100%) create mode 100644 tests/good-test-files/good-extern-declare-and-call.quil rename tests/good-test-files/{good-multiple-externs.quil => good-multiple-stubs.quil} (100%) diff --git a/tests/bad-test-files/bad-empty-extern.quil b/tests/bad-test-files/bad-empty-extern.quil index 865db8ee..e810faf2 100644 --- a/tests/bad-test-files/bad-empty-extern.quil +++ b/tests/bad-test-files/bad-empty-extern.quil @@ -1,5 +1,5 @@ -# "Empty" stub declarations are bad +# "Empty" extern declarations ar bad -STUB +EXTERN H 0 \ No newline at end of file diff --git a/tests/bad-test-files/bad-empty-stub.quil b/tests/bad-test-files/bad-empty-stub.quil new file mode 100644 index 00000000..865db8ee --- /dev/null +++ b/tests/bad-test-files/bad-empty-stub.quil @@ -0,0 +1,5 @@ +# "Empty" stub declarations are bad + +STUB + +H 0 \ No newline at end of file diff --git a/tests/bad-test-files/bad-pragma-extern-type-string-syntax.quil b/tests/bad-test-files/bad-pragma-extern-type-string-syntax.quil new file mode 100644 index 00000000..ccae51d9 --- /dev/null +++ b/tests/bad-test-files/bad-pragma-extern-type-string-syntax.quil @@ -0,0 +1,5 @@ +# Pragma extern type strings have a grammar + +PRAGMA EXTERN foo "(x y z)" + +H 0 \ No newline at end of file diff --git a/tests/bad-test-files/bad-extern-declaration-arg.quil b/tests/bad-test-files/bad-stub-declaration-arg.quil similarity index 100% rename from tests/bad-test-files/bad-extern-declaration-arg.quil rename to tests/bad-test-files/bad-stub-declaration-arg.quil diff --git a/tests/bad-test-files/bad-extern-multi-args.quil b/tests/bad-test-files/bad-stub-multi-args.quil similarity index 100% rename from tests/bad-test-files/bad-extern-multi-args.quil rename to tests/bad-test-files/bad-stub-multi-args.quil diff --git a/tests/extern-tests.lisp b/tests/extern-tests.lisp index cd88c30b..e0cbc663 100644 --- a/tests/extern-tests.lisp +++ b/tests/extern-tests.lisp @@ -56,20 +56,32 @@ CPHASE(pi*x/2) 0 1")) (cl-quil::register-classical-function "add2" 'add2) (deftest test-extern-in-expressions () - (let (parsed) + (let (parsed rx) ;; parsing works (not-signals error - (setf parsed (parse-quil "EXTERN add2;RX(add2(3,pi)/4) 0"))) + (setf parsed (parse-quil " +EXTERN add2; +PRAGMA EXTERN add2 \"REAL (x:REAL, y:REAL)\"; +RX(add2(3,pi)/4) 0"))) ;; because the expression involved no memory references, it is ;; actually evaluated + (setf rx (elt (parsed-program-executable-code parsed) + (1- (length (parsed-program-executable-code parsed))))) + (is (is-constant - (elt (application-parameters (elt (parsed-program-executable-code parsed) 0)) 0))) + (elt (application-parameters rx) 0))) ;; but this one will involve memory refs, and so will involve a delayed expression - (setf parsed (parse-quil "EXTERN add2;DECLARE x REAL;RX(add2(x,pi)/4) 0")) + (setf parsed (parse-quil " +EXTERN add2; +PRAGMA EXTERN add2 \"REAL (x:REAL, y:REAL)\"; +DECLARE x REAL; +RX(add2(x,pi)/4) 0")) + (setf rx (elt (parsed-program-executable-code parsed) + (1- (length (parsed-program-executable-code parsed))))) (is (cl-quil.frontend::delayed-expression-p - (elt (application-parameters (elt (parsed-program-executable-code parsed) 0)) 0))))) + (elt (application-parameters rx) 0))))) diff --git a/tests/good-test-files/good-basic-extern.quil b/tests/good-test-files/good-basic-stub.quil similarity index 100% rename from tests/good-test-files/good-basic-extern.quil rename to tests/good-test-files/good-basic-stub.quil diff --git a/tests/good-test-files/good-extern-declare-and-call.quil b/tests/good-test-files/good-extern-declare-and-call.quil new file mode 100644 index 00000000..a47f9a8e --- /dev/null +++ b/tests/good-test-files/good-extern-declare-and-call.quil @@ -0,0 +1,8 @@ +# Basic use of extern and call + +EXTERN foo +DECLARE x INTEGER +X 0 +CALL foo x 10 +CNOT 1 2 + diff --git a/tests/good-test-files/good-multiple-externs.quil b/tests/good-test-files/good-multiple-stubs.quil similarity index 100% rename from tests/good-test-files/good-multiple-externs.quil rename to tests/good-test-files/good-multiple-stubs.quil