about summary refs log blame commit diff stats
path: root/test/__init__.py
blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (plain) (tree)
 

-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 */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 088file.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.muRecipe { color: #ff8700; }
.muData { color: #ffff00; }
.Delimiter { color: #800080; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #c00000; }
.muControl { color: #c0a020; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># Wrappers around file system primitives that take a 'filesystem' object and</span>
<span class="Comment"># are thus easier to test.</span>

<span class="muData">container</span> filesystem [
  data:address:array:file-mapping
]

<span class="muData">container</span> file-mapping [
  name:text
  contents:text
]

<span class="muRecipe">def</span> start-reading fs:address:filesystem, filename:text<span class="muRecipe"> -&gt; </span>contents:address:source:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> fs
    <span class="Comment"># real file system</span>
    file:number<span class="Special"> &lt;- </span>$open-file-for-reading filename
    assert file, <span class="Constant">[file not found]</span>
    contents:address:source:character, sink:address:sink:character<span class="Special"> &lt;- </span>new-channel <span class="Constant">30</span>
    start-running transmit-from-file file, sink
    <span class="muControl">return</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># fake file system</span>
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  data:address:array:file-mapping<span class="Special"> &lt;- </span>get *fs, <span class="Constant">data:offset</span>
  len:number<span class="Special"> &lt;- </span>length *data
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    tmp:file-mapping<span class="Special"> &lt;- </span>index *data, i
    i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
    curr-filename:text<span class="Special"> &lt;- </span>get tmp, <span class="Constant">name:offset</span>
    found?:boolean<span class="Special"> &lt;- </span>equal filename, curr-filename
    <span class="muControl">loop-unless</span> found?
    contents:address:source:character, sink:address:sink:character<span class="Special"> &lt;- </span>new-channel <span class="Constant">30</span>
    curr-contents:text<span class="Special"> &lt;- </span>get tmp, <span class="Constant">contents:offset</span>
    start-running transmit-from-text curr-contents, sink
    <span class="muControl">return</span>
  <span class="Delimiter">}</span>
  <span class="muControl">return</span> <span class="Constant">0/not-found</span>
]

<span class="muRecipe">def</span> transmit-from-file file:number, sink:address:sink:character<span class="muRecipe"> -&gt; </span>sink:address:sink:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="Delimiter">{</span>
    c:character, eof?:boolean<span class="Special"> &lt;- </span>$read-from-file file
    <span class="muControl">break-if</span> eof?
    sink<span class="Special"> &lt;- </span>write sink, c
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  sink<span class="Special"> &lt;- </span>close sink
  file<span class="Special"> &lt;- </span>$close-file file
]

<span class="muRecipe">def</span> transmit-from-text contents:text, sink:address:sink:character<span class="muRecipe"> -&gt; </span>sink:address:sink:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  len:number<span class="Special"> &lt;- </span>length *contents
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    c:character<span class="Special"> &lt;- </span>index *contents, i
    sink<span class="Special"> &lt;- </span>write sink, c
    i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  sink<span class="Special"> &lt;- </span>close sink
]

<span class="muRecipe">def</span> start-writing fs:address:filesystem, filename:text<span class="muRecipe"> -&gt; </span>sink:address:sink:character, routine-id:number [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  source:address:source:character, sink:address:sink:character<span class="Special"> &lt;- </span>new-channel <span class="Constant">30</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> fs
    <span class="Comment"># real file system</span>
    file:number<span class="Special"> &lt;- </span>$open-file-for-writing filename
    assert file, <span class="Constant">[no such file]</span>
    routine-id<span class="Special"> &lt;- </span>start-running transmit-to-file file, source
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># fake file system</span>
  <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span>
  routine-id<span class="Special"> &lt;- </span>start-running transmit-to-fake-file fs, filename, source
]

<span class="muRecipe">def</span> transmit-to-file file:number, source:address:source:character<span class="muRecipe"> -&gt; </span>source:address:source:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="Delimiter">{</span>
    c:character, done?:boolean, source<span class="Special"> &lt;- </span>read source
    <span class="muControl">break-if</span> done?
    $write-to-file file, c
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  file<span class="Special"> &lt;- </span>$close-file file
]

<span class="muRecipe">def</span> transmit-to-fake-file fs:address:filesystem, filename:text, source:address:source:character<span class="muRecipe"> -&gt; </span>fs:address:filesystem, source:address:source:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="Comment"># compute new file contents</span>
  buf:address:buffer<span class="Special"> &lt;- </span>new-buffer <span class="Constant">30</span>
  <span class="Delimiter">{</span>
    c:character, done?:boolean, source<span class="Special"> &lt;- </span>read source
    <span class="muControl">break-if</span> done?
    buf<span class="Special"> &lt;- </span>append buf, c
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  contents:text<span class="Special"> &lt;- </span>buffer-to-array buf
  new-file-mapping:file-mapping<span class="Special"> &lt;- </span>merge filename, contents
  <span class="Comment"># write to filesystem</span>
  curr-filename:text<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  data:address:array:file-mapping<span class="Special"> &lt;- </span>get *fs, <span class="Constant">data:offset</span>
  <span class="Comment"># replace file contents if it already exists</span>
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  len:number<span class="Special"> &lt;- </span>length *data
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    tmp:file-mapping<span class="Special"> &lt;- </span>index *data, i
    curr-filename<span class="Special"> &lt;- </span>get tmp, <span class="Constant">name:offset</span>
    found?:boolean<span class="Special"> &lt;- </span>equal filename, curr-filename
    <span class="muControl">loop-unless</span> found?
    put-index *data, i, new-file-mapping
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># if file didn't already exist, make room for it</span>
  new-len:number<span class="Special"> &lt;- </span>add len, <span class="Constant">1</span>
  new-data:address:array:file-mapping<span class="Special"> &lt;- </span>new <span class="Constant">file-mapping:type</span>, new-len
  put *fs, <span class="Constant">data:offset</span>, new-data
  <span class="Comment"># copy over old files</span>
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    tmp:file-mapping<span class="Special"> &lt;- </span>index *data, i
    put-index *new-data, i, tmp
  <span class="Delimiter">}</span>
  <span class="Comment"># write new file</span>
  put-index *new-data, len, new-file-mapping
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->