Add regular expression statement, make sure rust functions work
This commit is contained in:
parent
c244edb9bc
commit
0a6d13c5f6
@ -5,5 +5,5 @@ function add(x)
|
||||
end
|
||||
end
|
||||
|
||||
pr = print(add(10)(15))
|
||||
pr = print(add(10)(15))
|
||||
print(max(11, 9))
|
||||
print(add(10)(15))
|
||||
@ -209,6 +209,7 @@ pub enum Statement {
|
||||
Assignment(Option<AccessModifier>, Vec<Node<String>>, ExpressionList),
|
||||
Return(ExpressionList),
|
||||
If(Node<Expression>, Block),
|
||||
Expression(Node<Expression>),
|
||||
}
|
||||
|
||||
impl Parse for Statement {
|
||||
@ -266,6 +267,8 @@ impl Parse for Statement {
|
||||
vec![name],
|
||||
ExpressionList(vec![stream.parse()?]),
|
||||
))
|
||||
} else if let Ok(expr) = stream.parse() {
|
||||
Ok(Self::Expression(expr))
|
||||
} else {
|
||||
Err(stream.expecting_err("statement"))
|
||||
}
|
||||
|
||||
@ -103,6 +103,7 @@ impl Statement {
|
||||
constants.extend(then.find_constants(scope));
|
||||
constants
|
||||
}
|
||||
Statement::Expression(expr) => expr.kind.find_constants(scope),
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,6 +225,10 @@ impl Statement {
|
||||
));
|
||||
}
|
||||
Statement::If(node, block) => todo!(),
|
||||
Statement::Expression(expr) => {
|
||||
let (instr, _) = expr.kind.compile(state, scope, None);
|
||||
instructions.extend(instr);
|
||||
}
|
||||
}
|
||||
|
||||
instructions
|
||||
|
||||
17
src/vm.rs
17
src/vm.rs
@ -291,11 +291,18 @@ impl ClosureRunner {
|
||||
match value {
|
||||
Value::RustFunction(func) => {
|
||||
let ret_values = func.borrow_mut().execute(params);
|
||||
for i in 0..=(*ret_len - 2) {
|
||||
self.stack.insert(
|
||||
*func_reg + i,
|
||||
ret_values.get(i as usize).cloned().unwrap_or(Value::Nil),
|
||||
);
|
||||
if *ret_len != 0 {
|
||||
for i in 0..=(*ret_len - 2) {
|
||||
self.stack.insert(
|
||||
*func_reg + i,
|
||||
ret_values.get(i as usize).cloned().unwrap_or(Value::Nil),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for (i, value) in ret_values.iter().enumerate() {
|
||||
self.stack.insert(*func_reg + i as u16 + 1, value.clone());
|
||||
}
|
||||
self.top = *func_reg + ret_values.len() as u16;
|
||||
}
|
||||
}
|
||||
Value::Function(closure) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user