Implement assigning to multiple variables
This commit is contained in:
parent
1673ae964a
commit
982bd48d64
@ -8,4 +8,5 @@ function test()
|
||||
return add(10)(15)
|
||||
end
|
||||
|
||||
local c = print(test())
|
||||
local a, b, c = add(10)(15)
|
||||
local pr = print(a, b, c)
|
||||
@ -112,15 +112,30 @@ impl Statement {
|
||||
|
||||
let mut expr_regs = Vec::new();
|
||||
for expr in &expr_list.0 {
|
||||
let (instr, regs) = expr.kind.compile(state, scope, Some(1));
|
||||
let (instr, regs) = expr.kind.compile(
|
||||
state,
|
||||
scope,
|
||||
if expr_list.0.len() == 1 {
|
||||
Some(names.len())
|
||||
} else {
|
||||
Some(1)
|
||||
},
|
||||
);
|
||||
instructions.extend(instr);
|
||||
expr_regs.extend(regs);
|
||||
}
|
||||
match access_modifier {
|
||||
AccessModifier::Local => {
|
||||
for (name, reg) in names.iter().zip(expr_regs) {
|
||||
scope.locals.insert(name.kind.clone(), reg);
|
||||
for (i, name) in names.iter().enumerate() {
|
||||
scope.locals.insert(
|
||||
name.kind.clone(),
|
||||
expr_regs
|
||||
.get(i)
|
||||
.cloned()
|
||||
.unwrap_or(scope.register_counter.0 + i as u16),
|
||||
);
|
||||
}
|
||||
dbg!(&scope.locals);
|
||||
}
|
||||
AccessModifier::Global => {
|
||||
for (name, reg) in names.iter().zip(expr_regs) {
|
||||
|
||||
@ -209,7 +209,8 @@ impl ClosureRunner {
|
||||
if let Some(instr) = instructions.get(self.program_counter) {
|
||||
match instr {
|
||||
Instruction::Move(a, b) => {
|
||||
self.stack.insert(*a, self.stack.get(b).unwrap().clone());
|
||||
self.stack
|
||||
.insert(*a, self.stack.get(b).unwrap_or(&Value::Nil).clone());
|
||||
}
|
||||
Instruction::LoadK(reg, constant) => {
|
||||
self.stack.insert(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user