changeset 55900dc9dbcf in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=55900dc9dbcf user: Simon Forman <sform****@hushm*****> date: Sat Nov 09 20:19:15 2019 -0800 description: Pass through label. changeset 04404f5a22c0 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=04404f5a22c0 user: Simon Forman <sform****@hushm*****> date: Sat Nov 09 21:20:31 2019 -0800 description: Minor refactor. It doesn't save space (but if I reuse it once it will.) changeset f492825e7987 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=f492825e7987 user: Simon Forman <sform****@hushm*****> date: Sat Nov 09 21:55:01 2019 -0800 description: merge_and_store, chain_link changeset 99084a77f23c in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=99084a77f23c user: Simon Forman <sform****@hushm*****> date: Sun Nov 10 10:53:55 2019 -0800 description: word works with negative numbers now. symbols moved to head of machine code. changeset 51de5a4098e3 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=51de5a4098e3 user: Simon Forman <sform****@hushm*****> date: Sun Nov 10 10:58:47 2019 -0800 description: halt. diffstat: thun/asm-dump.txt | 98 +++++++++++++++++++++++++++-------------------- thun/compiler.markII.pl | 95 +++++++++++++++++++++++++-------------------- thun/joy_asmii.bin | Bin thun/markII.rst | 17 ++++++++ 4 files changed, 126 insertions(+), 84 deletions(-) diffs (truncated from 356 to 300 lines): diff -r 9b1815aa90f9 -r 51de5a4098e3 thun/asm-dump.txt --- a/thun/asm-dump.txt Sat Nov 09 18:39:39 2019 -0800 +++ b/thun/asm-dump.txt Sun Nov 10 10:58:47 2019 -0800 @@ -1,97 +1,111 @@ [word(0), -do_offset(_7910), -allocate(_7920,20), -label(_7910), +do_offset(_2170), +allocate(_2180,20), +label(_2170), mov_imm(0,0), store_word(0,0,0), mov_imm(0,4096), -mov_imm(1,_7982), +mov_imm(1,_2242), mov_imm(2,0), mov_imm(3,0), store_word(2,0,0), -label(_8030), +labelv_imm(3,0), +store_word(2,0,0), +label(_2290), sub_imm(1,1,0), -eq_offset(_8042), +eq_offset(_2302), load_word(4,1,0), lsl_imm(5,4,2), asr_imm(5,5,17), -eq_offset(_8158), +eq_offset(_24346,4,17), +asr_imm(6,6,17), +eq_offset(), add(5,5,1), -label(_8158), +label(_2434), lsl_imm(6,4,17), asr_imm(6,6,17), -eq_offset(_8220), +eq_offset(_2502), add(6,6,1), -label(_8220), +label(_2502), load_word(3,5,0), mov(1,6), -asr_imm(6,3,30), +asr_imm(6,3,t(6,16383), +ior_imm(6,6,65535), +and(30), and_imm(6,6,2), sub_imm(6,6,2), -ne_offset(_8322), +ne_offset(_2564), mov_imm_with_shift(6,16383), ior_imm(6,6,65535), and(6,6,3), do(6), -label(_8322), -sub_imm(0,0,4), +label(_2564), +sub_imm(0(_2810), +store_word(2,0,0), +do_offse,0,4), sub(2,5,0), -hi_offset(_8424), +hi_offset(_2748), and_imm(2,2,32767), -label(_8424), +label(_2748), lsl_imm(2,2,15), ior_imm(2,2,4), -label(_8486), +label(_2810), store_word(2,0,0), -do_offset(_8030), -label(_8042), -do_offset(_8042), -label(_8540), +do_offset,lsl_imm(2,2,17), +asr_imm(2,2,17), +e(_2290), +label(_2302), +do_offset(_2302), +label(_2864), +symbol(_2864), lsl_imm(6,2,2), asr_imm(6,6,17), -eq_offset(_8656), +eq_offset(_3064), add(6,6,0), -label(_8656), -lsl_imm(2,2,17), +label(_3064), +9,7,17), +asr_imm(9,9,17), +eq_offset(lsl_imm(2,2,17), asr_imm(2,2,17), -eq_offset(_8718), +eq_offset(_3132), add(2,2,0), -label(_8718), +label(_3132), load_word(7,2,0), lsl_imm(8,7,2), asr_imm(8,8,17), -eq_offset(_8794), -add(8,8,2), -label(_8794), +eq_offset(_3214)q_offset(_3394), +sub(6,6,0), +and_imm,add(8,8,2), +label(_3214), lsl_imm(9,7,17), asr_imm(9,9,17), -eq_offset(_8856), +eq_offset(_3282), add(9,9,2), -label(_8856), +label(_3282), sub_imm(0,0,4), sub_imm(8,8,0), -eq_offset(_8900), +eq_offset,9,32767), +label(_3518), +mov_imm_wit(_3326), sub(8,8,0), and_imm(8,8,32767), -label(_8900), +label(_3326), sub_imm(6,6,0), -eq_offset(_8968), +eq_offset(_3394), sub(6,6,0), and_imm(6,6,32767), -label(_8968), +label(_3394), lsl_imm(8,8,15), ior(8,8,6), store_word(8,0,0), sub_imm(0,0,4), sub_imm(9,9,0), -eq_offset(_9114), +eq_offset(_3518), sub(9,9,0), and_imm(9,9,32767), -label(_9114), +label(_3518), mov_imm_with_shift(2,2), ior(2,2,9), -do_offset(_8486), -label(_7982), -expr_cell(_9232,0), -label(_9232), -symbol(_8540)] \ No newline at end of file +do_offset(_2810), +label(_2242), +expr_cell(_2864,0)] \ No newline at end of file diff -r 9b1815aa90f9 -r 51de5a4098e3 thun/compiler.markII.pl --- a/thun/compiler.markII.pl Sat Nov 09 18:39:39 2019 -0800 +++ b/thun/compiler.markII.pl Sun Nov 10 10:58:47 2019 -0800 @@ -29,7 +29,7 @@ { [SP, EXPR_addr, TOS, TERM, EXPR, TermAddr, TEMP0, TEMP1, TEMP2, TEMP3] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }, - [ % Mainloop. +[ word(0), % Zero root cell. do_offset(Reset), % Oberon bootloader writes MemLim to RAM[12] and allocate(_, 20), % stackOrg to RAM[24], we don't need these @@ -42,10 +42,9 @@ mov_imm(EXPR_addr, Expression), mov_imm(TOS, 0), mov_imm(TERM, 0), - store_word(TOS, SP, 0), % RAM[SP] := 0 - - label(Main) + store_word(TOS, SP, 0) % RAM[SP] := 0 ],⟐([ + label(Main), % Mainloop. if_zero(EXPR_addr, HALT), load(EXPR, EXPR_addr), % At this point EXPR holds the record word of the expression. @@ -59,14 +58,12 @@ ],⟐([ if_literal(TERM, PUSH, TEMP0), % if it is a symbol the rest of it is the pointer to the machine code. - lookup(TERM, TEMP0) % Jump to command. -]),[ + lookup(TERM, TEMP0), % Jump to command. % going into push we have the term - label(PUSH) + label(PUSH), % push2(TOS, TEMP1, SP), % stack = TERM, stack -],⟐( incr(SP) -),[ +]),[ % SP points to the future home of the new stack cell. sub(TOS, TermAddr, SP), % TOS := &temp - sp % Er, what if it's negative? @@ -80,15 +77,14 @@ label(Done), store_word(TOS, SP, 0), % RAM[SP] := TOS - do_offset(Main), + do_offset(Main) - label(HALT), % This is a HALT loop, the emulator detects and traps - do_offset(HALT), % on this "10 goto 10" instruction. + ],⟐([ -% ====================================== + halt(HALT), % ====================================== - label(Cons) % Let's cons. -],⟐([ + definition(Cons), % Let's cons. + unpack_pair(TOS, TEMP0, TOS, SP), % TEMP0 = Address of the list to which to append. % TOS = Address of the second stack cell. @@ -101,24 +97,17 @@ % Build and write the new list cell. incr(SP), sub_base_from_offset(TEMP2, SP), - sub_base_from_offset(TEMP0, SP) -]),[ - lsl_imm(TEMP2, TEMP2, 15), % TEMP2 := TEMP2 << 15 - ior(TEMP2, TEMP2, TEMP0), - store_word(TEMP2, SP, 0) -],⟐([ + sub_base_from_offset(TEMP0, SP), + merge_and_store(TEMP2, TEMP0, SP), incr(SP), - sub_base_from_offset(TEMP3, SP) + sub_base_from_offset(TEMP3, SP), + chain_link(TOS, TEMP3), + jump(Done) % Rely on mainloop::Done to write TOS to RAM. ]),[ - mov_imm_with_shift(TOS, 2), % TOS := 4 << 15 - ior(TOS, TOS, TEMP3), - do_offset(Done), % Rely on mainloop::Done to write TOS to RAM. + label(Expression), + expr_cell(Cons, 0) +]. - label(Expression), - expr_cell(ConsSym, 0), - label(ConsSym), symbol(Cons) - -]. /* @@ -139,19 +128,26 @@ label(Label)]. ⟐(unpack_pair(From, HeadAddr, TailAddr, Base)) --> - [lsl_imm(HeadAddr, From, 2), % Trim off the type tag 00 bits. - asr_imm(HeadAddr, HeadAddr, 17), % HeadAddr := From >> 15 - eq_offset(Label0), % if the offset is zero don't add the address. it's empty list. - add(HeadAddr, HeadAddr, Base), - label(Label0), - lsl_imm(TailAddr, From, 17), % Get the offset of the third stack cell - asr_imm(TailAddr, TailAddr, 17), % while preserving the sign. - eq_offset(Label1), % if the offset is zero don't add the address. it's empty list. - add(TailAddr, TailAddr, Base), - label(Label1)]. + [lsl_imm(HeadAddr, From, 2)], % Trim off the type tag 00 bits. + ⟐(roll_down_add_base_if_not_zero(HeadAddr, Base)), + [lsl_imm(TailAddr, From, 17)], % Trim off tag and head address. + ⟐(roll_down_add_base_if_not_zero(TailAddr, Base)). + +⟐(roll_down_add_base_if_not_zero(Addr, Base)) --> + [asr_imm(Addr, Addr, 17), % Preserving sign. + eq_offset(Label), % If the offset is zero don't add the address. it's empty list. + add(Addr, Addr, Base), + label(Label)]. ⟐(load(From, To)) --> [load_word(From, To, 0)]. +⟐(label(L)) --> [label(L)]. % Pass through. + +⟐(jump(To)) --> [do_offset(To)]. % Pass through. + +⟐(halt(Halt)) --> [label(Halt), do_offset(Halt)]. +% This is a HALT loop, the emulator detects and traps on this "10 goto 10" instruction. + ⟐(incr(SP)) --> [sub_imm(SP, SP, 4)]. % SP -= 1 (word, not byte). ⟐(if_literal(TERM, Push, TEMP)) --> @@ -167,6 +163,17 @@ and(TEMP, TEMP, TERM), do(TEMP)]. % Jump to command. +⟐(merge_and_store(HeadAddr, TailAddr, SP)) --> + [lsl_imm(HeadAddr, HeadAddr, 15), % HeadAddr := HeadAddr << 15 + ior(HeadAddr, HeadAddr, TailAddr),