Add block statements
This commit is contained in:
parent
fb82ce6feb
commit
ced6e79bcc
@ -279,6 +279,7 @@ pub enum Statement {
|
|||||||
Label(Node<String>),
|
Label(Node<String>),
|
||||||
GoTo(Node<String>),
|
GoTo(Node<String>),
|
||||||
Empty,
|
Empty,
|
||||||
|
Block(Block),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Statement {
|
impl Parse for Statement {
|
||||||
@ -455,6 +456,11 @@ impl Parse for Statement {
|
|||||||
} else if let Some(Token::Symbol(';')) = stream.peek() {
|
} else if let Some(Token::Symbol(';')) = stream.peek() {
|
||||||
stream.next();
|
stream.next();
|
||||||
Ok(Self::Empty)
|
Ok(Self::Empty)
|
||||||
|
} else if let Some(Token::Keyword(Keyword::Do)) = stream.peek() {
|
||||||
|
stream.next();
|
||||||
|
let block = stream.parse()?;
|
||||||
|
stream.expect(Token::Keyword(Keyword::End))?;
|
||||||
|
Ok(Self::Block(block))
|
||||||
} else {
|
} else {
|
||||||
Err(stream.expecting_err("statement"))
|
Err(stream.expecting_err("statement"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -246,6 +246,11 @@ impl Statement {
|
|||||||
Statement::Label(_) => HashSet::new(),
|
Statement::Label(_) => HashSet::new(),
|
||||||
Statement::GoTo(_) => HashSet::new(),
|
Statement::GoTo(_) => HashSet::new(),
|
||||||
Statement::Empty => HashSet::new(),
|
Statement::Empty => HashSet::new(),
|
||||||
|
Statement::Block(block) => {
|
||||||
|
let mut constants = HashSet::new();
|
||||||
|
constants.extend(block.find_constants(scope, Vec::new()));
|
||||||
|
constants
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,6 +659,10 @@ impl Statement {
|
|||||||
Statement::Label(node) => instructions.push(PreInstr::Label(node.kind.clone())),
|
Statement::Label(node) => instructions.push(PreInstr::Label(node.kind.clone())),
|
||||||
Statement::GoTo(node) => instructions.push(PreInstr::GoTo(node.kind.clone())),
|
Statement::GoTo(node) => instructions.push(PreInstr::GoTo(node.kind.clone())),
|
||||||
Statement::Empty => {}
|
Statement::Empty => {}
|
||||||
|
Statement::Block(block) => {
|
||||||
|
let mut inner_scope = scope.clone();
|
||||||
|
instructions.extend(block.compile(state, &mut inner_scope));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for reg in 0..scope.register_counter.0 {
|
for reg in 0..scope.register_counter.0 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user