From 072653935e6d888036ea7ac348fb63dfd2f94d0d Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Mon, 12 Sep 2022 18:23:10 +0200 Subject: [PATCH] [WIP] Conditional jump switch --- henceforth/src/lib/compiler.rs | 11 +++++++---- henceforth/src/lib/compiler/instruction.rs | 7 ++----- henceforth/src/lib/compiler/template.asm | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/henceforth/src/lib/compiler.rs b/henceforth/src/lib/compiler.rs index a130282..b0d5001 100644 --- a/henceforth/src/lib/compiler.rs +++ b/henceforth/src/lib/compiler.rs @@ -160,10 +160,13 @@ impl Data { // conditions for (id, c) in self.conditions.iter().enumerate() { - x.push(hence::parser::ast::Node::Label(format!("conditions_{}", id))); - x.extend( - - ); + x.push(hence::parser::ast::Node::Label(format!( + "conditions_if_{}", + id + ))); + x.extend(c.if_instructions.iter().map(|ins| ins.compile(self)).collect::>>()?.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::>>()?.into_iter().flatten()); } // words diff --git a/henceforth/src/lib/compiler/instruction.rs b/henceforth/src/lib/compiler/instruction.rs index 0237ac8..7f653ab 100644 --- a/henceforth/src/lib/compiler/instruction.rs +++ b/henceforth/src/lib/compiler/instruction.rs @@ -1227,7 +1227,7 @@ impl compiler::Compilable for Instruct if w.times_used > 1 { Ok(vec![hence::parser::ast::Node::MacroCall { 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 { Ok(w.instructions @@ -1242,10 +1242,7 @@ impl compiler::Compilable for Instruct None => bail!("Unknown word: {}", x), }, Instruction::AsmQuote(x) => Ok(hence::parser::parse(hence::lexer::lex(x)?)?.body), - Instruction::Condition(x) => Ok(vec![hence::parser::ast::Node::MacroCall { - name: "call_stack_jump".to_string(), - args: vec![hence::arg::Arg::Variable(format!("conditions_{}", x))], - }]), + Instruction::Condition(x) => Ok(vec![]), Instruction::Multiple { instruction, count } => { if *count == 0 { diff --git a/henceforth/src/lib/compiler/template.asm b/henceforth/src/lib/compiler/template.asm index 27a230a..83837f1 100644 --- a/henceforth/src/lib/compiler/template.asm +++ b/henceforth/src/lib/compiler/template.asm @@ -14,10 +14,9 @@ tlr CORE_REG_A .endmacro -.macro call_stack_jump, call_stack_jump_arg_0_label - .define call_stack_jump_local_offset, OFFSET +.macro call_stack_jump, call_stack_jump_arg_0_label, call_stack_jump_arg_1_offset .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 tlr CORE_REG_PC .endmacro