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,95 +1,95 @@
( (
(globals . ( (globals . (
(hline1 . (fn () (screen y lo hi color) (hline . [(def hline (fn (screen y color)
(while (< lo hi) (hline1 screen y 0 (width screen) color)))])
(pixel screen lo y color) (hline1 . [(def hline1 (fn (screen y lo hi color)
(set lo (+ lo 1))))) (while (< lo hi)
(vline1 . (fn () (screen x lo hi color) (pixel screen lo y color)
(while (< lo hi) (set lo (+ lo 1)))))])
(pixel screen x lo color) (vline . [(def vline (fn (screen x color)
(set lo (+ lo 1))))) (vline1 screen x 0 (height screen) color)))])
(hline . (fn () (screen y color) (vline1 . [(def vline1 (fn (screen x lo hi color)
(hline1 screen y 0 (width screen) color))) (while (< lo hi)
(vline . (fn () (screen y color) (pixel screen x lo color)
(vline1 screen y 0 (height screen) color))) (set lo (+ lo 1)))))])
(brline . (fn () (screen x0 y0 x1 y1 color) (fill_rect . [(def fill_rect (fn (screen x1 y1 x2 y2 color)
((fn (dx dy sx sy) (while (< y1 y2)
((fn (err) (hline1 screen y1 x1 x2 color)
(brline1 screen x0 y0 x1 y1 dx dy sx sy err color)) (set y1 (+ y1 1)))))])
(+ dx dy))) (brline . [(def brline (fn (screen x0 y0 x1 y1 color)
(abs (- x1 x0)) ((fn (dx dy sx sy)
(- 0 (abs (- y1 y0))) ((fn (err)
(sgn (- x1 x0)) (brline1 screen x0 y0 x1 y1 dx dy sx sy err color))
(sgn (- y1 y0))))) (+ dx dy)))
(brline1 . (fn () (screen x y xlast ylast dx dy sx sy err color) (abs (- x1 x0))
(while (not (and (= x xlast) (= y ylast))) (- 0 (abs (- y1 y0)))
(pixel screen x y color) (sgn (- x1 x0))
((fn (e2) (sgn (- y1 y0)))))])
(if (>= e2 dy) (brline1 . [(def brline1 (fn (screen x y xlast ylast dx dy sx sy err color)
(set x (+ x sx)) (while (not (and (= x xlast) (= y ylast)))
()) (pixel screen x y color)
(if (<= e2 dx) ((fn (e2)
(set y (+ y sy))) (if (>= e2 dy)
(set err (+ err (set x (+ x sx))
(+ ())
(if (>= e2 dy) (if (<= e2 dx)
dy (set y (+ y sy)))
0) (set err (+ err
(if (<= e2 dx) (+
dx (if (>= e2 dy)
0))))) dy
(* err 2))))) 0)
(read_line_2 . (fn () (keyboard stream) (if (<= e2 dx)
((fn (c) dx
(if (= c 10) 0)))))
stream (* err 2)))))])
(if (= c 0) (read_line_2 . [(def read_line_2 (fn (keyboard stream)
stream ((fn (c)
(read_line_2 keyboard (write stream c))))) (if (= c 10)
(key keyboard)))) stream
(read_line . (fn () (keyboard) (if (= c 0)
(read_line_2 keyboard (stream)))) stream
(fill_rect . (fn () (screen x1 y1 x2 y2 fill_color) (read_line_2 keyboard (write stream c)))))
(while (< y1 y2) (key keyboard))))])
(hline1 screen y1 x1 x2 fill_color) (read_line . [(def read_line (fn (keyboard)
(set y1 (+ y1 1))))) (read_line_2 keyboard (stream))))])
(chessboard . (fn () (screen px) (chessboard . [(def chessboard (fn (screen px)
(chessboard1 screen px 0 15))) (chessboard1 screen px 0 15)))])
(chessboard1 . (fn () (screen px y color) (chessboard1 . [(def 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)
(pixel screen (- cx y) (- cy x) color) (pixel screen (- cx y) (- cy x) color)
(pixel screen (+ cx x) (- cy y) color) (pixel screen (+ cx x) (- cy y) color)
(pixel screen (+ cx y) (+ cy x) color) (pixel screen (+ cx y) (+ cy x) color)
(set r err) (set r err)
(if (<= r y) (if (<= r y)
(set err (+ err (+ 1 (* 2 (set y (+ y 1)))))) (set err (+ err (+ 1 (* 2 (set y (+ y 1))))))
()) ())
(if (or (> r x) (> err y)) (if (or (> r x) (> err y))
(set err (+ err (+ 1 (* 2 (set x (+ x 1)))))) (set err (+ err (+ 1 (* 2 (set x (+ x 1))))))
()) ())
(set continue (< x 0)) (set continue (< x 0))
)) ))
(- 0 r) (- 0 r)
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\)*[^\]]*\]')