Allow returning expression lists
This commit is contained in:
parent
219d4b4f7e
commit
3305d3c162
@ -1,7 +1,5 @@
|
||||
function add(x)
|
||||
return function (y)
|
||||
return x + y
|
||||
end
|
||||
return x
|
||||
end
|
||||
|
||||
global c = print(add(5)(7))
|
||||
global c = print(add(5))
|
||||
@ -207,7 +207,7 @@ impl Parse for Block {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Statement {
|
||||
Assignment(AccessModifier, Node<String>, Node<Expression>),
|
||||
Return(Node<Expression>),
|
||||
Return(ExpressionList),
|
||||
If(Node<Expression>, Block),
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +77,13 @@ impl Statement {
|
||||
constants.extend(expr.kind.find_constants(scope));
|
||||
constants
|
||||
}
|
||||
Statement::Return(expr) => expr.kind.find_constants(scope),
|
||||
Statement::Return(expr_list) => {
|
||||
let mut constants = HashSet::new();
|
||||
for expr in &expr_list.0 {
|
||||
constants.extend(expr.kind.find_constants(scope));
|
||||
}
|
||||
constants
|
||||
}
|
||||
Statement::If(cond, then) => {
|
||||
let mut constants = HashSet::new();
|
||||
constants.extend(cond.kind.find_constants(scope));
|
||||
@ -106,12 +112,16 @@ impl Statement {
|
||||
}
|
||||
}
|
||||
}
|
||||
Statement::Return(expr) => {
|
||||
let (instr, registers) = expr.kind.compile(state, scope, 1);
|
||||
instructions.extend(instr);
|
||||
Statement::Return(expr_list) => {
|
||||
let mut ret_registers = Vec::new();
|
||||
for expr in &expr_list.0 {
|
||||
let (instr, registers) = expr.kind.compile(state, scope, 1);
|
||||
instructions.extend(instr);
|
||||
ret_registers.extend(registers);
|
||||
}
|
||||
instructions.push(Instruction::Return(
|
||||
*registers.first().unwrap(),
|
||||
*registers.last().unwrap(),
|
||||
*ret_registers.first().unwrap(),
|
||||
*ret_registers.last().unwrap(),
|
||||
));
|
||||
}
|
||||
Statement::If(node, block) => todo!(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user