1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use quil_rs::instruction::{Include, Pragma, PragmaArgument};

use rigetti_pyo3::{
    impl_hash, impl_repr, py_wrap_data_struct, py_wrap_union_enum,
    pyo3::{
        pymethods,
        types::{PyInt, PyString},
        Py, PyResult, Python,
    },
    PyTryFrom,
};

use crate::{impl_copy_for_instruction, impl_eq, impl_to_quil};

py_wrap_data_struct! {
    #[derive(Debug, PartialEq, Eq)]
    #[pyo3(subclass)]
    PyPragma(Pragma) as "Pragma" {
        name: String => Py<PyString>,
        arguments: Vec<PragmaArgument> => Vec<PyPragmaArgument>,
        data: Option<String> => Option<Py<PyString>>
    }
}
impl_repr!(PyPragma);
impl_to_quil!(PyPragma);
impl_copy_for_instruction!(PyPragma);
impl_hash!(PyPragma);
impl_eq!(PyPragma);

#[pymethods]
impl PyPragma {
    #[new]
    fn new(
        py: Python<'_>,
        name: String,
        arguments: Vec<PyPragmaArgument>,
        data: Option<String>,
    ) -> PyResult<Self> {
        Ok(Self(Pragma::new(
            name,
            Vec::<PragmaArgument>::py_try_from(py, &arguments)?,
            data,
        )))
    }
}

py_wrap_union_enum! {
    #[derive(Debug, PartialEq, Eq)]
    PyPragmaArgument(PragmaArgument) as "PragmaArgument" {
        identifier: Identifier => Py<PyString>,
        integer: Integer => Py<PyInt>
    }
}
impl_repr!(PyPragmaArgument);
impl_to_quil!(PyPragmaArgument);
impl_hash!(PyPragmaArgument);
impl_eq!(PyPragmaArgument);

py_wrap_data_struct! {
    #[derive(Debug, PartialEq, Eq)]
    #[pyo3(subclass)]
    PyInclude(Include) as "Include" {
        filename: String => Py<PyString>
    }
}
impl_repr!(PyInclude);
impl_to_quil!(PyInclude);
impl_copy_for_instruction!(PyInclude);
impl_hash!(PyInclude);
impl_eq!(PyInclude);

#[pymethods]
impl PyInclude {
    #[new]
    pub fn new(filename: String) -> Self {
        Self(Include::new(filename))
    }
}