This commit is contained in:
Kartik Agaram 2019-10-17 21:59:51 -07:00
parent 5a7f919dfa
commit 5409743432
32 changed files with 55 additions and 55 deletions

View File

@ -11,7 +11,7 @@ Entry: # just exit; can't test _write just yet
b8/copy-to-eax 1/imm32/exit
cd/syscall 0x80/imm8
_write: # fd : int, s : (address array byte) -> <void>
_write: # fd : int, s : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -21,7 +21,7 @@ Entry: # manual test
cd/syscall 0x80/imm8
# print msg to stderr if a != b, otherwise print "."
check-ints-equal: # (a : int, b : int, msg : (address array byte)) -> <void>
check-ints-equal: # (a : int, b : int, msg : (address array byte))
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -14,7 +14,7 @@
# . 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
clear-stream: # f : (address stream) -> <void>
clear-stream: # f : (address stream)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -51,7 +51,7 @@ $clear-stream:end:
5d/pop-to-ebp
c3/return
rewind-stream: # f : (address stream) -> <void>
rewind-stream: # f : (address stream)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -41,7 +41,7 @@ _test-trace-stream:
# Allocate a new segment for the trace stream, initialize its length, and save its address to Trace-stream.
# The Trace-stream segment will consist of variable-length lines separated by newlines (0x0a)
initialize-trace-stream: # n : int -> <void>
initialize-trace-stream: # n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -21,7 +21,7 @@
# . 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
# TODO: come up with a way to signal when a write to disk fails
write: # f : fd or (address stream), s : (address array byte) -> <void>
write: # f : fd or (address stream), s : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -41,7 +41,7 @@
# the stack.
# Ugly that we need to know the size of args. Don't allocate variables between
# tailor-exit-descriptor and the call it's for.
tailor-exit-descriptor: # ed : (address exit-descriptor), nbytes : int -> <void>
tailor-exit-descriptor: # ed : (address exit-descriptor), nbytes : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -15,7 +15,7 @@
#? b8/copy-to-eax 1/imm32/exit
#? cd/syscall 0x80/imm8
write-stream: # f : fd or (address stream), s : (address stream) -> <void>
write-stream: # f : fd or (address stream), s : (address stream)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -75,7 +75,7 @@ $write-stream:end:
5d/pop-to-ebp
c3/return
_write-stream: # fd : int, s : (address stream) -> <void>
_write-stream: # fd : int, s : (address stream)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -6,7 +6,7 @@
# . 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
# write(out, "Error: "+msg+"\n") then stop(ed, 1)
error: # ed : (address exit-descriptor), out : fd or (address stream), msg : (address array byte) -> <void>
error: # ed : (address exit-descriptor), out : fd or (address stream), msg : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -28,7 +28,7 @@ Stdout:
# . 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
# Write lower byte of 'n' to 'f'.
write-byte-buffered: # f : (address buffered-file), n : int -> <void>
write-byte-buffered: # f : (address buffered-file), n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -76,7 +76,7 @@ $write-byte-buffered:end:
5d/pop-to-ebp
c3/return
flush: # f : (address buffered-file) -> <void>
flush: # f : (address buffered-file)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -209,7 +209,7 @@ test-write-byte-buffered-multiple-flushes:
# - variant without buffering
# Write lower byte of 'n' to 'f'.
append-byte: # f : (address stream), n : int -> <void>
append-byte: # f : (address stream), n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -5,7 +5,7 @@
# . 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
write-buffered: # f : (address buffered-file), msg : (address array byte) -> <void>
write-buffered: # f : (address buffered-file), msg : (address array byte)
# pseudocode:
# in = msg->data
# inend = &msg->data[msg->length]

View File

