|
7 | 7 | from openpulse.parser import parse |
8 | 8 | from openpulse.ast import ( |
9 | 9 | AngleType, |
| 10 | + ArrayLiteral, |
| 11 | + ArrayType, |
10 | 12 | CalibrationDefinition, |
11 | 13 | CalibrationStatement, |
12 | 14 | ClassicalArgument, |
@@ -94,7 +96,8 @@ def test_calibration_definition(): |
94 | 96 | arguments=[Identifier(name="$1")], |
95 | 97 | ), |
96 | 98 | UnaryExpression( |
97 | | - op=UnaryOperator["-"], expression=Identifier(name="theta") |
| 99 | + op=UnaryOperator["-"], |
| 100 | + expression=Identifier(name="theta"), |
98 | 101 | ), |
99 | 102 | ], |
100 | 103 | ) |
@@ -194,7 +197,10 @@ def test_calibration2(): |
194 | 197 | identifier=Identifier(name="readout_waveform_wf"), |
195 | 198 | init_expression=FunctionCall( |
196 | 199 | name=Identifier(name="constant"), |
197 | | - arguments=[FloatLiteral(value=5e-06), FloatLiteral(value=0.03)], |
| 200 | + arguments=[ |
| 201 | + FloatLiteral(value=5e-06), |
| 202 | + FloatLiteral(value=0.03), |
| 203 | + ], |
198 | 204 | ), |
199 | 205 | ), |
200 | 206 | ForInLoop( |
@@ -229,6 +235,39 @@ def test_calibration2(): |
229 | 235 | SpanGuard().visit(program) |
230 | 236 |
|
231 | 237 |
|
| 238 | +def test_array(): |
| 239 | + p = """ |
| 240 | + cal { |
| 241 | + array[int[32], 4] my_array = {3, 4, 5, 5}; |
| 242 | + } |
| 243 | + """.strip() |
| 244 | + program = parse(p) |
| 245 | + assert _remove_spans(program) == Program( |
| 246 | + statements=[ |
| 247 | + CalibrationStatement( |
| 248 | + body=[ |
| 249 | + ClassicalDeclaration( |
| 250 | + type=ArrayType( |
| 251 | + base_type=IntType(size=IntegerLiteral(value=32)), |
| 252 | + dimensions=[IntegerLiteral(value=4)], |
| 253 | + ), |
| 254 | + identifier=Identifier(name="my_array"), |
| 255 | + init_expression=ArrayLiteral( |
| 256 | + values=[ |
| 257 | + IntegerLiteral(value=3), |
| 258 | + IntegerLiteral(value=4), |
| 259 | + IntegerLiteral(value=5), |
| 260 | + IntegerLiteral(value=5), |
| 261 | + ], |
| 262 | + ), |
| 263 | + ) |
| 264 | + ] |
| 265 | + ) |
| 266 | + ] |
| 267 | + ) |
| 268 | + SpanGuard().visit(program) |
| 269 | + |
| 270 | + |
232 | 271 | @pytest.mark.parametrize( |
233 | 272 | "p", |
234 | 273 | [ |
@@ -261,11 +300,6 @@ def test_calibration2(): |
261 | 300 | } |
262 | 301 | } |
263 | 302 | """, |
264 | | - """ |
265 | | - cal { |
266 | | - array[int[32], 3] my_ints = {5, 6, 7}; |
267 | | - } |
268 | | - """, |
269 | 303 | ], |
270 | 304 | ) |
271 | 305 | def test_parsing(p: str): |
|
0 commit comments