[fine] OK
This commit is contained in:
parent
50eb7a9673
commit
65fef78c44
10 changed files with 81 additions and 25 deletions
|
|
@ -219,10 +219,15 @@ pub fn compile(semantics: &Semantics) -> Module {
|
|||
fn file(c: &mut Compiler, t: TreeRef) {
|
||||
let tree = &c.syntax[t];
|
||||
compiler_assert_eq!(c, t, tree.kind, TreeKind::File, "must be compiling a file");
|
||||
for i in 0..tree.children.len() {
|
||||
if let Some(t) = tree.nth_tree(i) {
|
||||
compile_statement(c, t, false);
|
||||
|
||||
let children: Vec<_> = tree.child_trees().collect();
|
||||
if children.len() == 0 {
|
||||
c.push(Instruction::PushNothing);
|
||||
} else {
|
||||
for i in 0..children.len() - 1 {
|
||||
compile_statement(c, children[i], false);
|
||||
}
|
||||
compile_statement(c, *children.last().unwrap(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -485,18 +490,23 @@ fn compile_if_statement(c: &mut Compiler, tree: &Tree, gen_value: bool) -> CR {
|
|||
}
|
||||
|
||||
fn compile_expression_statement(c: &mut Compiler, tree: &Tree, gen_value: bool) -> CR {
|
||||
compile_expression(c, tree.nth_tree(0)?);
|
||||
if tree
|
||||
.nth_token(1)
|
||||
.is_some_and(|t| t.kind == TokenKind::Semicolon)
|
||||
{
|
||||
c.push(Instruction::Discard);
|
||||
if gen_value {
|
||||
c.push(Instruction::PushNothing);
|
||||
if let Some(expr) = tree.nth_tree(0) {
|
||||
compile_expression(c, expr);
|
||||
|
||||
if tree
|
||||
.nth_token(1)
|
||||
.is_some_and(|t| t.kind == TokenKind::Semicolon)
|
||||
{
|
||||
c.push(Instruction::Discard);
|
||||
if gen_value {
|
||||
c.push(Instruction::PushNothing);
|
||||
}
|
||||
} else if !gen_value {
|
||||
c.push(Instruction::Discard);
|
||||
}
|
||||
} else if !gen_value {
|
||||
c.push(Instruction::Discard);
|
||||
}
|
||||
} else if gen_value {
|
||||
c.push(Instruction::PushNothing);
|
||||
};
|
||||
|
||||
OK
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue