Make lists allow multires for final table constructor position

This commit is contained in:
Sofia 2026-03-18 01:54:39 +02:00
parent 73e33444c9
commit 38e5b41644
4 changed files with 13 additions and 9 deletions

View File

@ -21,7 +21,7 @@ function f(x)
end
global sometable = {}
sometable["hello"] = { add(10)(15) }
sometable["hello"] = { 100, 150, add(10)(15) }
print(#sometable["hello"])
sometable["hello"].there = "my dude"
print(sometable.hello.there)

BIN
luac.out

Binary file not shown.

View File

@ -647,7 +647,7 @@ impl Expression {
instructions.push(Instruction::NewTable(reg));
let mut counter = 1;
for (key, value) in entries {
for (i, (key, value)) in entries.iter().enumerate() {
if let Some(key) = key {
let (instr, key_regs) = key.kind.compile(state, scope, Some(1));
instructions.extend(instr);
@ -662,7 +662,11 @@ impl Expression {
let (instr, value_regs) = value.kind.compile(
state,
scope,
if entries.len() == 1 { None } else { Some(1) },
if i == entries.len() - 1 {
None
} else {
Some(1)
},
);
instructions.extend(instr);
@ -679,7 +683,7 @@ impl Expression {
));
counter += 1;
} else {
instructions.push(Instruction::SetList(reg));
instructions.push(Instruction::SetList(reg, counter as u32));
}
}
}

View File

@ -124,8 +124,8 @@ pub enum Instruction {
SetUpVal(u16, u16),
/// R(A)[R(B)] := R(C)
SetTable(u16, u16, u16),
/// R(A) := all values returned from previous function
SetList(u16),
/// R(A)[B...] := all values returned from previous function
SetList(u16, u32),
/// R(A) := R(B)[R(C)]
GetTable(u16, u16, u16),
/// R(A) := {}
@ -176,7 +176,7 @@ impl Debug for Instruction {
Instruction::GetTable(arg0, arg1, arg2) => {
write!(f, "GETTABLE {} {} {}", arg0, arg1, arg2)
}
Instruction::SetList(arg0) => write!(f, "SETLIST {}", arg0),
Instruction::SetList(arg0, arg1) => write!(f, "SETLIST {} {}", arg0, arg1),
Instruction::NewTable(arg0) => write!(f, "NEWTABLE {}", arg0),
Instruction::Jmp(arg0) => write!(f, "JMP {}", arg0),
Instruction::Test(arg0, arg1, arg2) => write!(f, "TEST {} {} {}", arg0, arg1, arg2),
@ -817,13 +817,13 @@ impl ClosureRunner {
self.set_stack(*res, value);
}
Instruction::SetList(reg) => {
Instruction::SetList(reg, start_idx) => {
let table = self.stack.get(reg).cloned();
match table {
Some(value) => {
let mut table = value.borrow_mut();
if let Value::Table(table) = &mut *table {
let mut counter = 1;
let mut counter = *start_idx as i64;
for i in self.function_register..self.top {
let value = self.get_stack(i + 1);
match value {