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

v0.7.2

Choose a tag to compare

@HelloAIXIAOJI HelloAIXIAOJI released this 05 Aug 19:16
· 457 commits to master since this release

CodeNothing v0.7.2 - 20250806

🎯 Implementation Goals

Added comprehensive bitwise operator support to CodeNothing language, including bitwise logic and shift operations, while ensuring seamless integration with the existing type system.

✅ Completed Features

1. Bitwise Operator Support

  • Bitwise AND (&): Performs bitwise AND on two integers
  • Bitwise OR (|): Performs bitwise OR on two integers
  • Bitwise XOR (^): Performs bitwise XOR on two integers
  • Left Shift (<<): Shifts bits left by specified amount
  • Right Shift (>>): Shifts bits right by specified amount

2. Type System Integration

  • Base type support: int and long bitwise operations
  • Mixed-type operations: Automatic type promotion for int/long operations
  • Auto type inference: Correct result type inference
  • Bounds checking: Safe shift operation boundaries

3. Expression Parsing

  • Operator precedence: Correctly implemented precedence rules
    • Shifts (<<, >>) > addition/subtraction
    • AND (&) > XOR (^) > OR (|)
  • Complex expressions: Support for combined bitwise and arithmetic operations

🔧 Technical Implementation

AST Extension

// Added 5 new operators to BinaryOperator enum
pub enum BinaryOperator {
    // ... existing operators
    BitwiseAnd,    // &
    BitwiseOr,     // |
    BitwiseXor,    // ^
    LeftShift,     // <<
    RightShift,    // >>
}

Lexer Updates

  • Added recognition for << and >> operators
  • Updated operator precedence parsing

Expression Evaluator

  • Added bitwise operation support across all evaluation contexts
  • Implemented type-safe bitwise logic
  • Added bounds checking for shift operations

JIT Compiler Support

  • Utilizes Cranelift's native bitwise instructions
  • Performance optimizations for bitwise operations

🧪 Test Verification

Basic Functionality

a : int = 12;  // 1100 (binary)
b : int = 10;  // 1010 (binary)

and_result : int = a & b;  // 8 (1000)
or_result : int = a | b;   // 14 (1110)
xor_result : int = a ^ b;  // 6 (0110)

Shift Operations

x : int = 5;  // 101 (binary)
left_shift : int = x << 2;   // 20 (10100)
right_shift : int = x >> 1;  // 2 (10)

Mixed-Type Operations

int_val : int = 255;
long_val : long = 65535;
mixed_result : long = int_val & long_val;  // Automatic type promotion

Auto Type Inference

auto_a : Auto = 15;
auto_b : Auto = 7;
auto_result : Auto = auto_a & auto_b;  // Inferred as int

📊 Test Results

Basic Bitwise Ops ✅

  • AND: 12 & 10 = 8 ✓
  • OR: 12 | 10 = 14 ✓
  • XOR: 12 ^ 10 = 6 ✓

Shift Ops ✅

  • Left shift: 5 << 2 = 20 ✓
  • Right shift: 5 >> 1 = 2 ✓

Complex Expressions ✅

  • (12 & 10) | (5 << 1) = 10 ✓
  • (12 ^ 10) & (5 >> 1) = 2 ✓

Type System ✅

  • Long integer operations ✓
  • Mixed-type operations ✓
  • Auto type inference ✓

🚀 Performance Optimizations

JIT Compilation

  • Uses Cranelift native bitwise instructions
  • Inlines simple integer operations
  • Eliminates function call overhead

Safety Checks

  • Compile-time shift bounds checking
  • Runtime safety guards

📝 Code Quality

Error Handling

  • Shift operand bounds checking
  • Clear type mismatch errors

Code Organization

  • Modular implementation
  • Comprehensive documentation

🔮 Future Plans

Friend Declarations

  • AST support already added
  • Parser and semantic analysis pending

Additional Features

  • Bitwise NOT operator (~)
  • Compound assignment operators (&=, |=, etc.)

📈 Version Comparison

v0.7.1 → v0.7.2 Improvements

  • ✅ 5 new bitwise operators
  • ✅ Enhanced type system support
  • ✅ JIT compiler upgrades
  • ✅ Expanded Auto inference
  • ✅ Comprehensive test coverage

🎉 Conclusion

CodeNothing v0.7.2 successfully implements complete bitwise operator support, significantly enhancing the language's expressiveness and practicality. All features have been thoroughly tested to ensure stability and correctness, establishing a solid foundation for future development.

CodeNothing v0.7.2 - 20250806

