Make lists allow multires for final table constructor position
This commit is contained in:
parent
73e33444c9
commit
38e5b41644
@ -21,7 +21,7 @@ function f(x)
|
|||||||
end
|
end
|
||||||
|
|
||||||
global sometable = {}
|
global sometable = {}
|
||||||
sometable["hello"] = { add(10)(15) }
|
sometable["hello"] = { 100, 150, add(10)(15) }
|
||||||
print(#sometable["hello"])
|
print(#sometable["hello"])
|
||||||
sometable["hello"].there = "my dude"
|
sometable["hello"].there = "my dude"
|
||||||
print(sometable.hello.there)
|
print(sometable.hello.there)
|
||||||
|
|||||||
@ -647,7 +647,7 @@ impl Expression {
|
|||||||
instructions.push(Instruction::NewTable(reg));
|
instructions.push(Instruction::NewTable(reg));
|
||||||
|
|
||||||
let mut counter = 1;
|
let mut counter = 1;
|
||||||
for (key, value) in entries {
|
for (i, (key, value)) in entries.iter().enumerate() {
|
||||||
if let Some(key) = key {
|
if let Some(key) = key {
|
||||||
let (instr, key_regs) = key.kind.compile(state, scope, Some(1));
|
let (instr, key_regs) = key.kind.compile(state, scope, Some(1));
|
||||||
instructions.extend(instr);
|
instructions.extend(instr);
|
||||||
@ -662,7 +662,11 @@ impl Expression {
|
|||||||
let (instr, value_regs) = value.kind.compile(
|
let (instr, value_regs) = value.kind.compile(
|
||||||
state,
|
state,
|
||||||
scope,
|
scope,
|
||||||
if entries.len() == 1 { None } else { Some(1) },
|
if i == entries.len() - 1 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(1)
|
||||||
|
},
|
||||||
);
|
);
|
||||||
instructions.extend(instr);
|
instructions.extend(instr);
|
||||||
|
|
||||||
@ -679,7 +683,7 @@ impl Expression {
|
|||||||
));
|
));
|
||||||
counter += 1;
|
counter += 1;
|
||||||
} else {
|
} else {
|
||||||
instructions.push(Instruction::SetList(reg));
|
instructions.push(Instruction::SetList(reg, counter as u32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/vm.rs
10
src/vm.rs
@ -124,8 +124,8 @@ pub enum Instruction {
|
|||||||
SetUpVal(u16, u16),
|
SetUpVal(u16, u16),
|
||||||
/// R(A)[R(B)] := R(C)
|
/// R(A)[R(B)] := R(C)
|
||||||
SetTable(u16, u16, u16),
|
SetTable(u16, u16, u16),
|
||||||
/// R(A) := all values returned from previous function
|
/// R(A)[B...] := all values returned from previous function
|
||||||
SetList(u16),
|
SetList(u16, u32),
|
||||||
/// R(A) := R(B)[R(C)]
|
/// R(A) := R(B)[R(C)]
|
||||||
GetTable(u16, u16, u16),
|
GetTable(u16, u16, u16),
|
||||||
/// R(A) := {}
|
/// R(A) := {}
|
||||||
@ -176,7 +176,7 @@ impl Debug for Instruction {
|
|||||||
Instruction::GetTable(arg0, arg1, arg2) => {
|
Instruction::GetTable(arg0, arg1, arg2) => {
|
||||||
write!(f, "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::NewTable(arg0) => write!(f, "NEWTABLE {}", arg0),
|
||||||
Instruction::Jmp(arg0) => write!(f, "JMP {}", arg0),
|
Instruction::Jmp(arg0) => write!(f, "JMP {}", arg0),
|
||||||
Instruction::Test(arg0, arg1, arg2) => write!(f, "TEST {} {} {}", arg0, arg1, arg2),
|
Instruction::Test(arg0, arg1, arg2) => write!(f, "TEST {} {} {}", arg0, arg1, arg2),
|
||||||
@ -817,13 +817,13 @@ impl ClosureRunner {
|
|||||||
|
|
||||||
self.set_stack(*res, value);
|
self.set_stack(*res, value);
|
||||||
}
|
}
|
||||||
Instruction::SetList(reg) => {
|
Instruction::SetList(reg, start_idx) => {
|
||||||
let table = self.stack.get(reg).cloned();
|
let table = self.stack.get(reg).cloned();
|
||||||
match table {
|
match table {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
let mut table = value.borrow_mut();
|
let mut table = value.borrow_mut();
|
||||||
if let Value::Table(table) = &mut *table {
|
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 {
|
for i in self.function_register..self.top {
|
||||||
let value = self.get_stack(i + 1);
|
let value = self.get_stack(i + 1);
|
||||||
match value {
|
match value {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user