This repository was archived by the owner on Aug 18, 2025. It is now read-only.
v0.5.2
[v0.5.2] - 2025-07-28
🎯 Major New Feature: Complete Function Pointer Implementation
🚀 Core Features
-
Full function pointer syntax support
- Declaration:
mathFunc : *fn(int, int) : int; - Assignment:
mathFunc = addNumbers; - Invocation:
result = mathFunc(10, 5); - Optional:
optFunc : ?*fn(int) : string;
- Declaration:
-
Function pointer methods
toString()- String representationgetName()- Function namegetParamCount()- Parameter countgetReturnType()- Return typeisNull()- Null checkisLambda()- Lambda check
-
Higher-order function support
- Passing function pointers as arguments
- Returning function pointers
- Runtime function selection/invocation
Technical Implementation
- AST Extension: Added
FunctionPointertype and expressions - Type System: Full type checking/matching
- Syntax Parsing: Supports
*fn(params...) : return_typesyntax - Runtime Invocation: Real function pointer calling mechanism
- Memory Management: Creation, assignment and destruction
Example Code
// Function definitions
fn add(a : int, b : int) : int {
return a + b;
};
fn multiply(a : int, b : int) : int {
return a * b;
};
// Function pointer usage
mathFunc : *fn(int, int) : int = add;
result1 : int = mathFunc(10, 5); // 15
mathFunc = multiply;
result2 : int = mathFunc(10, 5); // 50
// Higher-order function
fn calculate(a : int, b : int, op : *fn(int, int) : int) : int {
return op(a, b);
};
result3 : int = calculate(10, 5, add); // 15
[v0.5.2] - 2025-07-28
🎯 重大新功能:函数指针完整实现
🚀 核心特性
-
完整的函数指针语法支持
- 声明:
mathFunc : *fn(int, int) : int; - 赋值:
mathFunc = addNumbers; - 调用:
result = mathFunc(10, 5); - 可选:
optFunc : ?*fn(int) : string;
- 声明:
-
函数指针方法
toString()- 字符串表示getName()- 函数名getParamCount()- 参数数量getReturnType()- 返回类型isNull()- 空检查isLambda()- Lambda检查
-
高阶函数支持
- 函数指针作为参数传递
- 返回函数指针
- 运行时函数选择/调用
技术实现
- AST扩展:新增
FunctionPointer类型和表达式 - 类型系统:完整类型检查/匹配
- 语法解析:支持
*fn(参数...) : 返回类型语法 - 运行时调用:真实函数指针调用机制
- 内存管理:创建、赋值和销毁
示例代码
// 函数定义
fn add(a : int, b : int) : int {
return a + b;
};
fn multiply(a : int, b : int) : int {
return a * b;
};
// 函数指针使用
mathFunc : *fn(int, int) : int = add;
result1 : int = mathFunc(10, 5); // 15
mathFunc = multiply;
result2 : int = mathFunc(10, 5); // 50
// 高阶函数
fn calculate(a : int, b : int, op : *fn(int, int) : int) : int {
return op(a, b);
};
result3 : int = calculate(10, 5, add); // 15
Full Changelog: CodeNothingCommunity/CodeNothing@v0.5.1...v0.5.2