From 67583716f232442295e4f48599fed86c80f043c3 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sat, 9 Nov 2019 18:15:56 -0800 Subject: [PATCH] Refactoring and cleanup. --- thun/asm-dump.txt | 78 ++++++++++++++++++++-------------------- thun/compiler.markII.pl | 46 ++++++++---------------- thun/joy_asmii.bin | Bin 344 -> 344 bytes 3 files changed, 54 insertions(+), 70 deletions(-) diff --git a/thun/asm-dump.txt b/thun/asm-dump.txt index dd417cb..dfc7253 100644 --- a/thun/asm-dump.txt +++ b/thun/asm-dump.txt @@ -1,97 +1,97 @@ [word(0), -do_offset(_6814), -allocate(_6824,20), -label(_6814), +do_offset(_7362), +allocate(_7372,20), +label(_7362), mov_imm(0,0), store_word(0,0,0), mov_imm(0,4096), -mov_imm(1,_6886), +mov_imm(1,_7434), mov_imm(2,0), mov_imm(3,0), store_word(2,0,0), -label(_6934), +label(_7482), sub_imm(1,1,0), -eq_offset(_6946), +eq_offset(_7494), load_word(4,1,0), lsl_imm(5,4,2), asr_imm(5,5,17), -eq_offset(_7034), +eq_offset(_7610), add(5,5,1), -label(_7034), -load_word(3,5,0), +label(_7610), lsl_imm(6,4,17), asr_imm(6,6,17), -eq_offset(_7110), +eq_offset(_7672), add(6,6,1), -label(_7110), +label(_7672), +load_word(3,5,0), mov(1,6), asr_imm(6,3,30), and_imm(6,6,2), sub_imm(6,6,2), -ne_offset(_7198), +ne_offset(_7774), mov_imm_with_shift(6,16383), ior_imm(6,6,65535), and(6,6,3), do(6), -label(_7198), +label(_7774), sub_imm(0,0,4), sub(2,5,0), -hi_offset(_7296), +hi_offset(_7872), and_imm(2,2,32767), -label(_7296), +label(_7872), lsl_imm(2,2,15), ior_imm(2,2,4), -label(_7358), +label(_7934), store_word(2,0,0), -do_offset(_6934), -label(_6946), -do_offset(_6946), -label(_7412), +do_offset(_7482), +label(_7494), +do_offset(_7494), +label(_7988), lsl_imm(6,2,2), asr_imm(6,6,17), -eq_offset(_7494), +eq_offset(_8070), add(6,6,0), -label(_7494), +label(_8070), lsl_imm(2,2,17), asr_imm(2,2,17), -eq_offset(_7556), +eq_offset(_8132), add(2,2,0), -label(_7556), +label(_8132), load_word(7,2,0), lsl_imm(8,7,2), asr_imm(8,8,17), -eq_offset(_7632), +eq_offset(_8208), add(8,8,2), -label(_7632), +label(_8208), lsl_imm(9,7,17), asr_imm(9,9,17), -eq_offset(_7694), +eq_offset(_8270), add(9,9,2), -label(_7694), +label(_8270), sub_imm(0,0,4), sub_imm(8,8,0), -eq_offset(_7762), +eq_offset(_8338), sub(8,8,0), and_imm(8,8,32767), -label(_7762), +label(_8338), sub_imm(6,6,0), -eq_offset(_7830), +eq_offset(_8406), sub(6,6,0), and_imm(6,6,32767), -label(_7830), +label(_8406), 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(_7960), +eq_offset(_8536), sub(9,9,0), and_imm(9,9,32767), -label(_7960), +label(_8536), mov_imm_with_shift(2,2), ior(2,2,9), -do_offset(_7358), -label(_6886), -expr_cell(_8078,0), -label(_8078), -symbol(_7412)] \ No newline at end of file +do_offset(_7934), +label(_7434), +expr_cell(_8654,0), +label(_8654), +symbol(_7988)] \ No newline at end of file diff --git a/thun/compiler.markII.pl b/thun/compiler.markII.pl index 08e9d7d..c5f6d10 100644 --- a/thun/compiler.markII.pl +++ b/thun/compiler.markII.pl @@ -44,31 +44,17 @@ Mark II mov_imm(TERM, 0), store_word(TOS, SP, 0), % RAM[SP] := 0 - label(Main)], - ⟐([ + label(Main) +],⟐([ if_zero(EXPR_addr, HALT), - load(EXPR, EXPR_addr) - ]),[ + load(EXPR, EXPR_addr), % At this point EXPR holds the record word of the expression. - lsl_imm(TermAddr, EXPR, 2), % Trim off the type tag 00 bits. - asr_imm(TermAddr, TermAddr, 17), % preserve sign of offset. - eq_offset(Foo), % if the offset is zero don't add the address. it's empty list. - add(TermAddr, TermAddr, EXPR_addr), - label(Foo), - + unpack_pair(EXPR, TermAddr, TEMP0, EXPR_addr), + load(TERM, TermAddr) +]),[ % TermAddr has the address of the term record. - - load_word(TERM, TermAddr, 0), % Bring the record in from RAM. - - % Now Term has the term's record data and TermAddr has the address of the term. - - lsl_imm(TEMP0, EXPR, 17), % Get the offset of the tail of the expr - asr_imm(TEMP0, TEMP0, 17), % while preserving the sign. - eq_offset(Foo0), % if the offset is zero don't add the address. it's empty list. - add(TEMP0, TEMP0, EXPR_addr), % Add the address to the offset. - label(Foo0), + % Now TERM has the term's record data and TermAddr has the address of the term. mov(EXPR_addr, TEMP0), - % EXPR_addr now holds the address of the next cell of the expression list. % if_literal(TERM, PUSH), @@ -110,33 +96,31 @@ Mark II % ====================================== label(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. load(TEMP1, TOS), % TEMP1 contains the record of the second stack cell. unpack_pair(TEMP1, TEMP2, TEMP3, TOS) - ]),[ +]),[ % TEMP2 contains the address of the second item on the stack % TEMP3 = TOS + TEMP1[15:0] the address of the third stack cell % Build and write the new list cell. sub_imm(SP, SP, 4) - - ],⟐([ - +],⟐([ 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_imm(SP, SP, 4) ],⟐( - sub_base_from_offset(TEMP3, SP) ),[ + sub_imm(SP, SP, 4) +],⟐( + sub_base_from_offset(TEMP3, SP) +),[ 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. diff --git a/thun/joy_asmii.bin b/thun/joy_asmii.bin index 5cf847d47353c1632535106f64ed21101e2b4e86..263d53413069e715f0bc6a91685185b863fa0073 100644 GIT binary patch delta 30 lcmcb?bc1O^jEEqEqnjW@k{crf!$U@f3^oRafaZw>F93N62onGR delta 30 lcmcb?bc1O^j0gimK(io&qnjW@k{crf!$U@f47P~{F93V62onGR