@ -17,7 +17,7 @@ $to-hex-char:else:
05/add-to-eax 0x57/imm32/a-10
c3/return
append-byte-hex: # f : (address stream), n : int -> <void>
append-byte-hex: # f : (address stream), n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -89,7 +89,7 @@ test-append-byte-hex:
c3/return
# print the hex representation for the lowest byte of a number
print-byte-buffered: # f : (address buffered-file), n : int -> <void>
print-byte-buffered: # f : (address buffered-file), n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -176,7 +176,7 @@ test-print-byte-buffered:
# . end
c3/return
print-int32: # f : (address stream), n : int -> <void>
print-int32: # f : (address stream), n : int
# pseudocode:
# write(f, "0x")
# ecx = 28
@ -264,7 +264,7 @@ test-print-int32:
# . end
c3/return
print-int32-buffered: # f : (address buffered-file), n : int -> <void>
print-int32-buffered: # f : (address buffered-file), n : int
# pseudocode:
# write-buffered(f, "0x")
# ecx = 28

View File

@ -24,7 +24,7 @@
#? cd/syscall 0x80/imm8
# write(out, "Error: "+msg+": "+byte) then stop(ed, 1)
error-byte: # ed : (address exit-descriptor), out : (address buffered-file), msg : (address array byte), n : byte -> <void>
error-byte: # ed : (address exit-descriptor), out : (address buffered-file), msg : (address array byte), n : byte
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -6,7 +6,7 @@
# read bytes from 'f' until (and including) a newline and store them into 's'
# 's' fails to grow if and only if no data found
# just abort if 's' is too small
read-line-buffered: # f : (address buffered-file), s : (address stream byte) -> <void>
read-line-buffered: # f : (address buffered-file), s : (address stream byte)
# pseudocode:
# while true
# if (s->write >= s->length) abort
@ -220,7 +220,7 @@ test-read-line-buffered-reads-final-line-until-Eof:
# read bytes from 'f' until (and including) a newline and store them into 's'
# 's' fails to grow if and only if no data found
# just abort if 's' is too small
read-line: # f : (address stream), s : (address stream byte) -> <void>
read-line: # f : (address stream), s : (address stream byte)
# pseudocode:
# while true
# if (s->write >= s->length) abort

View File

@ -160,7 +160,7 @@ test-next-token-Eof:
# extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary)
# on reaching end of file, return an empty interval
next-token-from-slice: # start : (address byte), end : (address byte), delimiter : byte, out : (address slice) -> <void>
next-token-from-slice: # start : (address byte), end : (address byte), delimiter : byte, out : (address slice)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -8,7 +8,7 @@
# - construct a 'maximal slice' and pass it to write-slice-buffered
# - flush the buffered-file and pass the stream directly to its fd (disabling buffering)
# we'll go with the first way for now
write-stream-data: # f : (address buffered-file), s : (address stream) -> <void>
write-stream-data: # f : (address buffered-file), s : (address stream)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -4,7 +4,7 @@
# . 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
# print 'n' in hex in 'width' bytes in lower-endian order, with a space after every byte
emit-hex: # out : (address buffered-file), n : int, width : int -> <void>
emit-hex: # out : (address buffered-file), n : int, width : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -7,7 +7,7 @@
# it in 'width' bytes of hex, least significant first.
# Otherwise just print the entire word including metadata.
# Always print a trailing space.
emit: # out : (address buffered-file), word : (address slice), width : int -> <void>
emit: # out : (address buffered-file), word : (address slice), width : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -5,7 +5,7 @@
# read all bytes from 'f' and store them into 's'
# abort if 's' is too small
slurp: # f : (address buffered-file), s : (address stream byte) -> <void>
slurp: # f : (address buffered-file), s : (address stream byte)
# pseudocode:
# while true
# if (s->write >= s->length) abort

View File

@ -4,7 +4,7 @@
# . 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
# print 'arr' in hex with a space after every byte
emit-hex-array: # out : (address buffered-file), arr : (address array byte) -> <void>
emit-hex-array: # out : (address buffered-file), arr : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -5,7 +5,7 @@
# . 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
write-int: # out : (address stream), n : int -> <void>
write-int: # out : (address stream), n : int
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -86,7 +86,7 @@ $subx-assort-main:end:
# table: (address stream {string, (address stream byte)}) (8 bytes per row)
# inefficient; uses sequential search for looking up segments by name
subx-assort: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-assort: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var table : (address stream) = new-stream(10 rows, 8 bytes each)
# read-segments(in, table)

