Skip to content

Commit

Permalink
Add tests for extern and extern pragma processing
Browse files Browse the repository at this point in the history
  • Loading branch information
macrologist committed May 6, 2024
1 parent 2925a27 commit a28c904
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/bad-test-files/bad-empty-extern.quil
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# "Empty" stub declarations are bad
# "Empty" extern declarations ar bad

STUB
EXTERN

H 0
5 changes: 5 additions & 0 deletions tests/bad-test-files/bad-empty-stub.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# "Empty" stub declarations are bad

STUB

H 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Pragma extern type strings have a grammar

PRAGMA EXTERN foo "(x y z)"

H 0
22 changes: 17 additions & 5 deletions tests/extern-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))



Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/good-test-files/good-extern-declare-and-call.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Basic use of extern and call

EXTERN foo
DECLARE x INTEGER
X 0
CALL foo x 10
CNOT 1 2

0 comments on commit a28c904

Please sign in to comment.