https://github.com/akkartik/mu/blob/master/306files.subx
  1 # Methods for constructing buffered-file objects.
  2 #
  3 # TODO: There are hard-coded parameters here for buffer sizes. When they
  4 # overflow, tracking down what's going on can get hairy.
  5 #
  6 # HACK: buffered-file stores naked addrs. This is safe because buffered-file
  7 # objects are opaque. But still sub-optimal; they'll be harder to reclaim when
  8 # we get around to that.
  9 
 10 == code
 11 
 12 open:  # filename: (addr array byte), write?: boolean, out: (addr handle buffered-file)
 13     # . prologue
 14     55/push-ebp
 15     89/<- %ebp 4/r32/esp
 16     # . save registers
 17     50/push-eax
 18     51/push-ecx
 19     52/push-edx
 20     53/push-ebx
 21     56/push-esi
 22     57/push-edi
 23     # ecx = filename
 24     8b/-> *(ebp+8) 1/r32/ecx
 25     # var size/edx: int = filename->length + 1 for the trailing null character
 26     8b/-> *ecx 2/r32/edx
 27     42/increment-edx
 28     # var s/esi: (stream size)
 29     29/subtract-from %esp 2/r32/edx
 30     52/push-edx  # size
 31     68/push 0/imm32/read
 32     68/push 0/imm32/write
 33     89/<- %esi 4/r32/esp
 34     # copy filename and a final null character
 35     (clear-stream %esi)
 36     (write %esi %ecx)
 37     # spill edx
 38     52/push-edx
 39     # var fd/ecx: fd = open(filename)
 40     8d/copy-address *(esi+0xc) 3/r32/ebx
 41     8b/-> *(ebp+0xc) 1/r32/ecx/flags
 42     ba/copy-to-edx 0x180/imm32/permissions
 43     e8/call syscall_open/disp32
 4
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.ext.accumulator</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.ext.html"><font color="#ffffff">ext</font></a>.accumulator</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/ext/accumulator.py">/home/hut/ranger/ranger/ext/accumulator.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,