about summary refs log blame commit diff stats
path: root/shell/print.mu
blob: ea5db3cf4640ca2f681b0eb277e1314d8dd9d899 (plain) (tree)
6ef0eabd pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
Ranger v.1.3.0
==============

Ranger is a free console file manager that gives you greater flexibility
and a good overview of your files without having to leave your *nix console.
It visualizes the directory tree in two dimensions: the directory hierarchy
on one, lists of files on the other, with a preview to the right so you know
where you'll be going.

The default keys are similar to those of Vim, Emacs and Midnight Commander,
though Ranger is easily controllable with just the arrow keys or the mouse.

The program is written in Python (2.6 or 3.1) and uses curses for the
text-based user interface.


About
-----

* Author:          Roman Zimbelmann  <romanz@lavabit.com>
* Website:         http://savannah.nongnu.org/projects/ranger
* License:         GNU General Public License Version 3

* Download URL of the newest stable version:
http://git.savannah.gnu.org/cgit/ranger.git/snapshot/ranger-stable.tar.gz

* Git Clone URL:
git clone http://git.sv.gnu.org/r/ranger.git


Design Goals
------------

* An easily maintainable file manager in a high level language
* A quick way to switch directories and browse the file system
* Keep it small but useful, do one thing and do it well
* Console based, with smooth integration into the unix shell


Features
--------

* Multi-column display (Miller Columns)
* Preview of the selected file/directory
* Common file operations (create/chmod/copy/delete/...)
* VIM-like console and hotkeys
* Automatically determine file types and run them with correct programs
* Change the directory of your shell after exiting ranger
* Tabs, Bookmarks, Mouse support


Dependencies
------------

* A *nix-like operating system
* Python 2.6 or Python 3.1 with the curses module

Optional:
* The "file" program
* A pager ("less" by default)

For scope.sh: (enhanced file previews)
* img2txt (from caca-utils) for previewing images
* highlight for syntax highlighting of code
* atool for previews of archives
* lynx or elinks for previews of html pages


Getting Started
---------------

Ranger can be started without installing.  Just run the executable (in
a terminal.)  The switch "--clean" will prevent it from creating or
accessing configuration files.

Follow the instructions in the INSTALL file for installing ranger.

After starting ranger, you should see 4 columns. The third one is the main
column, the directory where you're currently at.  To the left you see the
parent directories and to the right there's a preview of the object you're
pointing at.  Now use the Arrow Keys to navigate, Enter to open a file
or type Q to quit.

To customize ranger, copy the files from ranger/defaults/ to ~/.config/ranger/
and modify them according to your wishes.


Usage Tips
----------

The author of ranger uses this function (in ~/.bashrc) to start ranger:
function ranger-cd {
  before="$(pwd)"
  python2.6 /the/path/to/ranger/ranger.py --fail-unless-cd "$@" || return 0
  after="$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)"
  if [[ "$before" != "$after" ]]; then
    cd "$after"
  fi
}
bind '"\C-o":"ranger-cd\C-m"'

This changes the directory after you close ranger and adds the shortcut
<CTRL-O> for starting ranger.

To change back to the previous directory, you can type: cd -


Troubleshooting, Getting Help
-----------------------------

If you encounter an error, try running ranger with --debug.  This will
sometimes display more detailed information about the error.  Also, try
deactivating optimization:

PYTHONOPTIMIZE="" ranger --debug

Report bugs on savannah:  (please include as much information as possible)
http://savannah.nongnu.org/bugs/?func=additem&group=ranger

Ask questions on the mailing list:
http://lists.nongnu.org/mailman/listinfo/ranger-users


Further Reading
---------------

Check the man page for information on common features and hotkeys.

The most detailed manual is accessible by pressing "?" from inside ranger.
It is also available at ranger/help/, contained in the *.py files.

The file ranger/defaults/keys.py contains all key combinations, so that's
another place you may want to check out.
='oid'>c3069ab8 ^
4b57c101 ^






c3069ab8 ^


97df52bf ^
17f77da2 ^

4b57c101 ^







17f77da2 ^



97df52bf ^







4b57c101 ^







97df52bf ^




17f77da2 ^



