https://github.com/akkartik/mu/blob/main/shell/print.mu
1 fn print-cell _in: (addr handle cell), out: (addr stream byte), trace: (addr trace) {
2 trace-text trace, "print", "print"
3 trace-lower trace
4 var in/eax: (addr handle cell) <- copy _in
5 var in-addr/eax: (addr cell) <- lookup *in
6 {
7 compare in-addr, 0
8 break-if-!=
9 write out, "NULL"
10 trace-higher trace
11 return
12 }
13 {
14 var nil?/eax: boolean <- nil? in-addr
15 compare nil?, 0/false
16 break-if-=
17 write out, "()"
18 trace-higher trace
19 return
20 }
21 var in-type/ecx: (addr int) <- get in-addr, type
22 compare *in-type, 0/pair
23 {
24 break-if-!=
25 print-list in-addr, out, trace
26 trace-higher trace
27 return
28 }
29 compare *in-type, 1/number
30 {
31 break-if-!=
32 print-number in-addr, out, trace
33 trace-higher trace
34 return
35 }
36 compare *in-type, 2/symbol
37 {
38 break-if-!=
39 print-symbol in-addr, out, trace
40 trace-higher trace
41 return
42 }
43 compare *in-type, 3/stream
44 {
45 break-if-!=
46 print-stream in-addr, out, trace
47 trace-higher trace
48 return
49 }
50 compare *in-type, 4/primitive
51 {
52 break-if-!=
53 write out, "[primitive]"
54 trace-higher trace
55 return
56 }
57 compare *in-type, 5/primitive
58 {
59 break-if-!=
60 write out, "[screen "
61 var screen-ah/eax: (addr handle screen) <- get in-addr, screen-data
62 var screen/eax: (addr screen) <- lookup *screen-ah
63 var screen-addr/eax: int <- copy screen
64 write-int32-decimal out, screen-addr
65 write out, "]"
66 trace-higher trace
67 return
68 }
69 }
70
71
72 fn dump-cell in-ah: (addr handle cell) {
73 var stream-storage: (stream byte 0x40)
74 var stream/edx: (addr stream byte) <- address stream-storage
75 print-cell in-ah, stream, 0/no-trace
76 var d1/eax: int <- copy 0
77 var d2/ecx: int <- copy 0
78 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, 0/bg
79 }
80
81 fn print-symbol _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
82 trace-text trace, "print", "symbol&quZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
#define luaZ_buffer(buff) ((buff)->buffer)
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
#define luaZ_bufflen(buff) ((buff)->n)
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
#define luaZ_resizebuffer(L, buff, size) \
(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
(buff)->buffsize = size)
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
void *data);
LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
LUAI_FUNC int luaZ_lookahead (ZIO *z);
/* --------- Private Part ------------------ */
struct Zio {
size_t n; /* bytes still unread */
const char *p; /* current position in buffer */
lua_Reader reader;
void* data; /* additional data */
lua_State *L; /* Lua state (for reader) */
};
LUAI_FUNC int luaZ_fill (ZIO *z);
#endif