diff --git a/hugr-cli/src/extensions.rs b/hugr-cli/src/extensions.rs index 757dba21f..8370e5648 100644 --- a/hugr-cli/src/extensions.rs +++ b/hugr-cli/src/extensions.rs @@ -27,7 +27,7 @@ impl ExtArgs { pub fn run_dump(&self) { let base_dir = &self.outdir; - for (name, ext) in hugr_core::std_extensions::std_reg().into_iter() { + for (name, ext) in hugr_core::std_extensions::STD_REG.iter() { let mut path = base_dir.clone(); for part in name.split('.') { path.push(part); diff --git a/hugr-cli/src/validate.rs b/hugr-cli/src/validate.rs index b603365fe..2e226fb08 100644 --- a/hugr-cli/src/validate.rs +++ b/hugr-cli/src/validate.rs @@ -57,7 +57,7 @@ impl HugrArgs { let mut reg: ExtensionRegistry = if self.no_std { hugr_core::extension::PRELUDE_REGISTRY.to_owned() } else { - hugr_core::std_extensions::std_reg() + hugr_core::std_extensions::STD_REG.to_owned() }; // register packed extensions diff --git a/hugr-core/src/std_extensions.rs b/hugr-core/src/std_extensions.rs index 8ce690674..a6738ddff 100644 --- a/hugr-core/src/std_extensions.rs +++ b/hugr-core/src/std_extensions.rs @@ -18,8 +18,14 @@ pub fn std_reg() -> ExtensionRegistry { arithmetic::conversions::EXTENSION.to_owned(), arithmetic::float_ops::EXTENSION.to_owned(), arithmetic::float_types::EXTENSION.to_owned(), + collections::EXTENSION.to_owned(), logic::EXTENSION.to_owned(), ptr::EXTENSION.to_owned(), ]) .unwrap() } + +lazy_static::lazy_static! { + /// Standard extension registry. + pub static ref STD_REG: ExtensionRegistry = std_reg(); +} diff --git a/hugr-core/src/std_extensions/collections.rs b/hugr-core/src/std_extensions/collections.rs index 3c4677f5c..480780496 100644 --- a/hugr-core/src/std_extensions/collections.rs +++ b/hugr-core/src/std_extensions/collections.rs @@ -30,7 +30,7 @@ pub const POP_NAME: OpName = OpName::new_inline("pop"); /// Push operation name. pub const PUSH_NAME: OpName = OpName::new_inline("push"); /// Reported unique name of the extension -pub const EXTENSION_NAME: ExtensionId = ExtensionId::new_unchecked("Collections"); +pub const EXTENSION_NAME: ExtensionId = ExtensionId::new_unchecked("collections"); /// Extension version. pub const VERSION: semver::Version = semver::Version::new(0, 1, 0); diff --git a/specification/std_extensions/collections.json b/specification/std_extensions/collections.json new file mode 100644 index 000000000..6263c2074 --- /dev/null +++ b/specification/std_extensions/collections.json @@ -0,0 +1,143 @@ +{ + "version": "0.1.0", + "name": "collections", + "extension_reqs": [], + "types": { + "List": { + "extension": "collections", + "name": "List", + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "description": "Generic dynamically sized list of type T.", + "bound": { + "b": "FromParams", + "indices": [ + 0 + ] + } + } + }, + "values": {}, + "operations": { + "pop": { + "extension": "collections", + "name": "pop", + "description": "Pop from back of list", + "signature": { + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "collections", + "id": "List", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "collections", + "id": "List", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + }, + { + "t": "V", + "i": 0, + "b": "A" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "push": { + "extension": "collections", + "name": "push", + "description": "Push to back of list", + "signature": { + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "collections", + "id": "List", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + }, + { + "t": "V", + "i": 0, + "b": "A" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "collections", + "id": "List", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "extension_reqs": [] + } + }, + "binary": false + } + } +}