diff --git a/thun/asm-dump.txt b/thun/asm-dump.txt index 5586273..d0ea581 100644 --- a/thun/asm-dump.txt +++ b/thun/asm-dump.txt @@ -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 --git a/thun/compiler.markII.pl b/thun/compiler.markII.pl index e3bfa45..77838f4 100644 --- a/thun/compiler.markII.pl +++ b/thun/compiler.markII.pl @@ -85,7 +85,7 @@ Mark II % ====================================== ],⟐([ - 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. @@ -107,8 +107,7 @@ Mark II jump(Done) % Rely on mainloop::Done to write TOS to RAM. ]),[ label(Expression), - expr_cell(ConsSym, 0), - label(ConsSym), symbol(Cons) + expr_cell(Cons, 0) ]. @@ -172,6 +171,8 @@ language. [mov_imm_with_shift(In, 2), % In := 4 << 15 ior(In, In, Term)]. +⟐(definition(Name)) --> [label(Name), symbol(Name)]. + do :- compile_program(Binary), @@ -218,9 +219,13 @@ asm([(N, Instruction)|Rest]) --> !, asm(N, Instruction), asm(Rest). asm(Here, expr_cell(Func, NextCell)) --> !, {Data is ((Func - Here) << 15) \/ NextCell}, asm(Here, word(Data)). -asm(_, symbol(Sym)) --> !, {Data is Sym \/ 0x80000000}, asm(_, word(Data)). +asm(_, symbol(Sym)) --> !, {Data is (Sym + 4) \/ 0x80000000}, asm(_, word(Data)). +% The symbol is at the beginning of the function machine code, so the pointer it +% holds to that code has to be one word beyond the pointer/label Sym that points +% to the symbol itself (one word before the machine code.) The symbol's address +% is used in expressions. -asm(_, word(Word)) --> !, {binary_number(Bits, Word)}, collect(32, Bits). +asm(_, word(Word)) --> !, encode_int(32, Word). asm(_, load_word(A, B, Offset)) --> !, instruction_format_F2(0, 0, A, B, Offset). asm(_, load_byte(A, B, Offset)) --> !, instruction_format_F2(0, 1, A, B, Offset). diff --git a/thun/joy_asmii.bin b/thun/joy_asmii.bin index 263d534..ca464de 100644 Binary files a/thun/joy_asmii.bin and b/thun/joy_asmii.bin differ diff --git a/thun/markII.rst b/thun/markII.rst index 4e4b453..5ab89a0 100644 --- a/thun/markII.rst +++ b/thun/markII.rst @@ -295,6 +295,23 @@ useful for appending lists to other lists. Yeah, I think that's the way to go... +--------------------------------------------- + +There's soething fishey with the symbols now that they are in the header +of the machine code. Each symbol's pointer field points to the next cell, +which seems really redundant. We need some symbol record to +differentiate from lists and ints. Maybe if more information was in the +header? Like the name of the function? It would make more sense? + +Right now I'm assuming that the eventual parser would be looking up +symbols at parse-time and reusing the header symbols rather than +allocating cells for new ones. If the symbols were kept apart from the +machine code then it makes sense for them to have pointers? + +Maybe I can dispense with symbol records by modifying the +is-this-a-symbol code to just check if the address is below the end of +the library code. + PC == 0