Skip to content

Commit 93ee945

Browse files
committed
Add Python bindings for hugr-model.
1 parent 6bd7665 commit 93ee945

30 files changed

+1815
-16
lines changed

Cargo.lock

+108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"hugr-cli",
1111
"hugr-model",
1212
"hugr-llvm",
13+
"hugr-py",
1314
]
1415
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]
1516

@@ -84,6 +85,7 @@ pest_derive = "2.7.12"
8485
pretty = "0.12.4"
8586
pretty_assertions = "1.4.1"
8687
zstd = "0.13.2"
88+
pyo3 = "0.23.4"
8789

8890
[profile.dev.package]
8991
insta.opt-level = 3

hugr-core/src/std_extensions/arithmetic/float_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl std::ops::Deref for ConstF64 {
6666
impl ConstF64 {
6767
/// Name of the constructor for creating constant 64bit floats.
6868
#[cfg_attr(not(feature = "model_unstable"), allow(dead_code))]
69-
pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const-f64";
69+
pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const_f64";
7070

7171
/// Create a new [`ConstF64`]
7272
pub fn new(value: f64) -> Self {

hugr-core/tests/model.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44

55
use hugr::std_extensions::std_reg;
66
use hugr_core::{export::export_hugr, import::import_hugr};
7-
use hugr_model::v0 as model;
7+
use hugr_model::v0::{self as model};
88

99
fn roundtrip(source: &str) -> String {
1010
let bump = model::bumpalo::Bump::new();

hugr-core/tests/snapshots/model__roundtrip_const.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
1212

1313
(import arithmetic.int.const)
1414

15+
(import arithmetic.float.const_f64)
16+
1517
(import core.const.adt)
1618

1719
(import arithmetic.int.types.int)
@@ -24,8 +26,6 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
2426

2527
(import core.adt)
2628

27-
(import arithmetic.float.const-f64)
28-
2929
(define-func
3030
example.bools
3131
(core.fn [] [(core.adt [[] []]) (core.adt [[] []])] (ext))
@@ -69,7 +69,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
6969
(arithmetic.int.const 6 3)
7070
(arithmetic.int.const 6 4)
7171
(arithmetic.int.const 6 5)])
72-
(arithmetic.float.const-f64 -3.0)]))
72+
(arithmetic.float.const_f64 -3.0)]))
7373
[] [%0]
7474
(signature
7575
(core.fn
@@ -88,7 +88,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
8888
[]
8989
[arithmetic.float.types.float64 arithmetic.float.types.float64]
9090
(ext)))
91-
((core.load_const _ _ (arithmetic.float.const-f64 1.0)) [] [%0]
91+
((core.load_const _ _ (arithmetic.float.const_f64 1.0)) [] [%0]
9292
(signature (core.fn [] [arithmetic.float.types.float64] (ext))))
9393
((core.load_const
9494
_

hugr-model/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pest_derive = { workspace = true }
2929
pretty = { workspace = true }
3030
smol_str = { workspace = true, features = ["serde"] }
3131
thiserror.workspace = true
32+
pyo3 = { workspace = true, optional = true }
3233

3334
[lints]
3435
workspace = true

hugr-model/src/v0/ast/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use super::{LinkName, Literal, RegionKind, SymbolName, VarName};
2929

3030
mod parse;
3131
mod print;
32+
#[cfg(feature = "pyo3")]
33+
mod python;
3234
mod resolve;
3335
mod view;
3436

hugr-model/src/v0/ast/parse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,4 @@ impl_from_str!(Param, param, parse_param);
444444
impl_from_str!(Module, module, parse_module);
445445
impl_from_str!(SeqPart, part, parse_seq_part);
446446
impl_from_str!(Literal, literal, parse_literal);
447+
impl_from_str!(Symbol, symbol, parse_symbol);

hugr-model/src/v0/ast/print.rs

+1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl_display!(Param, print_param);
426426
impl_display!(Term, print_term);
427427
impl_display!(SeqPart, print_seq_part);
428428
impl_display!(Literal, print_literal);
429+
impl_display!(Symbol, print_symbol);
429430

430431
impl Display for VarName {
431432
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

0 commit comments

Comments
 (0)