View File

@ -75,7 +75,7 @@ $subx-braces-main:end:
b8/copy-to-eax 1/imm32/exit
cd/syscall 0x80/imm8
subx-braces: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-braces: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var line = new-stream(512, 1)
# var label-stack : (address stack) = new-stack(32*4) # at most 32 levels of nesting

View File

@ -75,7 +75,7 @@ $subx-calls-main:end:
b8/copy-to-eax 1/imm32/exit
cd/syscall 0x80/imm8
subx-calls: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-calls: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var line = new-stream(512, 1)
# var words : (address stream slice) = new-stream(16, 8) # at most function name and 15 args

View File

@ -90,7 +90,7 @@ $main:end:
cd/syscall 0x80/imm8
# the main entry point
compile: # in : (address buffered-file), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void>
compile: # in : (address buffered-file), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -190,7 +190,7 @@ $compile:end:
# Read a single digit into 'out'. Abort if there are none, or if there is no space in 'out'.
# Input comes from the global variable 'Look', and we leave the next byte from
# 'in' into it on exit.
get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void>
get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor)
# pseudocode:
# if (!is-digit?(Look)) expected(ed, err, "integer")
# if out->write >= out->length
@ -472,7 +472,7 @@ test-get-num-aborts-on-non-digit-in-Look:
## helpers
# write(f, "Error: "+s+" expected\n") then stop(ed, 1)
expected: # ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void>
expected: # ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -514,7 +514,7 @@ $expected:dead-end:
c3/return
# read a byte from 'f', and save it in 'Look'
get-char: # f : (address buffered-file) -> <void>
get-char: # f : (address buffered-file)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -90,7 +90,7 @@ $main:end:
cd/syscall 0x80/imm8
# the main entry point
compile: # in : (address buffered-file), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void>
compile: # in : (address buffered-file), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -191,7 +191,7 @@ $compile:end:
# no space in 'out'.
# Input comes from the global variable 'Look' (first byte) and the argument
# 'in' (rest). We leave the next byte from 'in' into 'Look' on exit.
get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void>
get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor)
# pseudocode:
# if (!is-digit?(Look)) expected(ed, err, "integer")
# do
@ -672,7 +672,7 @@ test-get-num-reads-multiple-digits-followed-by-nondigit:
## helpers
# write(f, "Error: "+s+" expected\n") then stop(ed, 1)
expected: # ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void>
expected: # ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
@ -714,7 +714,7 @@ $expected:dead-end:
c3/return
# read a byte from 'f', and save it in 'Look'
get-char: # f : (address buffered-file) -> <void>
get-char: # f : (address buffered-file)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -82,7 +82,7 @@ $subx-dquotes-main:end:
# line = words separated by ' ', maybe followed by comment starting with '#'
# word = datum until '/', then 0 or more metadata separated by '/'
subx-dquotes: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-dquotes: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var line = new-stream(512, 1)
# var new-data-segment = new-stream(Heap, Segment-size, 1)

View File

@ -77,7 +77,7 @@ $subx-hex-main:end:
cd/syscall 0x80/imm8
# the main entry point
subx-hex: # in : (address buffered-file), out : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> <void>
subx-hex: # in : (address buffered-file), out : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor)
# pseudocode:
# while true
# eax = convert-next-octet(in, err, ed)
@ -1392,7 +1392,7 @@ $test-scan-next-byte-aborts-on-invalid-byte:end:
5d/pop-to-ebp
c3/return
skip-until-newline: # in : (address buffered-file) -> <void>
skip-until-newline: # in : (address buffered-file)
# pseudocode:
# push eax
# while true

View File

