From d3b110991d909b5f547437223d6b06a10295b2ca Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Thu, 15 Aug 2024 13:06:11 +0100 Subject: [PATCH] feat(tket2-hseries): make result operation internals public --- tket2-hseries/src/extension/result.rs | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tket2-hseries/src/extension/result.rs b/tket2-hseries/src/extension/result.rs index ff0e7e35..3a16b05e 100644 --- a/tket2-hseries/src/extension/result.rs +++ b/tket2-hseries/src/extension/result.rs @@ -100,7 +100,8 @@ pub enum ResultOpDef { } impl ResultOpDef { - fn arg_type(&self) -> Type { + /// Type of the argument to the result operation. + pub fn arg_type(&self) -> Type { match self { Self::Bool => BOOL_T, Self::Int | Self::UInt => int_tv(1), @@ -133,7 +134,8 @@ impl ResultOpDef { } } - fn type_params(&self) -> Vec { + /// Type parameters for result operation. + pub fn type_params(&self) -> Vec { match self { Self::Bool | Self::F64 => vec![], Self::Int | Self::UInt => vec![LOG_WIDTH_TYPE_PARAM], @@ -145,7 +147,8 @@ impl ResultOpDef { } } - fn instantiate(&self, args: &[TypeArg]) -> Result { + /// Instantiate the result operation with the given type arguments. + pub fn instantiate(&self, args: &[TypeArg]) -> Result { let parsed_args = concrete_result_op_type_args(args)?; match (parsed_args, self) { @@ -214,23 +217,32 @@ impl MakeOpDef for ResultOpDef { } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)] -enum SimpleArgs { +/// Type arguments to a numeric result operation (not an array). +pub enum SimpleArgs { + /// No type arguments, simple result type. Basic, + /// Integer type argument, specifying bit width. Int(u8), } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)] -enum ResultArgs { +/// Arguments to a "tket2.result" operation. +pub enum ResultArgs { + /// Simple result type, not an array. Simple(SimpleArgs), + /// Argument for array result type, with inner type arguments and array size. Array(SimpleArgs, u64), } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)] /// Concrete instantiation of a "tket2.result" operation. pub struct ResultOp { - tag: String, - result_op: ResultOpDef, - args: ResultArgs, + /// Static string tag for the result. + pub tag: String, + /// The result operation definition. + pub result_op: ResultOpDef, + /// Type arguments for the result operation. + pub args: ResultArgs, } impl ResultOp {