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