fix pyo3
bendn 5 weeks ago
parent 846537c · commit d7eb7ad
-rw-r--r--Cargo.lock185
-rw-r--r--Cargo.toml17
-rw-r--r--src/exec.rs34
-rw-r--r--src/exec/python.rs24
-rw-r--r--src/lexer.rs4
-rw-r--r--src/main.rs3
6 files changed, 138 insertions, 129 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9b837f9..6725666 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,9 +4,9 @@ version = 4
[[package]]
name = "aho-corasick"
-version = "1.1.3"
+version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
+checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
dependencies = [
"memchr",
]
@@ -44,24 +44,12 @@ dependencies = [
]
[[package]]
-name = "autocfg"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
-
-[[package]]
name = "beef"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
[[package]]
-name = "cfg-if"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-
-[[package]]
name = "chumsky"
version = "1.0.0-alpha.8"
source = "git+https://github.com/zesterer/chumsky#d12869af1701647e0f0034aef1cce14fa2e170be"
@@ -73,9 +61,10 @@ dependencies = [
[[package]]
name = "codespan-reporting"
-version = "0.11.1"
-source = "git+https://github.com/brendanzab/codespan#4d7189e36bc2e6f6093a474395e8f7c7607d9a4b"
+version = "0.13.1"
+source = "git+https://github.com/brendanzab/codespan#b56329354ce0ecbe4afe7c85f7b76417678a5ef8"
dependencies = [
+ "serde",
"termcolor",
"unicode-width",
]
@@ -88,7 +77,7 @@ checksum = "f24f01cb5d7f027b65718cfab34b16ae783a3290d9b16e15d7e4310e0c24c173"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.99",
+ "syn 2.0.119",
]
[[package]]
@@ -133,12 +122,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
-name = "indoc"
-version = "2.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
-
-[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -191,18 +174,18 @@ checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
[[package]]
name = "logos"
-version = "0.15.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab6f536c1af4c7cc81edf73da1f8029896e7e1e16a219ef09b184e76a296f3db"
+checksum = "ff472f899b4ec2d99161c51f60ff7075eeb3097069a36050d8037a6325eb8154"
dependencies = [
"logos-derive",
]
[[package]]
name = "logos-codegen"
-version = "0.15.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "189bbfd0b61330abea797e5e9276408f2edbe4f822d7ad08685d67419aafb34e"
+checksum = "192a3a2b90b0c05b27a0b2c43eecdb7c415e29243acc3f89cc8247a5b693045c"
dependencies = [
"beef",
"fnv",
@@ -211,23 +194,23 @@ dependencies = [
"quote",
"regex-syntax",
"rustc_version",
- "syn 2.0.99",
+ "syn 2.0.119",
]
[[package]]
name = "logos-derive"
-version = "0.15.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ebfe8e1a19049ddbfccbd14ac834b215e11b85b90bab0c2dba7c7b92fb5d5cba"
+checksum = "605d9697bcd5ef3a42d38efc51541aa3d6a4a25f7ab6d1ed0da5ac632a26b470"
dependencies = [
"logos-codegen",
]
[[package]]
name = "match_deref"
-version = "0.1.1"
+version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30dd27efba9ccf9069f76ff0b7b65eb293a844d9918e15a36098de609c9aacd7"
+checksum = "6653e44fdfe194f0276ecec9460aff0dfbe621f87097984d1816bd62ec626a53"
dependencies = [
"proc-macro2",
"quote",
@@ -236,30 +219,21 @@ dependencies = [
[[package]]
name = "memchr"
-version = "2.7.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
-
-[[package]]
-name = "memoffset"
-version = "0.9.1"
+version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
-dependencies = [
- "autocfg",
-]
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "once_cell"
-version = "1.20.3"
+version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "paste"
-version = "1.0.14"
+version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
+checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "portable-atomic"
@@ -269,46 +243,41 @@ checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "proc-macro2"
-version = "1.0.94"
+version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "pyo3"
-version = "0.23.5"
+version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
+checksum = "4688ddedf473e32662b9b067670129a8afb8c18e351482c70d62ba4a88171e8b"
dependencies = [
- "cfg-if",
- "indoc",
"libc",
- "memoffset",
"once_cell",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
- "unindent",
]
[[package]]
name = "pyo3-build-config"
-version = "0.23.5"
+version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
+checksum = "f41027e41b4bd03f6e60f9f417fe24a6341a6bb744edd62b6f709f2a52ea30e9"
dependencies = [
- "once_cell",
"target-lexicon",
]
[[package]]
name = "pyo3-ffi"
-version = "0.23.5"
+version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
+checksum = "e591a95526fead067432c3b3a33fc74770b87b1e04e73671090d9c2055a2b327"
dependencies = [
"libc",
"pyo3-build-config",
@@ -316,43 +285,42 @@ dependencies = [
[[package]]
name = "pyo3-macros"
-version = "0.23.5"
+version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
+checksum = "73225868fc1cd84eef2c3c230ddb91273bf1de46aeb8a4248da76d32a0924a1c"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
- "syn 2.0.99",
+ "syn 2.0.119",
]
[[package]]
name = "pyo3-macros-backend"
-version = "0.23.5"
+version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
+checksum = "571575aa3749fa6216757dd47d2a3e7ef360f329a40f0666a9fbd14889024952"
dependencies = [
"heck",
"proc-macro2",
- "pyo3-build-config",
"quote",
- "syn 2.0.99",
+ "syn 2.0.119",
]
[[package]]
name = "quote"
-version = "1.0.35"
+version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
-version = "1.11.1"
+version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
+checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
dependencies = [
"aho-corasick",
"memchr",
@@ -362,9 +330,9 @@ dependencies = [
[[package]]
name = "regex-automata"
-version = "0.4.9"
+version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
+checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
dependencies = [
"aho-corasick",
"memchr",
@@ -373,9 +341,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
-version = "0.8.5"
+version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
+checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
[[package]]
name = "rustc_version"
@@ -388,9 +356,39 @@ dependencies = [
[[package]]
name = "semver"
-version = "1.0.25"
+version = "1.0.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
+
+[[package]]
+name = "serde"
+version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.3",
+]
[[package]]
name = "syn"
@@ -405,9 +403,20 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.99"
+version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2"
+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "3.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
"proc-macro2",
"quote",
@@ -416,9 +425,9 @@ dependencies = [
[[package]]
name = "target-lexicon"
-version = "0.12.16"
+version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
+checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
[[package]]
name = "termcolor"
@@ -431,9 +440,9 @@ dependencies = [
[[package]]
name = "tinyvec"
-version = "1.6.0"
+version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
+checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f"
dependencies = [
"tinyvec_macros",
]
@@ -452,9 +461,9 @@ checksum = "42f74eb7957e3a63fa27bfa53c3d361e7ce3871e66f2518292a011eb8e2c00cc"
[[package]]
name = "unicode-ident"
-version = "1.0.12"
+version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-segmentation"
@@ -469,12 +478,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
-name = "unindent"
-version = "0.2.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
-
-[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8a7cc97..3a5a30d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,18 +6,19 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-chumsky = { git = "https://github.com/zesterer/chumsky", version = "1.0.0-alpha.8", features = [
+chumsky = { git = "https://github.com/zesterer/chumsky",version = "1.0.0-alpha.8", hash="d12869af1701647e0f0034aef1cce14fa2e170be", features = [
"nightly",
], default-features = false }
beef = "0.5.2"
-logos = "0.15.0"
-tinyvec = { version = "1.6.0", features = ["alloc"] }
+logos = "0.15.1"
+tinyvec = { version = "1.12.0", features = ["alloc"] }
comat = "0.1.3"
lerr = "0.1.5"
-match_deref = "0.1.1"
-paste = "1.0.14"
-regex = "1.11.1"
+match_deref = "0.1.2"
+paste = "1.0.15"
+regex = "1.13.1"
itertools = "0.14.0"
-codespan-reporting = { git = "https://github.com/brendanzab/codespan", version = "0.11.1" }
+codespan-reporting = { git = "https://github.com/brendanzab/codespan", version = "0.13.1" }
umath = "0.0.7"
-pyo3 = "0.23.5"
+pyo3 = "0.29.2"
+
diff --git a/src/exec.rs b/src/exec.rs
index 539d481..251b218 100644
--- a/src/exec.rs
+++ b/src/exec.rs
@@ -497,14 +497,17 @@ impl Error {
notes: vec![],
}
}
-
+ #[track_caller]
pub fn ef(
span: Span,
expected: impl Display,
found: Spanned<impl Display>,
) -> Self {
Error {
- name: "type mismatch".to_string(),
+ name: format!(
+ "type mismatch @ {:?}",
+ std::panic::Location::caller()
+ ),
labels: vec![
format!("found {found}, not an {expected}")
.spun(found.span()),
@@ -701,18 +704,19 @@ fn pervasive_binop<'a>(
b: &Spanned<Val<'a>>,
map: impl Fn(&Val<'a>, &Val<'a>) -> Result<Val<'a>> + Copy,
) -> Result<Val<'a>> {
+ // dbg!(a, b);
match (&a.inner, &b.inner) {
(Val::Array(x), Val::Array(y)) => {
- if x.len() != y.len() {
- return Err(Error {
- name: "argument length mismatch".to_string(),
- message: "for this function".to_string().spun(span),
- labels: vec![],
- notes: vec![],
- }
- .label("first argument".spun(a.span))
- .label("second argument".spun(b.span)));
- }
+ // if x.len() != y.len() {
+ // return Err(Error {
+ // name: "argument length mismatch".to_string(),
+ // message: "for this function".to_string().spun(span),
+ // labels: vec![],
+ // notes: vec![],
+ // }
+ // .label("first argument".spun(a.span))
+ // .label("second argument".spun(b.span)));
+ // }
if x.ty() != y.ty() {
return Err(Error {
name: "array type mismatch".to_string(),
@@ -758,7 +762,11 @@ fn pervasive_binop<'a>(
.collect::<Result<_>>()
.and_then(|x| Array::new(span, x))
.map(Val::Array),
- (x, y) => map(x, y),
+ // (x, Val::Array(x)) if x.len() == 1 => map(x, y),
+ (x, y) => {
+ // println!("{x:?} {y:?}");
+ map(x, y)
+ }
}
}
diff --git a/src/exec/python.rs b/src/exec/python.rs
index 5001584..6690fa6 100644
--- a/src/exec/python.rs
+++ b/src/exec/python.rs
@@ -44,25 +44,27 @@ impl<'s, 'py> IntoPyObject<'py> for Val<'s> {
}
}
-impl<'py, 's> FromPyObject<'py> for Val<'s> {
- fn extract_bound(x: &Bound<'py, PyAny>) -> PyResult<Self> {
+impl<'a, 'py, 's> FromPyObject<'a, 'py> for Val<'s> {
+ type Error = PyErr;
+ fn extract(x: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
Ok(match () {
() if let Ok(x) = x.extract::<i128>() => Val::Int(x),
() if let Ok(x) = x.extract::<f64>() => Val::Float(x),
() if let Ok(x) = x.extract::<bool>() => Val::Int(x as i128),
- () if let Ok(x) = x.downcast::<PyList>() => {
+ () if let Ok(x) = x.cast::<PyList>() => {
if let Ok(y) = x.get_item(0) {
match () {
() if y.is_instance_of::<PyFloat>() => {
Val::Array(Array::Float(
- x.into_iter()
+ x.clone()
+ .iter()
.map(|x| x.extract::<f64>())
.try_collect()?,
))
}
() if y.is_instance_of::<PyInt>() => {
Val::Array(Array::Int(
- x.into_iter()
+ x.iter()
.map(|x| x.extract::<i128>())
.try_collect()?,
))
@@ -77,10 +79,8 @@ impl<'py, 's> FromPyObject<'py> for Val<'s> {
Val::Array(Array::Int(vec![]))
}
}
- () if let Ok(x) = x.downcast::<PySet>() => Val::Set(
- x.into_iter()
- .map(|x| x.extract::<Val<'s>>())
- .try_collect()?,
+ () if let Ok(x) = x.cast::<PySet>() => Val::Set(
+ x.iter().map(|x| x.extract::<Val<'s>>()).try_collect()?,
),
_ => return Err(PyTypeError::new_err("bad types")),
})
@@ -94,8 +94,8 @@ pub fn exec<'s>(
argc: super::Argc,
context: &Context<'s, '_>,
) -> super::Result<()> {
- pyo3::prepare_freethreaded_python();
- Python::with_gil(|g| {
+ Python::initialize();
+ Python::attach(|g| {
let locals = PyDict::new(g);
context
.all()
@@ -125,7 +125,7 @@ pub fn exec<'s>(
Error::lazy(code.span, "you wrote your 🐍 (󰌠 python) wrong")
})?;
let x = locals.get_item("s").unwrap().unwrap();
- let x = x.downcast::<PyList>().unwrap();
+ let x = x.cast::<PyList>().unwrap();
let n = x.len();
stack.extend(
x.into_iter()
diff --git a/src/lexer.rs b/src/lexer.rs
index eda21b3..06d18a1 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -129,7 +129,7 @@ tokens! {
"🐍" => Python,
}
-pub fn lex(s: &str) -> Lexer {
+pub fn lex(s: &str) -> Lexer<'_> {
Lexer {
inner: Token::lexer(s).spanned(),
}
@@ -158,7 +158,7 @@ impl<'s> Iterator for Lexer<'s> {
#[test]
fn lexer() {
- let mut lex = lex(r#""1abc25hriwm4"
+ let lex = lex(r#""1abc25hriwm4"
/ { str → int } /
line ← λ (
'0'>🔎'9'<🔎
diff --git a/src/main.rs b/src/main.rs
index e67dc7c..bae9eca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,4 @@
#![feature(
- let_chains,
- try_trait_v2,
- if_let_guard,
iter_intersperse,
iterator_try_reduce,
formatting_options,