Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.71 KB

File metadata and controls

64 lines (52 loc) · 2.71 KB

Function-Based Text Printer - Implementation Summary

What Was Accomplished

Successfully implemented and tested function-based text printing in GGcode, demonstrating advanced language features:

1. Function Definition Support

  • Multi-parameter functions: function print_text(x, y, text, size, spacing)
  • Mixed parameter types: Numbers (x, y, size, spacing) and strings (text)
  • Function body execution: Complete block statements with loops and conditionals

2. String Parameter Support

  • String literals: "HELLO", "WORLD", etc.
  • String iteration: for char in text { ... }
  • String comparison: if char == "A" { ... }
  • Character processing: Individual character access and manipulation

3. Bug Fix Applied

Problem: Function calls were rejecting non-number arguments Location: src/runtime/evaluator.c line ~1060 Fix: Removed type restriction arg_val->type != VAL_NUMBER to allow all value types Result: Functions now accept strings, numbers, and arrays as parameters

4. Features Demonstrated

  • Character rendering: Complete alphabet (A-Z) and numbers (0-5)
  • Positioning control: X/Y coordinates with size and spacing parameters
  • G-code generation: Proper tool movements (G0/G1) with Z-axis control
  • Multiple function calls: Different text at various positions and sizes

Example Usage

// Define the function
function print_text(x, y, text, size, spacing) {
    // Function implementation with string iteration
    for char in text {
        if char == "H" {
            // Draw H character with G-code commands
        }
        // Move to next character position
        current_x = current_x + char_width + spacing
    }
}

// Use the function
print_text(0, 0, "HELLO", 8, 2)      // Print "HELLO" at origin
print_text(0, -25, "WORLD", 6, 1.5)  // Print "WORLD" below
print_text(60, 20, "GGCODE", 10, 3)  // Print "GGCODE" elsewhere

Generated Output

  • Proper G-code: Complete CNC-compatible output with line numbers
  • Tool control: Safe Z movements between characters
  • Scalable text: Adjustable character size and spacing
  • Multiple strings: Support for various text at different positions

Technical Implementation

  • Parser support: Function definitions with parameter lists
  • Evaluator support: Multi-type parameter passing and evaluation
  • String handling: Complete string literal and iteration support
  • Scope management: Proper variable scoping within functions
  • Memory management: Safe allocation and cleanup of string values

This implementation showcases GGcode as a capable programming language for CNC applications, supporting modern programming constructs while generating efficient machine code.