5009
This commit is contained in:
parent
938185b33c
commit
3fcc2371ec
|
@ -20,7 +20,7 @@ string-equal?: # s : (address string), benchmark : (address string) -> EAX : bo
|
|||
# i = 0
|
||||
# currs = s->data
|
||||
# currb = benchmark->data
|
||||
# while (i < s->length)
|
||||
# while i < s->length
|
||||
# c1 = *currs
|
||||
# c2 = *currb
|
||||
# if (c1 != c2) return false
|
||||
|
|
|
@ -235,10 +235,10 @@ next-stream-line-equal?: # f : (address stream), s : (address string) -> EAX :
|
|||
# pseudocode:
|
||||
# currf = f->read # bound: f->write
|
||||
# currs = 0 # bound : s->length
|
||||
# while true:
|
||||
# if (currf >= f->write)
|
||||
# while true
|
||||
# if currf >= f->write
|
||||
# return currs >= s->length
|
||||
# if (f[currf] == '\n')
|
||||
# if f[currf] == '\n'
|
||||
# ++currf
|
||||
# return currs >= s->length
|
||||
# if (currs >= s->length) return false # the current line of f still has data to match
|
||||
|
@ -249,7 +249,7 @@ next-stream-line-equal?: # f : (address stream), s : (address string) -> EAX :
|
|||
# collapsing the two branches that can return true:
|
||||
# currf = f->read # bound: f->write
|
||||
# currs = 0 # bound : s->length
|
||||
# while true:
|
||||
# while true
|
||||
# if (currf >= f->write) break
|
||||
# if (f[currf] == '\n') break
|
||||
# if (currs >= s->length) return false # the current line of f still has data to match
|
||||
|
|
|
@ -18,7 +18,7 @@ write-buffered: # f : (address buffered-file), msg : (address array byte) -> <v
|
|||
# in = msg->data
|
||||
# inend = &msg->data[msg->length]
|
||||
# while (in < inend)
|
||||
# if (f->write >= f->length)
|
||||
# if f->write >= f->length
|
||||
# flush(f)
|
||||
# clear-stream(f)
|
||||
# c = *in
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# just abort if 's' is too small
|
||||
read-line: # f : (address buffered-file), s : (address stream byte) -> <void>
|
||||
# pseudocode:
|
||||
# loop:
|
||||
# while true
|
||||
# if (s->write >= s->length) abort
|
||||
# if (f->read >= f->write) populate stream from file
|
||||
# if (f->write == 0) break
|
||||
|
|
|
@ -102,7 +102,7 @@ slice-equal?: # s : (address slice), p : (address string) -> EAX : boolean
|
|||
# maxs = s->end
|
||||
# if (maxs - currs != p->length) return false
|
||||
# currp = p->data
|
||||
# while (currs < maxs)
|
||||
# while currs < maxs
|
||||
# if (*currs != *currp) return false
|
||||
# ++currs
|
||||
# ++currp
|
||||
|
|
|
@ -201,7 +201,7 @@ $compile:end:
|
|||
get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void>
|
||||
# pseudocode:
|
||||
# if (!is-digit?(Look)) expected(ed, err, "integer")
|
||||
# if (out->write >= out->length)
|
||||
# if out->write >= out->length
|
||||
# write(err, "Error: too many digits in number\n")
|
||||
# stop(ed, 1)
|
||||
# out->data[out->write] = LSB(Look)
|
||||
|
|
|
@ -203,13 +203,13 @@ get-num: # in : (address buffered-file), out : (address stream), err : fd or (a
|
|||
# pseudocode:
|
||||
# if (!is-digit?(Look)) expected(ed, err, "integer")
|
||||
# do
|
||||
# if (out->write >= out->length)
|
||||
# if out->write >= out->length
|
||||
# write(err, "Error: too many digits in number\n")
|
||||
# stop(ed, 1)
|
||||
# out->data[out->write] = LSB(Look)
|
||||
# ++out->write
|
||||
# Look = get-char(in)
|
||||
# while (is-digit?(Look))
|
||||
# while is-digit?(Look)
|
||||
# This is complicated because I don't want to hard-code the error strategy in
|
||||
# a general helper like write-byte. Maybe I should just create a local helper.
|
||||
#
|
||||
|
|
|
@ -72,7 +72,7 @@ $main:end:
|
|||
# the main entry point
|
||||
convert: # in : (address buffered-file), out : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> <void>
|
||||
# pseudocode:
|
||||
# repeatedly
|
||||
# while true
|
||||
# EAX = convert-next-octet(in, err, ed)
|
||||
# if (EAX == Eof) break
|
||||
# write-byte(out, AL)
|
||||
|
@ -488,7 +488,7 @@ $test-convert-next-octet-aborts-on-single-hex-byte:end:
|
|||
# abort on any other byte
|
||||
scan-next-byte: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-Eof/EAX
|
||||
# pseudocode:
|
||||
# repeatedly
|
||||
# while true
|
||||
# EAX = read-byte(in)
|
||||
# if (EAX == Eof) return EAX
|
||||
# if (is-hex-digit?(EAX)) return EAX
|
||||
|
@ -1412,7 +1412,7 @@ $test-scan-next-byte-aborts-on-invalid-byte:end:
|
|||
skip-until-newline: # in : (address buffered-file) -> <void>
|
||||
# pseudocode:
|
||||
# push EAX
|
||||
# repeatedly:
|
||||
# while true
|
||||
# EAX = read-byte(in)
|
||||
# if (EAX == Eof) break
|
||||
# if (EAX == 0x0a) break
|
||||
|
|
|
@ -87,12 +87,12 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void
|
|||
# pseudocode:
|
||||
# var line = new-stream(512, 1)
|
||||
# var in-code? = false
|
||||
# repeatedly
|
||||
# while true
|
||||
# clear-stream(line)
|
||||
# read-line(in, line)
|
||||
# if (line->write == 0) break # end of file
|
||||
# var word-slice = next-word(line)
|
||||
# if (slice-empty?(word-slice)) # whitespace
|
||||
# if slice-empty?(word-slice) # whitespace
|
||||
# write-stream-buffered(out, line)
|
||||
# else if (slice-equal?(word-slice, "=="))
|
||||
# word-slice = next-word(line)
|
||||
|
@ -463,24 +463,24 @@ test-convert-passes-segment-headers-through:
|
|||
convert-code-segment: # in : (address buffered-file), out : (address buffered-file) -> <void>
|
||||
# pseudocode:
|
||||
# var line = new-stream(512, 1)
|
||||
# repeatedly
|
||||
# while true
|
||||
# clear-stream(line)
|
||||
# EAX = read-line(in, line)
|
||||
# if (EAX == Eof) break
|
||||
# word-slice = next-word(line)
|
||||
# if (slice-equal?(word-slice, "=="))
|
||||
# if slice-equal?(word-slice, "==")
|
||||
# return
|
||||
# convert-instruction(line, out)
|
||||
|
||||
convert-data-segment: # in : (address buffered-file), out : (address buffered-file) -> <void>
|
||||
# pseudocode:
|
||||
# var line = new-stream(512, 1)
|
||||
# repeatedly
|
||||
# while true
|
||||
# clear-stream(line)
|
||||
# EAX = read-line(in, line)
|
||||
# if (EAX == Eof) break
|
||||
# word-slice = next-word(line)
|
||||
# if (slice-equal?(word-slice, "=="))
|
||||
# if slice-equal?(word-slice, "==")
|
||||
# return
|
||||
# convert-data-word(line, out)
|
||||
|
||||
|
@ -488,7 +488,7 @@ convert-data-segment: # in : (address buffered-file), out : (address buffered-f
|
|||
# read first word as opcode and write-slice
|
||||
# if 0f or f2 or f3 read second opcode and write-slice
|
||||
# if 'f2 0f' or 'f3 0f' read third opcode and write-slice
|
||||
# while true:
|
||||
# while true
|
||||
# word-slice = next-word
|
||||
# if empty(word-slice) break
|
||||
# if has metadata 'mod', parse into mod
|
||||
|
@ -496,7 +496,7 @@ convert-data-segment: # in : (address buffered-file), out : (address buffered-f
|
|||
# if has metadata 'r32', parse into r32
|
||||
# if has metadata 'subop', parse into r32
|
||||
# if at least one of the 3 was present, print-byte
|
||||
# while true:
|
||||
# while true
|
||||
# word-slice = next-word
|
||||
# if empty(word-slice) break
|
||||
# if has metadata 'base', parse into base
|
||||
|
@ -504,13 +504,13 @@ convert-data-segment: # in : (address buffered-file), out : (address buffered-f
|
|||
# if has metadata 'scale', parse into scale
|
||||
# if at least one of the 3 was present, print-byte
|
||||
# parse errors => <abort>
|
||||
# while true:
|
||||
# while true
|
||||
# word-slice = next-word
|
||||
# if empty(word-slice) break
|
||||
# if has metadata 'disp8', emit as 1 byte
|
||||
# if has metadata 'disp16', emit as 2 bytes
|
||||
# if has metadata 'disp32', emit as 4 bytes
|
||||
# while true:
|
||||
# while true
|
||||
# word-slice = next-word
|
||||
# if empty(word-slice) break
|
||||
# if has metadata 'imm8', emit
|
||||
|
@ -536,7 +536,7 @@ convert-data-segment: # in : (address buffered-file), out : (address buffered-f
|
|||
convert-instruction: # line : (address stream byte), out : (address buffered-file) -> <void>
|
||||
# pseudocode:
|
||||
# word-slice = next-word
|
||||
# if (starts-with(word-slice, "#")) # comments
|
||||
# if starts-with(word-slice, "#") # comments
|
||||
# write-stream-buffered(out, line)
|
||||
# ...
|
||||
#
|
||||
|
@ -905,7 +905,7 @@ has-metadata?: # word : (address slice), s : (address string) -> EAX : boolean
|
|||
# pseudocode:
|
||||
# var twig : &slice = next-token-from-slice(word->start, word->end, '/') # skip name
|
||||
# curr = twig->end
|
||||
# while true:
|
||||
# while true
|
||||
# twig = next-token-from-slice(curr, word->end, '/')
|
||||
# if (twig.empty()) break
|
||||
# if (slice-equal?(twig, s)) return true
|
||||
|
|
|
@ -34,7 +34,7 @@ kernel-string-equal?: # s : null-terminated ascii string, benchmark : length-pr
|
|||
# s1 = s
|
||||
# s2 = benchmark->data
|
||||
# i = 0
|
||||
# while (i < n)
|
||||
# while i < n
|
||||
# c1 = *s1
|
||||
# c2 = *s2
|
||||
# if (c1 == 0) return false
|
||||
|
|
Loading…
Reference in New Issue