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:
+25
-25
@@ -23,10 +23,10 @@ fn register_constants(env: &Environment) {
|
||||
fn register_arithmetic(env: &Environment) {
|
||||
// --- Add (+) ---
|
||||
let add_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int },
|
||||
Signature { params: vec![StaticType::Float, StaticType::Float], ret: StaticType::Float },
|
||||
Signature { params: vec![StaticType::Text, StaticType::Text], ret: StaticType::Text },
|
||||
Signature { params: vec![StaticType::DateTime, StaticType::Int], ret: StaticType::DateTime },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float, StaticType::Float]), ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Text, StaticType::Text]), ret: StaticType::Text },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::DateTime, StaticType::Int]), ret: StaticType::DateTime },
|
||||
]);
|
||||
env.register_native("+", add_ty, |args| {
|
||||
if args.len() == 2 {
|
||||
@@ -56,12 +56,12 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
// --- Subtract (-) ---
|
||||
let sub_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int },
|
||||
Signature { params: vec![StaticType::Float, StaticType::Float], ret: StaticType::Float },
|
||||
Signature { params: vec![StaticType::Int], ret: StaticType::Int }, // Negation
|
||||
Signature { params: vec![StaticType::Float], ret: StaticType::Float },
|
||||
Signature { params: vec![StaticType::DateTime, StaticType::DateTime], ret: StaticType::Int },
|
||||
Signature { params: vec![StaticType::DateTime, StaticType::Int], ret: StaticType::DateTime },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float, StaticType::Float]), ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int]), ret: StaticType::Int }, // Negation
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float]), ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::DateTime, StaticType::DateTime]), ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::DateTime, StaticType::Int]), ret: StaticType::DateTime },
|
||||
]);
|
||||
env.register_native("-", sub_ty, |args| {
|
||||
if args.is_empty() { return Value::Void; }
|
||||
@@ -98,8 +98,8 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
// --- Multiply (*) ---
|
||||
let mul_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int },
|
||||
Signature { params: vec![StaticType::Float, StaticType::Float], ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float, StaticType::Float]), ret: StaticType::Float },
|
||||
]);
|
||||
env.register_native("*", mul_ty, |args| {
|
||||
if args.len() == 2 {
|
||||
@@ -122,8 +122,8 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
// --- Divide (/) ---
|
||||
let div_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Float },
|
||||
Signature { params: vec![StaticType::Float, StaticType::Float], ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Float },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float, StaticType::Float]), ret: StaticType::Float },
|
||||
]);
|
||||
env.register_native("/", div_ty, |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
@@ -134,7 +134,7 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
// --- Integer Divide (//) ---
|
||||
let int_div_ty = StaticType::Function(Box::new(
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int }
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int }
|
||||
));
|
||||
env.register_native("//", int_div_ty, |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
@@ -150,7 +150,7 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
// --- Modulus (%) ---
|
||||
let mod_ty = StaticType::Function(Box::new(
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int }
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int }
|
||||
));
|
||||
env.register_native("%", mod_ty, |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
@@ -165,9 +165,9 @@ fn register_arithmetic(env: &Environment) {
|
||||
|
||||
fn register_comparison(env: &Environment) {
|
||||
let cmp_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Bool },
|
||||
Signature { params: vec![StaticType::Float, StaticType::Float], ret: StaticType::Bool },
|
||||
Signature { params: vec![StaticType::DateTime, StaticType::DateTime], ret: StaticType::Bool },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Bool },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Float, StaticType::Float]), ret: StaticType::Bool },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::DateTime, StaticType::DateTime]), ret: StaticType::Bool },
|
||||
]);
|
||||
|
||||
// --- Greater Than (>) ---
|
||||
@@ -224,7 +224,7 @@ fn register_comparison(env: &Environment) {
|
||||
|
||||
// --- Equal (=) ---
|
||||
let eq_ty = StaticType::Function(Box::new(
|
||||
Signature { params: vec![StaticType::Any, StaticType::Any], ret: StaticType::Bool }
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Any, StaticType::Any]), ret: StaticType::Bool }
|
||||
));
|
||||
env.register_native("=", eq_ty.clone(), |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
@@ -265,8 +265,8 @@ fn register_comparison(env: &Environment) {
|
||||
fn register_logic(env: &Environment) {
|
||||
// --- Not (not) ---
|
||||
let not_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Bool], ret: StaticType::Bool },
|
||||
Signature { params: vec![StaticType::Int], ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Bool]), ret: StaticType::Bool },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int]), ret: StaticType::Int },
|
||||
]);
|
||||
env.register_native("not", not_ty, |args| {
|
||||
if args.len() != 1 { return Value::Void; }
|
||||
@@ -279,8 +279,8 @@ fn register_logic(env: &Environment) {
|
||||
|
||||
// --- And (and) ---
|
||||
let logic_op_ty = StaticType::FunctionOverloads(vec![
|
||||
Signature { params: vec![StaticType::Bool, StaticType::Bool], ret: StaticType::Bool },
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Bool, StaticType::Bool]), ret: StaticType::Bool },
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int },
|
||||
]);
|
||||
env.register_native("and", logic_op_ty.clone(), |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
@@ -313,7 +313,7 @@ fn register_logic(env: &Environment) {
|
||||
|
||||
// --- Shift Left (<<) ---
|
||||
let shift_ty = StaticType::Function(Box::new(
|
||||
Signature { params: vec![StaticType::Int, StaticType::Int], ret: StaticType::Int }
|
||||
Signature { params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]), ret: StaticType::Int }
|
||||
));
|
||||
env.register_native("<<", shift_ty.clone(), |args| {
|
||||
if args.len() != 2 { return Value::Void; }
|
||||
|
||||
@@ -4,7 +4,7 @@ use chrono::{NaiveDate, NaiveDateTime};
|
||||
|
||||
pub fn register(env: &Environment) {
|
||||
let date_ty = StaticType::Function(Box::new(Signature {
|
||||
params: vec![StaticType::Text],
|
||||
params: StaticType::Tuple(vec![StaticType::Text]),
|
||||
ret: StaticType::DateTime
|
||||
}));
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ impl TypeBuilder {
|
||||
|
||||
pub fn method(mut self, name: &str, params: Vec<StaticType>, ret: StaticType) -> Self {
|
||||
let key = Keyword::intern(name);
|
||||
let sig = StaticType::Function(Box::new(Signature { params, ret }));
|
||||
let sig = StaticType::Function(Box::new(Signature { params: StaticType::Tuple(params), ret }));
|
||||
self.fields.insert(key, sig);
|
||||
self
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user