2021-05-20 06:14:27 +00:00
|
|
|
# Scenario:
|
|
|
|
# print-cell can be used for printing into a trace
|
|
|
|
# traces can run out of space
|
|
|
|
# therefore, we need to gracefully handle insufficient space in 'out'
|
|
|
|
# if we're printing something 3 bytes or less, just make sure it doesn't crash
|
|
|
|
# if we're printing something longer than 3 bytes, try to fall back to ellipses (which are 3 bytes)
|
2021-02-27 21:05:07 +00:00
|
|
|
fn print-cell _in: (addr handle cell), out: (addr stream byte), trace: (addr trace) {
|
2021-04-19 06:10:01 +00:00
|
|
|
check-stack
|
2021-03-08 03:29:54 +00:00
|
|
|
trace-text trace, "print", "print"
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-lower trace
|
2021-02-22 06:06:03 +00:00
|
|
|
var in/eax: (addr handle cell) <- copy _in
|
|
|
|
var in-addr/eax: (addr cell) <- lookup *in
|
2021-04-06 16:07:25 +00:00
|
|
|
{
|
|
|
|
compare in-addr, 0
|
|
|
|
break-if-!=
|
2021-05-20 06:14:27 +00:00
|
|
|
var overflow?/eax: boolean <- try-write out, "NULL"
|
|
|
|
compare overflow?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
|
|
|
overflow? <- try-write out, "..."
|
|
|
|
error trace, "print-cell: no space for 'NULL'"
|
|
|
|
}
|
2021-04-06 16:07:25 +00:00
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
{
|
2021-03-08 03:46:21 +00:00
|
|
|
var nil?/eax: boolean <- nil? in-addr
|
|
|
|
compare nil?, 0/false
|
2021-03-02 07:25:22 +00:00
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
var overflow?/eax: boolean <- try-write out, "()"
|
|
|
|
compare overflow?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-cell: no space for '()'"
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-02-22 06:06:03 +00:00
|
|
|
var in-type/ecx: (addr int) <- get in-addr, type
|
2021-03-02 07:25:22 +00:00
|
|
|
compare *in-type, 0/pair
|
|
|
|
{
|
|
|
|
break-if-!=
|
2021-05-03 05:25:47 +00:00
|
|
|
print-pair in-addr, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-02-27 15:21:29 +00:00
|
|
|
compare *in-type, 1/number
|
|
|
|
{
|
|
|
|
break-if-!=
|
2021-02-27 21:05:07 +00:00
|
|
|
print-number in-addr, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-higher trace
|
2021-02-27 15:21:29 +00:00
|
|
|
return
|
|
|
|
}
|
2021-02-22 06:06:03 +00:00
|
|
|
compare *in-type, 2/symbol
|
|
|
|
{
|
|
|
|
break-if-!=
|
2021-02-27 21:05:07 +00:00
|
|
|
print-symbol in-addr, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-higher trace
|
2021-02-22 06:06:03 +00:00
|
|
|
return
|
|
|
|
}
|
2021-04-11 06:05:16 +00:00
|
|
|
compare *in-type, 3/stream
|
|
|
|
{
|
|
|
|
break-if-!=
|
|
|
|
print-stream in-addr, out, trace
|
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-04-09 05:37:05 +00:00
|
|
|
compare *in-type, 4/primitive
|
|
|
|
{
|
|
|
|
break-if-!=
|
2021-05-20 06:14:27 +00:00
|
|
|
var overflow?/eax: boolean <- try-write out, "[primitive]"
|
|
|
|
compare overflow?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
|
|
|
overflow? <- try-write out, "..."
|
|
|
|
error trace, "print-cell: no space for primitive"
|
|
|
|
}
|
2021-04-09 05:37:05 +00:00
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-04-18 06:40:49 +00:00
|
|
|
compare *in-type, 5/screen
|
2021-04-11 01:32:27 +00:00
|
|
|
{
|
|
|
|
break-if-!=
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var available-space/eax: int <- space-remaining-in-stream out
|
|
|
|
compare available-space, 0x10
|
|
|
|
break-if->=
|
|
|
|
var dummy/eax: boolean <- try-write out, "..."
|
|
|
|
error trace, "print-cell: no space for screen"
|
|
|
|
return
|
|
|
|
}
|
2021-04-11 01:32:27 +00:00
|
|
|
write out, "[screen "
|
|
|
|
var screen-ah/eax: (addr handle screen) <- get in-addr, screen-data
|
|
|
|
var screen/eax: (addr screen) <- lookup *screen-ah
|
|
|
|
var screen-addr/eax: int <- copy screen
|
2021-04-18 06:40:49 +00:00
|
|
|
write-int32-hex out, screen-addr
|
|
|
|
write out, "]"
|
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
|
|
|
compare *in-type, 6/keyboard
|
|
|
|
{
|
|
|
|
break-if-!=
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var available-space/eax: int <- space-remaining-in-stream out
|
|
|
|
compare available-space, 0x10
|
|
|
|
break-if->=
|
|
|
|
var dummy/eax: boolean <- try-write out, "..."
|
|
|
|
error trace, "print-cell: no space for keyboard"
|
|
|
|
return
|
|
|
|
}
|
2021-04-18 06:40:49 +00:00
|
|
|
write out, "[keyboard "
|
|
|
|
var keyboard-ah/eax: (addr handle gap-buffer) <- get in-addr, keyboard-data
|
|
|
|
var keyboard/eax: (addr gap-buffer) <- lookup *keyboard-ah
|
|
|
|
var keyboard-addr/eax: int <- copy keyboard
|
|
|
|
write-int32-hex out, keyboard-addr
|
2021-04-11 01:32:27 +00:00
|
|
|
write out, "]"
|
|
|
|
trace-higher trace
|
|
|
|
return
|
|
|
|
}
|
2021-02-22 06:06:03 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 23:18:46 +00:00
|
|
|
# debug helper
|
2021-04-22 14:56:49 +00:00
|
|
|
fn dump-cell-at-top-right in-ah: (addr handle cell) {
|
2021-05-06 22:46:54 +00:00
|
|
|
var stream-storage: (stream byte 0x1000)
|
2021-03-05 23:18:46 +00:00
|
|
|
var stream/edx: (addr stream byte) <- address stream-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edi: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell in-ah, stream, trace
|
2021-03-05 23:18:46 +00:00
|
|
|
var d1/eax: int <- copy 0
|
|
|
|
var d2/ecx: int <- copy 0
|
move color scheme closer to Solarized dark
sed -i 's,0x12/bg=almost-black,0xdc/bg=green-bg,g' shell/*.mu
sed -i 's, 0/bg, 0xc5/bg=blue-bg,g' shell/*.mu
sed -i 's, 7/fg=trace, 0x38/fg=trace,g' shell/*.mu
sed -i 's, 7/bg=grey, 0x5c/bg=black,g' shell/*.mu
Still a few issues.
Thanks Adrian Cochrane and Zach DeCook.
https://floss.social/@alcinnz/106152068473019933
https://social.librem.one/@zachdecook/106159988837603417
2021-05-01 22:37:55 +00:00
|
|
|
d1, d2 <- draw-stream-wrapping-right-then-down 0/screen, stream, 0/xmin, 0/ymin, 0x80/xmax, 0x30/ymax, 0/x, 0/y, 7/fg, 0xc5/bg=blue-bg
|
2021-03-05 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
snapshot: infix
Like parenthesize, I'm copying tests over from https://github.com/akkartik/wart
Unlike parenthesize, though, I can't just transliterate the code itself.
Wart was operating on an intermediate AST representation. Here I'm all
the way down to cells. That seemed like a good idea when I embarked, but
now I'm not so sure. Operating with the right AST data structure allowed
me to more easily iterate over the elements of a list. The natural recursion
for cells is not a good fit.
This patch and the next couple is an interesting case study in what makes
Unix so effective. Yes, you have to play computer, and yes it gets verbose
and ugly. But just diff and patch go surprisingly far in helping build a
picture of the state space in my brain.
Then again, there's a steep gradient of skills here. There are people who
can visualize state spaces using diff and patch far better than me, and
people who can't do it as well as me. Nature, nurture, having different
priorities, whatever the reason. Giving some people just the right crutch
excludes others.
2021-06-23 04:20:45 +00:00
|
|
|
fn dump-cell-from-cursor-over-full-screen in-ah: (addr handle cell), fg: int, bg: int {
|
2021-04-22 14:56:49 +00:00
|
|
|
var stream-storage: (stream byte 0x200)
|
|
|
|
var stream/edx: (addr stream byte) <- address stream-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edi: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell in-ah, stream, trace
|
snapshot: infix
Like parenthesize, I'm copying tests over from https://github.com/akkartik/wart
Unlike parenthesize, though, I can't just transliterate the code itself.
Wart was operating on an intermediate AST representation. Here I'm all
the way down to cells. That seemed like a good idea when I embarked, but
now I'm not so sure. Operating with the right AST data structure allowed
me to more easily iterate over the elements of a list. The natural recursion
for cells is not a good fit.
This patch and the next couple is an interesting case study in what makes
Unix so effective. Yes, you have to play computer, and yes it gets verbose
and ugly. But just diff and patch go surprisingly far in helping build a
picture of the state space in my brain.
Then again, there's a steep gradient of skills here. There are people who
can visualize state spaces using diff and patch far better than me, and
people who can't do it as well as me. Nature, nurture, having different
priorities, whatever the reason. Giving some people just the right crutch
excludes others.
2021-06-23 04:20:45 +00:00
|
|
|
draw-stream-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, stream, fg, bg
|
2021-04-22 14:56:49 +00:00
|
|
|
}
|
|
|
|
|
2021-02-27 21:05:07 +00:00
|
|
|
fn print-symbol _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
|
2021-03-02 07:25:22 +00:00
|
|
|
trace-text trace, "print", "symbol"
|
2021-02-22 06:06:03 +00:00
|
|
|
var in/esi: (addr cell) <- copy _in
|
|
|
|
var data-ah/eax: (addr handle stream byte) <- get in, text-data
|
|
|
|
var _data/eax: (addr stream byte) <- lookup *data-ah
|
|
|
|
var data/esi: (addr stream byte) <- copy _data
|
|
|
|
rewind-stream data
|
2021-05-20 06:14:27 +00:00
|
|
|
var _required-space/eax: int <- stream-size data
|
|
|
|
var required-space/ecx: int <- copy _required-space
|
|
|
|
var available-space/eax: int <- space-remaining-in-stream out
|
|
|
|
compare required-space, available-space
|
|
|
|
{
|
|
|
|
break-if-<=
|
|
|
|
var dummy/eax: boolean <- try-write out, "..."
|
|
|
|
error trace, "print-symbol: no space"
|
|
|
|
return
|
|
|
|
}
|
2021-07-04 01:27:01 +00:00
|
|
|
write-stream-immutable out, data
|
2021-03-02 07:25:22 +00:00
|
|
|
# trace
|
2021-05-20 03:56:37 +00:00
|
|
|
var should-trace?/eax: boolean <- should-trace? trace
|
|
|
|
compare should-trace?, 0/false
|
2021-04-19 06:10:01 +00:00
|
|
|
break-if-=
|
2021-03-02 07:25:22 +00:00
|
|
|
rewind-stream data
|
|
|
|
var stream-storage: (stream byte 0x40)
|
|
|
|
var stream/ecx: (addr stream byte) <- address stream-storage
|
|
|
|
write stream, "=> symbol "
|
|
|
|
write-stream stream, data
|
|
|
|
trace trace, "print", stream
|
|
|
|
}
|
|
|
|
|
2021-04-11 06:05:16 +00:00
|
|
|
fn print-stream _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
|
|
|
|
trace-text trace, "print", "stream"
|
|
|
|
var in/esi: (addr cell) <- copy _in
|
|
|
|
var data-ah/eax: (addr handle stream byte) <- get in, text-data
|
|
|
|
var _data/eax: (addr stream byte) <- lookup *data-ah
|
|
|
|
var data/esi: (addr stream byte) <- copy _data
|
2021-05-20 06:14:27 +00:00
|
|
|
var _required-space/eax: int <- stream-size data
|
|
|
|
var required-space/ecx: int <- copy _required-space
|
|
|
|
required-space <- add 2 # for []
|
|
|
|
var available-space/eax: int <- space-remaining-in-stream out
|
|
|
|
compare required-space, available-space
|
|
|
|
{
|
|
|
|
break-if-<=
|
|
|
|
var dummy/eax: boolean <- try-write out, "..."
|
|
|
|
error trace, "print-stream: no space"
|
|
|
|
return
|
|
|
|
}
|
2021-04-11 06:05:16 +00:00
|
|
|
write out, "["
|
2021-07-04 01:27:01 +00:00
|
|
|
write-stream-immutable out, data
|
2021-04-11 06:05:16 +00:00
|
|
|
write out, "]"
|
|
|
|
# trace
|
2021-05-20 03:56:37 +00:00
|
|
|
var should-trace?/eax: boolean <- should-trace? trace
|
|
|
|
compare should-trace?, 0/false
|
2021-04-19 06:10:01 +00:00
|
|
|
break-if-=
|
2021-04-11 06:05:16 +00:00
|
|
|
rewind-stream data
|
|
|
|
var stream-storage: (stream byte 0x40)
|
|
|
|
var stream/ecx: (addr stream byte) <- address stream-storage
|
|
|
|
write stream, "=> stream "
|
2021-07-04 01:27:01 +00:00
|
|
|
write-stream-immutable stream, data
|
2021-04-11 06:05:16 +00:00
|
|
|
trace trace, "print", stream
|
|
|
|
}
|
|
|
|
|
2021-03-02 07:25:22 +00:00
|
|
|
fn print-number _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
|
2021-05-20 06:14:27 +00:00
|
|
|
var available-space/eax: int <- space-remaining-in-stream out
|
|
|
|
compare available-space, 0x10
|
|
|
|
{
|
|
|
|
break-if->=
|
|
|
|
var dummy/eax: boolean <- try-write out, "..."
|
|
|
|
error trace, "print-number: no space"
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
var in/esi: (addr cell) <- copy _in
|
|
|
|
var val/eax: (addr float) <- get in, number-data
|
2021-06-18 04:24:11 +00:00
|
|
|
write-float-decimal-approximate out, *val, 0x10/precision
|
2021-03-02 07:25:22 +00:00
|
|
|
# trace
|
2021-05-20 03:56:37 +00:00
|
|
|
{
|
|
|
|
var should-trace?/eax: boolean <- should-trace? trace
|
|
|
|
compare should-trace?, 0/false
|
|
|
|
break-if-!=
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
var stream-storage: (stream byte 0x40)
|
|
|
|
var stream/ecx: (addr stream byte) <- address stream-storage
|
|
|
|
write stream, "=> number "
|
2021-06-18 04:24:11 +00:00
|
|
|
write-float-decimal-approximate stream, *val, 0x10/precision
|
2021-03-02 07:25:22 +00:00
|
|
|
trace trace, "print", stream
|
|
|
|
}
|
|
|
|
|
2021-05-03 05:25:47 +00:00
|
|
|
fn print-pair _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
|
2021-05-03 05:31:19 +00:00
|
|
|
# if in starts with a quote, print the quote outside the expression
|
|
|
|
var in/esi: (addr cell) <- copy _in
|
|
|
|
var left-ah/eax: (addr handle cell) <- get in, left
|
2021-05-03 19:02:12 +00:00
|
|
|
var _left/eax: (addr cell) <- lookup *left-ah
|
|
|
|
var left/ecx: (addr cell) <- copy _left
|
2021-05-03 05:31:19 +00:00
|
|
|
var is-quote?/eax: boolean <- symbol-equal? left, "'"
|
|
|
|
compare is-quote?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
var dummy/eax: boolean <- try-write out, "'"
|
2021-05-03 05:31:19 +00:00
|
|
|
var right-ah/eax: (addr handle cell) <- get in, right
|
|
|
|
print-cell right-ah, out, trace
|
|
|
|
return
|
|
|
|
}
|
2021-05-03 19:02:12 +00:00
|
|
|
var is-backquote?/eax: boolean <- symbol-equal? left, "`"
|
|
|
|
compare is-backquote?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
var dummy/eax: boolean <- try-write out, "`"
|
2021-05-03 19:02:12 +00:00
|
|
|
var right-ah/eax: (addr handle cell) <- get in, right
|
|
|
|
print-cell right-ah, out, trace
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var is-unquote?/eax: boolean <- symbol-equal? left, ","
|
|
|
|
compare is-unquote?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
var dummy/eax: boolean <- try-write out, ","
|
2021-05-03 19:02:12 +00:00
|
|
|
var right-ah/eax: (addr handle cell) <- get in, right
|
|
|
|
print-cell right-ah, out, trace
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var is-unquote-splice?/eax: boolean <- symbol-equal? left, ",@"
|
|
|
|
compare is-unquote-splice?, 0/false
|
|
|
|
{
|
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
var dummy/eax: boolean <- try-write out, ",@"
|
2021-05-03 19:02:12 +00:00
|
|
|
var right-ah/eax: (addr handle cell) <- get in, right
|
|
|
|
print-cell right-ah, out, trace
|
|
|
|
return
|
|
|
|
}
|
2021-05-03 05:31:19 +00:00
|
|
|
#
|
2021-03-02 07:25:22 +00:00
|
|
|
var curr/esi: (addr cell) <- copy _in
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var overflow?/eax: boolean <- try-write out, "("
|
|
|
|
compare overflow?, 0/false
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-pair: no space for '('"
|
|
|
|
return
|
|
|
|
}
|
2021-05-03 05:25:47 +00:00
|
|
|
$print-pair:loop: {
|
2021-03-02 07:25:22 +00:00
|
|
|
var left/ecx: (addr handle cell) <- get curr, left
|
|
|
|
print-cell left, out, trace
|
2021-05-20 06:14:27 +00:00
|
|
|
# errors? skip
|
|
|
|
{
|
|
|
|
var error?/eax: boolean <- has-errors? trace
|
|
|
|
compare error?, 0/false
|
|
|
|
break-if-=
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
var right/ecx: (addr handle cell) <- get curr, right
|
|
|
|
var right-addr/eax: (addr cell) <- lookup *right
|
|
|
|
{
|
|
|
|
compare right-addr, 0
|
|
|
|
break-if-!=
|
2021-07-01 03:43:34 +00:00
|
|
|
{
|
|
|
|
var overflow?/eax: boolean <- try-write out, " ... NULL"
|
|
|
|
compare overflow?, 0/false
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-pair: no space for ' ... NULL'"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
2021-03-02 07:25:22 +00:00
|
|
|
}
|
|
|
|
{
|
2021-03-08 03:46:21 +00:00
|
|
|
var right-nil?/eax: boolean <- nil? right-addr
|
|
|
|
compare right-nil?, 0/false
|
2021-03-02 07:25:22 +00:00
|
|
|
{
|
|
|
|
break-if-=
|
2021-04-17 15:23:55 +00:00
|
|
|
trace-text trace, "print", "right is nil"
|
2021-05-03 05:25:47 +00:00
|
|
|
break $print-pair:loop
|
2021-03-02 07:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var overflow?/eax: boolean <- try-write out, " "
|
|
|
|
compare overflow?, 0/false
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-pair: no space"
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
var right-type-addr/edx: (addr int) <- get right-addr, type
|
|
|
|
{
|
|
|
|
compare *right-type-addr, 0/pair
|
|
|
|
break-if-=
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var overflow?/eax: boolean <- try-write out, ". "
|
|
|
|
compare overflow?, 0/false
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-pair: no space"
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
print-cell right, out, trace
|
2021-05-03 05:25:47 +00:00
|
|
|
break $print-pair:loop
|
2021-03-02 07:25:22 +00:00
|
|
|
}
|
|
|
|
curr <- copy right-addr
|
2021-02-22 06:06:03 +00:00
|
|
|
loop
|
|
|
|
}
|
2021-05-20 06:14:27 +00:00
|
|
|
{
|
|
|
|
var overflow?/eax: boolean <- try-write out, ")"
|
|
|
|
compare overflow?, 0/false
|
|
|
|
break-if-=
|
|
|
|
error trace, "print-pair: no space for ')'"
|
|
|
|
return
|
|
|
|
}
|
2021-02-22 06:06:03 +00:00
|
|
|
}
|
2021-02-27 15:21:29 +00:00
|
|
|
|
2021-03-02 07:25:22 +00:00
|
|
|
# Most lisps intern nil, but we don't really have globals yet, so we'll be
|
|
|
|
# less efficient for now.
|
2021-03-08 03:46:21 +00:00
|
|
|
fn nil? _in: (addr cell) -> _/eax: boolean {
|
2021-03-02 07:25:22 +00:00
|
|
|
var in/esi: (addr cell) <- copy _in
|
|
|
|
# if type != pair, return false
|
|
|
|
var type/eax: (addr int) <- get in, type
|
|
|
|
compare *type, 0/pair
|
2021-02-27 21:05:07 +00:00
|
|
|
{
|
|
|
|
break-if-=
|
2021-03-02 07:25:22 +00:00
|
|
|
return 0/false
|
2021-02-27 21:05:07 +00:00
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
# if left != null, return false
|
|
|
|
var left-ah/eax: (addr handle cell) <- get in, left
|
|
|
|
var left/eax: (addr cell) <- lookup *left-ah
|
|
|
|
compare left, 0
|
|
|
|
{
|
|
|
|
break-if-=
|
|
|
|
return 0/false
|
|
|
|
}
|
|
|
|
# if right != null, return false
|
|
|
|
var right-ah/eax: (addr handle cell) <- get in, right
|
|
|
|
var right/eax: (addr cell) <- lookup *right-ah
|
|
|
|
compare right, 0
|
|
|
|
{
|
|
|
|
break-if-=
|
|
|
|
return 0/false
|
|
|
|
}
|
|
|
|
return 1/true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-zero {
|
|
|
|
var num-storage: (handle cell)
|
|
|
|
var num/esi: (addr handle cell) <- address num-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
new-integer num, 0
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell num, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "0", "F - test-print-cell-zero"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-integer {
|
|
|
|
var num-storage: (handle cell)
|
|
|
|
var num/esi: (addr handle cell) <- address num-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
new-integer num, 1
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell num, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "1", "F - test-print-cell-integer"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-integer-2 {
|
|
|
|
var num-storage: (handle cell)
|
|
|
|
var num/esi: (addr handle cell) <- address num-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
new-integer num, 0x30
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell num, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "48", "F - test-print-cell-integer-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-fraction {
|
|
|
|
var num-storage: (handle cell)
|
|
|
|
var num/esi: (addr handle cell) <- address num-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
var val/xmm0: float <- rational 1, 2
|
|
|
|
new-float num, val
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell num, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "0.5", "F - test-print-cell-fraction"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-symbol {
|
|
|
|
var sym-storage: (handle cell)
|
|
|
|
var sym/esi: (addr handle cell) <- address sym-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
new-symbol sym, "abc"
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell sym, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "abc", "F - test-print-cell-symbol"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-nil-list {
|
|
|
|
var nil-storage: (handle cell)
|
|
|
|
var nil/esi: (addr handle cell) <- address nil-storage
|
2021-03-02 07:27:07 +00:00
|
|
|
allocate-pair nil
|
2021-03-02 07:25:22 +00:00
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell nil, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "()", "F - test-print-cell-nil-list"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-singleton-list {
|
2021-03-02 07:43:25 +00:00
|
|
|
# list
|
|
|
|
var left-storage: (handle cell)
|
|
|
|
var left/ecx: (addr handle cell) <- address left-storage
|
|
|
|
new-symbol left, "abc"
|
|
|
|
var nil-storage: (handle cell)
|
|
|
|
var nil/edx: (addr handle cell) <- address nil-storage
|
|
|
|
allocate-pair nil
|
2021-03-02 07:25:22 +00:00
|
|
|
var list-storage: (handle cell)
|
|
|
|
var list/esi: (addr handle cell) <- address list-storage
|
2021-03-02 07:43:25 +00:00
|
|
|
new-pair list, *left, *nil
|
2021-03-02 07:25:22 +00:00
|
|
|
#
|
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell list, out, trace
|
2021-03-02 07:25:22 +00:00
|
|
|
check-stream-equal out, "(abc)", "F - test-print-cell-singleton-list"
|
2021-02-27 15:21:29 +00:00
|
|
|
}
|
2021-03-02 07:46:00 +00:00
|
|
|
|
|
|
|
fn test-print-cell-list {
|
|
|
|
# list = cons "abc", nil
|
|
|
|
var left-storage: (handle cell)
|
|
|
|
var left/ecx: (addr handle cell) <- address left-storage
|
|
|
|
new-symbol left, "abc"
|
|
|
|
var nil-storage: (handle cell)
|
|
|
|
var nil/edx: (addr handle cell) <- address nil-storage
|
|
|
|
allocate-pair nil
|
|
|
|
var list-storage: (handle cell)
|
|
|
|
var list/esi: (addr handle cell) <- address list-storage
|
|
|
|
new-pair list, *left, *nil
|
|
|
|
# list = cons 64, list
|
|
|
|
new-integer left, 0x40
|
|
|
|
new-pair list, *left, *list
|
|
|
|
#
|
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell list, out, trace
|
2021-03-02 07:46:00 +00:00
|
|
|
check-stream-equal out, "(64 abc)", "F - test-print-cell-list"
|
|
|
|
}
|
|
|
|
|
2021-03-07 19:05:03 +00:00
|
|
|
fn test-print-cell-list-of-nil {
|
|
|
|
# list = cons "abc", nil
|
|
|
|
var left-storage: (handle cell)
|
|
|
|
var left/ecx: (addr handle cell) <- address left-storage
|
|
|
|
allocate-pair left
|
|
|
|
var nil-storage: (handle cell)
|
|
|
|
var nil/edx: (addr handle cell) <- address nil-storage
|
|
|
|
allocate-pair nil
|
|
|
|
var list-storage: (handle cell)
|
|
|
|
var list/esi: (addr handle cell) <- address list-storage
|
|
|
|
new-pair list, *left, *nil
|
|
|
|
# list = cons 64, list
|
|
|
|
new-integer left, 0x40
|
|
|
|
new-pair list, *left, *list
|
|
|
|
#
|
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell list, out, trace
|
2021-03-07 19:05:03 +00:00
|
|
|
check-stream-equal out, "(64 ())", "F - test-print-cell-list-nil"
|
|
|
|
}
|
|
|
|
|
2021-03-02 07:46:00 +00:00
|
|
|
fn test-print-dotted-list {
|
|
|
|
# list = cons 64, "abc"
|
|
|
|
var left-storage: (handle cell)
|
|
|
|
var left/ecx: (addr handle cell) <- address left-storage
|
|
|
|
new-symbol left, "abc"
|
|
|
|
var right-storage: (handle cell)
|
|
|
|
var right/edx: (addr handle cell) <- address right-storage
|
|
|
|
new-integer right, 0x40
|
|
|
|
var list-storage: (handle cell)
|
|
|
|
var list/esi: (addr handle cell) <- address list-storage
|
|
|
|
new-pair list, *left, *right
|
|
|
|
#
|
|
|
|
var out-storage: (stream byte 0x40)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
2021-05-20 03:56:37 +00:00
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell list, out, trace
|
2021-03-02 07:46:00 +00:00
|
|
|
check-stream-equal out, "(abc . 64)", "F - test-print-dotted-list"
|
|
|
|
}
|
2021-05-20 06:14:27 +00:00
|
|
|
|
|
|
|
fn test-print-cell-interrupted {
|
|
|
|
var sym-storage: (handle cell)
|
|
|
|
var sym/esi: (addr handle cell) <- address sym-storage
|
|
|
|
new-symbol sym, "abcd" # requires 4 bytes
|
|
|
|
var out-storage: (stream byte 3) # space for just 3 bytes
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell sym, out, trace
|
|
|
|
# insufficient space to print out the symbol; print out ellipses if we can
|
|
|
|
check-stream-equal out, "...", "F - test-print-cell-interrupted"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-impossible {
|
|
|
|
var sym-storage: (handle cell)
|
|
|
|
var sym/esi: (addr handle cell) <- address sym-storage
|
|
|
|
new-symbol sym, "abcd" # requires 4 bytes
|
|
|
|
var out-storage: (stream byte 2)
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell sym, out, trace
|
|
|
|
# insufficient space even for ellipses; print nothing
|
|
|
|
check-stream-equal out, "", "F - test-print-cell-impossible"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test-print-cell-interrupted-list {
|
|
|
|
# list = (abcd) requires 6 bytes
|
|
|
|
var left-storage: (handle cell)
|
|
|
|
var left/ecx: (addr handle cell) <- address left-storage
|
|
|
|
new-symbol left, "abcd"
|
|
|
|
var nil-storage: (handle cell)
|
|
|
|
var nil/edx: (addr handle cell) <- address nil-storage
|
|
|
|
allocate-pair nil
|
|
|
|
var list-storage: (handle cell)
|
|
|
|
var list/esi: (addr handle cell) <- address list-storage
|
|
|
|
new-pair list, *left, *nil
|
|
|
|
#
|
|
|
|
var out-storage: (stream byte 4) # space for just 4 bytes
|
|
|
|
var out/edi: (addr stream byte) <- address out-storage
|
|
|
|
var trace-storage: trace
|
|
|
|
var trace/edx: (addr trace) <- address trace-storage
|
|
|
|
initialize-trace trace, 1/only-errors, 0x10/capacity, 0/visible
|
|
|
|
print-cell list, out, trace
|
|
|
|
check-stream-equal out, "(...", "F - test-print-cell-interrupted-list"
|
|
|
|
}
|