shell: stream literals

This commit is contained in:
Kartik K. Agaram 2021-04-27 23:10:30 -07:00
parent 9e9e40c05a
commit 55cde01edf
4 changed files with 47 additions and 3 deletions

View File

@ -85,6 +85,15 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel
trace-higher trace
return
}
compare *in-type, 3/stream
{
break-if-!=
# numbers are literals
trace-text trace, "eval", "stream"
copy-object _in, out
trace-higher trace
return
}
compare *in-type, 2/symbol
{
break-if-!=

View File

@ -175,9 +175,20 @@ fn parse-atom _curr-token: (addr cell), _out: (addr handle cell), trace: (addr t
}
return
}
# default: symbol
# just copy token data
allocate-symbol _out
# default: copy either to a symbol or a stream
# stream token -> literal
var stream-token?/eax: boolean <- stream-token? curr-token
compare stream-token?, 0/false
{
break-if-=
allocate-stream _out
}
compare stream-token?, 0/false
{
break-if-!=
allocate-symbol _out
}
# copy token data
var out/eax: (addr handle cell) <- copy _out
var out-addr/eax: (addr cell) <- lookup *out
var curr-token-data-ah/ecx: (addr handle stream byte) <- get curr-token, text-data

View File

@ -885,6 +885,23 @@ fn test-run-multiple-expressions-after-dot {
# further errors may occur
}
fn test-run-stream {
var sandbox-storage: sandbox
var sandbox/esi: (addr sandbox) <- address sandbox-storage
initialize-sandbox-with sandbox, "[a b]"
# eval
edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk, 0/no-screen, 0/no-tweak-screen
# setup: screen
var screen-on-stack: screen
var screen/edi: (addr screen) <- address screen-on-stack
initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
#
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
check-screen-row screen, 0/y, "[a b] ", "F - test-run-stream/0"
check-screen-row screen, 1/y, "... ", "F - test-run-stream/1"
check-screen-row screen, 2/y, "=> [a b] ", "F - test-run-stream/2"
}
fn test-run-move-cursor-into-trace {
var sandbox-storage: sandbox
var sandbox/esi: (addr sandbox) <- address sandbox-storage

View File

@ -624,6 +624,13 @@ fn number-token? _in: (addr cell) -> _/eax: boolean {
fn bracket-token? _in: (addr cell) -> _/eax: boolean {
var in/eax: (addr cell) <- copy _in
{
var in-type/eax: (addr int) <- get in, type
compare *in-type, 3/stream
break-if-!=
# streams are never paren tokens
return 0/false
}
var in-data-ah/eax: (addr handle stream byte) <- get in, text-data
var in-data/eax: (addr stream byte) <- lookup *in-data-ah
rewind-stream in-data