This repository was archived by the owner on Aug 18, 2025. It is now read-only.
v0.4.3
CodeNothing Programming Language Interpreter v0.4.3 Changelog
[v0.4.3] - 2025-07-25
🚀 Major Feature: Switch Pattern Matching Expansion
- Range Matching: Added
case 1..10syntax- Integer ranges:
case 1..100 - Float ranges:
case 0.0..1.0 - Mixed-type range comparisons
- Integer ranges:
- Guard Conditions: Added
case x if conditionsyntax- Variable binding:
case x if x > 0 - Complex conditions:
case x if x % 2 == 0 && x < 100 - Dynamic condition evaluation
- Variable binding:
- Switch Expressions: Added value-returning switch expressions
- Expression syntax:
case value => expression - Auto-break mechanism
- Fully compatible with existing statement form
- Expression syntax:
✨ Syntax Enhancements
- Pattern Matching System: New
CasePatternenum supporting multiple patternsValue(Expression): Traditional value matchingRange(start, end): Range matchingGuard(var, condition): Guard condition matchingDestructure(pattern): Destructuring matching (reserved interface)
- Mixed Syntax Support: Different patterns can be mixed in single switch
- Type Safety: Strong type checking ensures pattern consistency
🔧 Technical Implementation
- AST Extension: Added
CasePattern,SwitchType,DestructurePattern - Parser Enhancement: Intelligent pattern recognition
- Auto-detection of range operator
.. - Guard condition
ifkeyword recognition - Expression form
=>operator support
- Auto-detection of range operator
- Interpreter Optimization: Efficient pattern matching algorithm
- Range check optimization
- Guard condition variable binding
- Expression evaluation caching
📝 Syntax Examples
// Range matching
switch (score) {
case 90..100 => "Excellent",
case 80..89 => "Good",
default => "Needs improvement"
};
// Guard conditions
switch (value) {
case x if x % 2 == 0 => "Even",
case x if x > 100 => "Large number",
default => "Other"
};
// Switch expression (reserved feature)
grade : string = switch (score) {
case 90..100 => "A",
case 80..89 => "B",
default => "F"
};
🎯 Compatibility
- Fully Backward Compatible: Existing switch statements unchanged
- Gradual Adoption: New features can be adopted progressively
- Performance Optimized: No impact on existing code performance
🧪 Test Coverage
- Basic Tests: Core pattern matching verification
- Complex Tests: Nested/mixed patterns and edge cases
- Practical Tests: Real-world scenario simulations
🔧 Critical Fix: using file Statement Optimization
-
Smart Preprocessing: Complete file import mechanism redesign
- Recursive import support
- Intelligent path resolution
- Cycle detection
- File caching optimization
-
Preprocessing Stage Handling: Major architectural improvement
- Direct file content merging
- Zero runtime overhead
- Clear import markers
- Simplified AST
-
Enhanced Error Handling: Better developer experience
- Detailed error messages
- Early error detection
- Clear cycle import warnings
-
Seamless Switch Integration:
// patterns.cn fn isEven(x : int) : bool { return x % 2 == 0; } const SMALL_RANGE : int = 10; // main.cn using file "patterns.cn"; switch (value) { case 1..SMALL_RANGE => "Small range", case x if isEven(x) => "Even", default => "Other" }
🚀 Modular Development Support
- Pattern Libraries: Reusable pattern matching libraries
- Constant Library Import: Constants for range matching
- Function Library Integration: Guard conditions using imported functions
- Large Project Support: Modular development capabilities
📈 Performance Optimization
- Preprocessing Optimization: File imports handled at compile-time
- Smart Caching: Files processed only once
- Memory Optimization: Reduced runtime memory usage
🔧 Critical Fix: Relative Path Resolution
CodeNothing 编程语言解释器 v0.4.3 更新日志
[v0.4.3] - 2025-07-25
🚀 重大新功能:Switch 模式匹配扩展
- 范围匹配支持: 新增
case 1..10语法- 整数范围:
case 1..100 - 浮点数范围:
case 0.0..1.0 - 混合类型范围比较
- 整数范围:
- Guard 条件支持: 新增
case x if condition语法- 变量绑定:
case x if x > 0 - 复杂条件:
case x if x % 2 == 0 && x < 100 - 动态条件判断
- 变量绑定:
- Switch 表达式支持: 新增返回值的 switch 表达式
- 表达式语法:
case value => expression - 自动 break 机制
- 完全兼容现有语句形式
- 表达式语法:
✨ 语法增强
- 模式匹配系统: 全新
CasePattern枚举支持多种模式Value(Expression): 传统值匹配Range(start, end): 范围匹配Guard(var, condition): Guard 条件匹配Destructure(pattern): 解构匹配(预留接口)
- 混合语法支持: 同一 switch 支持不同模式混用
- 类型安全: 强类型检查确保模式一致性
🔧 技术实现
- AST 扩展: 新增
CasePattern、SwitchType、DestructurePattern - 解析器增强: 智能模式识别
- 自动检测范围操作符
.. - Guard 条件
if关键字识别 - 表达式形式
=>操作符支持
- 自动检测范围操作符
- 解释器优化: 高效模式匹配算法
- 范围检查优化
- Guard 条件变量绑定
- 表达式求值缓存
📝 语法示例
// 范围匹配
switch (score) {
case 90..100 => "优秀",
case 80..89 => "良好",
default => "需努力"
};
// Guard 条件
switch (value) {
case x if x % 2 == 0 => "偶数",
case x if x > 100 => "大数",
default => "其他"
};
// Switch 表达式(预留功能)
grade : string = switch (score) {
case 90..100 => "A",
case 80..89 => "B",
default => "F"
};
🎯 兼容性
- 完全向后兼容: 现有 switch 语句无需修改
- 渐进式采用: 可逐步引入新特性
- 性能优化: 不影响现有代码性能
🧪 测试覆盖
- 基础测试: 核心模式匹配验证
- 复杂测试: 嵌套/混合模式及边界条件
- 实际测试: 真实场景模拟
🔧 重大修复:using file 语句优化
-
智能预处理系统: 文件导入机制重构
- 递归导入支持
- 智能路径解析
- 循环检测
- 文件缓存优化
-
预处理阶段处理: 重大架构改进
- 直接文件内容合并
- 零运行时开销
- 清晰导入标记
- AST 简化
-
错误处理增强: 更好开发体验
- 详细错误信息
- 提前错误检测
- 明确循环导入警告
-
无缝 Switch 集成:
// patterns.cn fn isEven(x : int) : bool { return x % 2 == 0; } const SMALL_RANGE : int = 10; // main.cn using file "patterns.cn"; switch (value) { case 1..SMALL_RANGE => "小范围", case x if isEven(x) => "偶数", default => "其他" }
🚀 模块化开发支持
- 模式库系统: 可重用模式匹配库
- 常量库导入: 范围匹配用常量
- 函数库集成: Guard 条件使用导入函数
- 大型项目支持: 模块化开发能力
📈 性能优化
- 预处理优化: 文件导入编译时完成
- 智能缓存: 文件仅处理一次
- 内存优化: 降低运行时内存占用
🔧 重大修复:相对路径解析问题修复
Full Changelog: CodeNothingCommunity/CodeNothing@v0.4.2...v0.4.3