# Translate literal strings within double quotes. # Replace them with references to new variables in the data segment. # # To run: # $ bootstrap/bootstrap translate [01]*.subx subx-params.subx dquotes.subx -o dquotes # $ cat x # == code # ab "cd ef"/imm32 # $ cat x |bootstrap/bootstrap run dquotes # == code # ab __string1/imm32 # == data # __string1: # 5/imm32 # 0x63/c 0x64/d 0x20/ 0x65/e 0x66/f == code # instruction effective address register displacement immediate # . op subop mod rm32 base index scale r32 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes Entry: # run tests if necessary, convert stdin if not # . prologue 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # initialize heap # . Heap = new-segment(Heap-size) # . . push args 68/push Heap/imm32 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32 # push *Heap-size # . . call e8/call new-segment/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # - if argc > 1 and argv[1] == "test", then return run-tests() # if (argc <= 1) goto interactive 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0/disp8 1/imm32 # compare *ebp 7e/jump-if-<= $subx-dquotes-main:interactive/disp8 # if (!kernel-string-equal?(argv[1], "test")) goto interactive # . eax = kernel-string-equal?(argv[1], "test") # . . push args 68/push "test"/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call kernel-string-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax == false) goto interactive 3d/compare-eax-and 0/imm32/false 74/jump-if-= $subx-dquotes-main:interactive/disp8 # run-tests() e8/call run-tests/disp32 # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $subx-dquotes-main:end/disp8 $subx-dquotes-main:interactive: # - otherwise convert stdin # var ed/eax: exit-descriptor 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # subtract from esp 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . . # copy esp to eax # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax # subx-dquotes(Stdin, Stdout, Stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 68/push Stdout/imm32 68/push Stdin/imm32 # . . call e8/call subx-dquotes/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $subx-dquotes-main:end: e8/call syscall_exit/disp32 # conceptual hierarchy within a line: # line = words separated by ' ', maybe followed by comment starting with '#' # word = datum until '/', then 0 or more metadata separated by '/' subx-dquotes: # in: (addr buffered-file), out: (addr buffered-file) # pseudocode: # var line: (stream byte 512) # var new-data-segment-handle: (handle stream byte) # new-stream(Heap, Segment-size, 1, new-data-segment-handle) # var new-data-segment: (addr stream byte) = lookup(new-data-segment-handle) # # write(new-data-segment, "== data\n") # # TODO: When it was originally written dquotes ran before assort, so # # it assumes lots of segment headers, and emits a new segment of its # # own. We've since had to reorder the phases (see the explanation # # for a.assort2 in translate_subx). We could clean up a.assort2 if we # # conditionally emit the previous line. But this would require # # teaching dquotes to parse segment headers, so maybe that's not # # best.. # # while true # clear-stream(line) # read-line-buffered(in, line) # if (line->write == 0) break # end of file # while true # var word-slice = next-word-or-string(line) # if slice-empty?(word-slice) # end of line # break # if slice-starts-with?(word-slice, "#") # comment # continue # if slice-starts-with?(word-slice, '"') # string literal <== what we're here for # process-string-literal(word-slice, out, new-data-segment) # else # write-slice-buffered(out, word-slice) # write(out, " ") # write(out, "\n\n") # write-stream-data(out, new-data-segment) # flush(out) # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 51/push-ecx 52/push-edx 53/push-ebx 56/push-esi 57/push-edi # var line/ecx: (stream byte 512) 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x200/imm32 # subtract from esp 68/push 0x200/imm32/length 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # var word-slice/edx: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . . # copy esp to edx # var new-data-segment-handle/edi: (handle stream byte) 68/push 0/imm32 68/push 0/imm32 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . . # copy esp to edi # new-stream(Heap, Segment-size, 1, new-data-segment-handle) # . . push args 57/push-edi 68/push 1/imm32 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32 # push *Segment-size 68/push Heap/imm32 # . . call e8/call new-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # var new-data-segment/edi: (addr stream byte) = lookup(*new-data-segment-handle) # . eax = lookup(*new-data-segment-handle) # . . push args ff 6/subop/push 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 . # push *(edi+4) ff 6/subop/push 0/mod/indirect 7/rm32/edi . . . . . . # push *edi # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . new-data-segment = eax 89/copy 3/mod/direct 7/rm32/edi . . . 0/r32/eax . . # copy eax to edi # write(new-data-segment, "== data\n") # . . push args 68/push "== data\n"/imm32 57/push-edi # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp $subx-dquotes:line-loop: # clear-stream(line) # . . push args 51/push-ecx # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # read-line-buffered(in, line) # . . push args 51/push-ecx ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp $subx-dquotes:check0: # if (line->write == 0) break 81 7/subop/compare 0/mod/indirect 1/rm32/ecx . . . . . 0/imm32 # compare *ecx 0f 84/jump-if-= $subx-dquotes:break/disp32 $subx-dquotes:word-loop: # next-word-or-string(line, word-slice) # . . push args 52/push-edx 51/push-ecx # . . call e8/call next-word-or-string/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp $subx-dquotes:check1: # if (slice-empty?(word-slice)) break # . eax = slice-empty?(word-slice) # . . push args 52/push-edx # . . call e8/call slice-empty?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . if (eax != false) break 3d/compare-eax-and 0/imm32/false 0f 85/jump-if-!= $subx-dquotes:next-line/disp32 $subx-dquotes:check-for-comment: # if (slice-starts-with?(word-slice, "#")) continue # . var start/esi: (addr byte) = word-slice->start 8b/copy 0/mod/indirect 2/rm32/edx . . . 6/r32/esi . . # copy *edx to esi # . var c/eax: byte = *start 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . . # copy byte at *esi to AL # . if (c == '#') continue 3d/compare-eax-and 0x23/imm32/hash 74/jump-if-= $subx-dquotes:word-loop/disp8 $subx-dquotes:check-for-string-literal: # if (slice-starts-with?(word-slice, '"')) continue 3d/compare-eax-and 0x22/imm32/dquote 75/jump-if-!= $subx-dquotes:regular-word/disp8 $subx-dquotes:string-literal: # process-string-literal(word-slice, out, new-data-segment) # . . push args 57/push-edi ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) 52/push-edx # . . call e8/call process-string-literal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # continue eb/jump $subx-dquotes:next-word/disp8 $subx-dquotes:regular-word: # write-slice-buffered(out, word-slice) # . . push args 52/push-edx ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # fall through $subx-dquotes:next-word: # write-buffered(out, " ") # . . push args 68/push Space/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # loop eb/jump $subx-dquotes:word-loop/disp8 $subx-dquotes:next-line: # write-buffered(out, "\n") # . . push args 68/push Newline/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # loop e9/jump $subx-dquotes:line-loop/disp32 $subx-dquotes:break: # write-stream-data(out, new-data-segment) # . . push args 57/push-edi ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-stream-data/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # flush(out) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call flush/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp $subx-dquotes:end: # . reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x21c/imm32 # add to esp # . restore registers 5f/pop-to-edi 5e/pop-to-esi 5b/pop-to-ebx 5a/pop-to-edx 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # Write out 'string-literal' in a new format to 'out-segment', assign it a new # label, and write the new label out to 'out'. process-string-literal: # string-literal: (addr slice), out: (addr buffered-file), out-segment: (addr stream byte) # pseudocode: # print(out-segment, "_string#{Next-string-literal}:\n") # emit-string-literal-data(out-segment, string-literal) # print(out, "_string#{Next-string-literal}") # emit-metadata(out, string-literal) # ++ *Next-string-literal # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx # var int32-stream/ecx: (stream byte 10) # number of decimal digits a 32-bit number can have 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0xa/imm32 # subtract from esp 68/push 0xa/imm32/decimal-digits-in-32bit-number 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # print(out-segment, "_string#{Next-string-literal}:\n") # . write(out-segment, "_string") # . . push args 68/push "_string"/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-int32-decimal(out-segment, *Next-string-literal) # . . push args ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-string-literal/disp32 # push *Next-string-literal ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) # . . call e8/call write-int32-decimal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(out-segment, ":\n") # . . push args 68/push ":\n"/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # emit-string-literal-data(out-segment, string-literal) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) # . . call e8/call emit-string-literal-data/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # write(out-segment, "\n") # . . push args 68/push Newline/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # print(out, "_string#{Next-string-literal}") # . write-buffered(out, "_string") # . . push args 68/push "_string"/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-int32-decimal(int32-stream, *Next-string-literal) # . . push args ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-string-literal/disp32 # push *Next-string-literal 51/push-ecx # . . call e8/call write-int32-decimal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-stream-data(out, int32-stream) # . . push args 51/push-ecx ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call write-stream-data/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # emit-metadata(out, string-literal) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call emit-metadata/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # ++ *Next-string-literal ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 . . . Next-string-literal/disp32 # increment *Num-test-failures $process-string-literal:end: # . reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x16/imm32 # add to esp # . restore registers 59/pop-to-ecx # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-subx-dquotes-is-idempotent-by-default: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-input-stream) # . . push args 68/push _test-input-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-input-buffered-file->buffer) # . . push args 68/push $_test-input-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream(_test-output-stream) # . . push args 68/push _test-output-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-output-buffered-file->buffer) # . . push args 68/push $_test-output-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # initialize input (meta comments in parens) # # comment 1 # # comment 2 indented # == code 0x1 (new segment) # # comment 3 inside a segment # 1 # (empty line) # 2 3 # comment 4 inline with other contents # == data 0x2 (new segment) # 4 5/imm32 # . write(_test-input-stream, "# comment 1\n") # . . push args 68/push "# comment 1\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, " # comment 2 indented\n") # . . push args 68/push " # comment 2 indented\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "== code 0x1\n") # . . push args 68/push "== code 0x1\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "# comment 3 inside a segment\n") # . . push args 68/push "# comment 3 inside a segment\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "1\n") # . . push args 68/push "1\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "\n") # empty line # . . push args 68/push Newline/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "2 3 # comment 4 inline with other contents\n") # . . push args 68/push "2 3 # comment 4 inline with other contents\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "== data 0x2\n") # . . push args 68/push "== data 0x2\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write(_test-input-stream, "4 5/imm32\n") # . . push args 68/push "4 5/imm32\n"/imm32 68/push _test-input-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # subx-dquotes(_test-input-buffered-file, _test-output-buffered-file) # . . push args 68/push _test-output-buffered-file/imm32 68/push _test-input-buffered-file/imm32 # . . call e8/call subx-dquotes/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . flush(_test-output-buffered-file) # . . push args 68/push _test-output-buffered-file/imm32 # . . call e8/call flush/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # check output # (comment dropped for now) # (comment dropped for now) # == code 0x1 # (comment dropped for now) # 1 # (comment dropped for now) # 2 3 # == data 0x2 # 4 5/imm32 # We don't care right now what exactly happens to comments. Trailing spaces are also minor details. #? # dump output {{{ #? # . write(2/stderr, "result: ^") #? # . . push args #? 68/push "result: ^"/imm32 #? 68/push 2/imm32/stderr #? # . . call #? e8/call write/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp #? # . write-stream(2/stderr, _test-output-stream) #? # . . push args #? 68/push _test-output-stream/imm32 #? 68/push 2/imm32/stderr #? # . . call #? e8/call write-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp #? # . write(2/stderr, "$\n") #? # . . push args #? 68/push "$\n"/imm32 #? 68/push 2/imm32/stderr #? # . . call #? e8/call write/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp #? # }}} # . check-next-stream-line-equal(_test-output-stream, "", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/0"/imm32 68/push ""/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/1"/imm32 68/push ""/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "== code 0x1 ", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/2"/imm32 68/push "== code 0x1 "/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/3"/imm32 68/push ""/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "1 ", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/4"/imm32 68/push "1 "/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/5"/imm32 68/push ""/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "2 3 ", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/6"/imm32 68/push "2 3 "/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "== data 0x2 ", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/7"/imm32 68/push "== data 0x2 "/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . check-next-stream-line-equal(_test-output-stream, "4 5/imm32 ", msg) # . . push args 68/push "F - test-subx-dquotes-is-idempotent-by-default/8"/imm32 68/push "4 5/imm32 "/imm32 68/push _test-output-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-subx-dquotes-processes-string-literals: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-input-stream) # . . push args 68/push _test-input-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-input-buffered-file->buffer) # . . push args 68/push $_test-input-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream(_test-output-stream) # . . push args 68/push _test-output-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-output-buffered-file->buffer) # . . push args 68/push $_test-output-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - linux/tile/rpn.mu</title>
<meta name="Generator" content="Vim/8.1">
<meta name="plugin-version" content="vim8.1_v1">
<meta name="syntax" content="none">
<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
<meta name="colorscheme" content="minimal-light">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; }
a { color:inherit; }
* { font-size:12pt; font-size: 1em; }
.PreProc { color: #c000c0; }
.LineNr { }
.CommentedCode { color: #8a8a8a; }
.Constant { color: #008787; }
.muComment { color: #005faf; }
.Delimiter { color: #c000c0; }
.muFunction { color: #af5f00; text-decoration: underline; }
.muTest { color: #5f8700; }
.Special { color: #ff6060; }
-->
</style>

<script type='text/javascript'>
<!--

/* function to open any folds containing a jumped-to line before jumping to it */
function JumpToLine()
{
  var lineNum;
  lineNum = window.location.hash;
  lineNum = lineNum.substr(1); /* strip off '#' */

  if (lineNum.indexOf('L') == -1) {
    lineNum = 'L'+lineNum;
  }
  var lineElem = document.getElementById(lineNum);
  /* Always jump to new location even if the line was hidden inside a fold, or
   * we corrected the raw number to a line ID.
   */
  if (lineElem) {
    lineElem.scrollIntoView(true);
  }
  return true;
}
if ('onhashchange' in window) {
  window.onhashchange = JumpToLine;
}

-->
</script>
</head>
<body onload='JumpToLine();'>
<a href='https://github.com/akkartik/mu/blob/main/linux/tile/rpn.mu'>https://github.com/akkartik/mu/blob/main/linux/tile/rpn.mu</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr">  1 </span><span class="PreProc">fn</span> <span class="muFunction"><a href='rpn.mu.html#L1'>evaluate</a></span> functions: (addr handle <a href='data.mu.html#L21'>function</a>), bindings: (addr <a href='data.mu.html#L59'>table</a>), scratch: (addr <a href='data.mu.html#L34'>line</a>), end: (addr <a href='data.mu.html#L42'>word</a>), out: (addr <a href='value-stack.mu.html#L3'>value-stack</a>) <span class="Delimiter">{</span>
<span id="L2" class="LineNr">  2 </span>  <span class="PreProc">var</span> <a href='data.mu.html#L34'>line</a>/<span class="Constant">eax</span>: (addr <a href='data.mu.html#L34'>line</a>) <span class="Special">&lt;-</span> copy scratch
<span id="L3" class="LineNr">  3 </span>  <span class="PreProc">var</span> word-ah/<span class="Constant">eax</span>: (addr handle <a href='data.mu.html#L42'>word</a>) <span class="Special">&lt;-</span> <a href='../131table.subx.html#L26'>get</a> <a href='data.mu.html#L34'>line</a>, data
<span id="L4" class="LineNr">  4 </span>  <span class="PreProc">var</span> curr/<span class="Constant">eax</span>: (addr <a href='data.mu.html#L42'>word</a>) <span class="Special">&lt;-</span> <a href='../120allocate.subx.html#L258'>lookup</a> *word-ah
<span id="L5" class="LineNr">  5 </span>  <span class="PreProc">var</span> curr-stream-storage: (stream byte <span class="Constant">0x10</span>)
<span id="L6" class="LineNr">  6 </span>  <span class="PreProc">var</span> curr-stream/<span class="Constant">edi</span>: (addr stream byte) <span class="Special">&lt;-</span> address curr-stream-storage
<span id="L7" class="LineNr">  7 </span>  <a href='value-stack.mu.html#L16'>clear-value-stack</a> out
<span id="L8" class="LineNr">  8 </span>  $evaluate:<span class="PreProc">loop</span>: <span class="Delimiter">{</span>
<span id="L9" class="LineNr">  9 </span>    <span class="muComment"># precondition (should never hit)</span>
<span id="L10" class="LineNr"> 10 </span>    compare curr, <span class="Constant">0</span>
<span id="L11" class="LineNr"> 11 </span>    <span class="PreProc">break-if-=</span>
<span id="L12" class="LineNr"> 12 </span>    <span class="muComment"># update curr-stream</span>
<span id="L13" class="LineNr"> 13 </span>    <a href='word.mu.html#L473'>emit-word</a> curr, curr-stream
<span id="L14" class="LineNr"> 14 </span><span class="CommentedCode">#?     print-string-to-real-screen &quot;eval: &quot;</span>
<span id="L15" class="LineNr"> 15 </span><span class="CommentedCode">#?     print-stream-to-real-screen curr-stream</span>
<span id="L16" class="LineNr"> 16 </span><span class="CommentedCode">#?     print-string-to-real-screen &quot;\n&quot;</span>
<span id="L17" class="LineNr"> 17 </span>    $evaluate:process-word: <span class="Delimiter">{</span>
<span id="L18" class="LineNr"> 18 </span>      <span class="muComment">### if curr-stream is an operator, perform it</span>
<span id="L19" class="LineNr"> 19 </span>      <span class="muComment">## numbers</span>
<span id="L20" class="LineNr"> 20 </span>      <span class="Delimiter">{</span>
<span id="L21" class="LineNr"> 21 </span>        <span class="PreProc">var</span> add?/<span class="Constant">eax</span>: boolean <span class="Special">&lt;-</span> <a href='../109stream-equal.subx.html#L9'>stream-data-equal?</a> curr-stream, <span class="Constant">&quot;+&quot;</span>
<span id="L22" class="LineNr"> 22 </span>        compare add?, <span class="Constant">0</span>
<span id="L23" class="LineNr"> 23 </span>        <span class="PreProc">break-if-=</span>
<span id="L24" class="LineNr"> 24 </span>        <span class="PreProc">var</span> _b/<span class="Constant">xmm0</span>: float <span class="Special">&lt;-</span> <a href='value-stack.mu.html#L88'>pop-number-from-value-stack</a> out
<span id="L25" class="LineNr"> 25 </span>        <span class="PreProc">var</span> b/<span class="Constant">xmm1</span>: float <span class="Special">&lt;-</span> copy _b
<span id="L26" class="LineNr"> 26 </span>        <span class="PreProc">var</span> a/<span class="Constant">xmm0</span>: float <span class="Special">&lt;-</span> <a href='value-stack.mu.html#L88'>pop-number-from-value-stack</a> out
<span id="L27" class="LineNr"> 27 </span>        a <span class="Special">&lt;-</span> add b
<span id="L28" class="LineNr"> 28 </span>        <a href='value-stack.mu.html#L22'>push-number-to-value-stack</a> out, a
<span id="L29" class="LineNr"> 29 </span>        <span class="PreProc">break</span> $evaluate:process-word
<span id="L30" class="LineNr"> 30 </span>      <span class="Delimiter">}</span>
<span id="L31" class="LineNr"> 31 </span>      <span class="Delimiter">{</span>
<span id="L32" class="LineNr"> 32 </span>        <span class="PreProc">var</span> sub?/<span class="Constant">eax</span>: boolean <span class="Special">&lt;-</span> <a href='../109stream-equal.subx.html#L9'>stream-data-equal?</a> curr-stream, <span class="Constant">&quot;-&quot;</span>
<span id="L33" class="LineNr"> 33 </span>        compare sub?, <span class="Constant">0</span>
<span id="L34" class="LineNr"> 34 </span>        <span class="PreProc">break-if-=</span>
<span id="L35" class="LineNr"> 35 </span>        <span class="PreProc">var</span> _b/<span class="Constant">xmm0</span>: float <span class="Special">&lt;-</span> <a href='value-stack.mu.html#L88'>pop-number-from-value-stack</a> out
<span id="L36" class="LineNr"> 36 </span>        <span class="PreProc">var</span> b/<span class="Constant">xmm1</span>: float <span class="Special">&lt;-</span> copy _b
<span id="L37" class="LineNr"> 37 </span>        <span class="PreProc">var</span> a/<span class="Constant">xmm0</span>: float <span class="Special">&lt;-</span> <a href='value-stack.mu.html#L88'>pop-number-from-value-stack</a> out
<span id="L38" class="LineNr"> 38 </span>        a <span class="Special">&lt;-</span> subtract b
<span id="L39" class="LineNr"> 39 </span>        <a href='value-stack.mu.html#L22'>push-number-to-value-stack</a> out, a
<span id="L40" class="LineNr"> 40 </span>        <span class="PreProc">break</span> $evaluate:process-word
<span id="L41" class="LineNr"> 41 </span>      <span class="Delimiter">}</span>
<span id="L42" class="LineNr"> 42 </span>      <span class="Delimiter">{</span>
<span id="L43" class="LineNr"> 43 </span>        <span class="PreProc">var</span> mul?/<span class="Constant">eax</span>: boolean <span class="Special">&lt;-</span> <a href='../109stream-equal.subx.html#L9'>stream-data-equal?</a> curr-stream, <span class="Constant">&quot;*&quot;</span>
<span id="L44" class="LineNr"> 44 </span>        compare mul?, <span class="Constant">0</span>
<span id="L45" class="LineNr"> 45 </span>        <span class="PreProc">break-if-=</span>
<span id="L46" class="LineNr"> 46 </span>        <span class="PreProc">var</span> _b/<s