This commit is contained in:
Dominic Grimm 2023-04-04 20:22:36 +02:00
parent fcc8379cc3
commit 7144eb4b24
Signed by: dergrimm
GPG key ID: 12EFFCAEA9E620BF
3 changed files with 129 additions and 32 deletions

View file

@ -3,8 +3,11 @@
.include "$lib/core.asm"
.include "$lib/std.asm"
.define PLACEHOLDER_U8, CORE_U8_MAX
.define PLACEHOLDER_U16, CORE_U16_MAX
.define_eval prev, OFFSET
ts CORE_U16_MAX
ts PLACEHOLDER_U16
tlr CORE_REG_PC
.define_eval diff, (OFFSET - prev)
.define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - diff)
@ -12,13 +15,13 @@
.delete prev, diff
.define_eval prev, OFFSET
.bytes CORE_U16_MAX, CORE_U16_MAX
.bytes CORE_U16_MAX
.bytes PLACEHOLDER_U16, PLACEHOLDER_U16
.bytes PLACEHOLDER_U16
.define_eval JUMP_TABLE_CONDITIONS_SIZE, (OFFSET - prev)
.org prev
.delete prev
.define_eval JUMP_TABLE_WORDS_SIZE, (1 * 2)
.define_eval JUMP_TABLE_WORDS_SIZE, (3 * 2)
.define_eval JUMP_TABLE_PTR, (MAIN_JUMPER - JUMP_TABLE_CONDITIONS_SIZE - JUMP_TABLE_WORDS_SIZE)
.debug JUMP_TABLE_CONDITIONS_SIZE, JUMP_TABLE_WORDS_SIZE, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2), JUMP_TABLE_PTR
@ -32,6 +35,14 @@
.define_eval counter, (counter + 2)
.define_eval jump_table_conditions_if_1, (JUMP_TABLE_PTR + counter)
.define_eval counter, (counter + 2)
; words
.define_eval jump_table_words_0, (JUMP_TABLE_PTR + counter)
.define_eval counter, (counter + 1)
.define_eval jump_table_words_1, (JUMP_TABLE_PTR + counter)
.define_eval counter, (counter + 1)
.define_eval jump_table_words_2, (JUMP_TABLE_PTR + counter)
.define_eval counter, (counter + 1)
.delete counter
.define_eval MEM_JUMP_TABLE_LEN, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2)
@ -55,27 +66,50 @@
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
.macro jump_table_pull_ptr, jump_table_pull_ptr_arg_0_ptr, jump_table_pull_ptr_arg_1_counter
ts jump_table_pull_ptr_arg_0_ptr
tls
ts 8
tlr CORE_REG_B
.std_get jump_table_pull_ptr_arg_0_ptr
tlr CORE_REG_A
ts CORE_ALU_LSH
alu
tlr CORE_REG_A
.std_get (jump_table_pull_ptr_arg_0_ptr + 1)
tlr CORE_REG_B
ts CORE_ALU_OR
alu
tlr CORE_REG_A
tls
dbg
pop
pop
.endmacro
.define_eval counter, 0
; setup jump table
; conditions
; condition 0
; if
.jump_table_pull_ptr jump_table_conditions_if_0
.jump_table_pull_ptr jump_table_conditions_if_0, counter
.define_eval counter, (counter + 1)
.jump_table_pull_ptr jump_table_conditions_else_0, counter
.define_eval counter, (counter + 1)
.jump_table_pull_ptr jump_table_conditions_if_1, counter
.define_eval counter, (counter + 1)
; else
.jump_table_pull_ptr jump_table_conditions_else_0
; condition 1
; if
.jump_table_pull_ptr jump_table_conditions_if_1
; words
.jump_table_pull_ptr jump_table_words_0, counter
.define_eval counter, (counter + 1)
.jump_table_pull_ptr jump_table_words_1, counter
.define_eval counter, (counter + 1)
.jump_table_pull_ptr jump_table_words_2, counter
.define_eval counter, (counter + 1)
.delete counter
.delete_macro jump_table_pull_ptr
.macro self_ref, self_ref_arg_0_ptr
.std_rset CORE_REG_A, self_ref_arg_0_ptr
@ -140,13 +174,13 @@ return_call_stack_jump:
.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
.std_rset CORE_REG_C, PLACEHOLDER_U16
.std_rset CORE_REG_D, PLACEHOLDER_U16
ts call_stack_jump
tlrc CORE_REG_PC
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
.std_rset CORE_REG_C, PLACEHOLDER_U16
.std_rset CORE_REG_D, PLACEHOLDER_U16
ts call_stack_jump
tlr CORE_REG_PC
.define_eval CALL_STACK_JUMP_COND_IF_ELSE_SIZE, (OFFSET - prev)
@ -230,6 +264,16 @@ return_call_stack_jump:
tls
.return_call_stack_jump
words_1:
push 32
.return_call_stack_jump
words_2:
push 4875
push 8748
dbg
.return_call_stack_jump
; static jump table
.define_eval prev, OFFSET
@ -244,6 +288,17 @@ return_call_stack_jump:
.org jump_table_conditions_if_1
.bytes conditions_if_1
; words
.org jump_table_words_0
.bytes words_0
.org jump_table_words_1
.bytes words_1
.org jump_table_words_2
.bytes words_2
.org prev
.delete prev
@ -305,4 +360,8 @@ main:
.std_cond_jump loop_strings_0
.std_rset CORE_REG_A, '\n'
.std_set CORE_MEM_CHR
.call_stack_jump words_2
.call_stack_jump words_1
.call_stack_jump words_2
.call_stack_jump words_1
.std_stop