210c4837 ^

bcde6be5 ^
6842dddd ^
a54c6f2e ^
bcde6be5 ^
e2ab1b30 ^



bcde6be5 ^

2b616894 ^
bcde6be5 ^

6842dddd ^


e2ab1b30 ^



66c18fda ^
6842dddd ^

cb66df2e ^
0749772b ^
210c4837 ^




4b57c101 ^









0749772b ^

e2ab1b30 ^

ad46997f ^
0749772b ^







b0096cd6 ^






4b57c101 ^










b0096cd6 ^



e2ab1b30 ^

ad46997f ^
b0096cd6 ^







0749772b ^
4b57c101 ^







0749772b ^

f36f022b ^
0749772b ^
e2ab1b30 ^





0749772b ^


f36f022b ^
0749772b ^


27691024 ^
71a04056 ^


93f1bee0 ^

71a04056 ^



4b57c101 ^
71a04056 ^



93f1bee0 ^



4b57c101 ^
93f1bee0 ^







4b57c101 ^
93f1bee0 ^







4b57c101 ^
93f1bee0 ^



71a04056 ^
0749772b ^
4b57c101 ^






27691024 ^
0749772b ^
0749772b ^
4b57c101 ^






0749772b ^




4b57c101 ^
0749772b ^

1a1a1671 ^

0749772b ^

6d9a1e6a ^
27691024 ^
0749772b ^

4b57c101 ^






0749772b ^



4b57c101 ^






0749772b ^
27691024 ^
0749772b ^

210c4837 ^

4b57c101 ^






210c4837 ^
03178cde ^
0749772b ^

1a1a1671 ^
0749772b ^



cb66df2e ^
cb66df2e ^
0749772b ^
cb66df2e ^
0749772b ^





















89b7ea80 ^
0749772b ^

e2ab1b30 ^



0749772b ^





89b7ea80 ^
0749772b ^

e2ab1b30 ^



0749772b ^





89b7ea80 ^
0749772b ^

e2ab1b30 ^



0749772b ^





89b7ea80 ^

0749772b ^

e2ab1b30 ^



0749772b ^





89b7ea80 ^
0749772b ^

e2ab1b30 ^



0749772b ^





124be197 ^
0749772b ^

e2ab1b30 ^



0749772b ^



89b7ea80 ^






0749772b ^

89b7ea80 ^
0749772b ^


e2ab1b30 ^



0749772b ^
03178cde ^
249bef13 ^

















e2ab1b30 ^



249bef13 ^


d2b7e3f4 ^
















e2ab1b30 ^



d2b7e3f4 ^


249bef13 ^













e2ab1b30 ^



249bef13 ^

