Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

v0.5.3

Choose a tag to compare

@HelloAIXIAOJI HelloAIXIAOJI released this 29 Jul 15:00
· 775 commits to master since this release

[v0.5.3] - 2025-07-29

🎯 Major New Feature: Complete Function Pointers & Lambda Functions

🚀 Core Features

  • Full Function Pointer Support

    • Declaration: mathFunc : *fn(int, int) : int;
    • Assignment: mathFunc = addNumbers;
    • Invocation: result = mathFunc(10, 5);
    • Optional: optFunc : ?*fn(int) : string;
  • Complete Lambda Implementation

    • Lambda syntax: (x => x + 1), ((a, b) => a + b)
    • Typed lambdas: ((a : int, b : int) => a + b)
    • Lambda function pointer creation/calling
    • Lambda parameter binding/execution
  • Function Pointer Methods

    • toString() - String representation
    • getName() - Function name
    • getParamCount() - Parameter count
    • getReturnType() - Return type
    • isNull() - Null check
    • isLambda() - Lambda check
  • Higher-Order Functions

    • Passing/returning function pointers
    • Runtime function selection
    • Complex invocations (locals, conditionals)
    • Recursive calls

Technical Implementation

  • AST Extension: Added FunctionPointer/LambdaFunctionPointer
  • Type System: Full type checking/matching
  • Parser: Supports *fn(params...) : return_type and lambda syntax
  • Runtime: Real function/lambda calling
  • Environment: Proper scope/local variable handling

Example Code

// Function definition
fn add(a : int, b : int) : int {
    return a + b;
};

// Function pointer
mathFunc : *fn(int, int) : int = add;
result1 : int = mathFunc(10, 5); // 15

// Lambda
square : *fn(int) : int = (x => x * x);
result2 : int = square(7); // 49

// Multi-param lambda
power : *fn(int, int) : int = ((base, exp) => base * base * exp);
result3 : int = power(3, 2); // 18

// Higher-order function
fn calculate(a : int, b : int, op : *fn(int, int) : int) : int {
    return op(a, b);
};

result4 : int = calculate(10, 5, add); // 15
result5 : int = calculate(10, 5, ((a, b) => a - b)); // 5

[v0.5.3] - 2025-07-29

🎯 重大新功能:函数指针与Lambda函数完整实现

🚀 核心特性

  • 完整函数指针支持

    • 声明:mathFunc : *fn(int, int) : int;
    • 赋值:mathFunc = addNumbers;
    • 调用:result = mathFunc(10, 5);
    • 可选:optFunc : ?*fn(int) : string;
  • Lambda函数实现

    • Lambda语法:(x => x + 1), ((a, b) => a + b)
    • 类型注解:((a : int, b : int) => a + b)
    • Lambda函数指针创建/调用
    • 参数绑定/执行
  • 函数指针方法

    • toString() - 字符串表示
    • getName() - 函数名
    • getParamCount() - 参数数量
    • getReturnType() - 返回类型
    • isNull() - 空检查
    • isLambda() - Lambda检查
  • 高阶函数

    • 传递/返回函数指针
    • 运行时函数选择
    • 复杂调用(局部变量/条件语句)
    • 递归调用

技术实现

  • AST扩展:新增FunctionPointer/LambdaFunctionPointer
  • 类型系统:完整类型检查/匹配
  • 解析器:支持*fn(参数...) : 返回类型和Lambda语法
  • 运行时:真实函数/Lambda调用机制
  • 环境管理:正确作用域/局部变量处理

示例代码

// 函数定义
fn add(a : int, b : int) : int {
    return a + b;
};

// 函数指针
mathFunc : *fn(int, int) : int = add;
result1 : int = mathFunc(10, 5); // 15

// Lambda函数
square : *fn(int) : int = (x => x * x);
result2 : int = square(7); // 49

// 多参数Lambda
power : *fn(int, int) : int = ((base, exp) => base * base * exp);
result3 : int = power(3, 2); // 18

// 高阶函数
fn calculate(a : int, b : int, op : *fn(int, int) : int) : int {
    return op(a, b);
};

result4 : int = calculate(10, 5, add); // 15
result5 : int = calculate(10, 5, ((a, b) => a - b)); // 5

Full Changelog: CodeNothingCommunity/CodeNothing@v0.5.2...v0.5.3