@ -74,7 +74,7 @@ $main:end:
# data contains a pointer to an array of 8-byte data fields and the common
# tag for them all
repl: # in : (address buffered-file), out : (address buffered-file) -> <void>
repl: # in : (address buffered-file), out : (address buffered-file)
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp

View File

@ -97,7 +97,7 @@ $subx-pack-main:end:
# next-token-from-slice(start, end, delim char) -> slice
# slice-equal?(slice, string)
subx-pack: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-pack: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var line = new-stream(512, 1)
# var in-code? = false
@ -933,7 +933,7 @@ test-subx-pack-code-and-data-segments:
5d/pop-to-ebp
c3/return
convert-data: # line : (address stream byte), out : (address buffered-file) -> <void>
convert-data: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# var word-slice = {0, 0}
# while true
@ -1853,7 +1853,7 @@ test-convert-data-trailing-comment:
# unceremoniously abort on non-numeric operands except disp or imm
# opcodes must be lowercase and zero padded
# opcodes with misleading operand metadata may get duplicated as operands as well. don't rely on this.
convert-instruction: # line : (address stream byte), out : (address buffered-file) -> <void>
convert-instruction: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# # some early exits
# var word-slice = next-word(line)
@ -1997,7 +1997,7 @@ $convert-instruction:end:
5d/pop-to-ebp
c3/return
emit-opcodes: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-opcodes: # line : (address stream byte), out : (address buffered-file)
# opcodes occupy 1-3 bytes:
# xx
# 0f xx
@ -2293,7 +2293,7 @@ $emit-opcodes:end:
5d/pop-to-ebp
c3/return
emit-modrm: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-modrm: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# rewind-stream(line)
# var has-modrm? = false, mod = 0, rm32 = 0, r32 = 0
@ -2612,7 +2612,7 @@ $emit-modrm:end:
5d/pop-to-ebp
c3/return
emit-sib: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-sib: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# var has-sib? = false, base = 0, index = 0, scale = 0
# var word-slice = {0, 0}
@ -2895,7 +2895,7 @@ $emit-sib:end:
5d/pop-to-ebp
c3/return
emit-disp: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-disp: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# rewind-stream(line)
# var word-slice = {0, 0}
@ -3116,7 +3116,7 @@ $emit-disp:break:
5d/pop-to-ebp
c3/return
emit-imm: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-imm: # line : (address stream byte), out : (address buffered-file)
# pseudocode:
# rewind-stream(line)
# var word-slice = {0, 0}
@ -3337,7 +3337,7 @@ $emit-imm:break:
5d/pop-to-ebp
c3/return
emit-line-in-comment: # line : (address stream byte), out : (address buffered-file) -> <void>
emit-line-in-comment: # line : (address stream byte), out : (address buffered-file)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp

View File

@ -104,7 +104,7 @@ $subx-sigils-main:end:
# error messages considered:
# *x + 34 -> error: base+disp addressing must be within '()'
subx-sigils: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-sigils: # in : (address buffered-file), out : (address buffered-file)
# pseudocode:
# var line = new-stream(512, 1)
# while true

View File

@ -113,7 +113,7 @@ $subx-survey-main:end:
# labels: (address stream {string, label-info}) (16 bytes per row)
# these are all inefficient; use sequential scans for lookups
subx-survey: # infile : (address buffered-file), out : (address buffered-file) -> <void>
subx-survey: # infile : (address buffered-file), out : (address buffered-file)
# pseudocode
# var in : (address stream byte) = stream(4096)
# slurp(infile, in)

View File

@ -67,7 +67,7 @@ $subx-tests-main:end:
b8/copy-to-eax 1/imm32/exit
cd/syscall 0x80/imm8
subx-gen-run-tests: # in : (address buffered-file), out : (address buffered-file) -> <void>
subx-gen-run-tests: # in : (address buffered-file), out : (address buffered-file)
# pseudocode
# bool tests-found = false
# var line = new-stream(512, 1)