belatedly migrate stale example definitions

Also bare-bones syntax highlighting for .limg files. Doesn't work when
.limg file is first file opened with Vim.
This commit is contained in:
Kartik K. Agaram 2021-05-06 15:46:54 -07:00
parent effbe423a7
commit a54c6f2ee7
4 changed files with 99 additions and 93 deletions

View File

@ -1,18 +1,22 @@
( (
(globals . ( (globals . (
(hline1 . (fn () (screen y lo hi color) (hline . [(def hline (fn (screen y color)
(hline1 screen y 0 (width screen) color)))])
(hline1 . [(def hline1 (fn (screen y lo hi color)
(while (< lo hi) (while (< lo hi)
(pixel screen lo y color) (pixel screen lo y color)
(set lo (+ lo 1))))) (set lo (+ lo 1)))))])
(vline1 . (fn () (screen x lo hi color) (vline . [(def vline (fn (screen x color)
(vline1 screen x 0 (height screen) color)))])
(vline1 . [(def vline1 (fn (screen x lo hi color)
(while (< lo hi) (while (< lo hi)
(pixel screen x lo color) (pixel screen x lo color)
(set lo (+ lo 1))))) (set lo (+ lo 1)))))])
(hline . (fn () (screen y color) (fill_rect . [(def fill_rect (fn (screen x1 y1 x2 y2 color)
(hline1 screen y 0 (width screen) color))) (while (< y1 y2)
(vline . (fn () (screen y color) (hline1 screen y1 x1 x2 color)
(vline1 screen y 0 (height screen) color))) (set y1 (+ y1 1)))))])
(brline . (fn () (screen x0 y0 x1 y1 color) (brline . [(def brline (fn (screen x0 y0 x1 y1 color)
((fn (dx dy sx sy) ((fn (dx dy sx sy)
((fn (err) ((fn (err)
(brline1 screen x0 y0 x1 y1 dx dy sx sy err color)) (brline1 screen x0 y0 x1 y1 dx dy sx sy err color))
@ -20,8 +24,8 @@
(abs (- x1 x0)) (abs (- x1 x0))
(- 0 (abs (- y1 y0))) (- 0 (abs (- y1 y0)))
(sgn (- x1 x0)) (sgn (- x1 x0))
(sgn (- y1 y0))))) (sgn (- y1 y0)))))])
(brline1 . (fn () (screen x y xlast ylast dx dy sx sy err color) (brline1 . [(def brline1 (fn (screen x y xlast ylast dx dy sx sy err color)
(while (not (and (= x xlast) (= y ylast))) (while (not (and (= x xlast) (= y ylast)))
(pixel screen x y color) (pixel screen x y color)
((fn (e2) ((fn (e2)
@ -38,36 +42,32 @@
(if (<= e2 dx) (if (<= e2 dx)
dx dx
0))))) 0)))))
(* err 2))))) (* err 2)))))])
(read_line_2 . (fn () (keyboard stream) (read_line_2 . [(def read_line_2 (fn (keyboard stream)
((fn (c) ((fn (c)
(if (= c 10) (if (= c 10)
stream stream
(if (= c 0) (if (= c 0)
stream stream
(read_line_2 keyboard (write stream c))))) (read_line_2 keyboard (write stream c)))))
(key keyboard)))) (key keyboard))))])
(read_line . (fn () (keyboard) (read_line . [(def read_line (fn (keyboard)
(read_line_2 keyboard (stream)))) (read_line_2 keyboard (stream))))])
(fill_rect . (fn () (screen x1 y1 x2 y2 fill_color) (chessboard . [(def chessboard (fn (screen px)
(while (< y1 y2) (chessboard1 screen px 0 15)))])
(hline1 screen y1 x1 x2 fill_color) (chessboard1 . [(def chessboard1 (fn (screen px y color)
(set y1 (+ y1 1)))))
(chessboard . (fn () (screen px)
(chessboard1 screen px 0 15)))
(chessboard1 . (fn () (screen px y color)
(clear screen) (clear screen)
(while (< y (height screen)) (while (< y (height screen))
(chessboard2 screen px y 0 color) (chessboard2 screen px y 0 color)
(set y (+ y px)) (set y (+ y px))
(chessboard2 screen px y px color) (chessboard2 screen px y px color)
(set y (+ y px))))) (set y (+ y px)))))])
(chessboard2 . (fn () (screen px y x color) (chessboard2 . [(def chessboard2 (fn (screen px y x color)
(while (< x (width screen)) (while (< x (width screen))
(fill_rect screen x y (+ x px) (+ y px) color) (fill_rect screen x y (+ x px) (+ y px) color)
(set x (+ x px)) (set x (+ x px))
(set x (+ x px))))) (set x (+ x px)))))])
(brcircle . (fn () (screen cx cy r color) (brcircle . [(def brcircle (fn (screen cx cy r color)
((fn (x y err continue) ((fn (x y err continue)
(while continue (while continue
(pixel screen (- cx x) (+ cy y) color) (pixel screen (- cx x) (+ cy y) color)
@ -87,9 +87,9 @@
0 0
(- 2 (* 2 r)) (- 2 (* 2 r))
1 1
))) )))])
(main . (fn () (screen keyboard) (main . [(def main (fn (screen keyboard)
(chessboard screen 16))) (chessboard screen 16)))])
)) ))
(sandbox . (brcircle screen 5 5 3 12)) (sandbox . (fill_rect screen 0 0 8 8 2))
) )

View File

@ -83,7 +83,7 @@ fn print-cell _in: (addr handle cell), out: (addr stream byte), trace: (addr tra
# debug helper # debug helper
fn dump-cell-at-top-right in-ah: (addr handle cell) { fn dump-cell-at-top-right in-ah: (addr handle cell) {
var stream-storage: (stream byte 0x200) var stream-storage: (stream byte 0x1000)
var stream/edx: (addr stream byte) <- address stream-storage var stream/edx: (addr stream byte) <- address stream-storage
print-cell in-ah, stream, 0/no-trace print-cell in-ah, stream, 0/no-trace
var d1/eax: int <- copy 0 var d1/eax: int <- copy 0

View File

@ -9,13 +9,15 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
var token-storage: cell var token-storage: cell
var token/edx: (addr cell) <- address token-storage var token/edx: (addr cell) <- address token-storage
{ {
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "a", 7/fg 0/bg
skip-whitespace-from-gap-buffer in skip-whitespace-from-gap-buffer in
var done?/eax: boolean <- gap-buffer-scan-done? in var done?/eax: boolean <- gap-buffer-scan-done? in
compare done?, 0/false compare done?, 0/false
break-if-!= break-if-!=
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "b", 7/fg 0/bg
# initialize token data each iteration to avoid aliasing # initialize token data each iteration to avoid aliasing
var dest-ah/eax: (addr handle stream byte) <- get token, text-data var dest-ah/eax: (addr handle stream byte) <- get token, text-data
populate-stream dest-ah, 0x100/max-definition-size populate-stream dest-ah, 0x400/max-definition-size
# #
next-token in, token, trace next-token in, token, trace
var skip?/eax: boolean <- comment-token? token var skip?/eax: boolean <- comment-token? token
@ -27,7 +29,9 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
break-if-= break-if-=
return return
} }
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "y", 7/fg 0/bg
write-to-stream out, token # shallow-copy text-data write-to-stream out, token # shallow-copy text-data
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "z", 7/fg 0/bg
loop loop
} }
trace-higher trace trace-higher trace

View File

@ -96,3 +96,5 @@ inoremap <Leader>ahs <Esc>F<Space>a(addr handle stream <Esc>A)
inoremap <Leader>o <Esc>F<Space>a(offset <Esc>A) inoremap <Leader>o <Esc>F<Space>a(offset <Esc>A)
inoremap ,- <- inoremap ,- <-
inoremap -. -> inoremap -. ->
autocmd BufReadPost,BufNewFile *.limg call matchadd('String', '\[\([^\]]*\_$\_s\)*[^\]]*\]')