This commit is contained in:
Dominic Grimm 2023-04-04 14:07:21 +02:00
parent 7d96943862
commit fcc8379cc3
No known key found for this signature in database
GPG key ID: 12EFFCAEA9E620BF
6 changed files with 182 additions and 97 deletions

View file

@ -1,7 +1,3 @@
{%- macro escape_name(name) -%}
{% if name.starts_with('"') %}{{ name }}{% else %}"{{ name }}"{% endif %}
{%- endmacro -%}
; Generated by Henceforth {{ env!("CARGO_PKG_VERSION") }} ({{ env!("CARGO_PKG_REPOSITORY") }})
.include "$lib/core.asm"
@ -62,26 +58,41 @@
tlr CORE_REG_A
.endmacro
.macro jump_table_pull_ptr, jump_table_pull_ptr_arg_0_ptr
.std_get jump_table_pull_ptr_arg_0_ptr
tls
.std_get (jump_table_pull_ptr_arg_0_ptr + 1)
tls
dbg
pop
pop
.endmacro
; setup jump table
; conditions
{%- for c in conditions %}
; condition {{ c.id }}
.std_get jump_table_conditions_if_{{ c.id }}
tls
.std_get (jump_table_conditions_if_{{ c.id }} + 1)
tls
dbg
pop
pop
; if
.jump_table_pull_ptr jump_table_conditions_if_{{ c.id }}
{%- if !c.data.1.is_empty() %}
; else
.jump_table_pull_ptr jump_table_conditions_else_{{ c.id }}
{%- endif %}
{%- endfor %}
.macro self_ref, self_ref_arg_0_ptr
.std_rset CORE_REG_A, self_ref_arg_0_ptr
.std_set self_ref_arg_0_ptr
.endmacro
; reference MEM_CALL_STACK_PTR to itself
.std_rset CORE_REG_A, MEM_CALL_STACK_PTR
.std_set MEM_CALL_STACK_PTR
.self_ref MEM_CALL_STACK_PTR
; reference MEM_ALLOC_PTR to itself
.std_rset CORE_REG_A, MEM_ALLOC_PTR
.std_set MEM_ALLOC_PTR
.self_ref MEM_ALLOC_PTR
.delete_macro self_ref
.std_jump MAIN_JUMPER
@ -114,50 +125,20 @@ return_call_stack_jump:
get
tlr CORE_REG_PC
.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)
.std_rset CORE_REG_D, (OFFSET + 7)
ts call_stack_jump
tlr CORE_REG_PC
.delete prev, offset_till_end
.endmacro
.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, (OFFSET + offset_till_end)
.std_rset CORE_REG_D, (OFFSET + 7)
ts call_stack_jump
tlrc CORE_REG_PC
.delete prev, offset_till_end
.endmacro
.define_eval prev, OFFSET
@ -204,9 +185,6 @@ return_call_stack_jump:
{%- for s in strings %}
{% let bytes = s.data.as_bytes() -%}
data_strings_{{ s.id }}:
{% let name = snailquote::escape(s.data) -%}
; original : {% call escape_name(name) %}
; size : {{ bytes.len() }}
{%- for byte in bytes %}
.bytes {{ "0x{:02x}"|format(byte) }}
{%- endfor %}
@ -221,28 +199,37 @@ return_call_stack_jump:
{{ ins }}
{%- endfor %}
.return_call_stack_jump
{%- if !c.data.1.is_empty() %}
conditions_else_{{ c.id }}:
{%- for ins in c.data.1 %}
{{ ins }}
{%- endfor %}
.return_call_stack_jump
{%- endif %}
{% endfor %}
; words
{%- for w in words %}
words_{{ w.id }}:
{% let name = snailquote::escape(w.data.0) -%}
; name : {% call escape_name(name) %}
{%- for node in w.data.1 %}
{{ node }}
{%- endfor %}
.return_call_stack_jump
{% endfor %}
; static jump table
.define_eval prev, OFFSET
.org JUMP_TABLE_PTR
; conditions
{%- for c in conditions %}
; condition: {{ c.id }}
.org jump_table_conditions_if_{{ c.id }}
.bytes conditions_if_{{ c.id }}
{%- if !c.data.1.is_empty() %}
.org jump_table_conditions_else_{{ c.id }}
.bytes conditions_else_{{ c.id }}
{%- endif %}
{% endfor %}
.org prev
.delete prev