4b57c101 ^
















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591





                                                                                                       
                                                                                     
             
                                    
                   

                                            
   

                      






                                                       



                      

                                         
              





                                                     


                      
                                                  


                          
                                  


                      


                            
                                    
                      

          


                            
                                    
                      

          






                                    


                               






                                                              


                      
                            

               







                                                                   



                                                                       







                                    







                                                                   




                                                                               



                      

 
              
                                                     
                                          
                                                              



                                                                 

                           
                                                                                                                                        

 


                                                                     



                                                                 
                                                                                                

 
                                                                                
                                     




                                                                 









                                                               

                        

                                                       
            







                                                              






                                                                                










                                                               



                        

                                                       
            







                                                              
                                                                                







                                                               

                                                  
                                                           
         





                                                         


                                                              
                                                              


                              
                                                                              


                                                                     

                                               



                                                       
                                                



                                                         



                                                           
                                                







                                                         
                                                







                                                                 
                                                 



                                                         
   
                                       






                                                    
                     
                                                      
                               






                                                  




                                                        
                            

     

                                                    

                  
                                                 
                              

       






                                                      



                                                               






                                                         
                                  
                            

                           

        






                                                    
 
 

                                                                          
                                            



                                          
   
              
                  
   





















                                                        
                    

                                                        



                                                                 





                                                         
                    

                                                        



                                                                 





                                                            
                       

                                                        



                                                                 





                                                               

                                      

                                                        



                                                                 





                                                               
                       

                                                        



                                                                 





                                                             
                   

                                                        



                                                                 



                                                              






                                                          

                                                          
                            


                                                        



                                                                 
                                                                       
 

















                                                          



                                                                 


                                                                
















                                                          



                                                                 


                                                                   













                                                            



                                                                 

                                                                    
















































                                                                            
# 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)
fn print-cell _in: (addr handle cell), out: (addr stream byte), trace: (addr trace) {
  check-stack
  trace-text trace, "print", "print"
  trace-lower trace
  var in/eax: (addr handle cell) <- copy _in
  var in-addr/eax: (addr cell) <- lookup *in
  {
    compare in-addr, 0
    break-if-!=
    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'"
    }
    trace-higher trace
    return
  }
  {
    var nil?/eax: boolean <- nil? in-addr
    compare nil?, 0/false
    break-if-=
    var overflow?/eax: boolean <- try-write out, "()"
    compare overflow?, 0/false
    {
      break-if-=
      error trace, "print-cell: no space for '()'"
    }
    trace-higher trace
    return
  }
  var in-type/ecx: (addr int) <- get in-addr, type
  compare *in-type, 0/pair
  {
    break-if-!=
    print-pair in-addr, out, trace
    trace-higher trace
    return
  }
  compare *in-type, 1/number
  {
    break-if-!=
    print-number in-addr, out, trace
    trace-higher trace
    return
  }
  compare *in-type, 2/symbol
  {
    break-if-!=
    print-symbol in-addr, out, trace
    trace-higher trace
    return
  }
  compare *in-type, 3/stream
  {
    break-if-!=
    print-stream in-addr, out, trace
    trace-higher trace
    return
  }
  compare *in-type, 4/primitive
  {
    break-if-!=
    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"
    }
    trace-higher trace
    return
  }
  compare *in-type, 5/screen
  {
    break-if-!=
    {
      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
    }
    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
    write-int32-hex out, screen-addr
    write out, "]"
    trace-higher trace
    return
  }
  compare *in-type, 6/keyboard
  {
    break-if-!=
    {
      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
    }
    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
    write out, "]"
    trace-higher trace
    return
  }
}

# debug helper
fn dump-cell-at-top-right in-ah: (addr handle cell) {
  var stream-storage: (stream byte 0x1000)
  var stream/edx: (addr stream byte) <- address stream-storage
  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
  var d1/eax: int <- copy 0
  var d2/ecx: int <- copy 0
  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
}

fn dump-cell-from-cursor-over-full-screen in-ah: (addr handle cell) {
  var stream-storage: (stream byte 0x200)
  var stream/edx: (addr stream byte) <- address stream-storage
  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
  draw-stream-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, stream, 7/fg, 0/bg
}

fn print-symbol _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
  trace-text trace, "print", "symbol"
  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
  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
  }
  write-stream out, data
  # trace
  var should-trace?/eax: boolean <- should-trace? trace
  compare should-trace?, 0/false
  break-if-=
  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
}

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
  rewind-stream data
  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
  }
  write out, "["
  write-stream out, data
  write out, "]"
  # trace
  var should-trace?/eax: boolean <- should-trace? trace
  compare should-trace?, 0/false
  break-if-=
  rewind-stream data
  var stream-storage: (stream byte 0x40)
  var stream/ecx: (addr stream byte) <- address stream-storage
  write stream, "=> stream "
  write-stream stream, data
  trace trace, "print", stream
}

fn print-number _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
  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
  }
  var in/esi: (addr cell) <- copy _in
  var val/eax: (addr float) <- get in, number-data
  write-float-decimal-approximate out, *val, 0x10/precision
  # trace
  {
    var should-trace?/eax: boolean <- should-trace? trace
    compare should-trace?, 0/false
    break-if-!=
    return
  }
  var stream-storage: (stream byte 0x40)
  var stream/ecx: (addr stream byte) <- address stream-storage
  write stream, "=> number "
  write-float-decimal-approximate stream, *val, 0x10/precision
  trace trace, "print", stream
}

