Update WIP with jump table for words and conditions
This commit is contained in:
parent
df73353bc6
commit
00bab636db
10 changed files with 234 additions and 116 deletions
|
@ -166,14 +166,14 @@ impl Compiler {
|
|||
.collect::<Result<Vec<_>>>()?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
.collect::<Vec<_>>(),
|
||||
c.else_instructions
|
||||
.iter()
|
||||
.map(|ins| ins.compile(self))
|
||||
.collect::<Result<Vec<_>>>()?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1228,10 +1228,7 @@ impl compiler::Compilable<compiler::Compiler, hence::parser::ast::Body> for Inst
|
|||
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)),
|
||||
hence::arg::Arg::Variable("OFFSET".to_string()),
|
||||
],
|
||||
args: vec![hence::arg::Arg::Variable(format!("words_{}", w.id))],
|
||||
}])
|
||||
} else {
|
||||
Ok(w.instructions
|
||||
|
@ -1252,10 +1249,7 @@ impl compiler::Compilable<compiler::Compiler, hence::parser::ast::Body> for Inst
|
|||
Some(cond) => Ok(vec![if cond.only_if() {
|
||||
hence::parser::ast::Node::MacroCall {
|
||||
name: "call_stack_jump_cond_if".to_string(),
|
||||
args: vec![
|
||||
hence::arg::Arg::Variable(format!("conditions_if_{}", x)),
|
||||
hence::arg::Arg::Variable("OFFSET".to_string()),
|
||||
],
|
||||
args: vec![hence::arg::Arg::Variable(format!("conditions_if_{}", x))],
|
||||
}
|
||||
} else {
|
||||
hence::parser::ast::Node::MacroCall {
|
||||
|
@ -1263,7 +1257,6 @@ impl compiler::Compilable<compiler::Compiler, hence::parser::ast::Body> for Inst
|
|||
args: vec![
|
||||
hence::arg::Arg::Variable(format!("conditions_if_{}", x)),
|
||||
hence::arg::Arg::Variable(format!("conditions_else_{}", x)),
|
||||
hence::arg::Arg::Variable("OFFSET".to_string()),
|
||||
],
|
||||
}
|
||||
}]),
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
{% if name.starts_with('"') %}{{ name }}{% else %}"{{ name }}"{% endif %}
|
||||
{%- endmacro -%}
|
||||
|
||||
; Generated by Henceforth {{ env!("CARGO_PKG_VERSION") }} ({{ env!("CARGO_PKG_REPOSITORY") }})
|
||||
|
||||
.include "$lib/core.asm"
|
||||
.include "$lib/std.asm"
|
||||
;.include "$lib/main.asm"
|
||||
|
||||
.define_eval prev, OFFSET
|
||||
ts CORE_U16_MAX
|
||||
|
@ -14,7 +15,21 @@
|
|||
.org prev
|
||||
.delete prev, diff
|
||||
|
||||
.define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - 3 - 1)
|
||||
.define_eval prev, OFFSET
|
||||
{%- for c in conditions %}
|
||||
.bytes NULL
|
||||
{% if !c.data.1.is_empty() %}.bytes NULL{% endif %}
|
||||
{% endfor %}
|
||||
.define_eval INDEX_CONDITIONS_SIZE, (OFFSET - prev)
|
||||
.org prev
|
||||
.delete prev
|
||||
|
||||
.debug INDEX_CONDITIONS_SIZE
|
||||
|
||||
; index
|
||||
{%- for c in conditions %}
|
||||
index_conditions_if_{{ c.id }}:
|
||||
{% endfor %}
|
||||
|
||||
.define_eval MEM_LOOP_DEPTH, CORE_MEM_MEM
|
||||
.define_eval MEM_LOOP_I, (MEM_LOOP_DEPTH + 1)
|
||||
|
@ -70,20 +85,50 @@ return_call_stack_jump:
|
|||
get
|
||||
tlr CORE_REG_PC
|
||||
|
||||
.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_arg_1_offset + 7)
|
||||
.define_eval prev, OFFSET
|
||||
.std_rset CORE_REG_C, CORE_U16_MAX
|
||||
.std_rset CORE_REG_D, CORE_U16_MAX
|
||||
ts call_stack_jump
|
||||
tlr CORE_REG_PC
|
||||
.define_eval CALL_STACK_JUMP_SIZE, (OFFSET - prev)
|
||||
.org prev
|
||||
.delete prev
|
||||
|
||||
.macro call_stack_jump, call_stack_jump_arg_0_label
|
||||
.define_eval prev, OFFSET
|
||||
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
|
||||
|
||||
.std_rset CORE_REG_C, call_stack_jump_arg_0_label
|
||||
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
||||
ts call_stack_jump
|
||||
tlr CORE_REG_PC
|
||||
|
||||
.delete prev, offset_till_end
|
||||
.endmacro
|
||||
|
||||
.macro call_stack_jump_cond_if, call_stack_jump_cond_if_arg_0_if_label, call_stack_jump_cond_if_arg_1_offset
|
||||
.define_eval prev, OFFSET
|
||||
.std_ld
|
||||
tlr CORE_REG_A
|
||||
.std_rset CORE_REG_C, CORE_U16_MAX
|
||||
.std_rset CORE_REG_D, CORE_U16_MAX
|
||||
ts call_stack_jump
|
||||
tlrc CORE_REG_PC
|
||||
.define_eval CALL_STACK_JUMP_COND_IF_SIZE, (OFFSET - prev)
|
||||
.org prev
|
||||
.delete prev
|
||||
|
||||
.macro call_stack_jump_cond_if, call_stack_jump_cond_if_arg_0_if_label
|
||||
.define_eval prev, OFFSET
|
||||
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
|
||||
|
||||
.std_ld
|
||||
tlr CORE_REG_A
|
||||
.std_rset CORE_REG_C, call_stack_jump_cond_if_arg_0_if_label
|
||||
.std_rset CORE_REG_D, (call_stack_jump_cond_if_arg_1_offset + 7)
|
||||
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
||||
ts call_stack_jump
|
||||
tlrc CORE_REG_PC
|
||||
|
||||
.delete prev, offset_till_end
|
||||
.endmacro
|
||||
|
||||
.define_eval prev, OFFSET
|
||||
|
@ -99,24 +144,26 @@ return_call_stack_jump:
|
|||
ts call_stack_jump
|
||||
tlr CORE_REG_PC
|
||||
.define_eval CALL_STACK_JUMP_COND_IF_ELSE_SIZE, (OFFSET - prev)
|
||||
.org prev
|
||||
.delete prev
|
||||
|
||||
.macro call_stack_jump_cond_if_else, call_stack_jump_cond_if_else_arg_0_if_label, call_stack_jump_cond_if_else_arg_1_else_label, call_stack_jump_cond_if_else_arg_2_offset
|
||||
.macro call_stack_jump_cond_if_else, call_stack_jump_cond_if_else_arg_0_if_label, call_stack_jump_cond_if_else_arg_1_else_label
|
||||
.define_eval prev, OFFSET
|
||||
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
|
||||
|
||||
.std_ld
|
||||
tlr CORE_REG_A
|
||||
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_0_if_label
|
||||
.std_rset CORE_REG_D, (call_stack_jump_cond_if_else_arg_2_offset)
|
||||
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
||||
ts call_stack_jump
|
||||
tlrc CORE_REG_PC
|
||||
|
||||
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_1_else_label
|
||||
.std_rset CORE_REG_D, (call_stack_jump_cond_if_else_arg_2_offset + 11)
|
||||
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
||||
ts call_stack_jump
|
||||
tlr CORE_REG_PC
|
||||
|
||||
.delete prev
|
||||
.delete prev, offset_till_end
|
||||
.endmacro
|
||||
|
||||
.macro return_call_stack_jump
|
||||
|
@ -147,7 +194,7 @@ return_call_stack_jump:
|
|||
.return_call_stack_jump
|
||||
|
||||
conditions_else_{{ c.id }}:
|
||||
{%- for ins in c.data.0 %}
|
||||
{%- for ins in c.data.1 %}
|
||||
{{ ins }}
|
||||
{%- endfor %}
|
||||
.return_call_stack_jump
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue