Skip to main content

quil/instruction/
pragma.rs

1use quil_rs::instruction::{Include, Pragma, PragmaArgument};
2
3use rigetti_pyo3::{
4    impl_hash, impl_repr, py_wrap_data_struct, py_wrap_union_enum,
5    pyo3::{
6        pymethods,
7        types::{PyInt, PyString},
8        Py, PyResult, Python,
9    },
10    PyTryFrom,
11};
12
13use crate::{impl_copy_for_instruction, impl_eq, impl_pickle_for_instruction, impl_to_quil};
14
15py_wrap_data_struct! {
16    #[derive(Debug, PartialEq, Eq)]
17    #[pyo3(subclass, module = "quil.instructions")]
18    PyPragma(Pragma) as "Pragma" {
19        name: String => Py<PyString>,
20        arguments: Vec<PragmaArgument> => Vec<PyPragmaArgument>,
21        data: Option<String> => Option<Py<PyString>>
22    }
23}
24impl_repr!(PyPragma);
25impl_to_quil!(PyPragma);
26impl_copy_for_instruction!(PyPragma);
27impl_hash!(PyPragma);
28impl_eq!(PyPragma);
29impl_pickle_for_instruction!(PyPragma);
30
31#[pymethods]
32impl PyPragma {
33    #[new]
34    fn new(
35        py: Python<'_>,
36        name: String,
37        arguments: Vec<PyPragmaArgument>,
38        data: Option<String>,
39    ) -> PyResult<Self> {
40        Ok(Self(Pragma::new(
41            name,
42            Vec::<PragmaArgument>::py_try_from(py, &arguments)?,
43            data,
44        )))
45    }
46}
47
48py_wrap_union_enum! {
49    #[derive(Debug, PartialEq, Eq)]
50    PyPragmaArgument(PragmaArgument) as "PragmaArgument" {
51        identifier: Identifier => Py<PyString>,
52        integer: Integer => Py<PyInt>
53    }
54}
55impl_repr!(PyPragmaArgument);
56impl_to_quil!(PyPragmaArgument);
57impl_hash!(PyPragmaArgument);
58impl_eq!(PyPragmaArgument);
59
60py_wrap_data_struct! {
61    #[derive(Debug, PartialEq, Eq)]
62    #[pyo3(subclass, module = "quil.instructions")]
63    PyInclude(Include) as "Include" {
64        filename: String => Py<PyString>
65    }
66}
67impl_repr!(PyInclude);
68impl_to_quil!(PyInclude);
69impl_copy_for_instruction!(PyInclude);
70impl_hash!(PyInclude);
71impl_eq!(PyInclude);
72impl_pickle_for_instruction!(PyInclude);
73
74#[pymethods]
75impl PyInclude {
76    #[new]
77    pub fn new(filename: String) -> Self {
78        Self(Include::new(filename))
79    }
80}