fn print-pair _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
  # 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
  var _left/eax: (addr cell) <- lookup *left-ah
  var left/ecx: (addr cell) <- copy _left
  var is-quote?/eax: boolean <- symbol-equal? left, "'"
  compare is-quote?, 0/false
  {
    break-if-=
    var dummy/eax: boolean <- try-write out, "'"
    var right-ah/eax: (addr handle cell) <- get in, right
    print-cell right-ah, out, trace
    return
  }
  var is-backquote?/eax: boolean <- symbol-equal? left, "`"
  compare is-backquote?, 0/false
  {
    break-if-=
    var dummy/eax: boolean <- try-write out, "`"
    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-=
    var dummy/eax: boolean <- try-write out, ","
    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-=
    var dummy/eax: boolean <- try-write out, ",@"
    var right-ah/eax: (addr handle cell) <- get in, right
    print-cell right-ah, out, trace
    return
  }
  #
  var curr/esi: (addr cell) <- copy _in
  {
    var overflow?/eax: boolean <- try-write out, "("
    compare overflow?, 0/false
    break-if-=
    error trace, "print-pair: no space for '('"
    return
  }
  $print-pair:loop: {
    var left/ecx: (addr handle cell) <- get curr, left
    print-cell left, out, trace
    # errors? skip
    {
      var error?/eax: boolean <- has-errors? trace
      compare error?, 0/false
      break-if-=
      return
    }
    var right/ecx: (addr handle cell) <- get curr, right
    var right-addr/eax: (addr cell) <- lookup *right
    {
      compare right-addr, 0
      break-if-!=
      abort "NULL in print!"
    }
    {
      var right-nil?/eax: boolean <- nil? right-addr
      compare right-nil?, 0/false
      {
        break-if-=
        trace-text trace, "print", "right is nil"
        break $print-pair:loop
      }
    }
    {
      var overflow?/eax: boolean <- try-write out, " "
      compare overflow?, 0/false
      break-if-=
      error trace, "print-pair: no space"
      return
    }
    var right-type-addr/edx: (addr int) <- get right-addr, type
    {
      compare *right-type-addr, 0/pair
      break-if-=
      {
        var overflow?/eax: boolean <- try-write out, ". "
        compare overflow?, 0/false
        break-if-=
        error trace, "print-pair: no space"
        return
      }
      print-cell right, out, trace
      break $print-pair:loop
    }
    curr <- copy right-addr
    loop
  }
  {
    var overflow?/eax: boolean <- try-write out, ")"
    compare overflow?, 0/false
    break-if-=
    error trace, "print-pair: no space for ')'"
    return
  }
}

# Most lisps intern nil, but we don't really have globals yet, so we'll be
# less efficient for now.
fn nil? _in: (addr cell) -> _/eax: boolean {
  var in/esi: (addr cell) <- copy _in
  # if type != pair, return false
  var type/eax: (addr int) <- get in, type
  compare *type, 0/pair
  {
    break-if-=
    return 0/false
  }
  # 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
  new-integer num, 0
  var out-storage: (stream byte 0x40)
  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 num, out, trace
  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
  new-integer num, 1
  var out-storage: (stream byte 0x40)
  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 num, out, trace
  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
  new-integer num, 0x30
  var out-storage: (stream byte 0x40)
  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 num, out, trace
  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
  var val/xmm0: float <- rational 1, 2
  new-float num, val
  var out-storage: (stream byte 0x40)
  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 num, out, trace
  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
  new-symbol sym, "abc"
  var out-storage: (stream byte 0x40)
  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
  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
  allocate-pair nil
  var out-storage: (stream byte 0x40)
  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 nil, out, trace
  check-stream-equal out, "()", "F - test-print-cell-nil-list"
}

fn test-print-cell-singleton-list {
  # 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
  var list-storage: (handle cell)
  var list/esi: (addr handle cell) <- address list-storage
  new-pair list, *left, *nil
  #
  var out-storage: (stream byte 0x40)
  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, "(abc)", "F - test-print-cell-singleton-list"
}

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
  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, "(64 abc)", "F - test-print-cell-list"
}

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
  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, "(64 ())", "F - test-print-cell-list-nil"
}

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
  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, "(abc . 64)", "F - test-print-dotted-list"
}

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"
}