[WIP] Add conditions
This commit is contained in:
parent
0530522847
commit
2e71d9e99e
10 changed files with 51 additions and 62 deletions
|
@ -20,17 +20,17 @@ pub struct Word {
|
|||
pub times_used: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Condition {
|
||||
pub if_instructions: Vec<Instruction>,
|
||||
pub else_instructions: Vec<Instruction>,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Data {
|
||||
pub words: HashMap<String, Word>,
|
||||
// pub word_graph:
|
||||
pub conditions: IndexSet<Instruction>,
|
||||
// pub word_graph:
|
||||
pub conditions: IndexSet<Condition>,
|
||||
pub strings: IndexSet<String>,
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub const TEMPLATE_ASM: &str = include_str!("compiler/template.asm");
|
|||
lazy_static! {
|
||||
#[derive(Debug)]
|
||||
pub static ref TEMPLATE: hence::parser::ast::Body = hence::parser::parse(
|
||||
hence::lexer::lex(TEMPLATE_ASM.to_string()).unwrap()
|
||||
hence::lexer::lex(TEMPLATE_ASM).unwrap()
|
||||
)
|
||||
.unwrap()
|
||||
.body;
|
||||
|
@ -116,10 +116,16 @@ impl Data {
|
|||
);
|
||||
}
|
||||
parser::ast::Node::Condition { if_body, else_body } => {
|
||||
instructions.push(Instruction::Condition {
|
||||
if_instructions: self.generate_instructions(if_body, optimize)?,
|
||||
else_instructions: self.generate_instructions(else_body, optimize)?,
|
||||
});
|
||||
let if_instructions = self.generate_instructions(if_body, optimize)?;
|
||||
let else_instructions = self.generate_instructions(else_body, optimize)?;
|
||||
let id = self
|
||||
.conditions
|
||||
.insert_full(Condition {
|
||||
if_instructions,
|
||||
else_instructions,
|
||||
})
|
||||
.0;
|
||||
instructions.push(Instruction::Condition(id));
|
||||
}
|
||||
parser::ast::Node::Word(x) => {
|
||||
if let Some(ins) = Instruction::from_word(&x) {
|
||||
|
@ -152,6 +158,14 @@ impl Data {
|
|||
]);
|
||||
}
|
||||
|
||||
// conditions
|
||||
for (id, c) in self.conditions.iter().enumerate() {
|
||||
x.push(hence::parser::ast::Node::Label(format!("conditions_{}", id)));
|
||||
x.extend(
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
// words
|
||||
for (name, word) in &self
|
||||
.words
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue