[WIP] Conditional jump switch
This commit is contained in:
parent
2e71d9e99e
commit
072653935e
3 changed files with 11 additions and 12 deletions
|
@ -160,10 +160,13 @@ impl Data {
|
||||||
|
|
||||||
// conditions
|
// conditions
|
||||||
for (id, c) in self.conditions.iter().enumerate() {
|
for (id, c) in self.conditions.iter().enumerate() {
|
||||||
x.push(hence::parser::ast::Node::Label(format!("conditions_{}", id)));
|
x.push(hence::parser::ast::Node::Label(format!(
|
||||||
x.extend(
|
"conditions_if_{}",
|
||||||
|
id
|
||||||
);
|
)));
|
||||||
|
x.extend(c.if_instructions.iter().map(|ins| ins.compile(self)).collect::<Result<Vec<_>>>()?.into_iter().flatten());
|
||||||
|
x.push(hence::parser::ast::Node::Label(format!("conditions_else_{}", id)));
|
||||||
|
x.extend(c.else_instructions.iter().map(|ins| ins.compile(self)).collect::<Result<Vec<_>>>()?.into_iter().flatten());
|
||||||
}
|
}
|
||||||
|
|
||||||
// words
|
// words
|
||||||
|
|
|
@ -1227,7 +1227,7 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
|
||||||
if w.times_used > 1 {
|
if w.times_used > 1 {
|
||||||
Ok(vec![hence::parser::ast::Node::MacroCall {
|
Ok(vec![hence::parser::ast::Node::MacroCall {
|
||||||
name: "call_stack_jump".to_string(),
|
name: "call_stack_jump".to_string(),
|
||||||
args: vec![hence::arg::Arg::Variable(format!("words_{}", w.id))],
|
args: vec![hence::arg::Arg::Variable(format!("words_{}", w.id)), hence::arg::Arg::Variable("OFFSET".to_string())],
|
||||||
}])
|
}])
|
||||||
} else {
|
} else {
|
||||||
Ok(w.instructions
|
Ok(w.instructions
|
||||||
|
@ -1242,10 +1242,7 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
|
||||||
None => bail!("Unknown word: {}", x),
|
None => bail!("Unknown word: {}", x),
|
||||||
},
|
},
|
||||||
Instruction::AsmQuote(x) => Ok(hence::parser::parse(hence::lexer::lex(x)?)?.body),
|
Instruction::AsmQuote(x) => Ok(hence::parser::parse(hence::lexer::lex(x)?)?.body),
|
||||||
Instruction::Condition(x) => Ok(vec![hence::parser::ast::Node::MacroCall {
|
Instruction::Condition(x) => Ok(vec![]),
|
||||||
name: "call_stack_jump".to_string(),
|
|
||||||
args: vec![hence::arg::Arg::Variable(format!("conditions_{}", x))],
|
|
||||||
}]),
|
|
||||||
|
|
||||||
Instruction::Multiple { instruction, count } => {
|
Instruction::Multiple { instruction, count } => {
|
||||||
if *count == 0 {
|
if *count == 0 {
|
||||||
|
|
|
@ -14,10 +14,9 @@
|
||||||
tlr CORE_REG_A
|
tlr CORE_REG_A
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
.macro call_stack_jump, call_stack_jump_arg_0_label
|
.macro call_stack_jump, call_stack_jump_arg_0_label, call_stack_jump_arg_1_offset
|
||||||
.define call_stack_jump_local_offset, OFFSET
|
|
||||||
.std_rset CORE_REG_C, call_stack_jump_arg_0_label
|
.std_rset CORE_REG_C, call_stack_jump_arg_0_label
|
||||||
.std_rset CORE_REG_D, (call_stack_jump_local_offset + 7)
|
.std_rset CORE_REG_D, (call_stack_jump_arg_1_offset + 7)
|
||||||
ts call_stack_jump
|
ts call_stack_jump
|
||||||
tlr CORE_REG_PC
|
tlr CORE_REG_PC
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
Loading…
Reference in a new issue