🎯 实现目标

为CodeNothing语言添加完整的位运算符支持,包括按位逻辑运算和移位运算,同时确保与现有类型系统的完美集成。

✅ 已完成功能

1. 位运算符支持

  • 按位与 (&): 对两个整数执行按位与操作
  • 按位或 (|): 对两个整数执行按位或操作
  • 按位异或 (^): 对两个整数执行按位异或操作
  • 左移 (<<): 将整数的位向左移动指定位数
  • 右移 (>>): 将整数的位向右移动指定位数

2. 类型系统集成

  • 基本类型支持: int、long类型的位运算
  • 混合类型运算: int与long的混合位运算,自动类型提升
  • Auto类型推断: 位运算结果的自动类型推断
  • 边界检查: 移位操作的安全边界检查

3. 表达式解析

  • 运算符优先级: 正确实现位运算符的优先级
    • 移位运算 (<<, >>) > 加减法
    • 按位与 (&) > 按位异或 (^) > 按位或 (|)
  • 复杂表达式: 支持位运算与算术运算的组合

🔧 技术实现细节

AST扩展

// 在BinaryOperator枚举中添加了5个新的位运算符
pub enum BinaryOperator {
    // ... 现有运算符
    BitwiseAnd,    // &
    BitwiseOr,     // |
    BitwiseXor,    // ^
    LeftShift,     // <<
    RightShift,    // >>
}

词法分析器更新

  • 添加了<<>>双字符运算符的识别
  • 更新了运算符优先级解析

表达式求值器增强

  • 在所有求值上下文中添加位运算支持
  • 实现了类型安全的位运算逻辑
  • 添加了移位操作的边界检查

JIT编译器支持

  • 使用Cranelift的原生位运算指令
  • 优化了位运算的性能表现

🧪 测试验证

基本功能测试

a : int = 12;  // 1100 (二进制)
b : int = 10;  // 1010 (二进制)

and_result : int = a & b;  // 8 (1000)
or_result : int = a | b;   // 14 (1110)
xor_result : int = a ^ b;  // 6 (0110)

移位运算测试

x : int = 5;  // 101 (二进制)
left_shift : int = x << 2;   // 20 (10100)
right_shift : int = x >> 1;  // 2 (10)

混合类型测试

int_val : int = 255;
long_val : long = 65535;
mixed_result : long = int_val & long_val;  // 自动类型提升

Auto类型推断测试

auto_a : Auto = 15;
auto_b : Auto = 7;
auto_result : Auto = auto_a & auto_b;  // 自动推断为int类型

📊 测试结果

基本位运算 ✅

  • 按位与: 12 & 10 = 8 ✓
  • 按位或: 12 | 10 = 14 ✓
  • 按位异或: 12 ^ 10 = 6 ✓

移位运算 ✅

  • 左移: 5 << 2 = 20 ✓
  • 右移: 5 >> 1 = 2 ✓

复杂表达式 ✅

  • (12 & 10) | (5 << 1) = 10 ✓
  • (12 ^ 10) & (5 >> 1) = 2 ✓

类型系统 ✅

  • 长整型位运算正常 ✓
  • 混合类型运算正常 ✓
  • Auto类型推断正常 ✓

🚀 性能优化

JIT编译支持

  • 使用Cranelift的原生位运算指令
  • 内联优化简单的整数位运算
  • 避免函数调用开销

边界检查优化

  • 移位操作的编译时边界检查
  • 运行时安全保护

📝 代码质量

错误处理

  • 移位操作数超出范围的错误检查
  • 类型不匹配的友好错误信息

代码组织

  • 模块化的实现结构
  • 清晰的代码注释和文档

🔮 后续计划

友元声明实现

  • 已添加AST结构支持
  • 待实现解析器和语义分析

更多位运算特性

  • 按位取反运算符 (~)
  • 位运算的复合赋值操作符 (&=, |=, ^=, <<=, >>=)

📈 版本对比

v0.7.1 → v0.7.2 改进

  • ✅ 新增5个位运算符
  • ✅ 完善类型系统支持
  • ✅ 增强JIT编译器
  • ✅ 扩展Auto类型推断
  • ✅ 添加全面测试覆盖

🎉 总结

CodeNothing v0.7.2成功实现了完整的位运算符支持,为语言的表达能力和实用性带来了显著提升。所有功能都经过了充分测试,确保了稳定性和正确性。这为后续版本的进一步功能扩展奠定了坚实基础。

Full Changelog: CodeNothingCommunity/CodeNothing@v0.7.1...v0.7.2