-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Parser #4
Added Parser #4
Conversation
crates/benda/Cargo.toml
Outdated
indexmap = "2.2.3" | ||
interner = "0.2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments to non-obvious dependencies.
(We are always striving to have fewer dependencies, so it's good to have the non-obvious ones explained)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexMap is used by Bend to store their ADTs and constructor definitions, so I needed to add it to be able to construct a new IndexMap when parsing a new ADT.
crates/benda/src/types/mod.rs
Outdated
impl BendType for PyFloat { | ||
fn to_bend(&self) -> imp::Expr { | ||
let num: f32 = self.extract().unwrap(); | ||
imp::Expr::Num { val: Num::F24(num) } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cast from f32
to F24
is an operation that could fail, so I imagine BendType::to_bend
should actually return a Result akin to std::convert::TryInto.
Actually, the whole type BendType
could be TryInto<Expr>
if it's only method will be to_bend
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about some other methods that could help a type implementation in Benda, I will change the return type to a Result for now.
The BendType is useful for Generics, I'm using it in:
benda/crates/benda/src/types/mod.rs
Lines 18 to 27 in 28e0bdd
pub fn extract_inner<'py, T: BendType + PyTypeCheck + FromPyObject<'py>>( | |
arg: Bound<'py, PyAny>, | |
) -> Option<T> { | |
let inner = arg.downcast::<T>(); | |
if let Ok(inner) = inner { | |
let inner = <T as FromPyObject>::extract_bound(inner.as_any()); | |
return Some(inner.unwrap()); | |
} | |
None | |
} |
Node, | ||
} | ||
|
||
impl From<String> for BuiltinType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used anywhere?
I don't think we should be relying on strings like this in the final version.
(if we can rely on in the identity of the types though the Python API and Python itself is not using strings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll find a way to reference these types in a better way. I don't like this kind of String usage either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types names are not mapped anywhere in pyo3. I will find a better solution when our subset are better defined.
I use this From here:
benda/crates/benda/src/types/mod.rs
Line 48 in 28e0bdd
let arg_type = BuiltinType::from(name.to_string()); |
Added a lot of Python AST Parsing to Bend Books.