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