View file

@ -8,3 +8,4 @@
1 debug if 32 . cr else then
test debug test debug space ." Hello world!" cr space space ." Hello world!" cr
morp meep morp meep

View file

@ -3,8 +3,11 @@
.include "$lib/core.asm"
.include "$lib/std.asm"
.define PLACEHOLDER_U8, CORE_U8_MAX
.define PLACEHOLDER_U16, CORE_U16_MAX
.define_eval prev, OFFSET
ts CORE_U16_MAX
ts PLACEHOLDER_U16
tlr CORE_REG_PC
.define_eval diff, (OFFSET - prev)
.define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - diff)
@ -13,7 +16,7 @@
.define_eval prev, OFFSET
{%- for c in conditions %}
.bytes CORE_U16_MAX{% if !c.data.1.is_empty() %}, CORE_U16_MAX{% endif %}
.bytes PLACEHOLDER_U16{% if !c.data.1.is_empty() %}, PLACEHOLDER_U16{% endif %}
{%- endfor %}
.define_eval JUMP_TABLE_CONDITIONS_SIZE, (OFFSET - prev)
.org prev
@ -35,6 +38,12 @@
.define_eval counter, (counter + 2)
{%- endif %}
{%- endfor %}
; words
{%- for w in words %}
.define_eval jump_table_words_{{ w.id }}, (JUMP_TABLE_PTR + counter)
.define_eval counter, (counter + 1)
{%- endfor %}
.delete counter
.define_eval MEM_JUMP_TABLE_LEN, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2)
@ -58,29 +67,51 @@
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
.macro jump_table_pull_ptr, jump_table_pull_ptr_arg_0_ptr, jump_table_pull_ptr_arg_1_counter
ts jump_table_pull_ptr_arg_0_ptr
tls
ts 8
tlr CORE_REG_B
.std_get jump_table_pull_ptr_arg_0_ptr
tlr CORE_REG_A
ts CORE_ALU_LSH
alu
tlr CORE_REG_A
.std_get (jump_table_pull_ptr_arg_0_ptr + 1)
tlr CORE_REG_B
ts CORE_ALU_OR
alu
tlr CORE_REG_A
tls
dbg
pop
pop
.endmacro
.define_eval counter, 0
; setup jump table
; conditions
{%- for c in conditions %}
; condition {{ c.id }}
; if
.jump_table_pull_ptr jump_table_conditions_if_{{ c.id }}
.jump_table_pull_ptr jump_table_conditions_if_{{ c.id }}, counter
.define_eval counter, (counter + 1)
{%- if !c.data.1.is_empty() %}
; else
.jump_table_pull_ptr jump_table_conditions_else_{{ c.id }}
.jump_table_pull_ptr jump_table_conditions_else_{{ c.id }}, counter
.define_eval counter, (counter + 1)
{%- endif %}
{%- endfor %}
; words
{%- for w in words %}
.jump_table_pull_ptr jump_table_words_{{ w.id }}, counter
.define_eval counter, (counter + 1)
{%- endfor %}
.delete counter
.delete_macro jump_table_pull_ptr
.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
@ -144,13 +175,13 @@ return_call_stack_jump:
.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
.std_rset CORE_REG_C, PLACEHOLDER_U16
.std_rset CORE_REG_D, PLACEHOLDER_U16
ts call_stack_jump
tlrc CORE_REG_PC
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
.std_rset CORE_REG_C, PLACEHOLDER_U16
.std_rset CORE_REG_D, PLACEHOLDER_U16
ts call_stack_jump
tlr CORE_REG_PC
.define_eval CALL_STACK_JUMP_COND_IF_ELSE_SIZE, (OFFSET - prev)
@ -230,6 +261,12 @@ return_call_stack_jump:
.bytes conditions_else_{{ c.id }}
{%- endif %}
{% endfor %}
; words
{%- for w in words %}
.org jump_table_words_{{ w.id }}
.bytes words_{{ w.id }}
{% endfor %}
.org prev
.delete prev