This repository was archived by the owner on Aug 18, 2025. It is now read-only.
v0.5.4
[v0.5.4] - 2025-07-30
🎯 Major New Feature: Function Pointer Arrays & Lambda Closures
🚀 Core Features
-
Function Pointer Arrays
- Declaration:
operations : []*fn(int, int) : int; - Initialization:
operations = [add, subtract, multiply, divide]; - Array access:
firstOp = operations[0]; - Direct invocation:
result = operations[0](10, 5); - Lambda arrays:
lambdas = [((a,b)=>a+b), ((a,b)=>a-b)];
- Declaration:
-
Lambda Closures
- Automatic variable capture
- Smart variable analysis
- Multi-variable capture
- Scope priority (parameters > closures)
- Proper closure lifecycle management
-
Compound Expressions
- Array-indexed calls:
array[index](args) - Function pointer call expressions
- Nested expression chains
- Array-indexed calls:
Technical Implementation
- AST Extension: Added
ArrayAccessandFunctionPointerCall - Closure System:
closure_envfield for captured variables - Variable Analysis:
analyze_lambda_variablesmethod - Type Checking: Full array/function pointer type matching
- Expression Parsing: Recursive compound expression parsing
Example Code
// Function pointer array
fn add(a:int, b:int):int { return a+b; };
fn subtract(a:int, b:int):int { return a-b; };
operations : []*fn(int,int):int = [add, subtract];
result1 = operations[0](10,5); // 15
result2 = operations[1](10,5); // 5
// Lambda array
lambdas : []*fn(int,int):int = [
((a,b)=>a+b),
((a,b)=>a*b),
((a,b)=>a*a + b*b)
];
result3 = lambdas[2](3,4); // 25
// Lambda closures
multiplier:int = 3;
base:int = 10;
multiply:*fn(int):int = (x=>x*multiplier);
calculate:*fn(int):int = (x=>x+base+multiplier);
result4 = multiply(5); // 15
result5 = calculate(7); // 20
[v0.5.4] - 2025-07-30
🎯 重大新功能:函数指针数组与Lambda闭包
🚀 核心特性
-
函数指针数组
- 声明:
operations : []*fn(int, int) : int; - 初始化:
operations = [add, subtract, multiply, divide]; - 数组访问:
firstOp = operations[0]; - 直接调用:
result = operations[0](10, 5); - Lambda数组:
lambdas = [((a,b)=>a+b), ((a,b)=>a-b)];
- 声明:
-
Lambda闭包
- 自动变量捕获
- 智能变量分析
- 多变量捕获
- 作用域优先级(参数 > 闭包)
- 正确的闭包生命周期管理
-
复合表达式
- 数组索引调用:
array[index](args) - 函数指针调用表达式
- 嵌套表达式链
- 数组索引调用:
技术实现
- AST扩展:新增
ArrayAccess和FunctionPointerCall - 闭包系统:
closure_env存储捕获变量 - 变量分析:
analyze_lambda_variables方法 - 类型检查:完整数组/函数指针类型匹配
- 表达式解析:递归复合表达式解析
示例代码
// 函数指针数组
fn add(a:int, b:int):int { return a+b; };
fn subtract(a:int, b:int):int { return a-b; };
operations : []*fn(int,int):int = [add, subtract];
result1 = operations[0](10,5); // 15
result2 = operations[1](10,5); // 5
// Lambda数组
lambdas : []*fn(int,int):int = [
((a,b)=>a+b),
((a,b)=>a*b),
((a,b)=>a*a + b*b)
];
result3 = lambdas[2](3,4); // 25
// Lambda闭包
multiplier:int = 3;
base:int = 10;
multiply:*fn(int):int = (x=>x*multiplier);
calculate:*fn(int):int = (x=>x+base+multiplier);
result4 = multiply(5); // 15
result5 = calculate(7); // 20
Full Changelog: CodeNothingCommunity/CodeNothing@v0.5.3...v0.5.4