feat: functions with formal parameters

This commit is contained in:
2025-05-04 15:21:44 +08:00
parent bc50464db9
commit eea4a4ce9f
6 changed files with 53 additions and 10 deletions

View File

@@ -173,4 +173,7 @@ fn test_func() {
test_expr("(x: x) 1", int!(1));
test_expr("(x: x) (x: x) 1", int!(1));
test_expr("(x: y: x + y) 1 1", int!(2));
test_expr("({ x, y }: x + y) { x = 1; y = 2; }", int!(3));
test_expr("({ x, y, ... }: x + y) { x = 1; y = 2; z = 3; }", int!(3));
test_expr("(inputs@{ x, y, ... }: x + inputs.y) { x = 1; y = 2; z = 3; }", int!(3));
}

View File

@@ -111,9 +111,6 @@ impl VM {
OpCode::SetAlias { sym } => {
stack.tos_mut()?.as_mut().unwrap_func().set_alias(sym);
}
OpCode::Ret => {
todo!()
}
OpCode::UnOp { op } => {
use UnOp::*;
let value = stack.pop()?;
@@ -200,7 +197,7 @@ impl VM {
)?;
}
OpCode::EnterEnv => {
env.enter(stack.pop()?.unwrap_attr_set().to_data());
env.enter(stack.pop()?.unwrap_attr_set().into_inner());
}
OpCode::LeaveEnv => {
env.leave();