Skip to content

Conversation

@davydog187
Copy link
Contributor

Summary

  • Implements comprehensive varargs (...) support for Lua 5.3 compatibility
  • Enables running Lua 5.3 test suite files like vararg.lua
  • All varargs test cases pass (7/7)

Changes

Compiler

  • Return statements: Detects return a, b, ... and generates vararg expansion with variable return count
  • Table constructors: Detects {a, b, ...} and generates vararg expansion for list fields
  • Function calls: Detects f(a, b, ...) and generates vararg expansion with encoded arg counts
  • Uses negative arg counts in call instructions to encode fixed + vararg arguments

VM

  • vararg instruction: Supports count==0 to load all varargs into consecutive registers
  • return instruction: Supports count==-1 to return all values including expanded varargs
  • set_list instruction: Supports count==0 for variable number of values from varargs
  • call instruction: Decodes negative arg counts as fixed args + varargs

Features Supported

  • ✅ Simple varargs: function f(...) return ... end
  • ✅ Mixed params: function f(a, b, ...) return a, b, ... end
  • ✅ Varargs in tables: {...} and {a, b, ...}
  • ✅ Varargs in function calls: g(...) and g(a, b, ...)
  • ✅ Empty varargs handling
  • ✅ Works with select('#', ...) and other stdlib functions

Test Results

7 varargs tests, 0 failures
Full test suite: 1094 tests, 0 failures

🤖 Generated with Claude Code


multiple ->
base_reg = ctx.next_reg
multiple when length(multiple) > 1 ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pattern matching

Comment on lines 132 to 134
if value_reg == target_reg,
do: [],
else: [Instruction.move(target_reg, value_reg)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should integrate styler here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont use this if syntax, remove the keyword syntax

Dave Lucia and others added 2 commits February 10, 2026 20:30
Implements comprehensive varargs (`...`) support including:

**Compiler changes:**
- Detect when `...` is the last value in return statements and generate
  vararg expansion with variable return count
- Detect when `...` is the last element in table constructors and generate
  vararg expansion for list fields
- Detect when `...` is the last argument in function calls and generate
  vararg expansion with encoded arg counts
- Use negative arg counts in call instructions to encode fixed args + varargs

**VM changes:**
- Update vararg instruction to support count==0 meaning "load all varargs"
- Update return instruction to support count==-1 meaning "return all values
  including expanded varargs"
- Update set_list instruction to support count==0 meaning "variable number
  of values from varargs"
- Update call instruction to decode negative arg counts as fixed + varargs

**Features supported:**
- Simple varargs: `function f(...) return ... end`
- Mixed params: `function f(a, b, ...) return a, b, ... end`
- Varargs in tables: `{...}` and `{a, b, ...}`
- Varargs in function calls: `g(...)` and `g(a, b, ...)`
- Empty varargs handling
- Works with select('#', ...) and other stdlib functions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Use pattern matching instead of length guard
- Replace if/do/else keyword syntax with regular if/else/end blocks
@davydog187 davydog187 merged commit 6866566 into main Feb 11, 2026
2 checks passed
@davydog187 davydog187 deleted the add-varargs-support branch February 11, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant