Refactor lambda binding and parameter handling
Introduce `BoundKind::Parameter` to represent function parameters. Modify `Binder` to correctly handle parameters within lambda definitions, ensuring they are only defined within function scopes. Update `LambdaCollector` to register the body of lambdas as templates for global definitions. Adjust `Dumper` to accurately represent lambda parameters. Update `Specializer` and `TCO` to handle the new `BoundKind::Parameter`. Refactor `Call` and `TailCall` to use a single `args` node, often a tuple. Adjust type signatures in RTL to use `StaticType::Tuple` for function parameters.
This commit is contained in:
+6
-18
@@ -75,7 +75,7 @@ pub enum Value {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Signature {
|
||||
pub params: Vec<StaticType>,
|
||||
pub params: StaticType,
|
||||
pub ret: StaticType,
|
||||
}
|
||||
|
||||
@@ -137,12 +137,7 @@ impl fmt::Display for StaticType {
|
||||
write!(f, "}}")
|
||||
},
|
||||
StaticType::Function(sig) => {
|
||||
write!(f, "fn(")?;
|
||||
for (i, p) in sig.params.iter().enumerate() {
|
||||
if i > 0 { write!(f, " ")?; }
|
||||
write!(f, "{}", p)?;
|
||||
}
|
||||
write!(f, ") -> {}", sig.ret)
|
||||
write!(f, "fn({}) -> {}", sig.params, sig.ret)
|
||||
},
|
||||
StaticType::FunctionOverloads(sigs) => {
|
||||
write!(f, "overloads({} variants)", sigs.len())
|
||||
@@ -180,12 +175,12 @@ impl StaticType {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to resolve a call with the given argument types and returns the return type.
|
||||
pub fn resolve_call(&self, arg_types: &[StaticType]) -> Option<StaticType> {
|
||||
/// Tries to resolve a call with the given argument type (usually a Tuple) and returns the return type.
|
||||
pub fn resolve_call(&self, args_ty: &StaticType) -> Option<StaticType> {
|
||||
match self {
|
||||
StaticType::Any => Some(StaticType::Any),
|
||||
StaticType::Function(sig) => {
|
||||
if self.match_params(&sig.params, arg_types) {
|
||||
if sig.params.is_assignable_from(args_ty) {
|
||||
Some(sig.ret.clone())
|
||||
} else {
|
||||
None
|
||||
@@ -193,20 +188,13 @@ impl StaticType {
|
||||
}
|
||||
StaticType::FunctionOverloads(sigs) => {
|
||||
sigs.iter()
|
||||
.find(|sig| self.match_params(&sig.params, arg_types))
|
||||
.find(|sig| sig.params.is_assignable_from(args_ty))
|
||||
.map(|sig| sig.ret.clone())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn match_params(&self, expected: &[StaticType], actual: &[StaticType]) -> bool {
|
||||
if expected.len() != actual.len() {
|
||||
return false;
|
||||
}
|
||||
expected.iter().zip(actual).all(|(e, a)| e.is_assignable_from(a))
|
||||
}
|
||||
|
||||
/// Returns true if this type and all its recursive elements are scalars (Int, Float, etc.)
|
||||
pub fn is_scalar_pure(&self) -> bool {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user