about summary refs log tree commit diff stats
path: root/309stream.subx
Commit message (Collapse)AuthorAgeFilesLines
* .Kartik K. Agaram2021-07-081-1/+1
|
* snapshotKartik K. Agaram2021-06-201-1/+19
| | | | | This is going better than expected; just 3 failing tests among the new ones.
* print call stack on all low-level errorsKartik K. Agaram2021-05-151-8/+2
|
* shell: separate 'def' from 'set'Kartik K. Agaram2021-04-211-0/+89
| | | | | 'def' creates new bindings (only in globals) 'set' only modifies existing bindings (either in env or globals)
* 7842 - new directory organizationKartik K. Agaram2021-03-031-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Baremetal is now the default build target and therefore has its sources at the top-level. Baremetal programs build using the phase-2 Mu toolchain that requires a Linux kernel. This phase-2 codebase which used to be at the top-level is now under the linux/ directory. Finally, the phase-2 toolchain, while self-hosting, has a way to bootstrap from a C implementation, which is now stored in linux/bootstrap. The bootstrap C implementation uses some literate programming tools that are now in linux/bootstrap/tools. So the whole thing has gotten inverted. Each directory should build one artifact and include the main sources (along with standard library). Tools used for building it are relegated to sub-directories, even though those tools are often useful in their own right, and have had lots of interesting programs written using them. A couple of things have gotten dropped in this process: - I had old ways to run on just a Linux kernel, or with a Soso kernel. No more. - I had some old tooling for running a single test at the cursor. I haven't used that lately. Maybe I'll bring it back one day. The reorg isn't done yet. Still to do: - redo documentation everywhere. All the README files, all other markdown, particularly vocabulary.md. - clean up how-to-run comments at the start of programs everywhere - rethink what to do with the html/ directory. Do we even want to keep supporting it? In spite of these shortcomings, all the scripts at the top-level, linux/ and linux/bootstrap are working. The names of the scripts also feel reasonable. This is a good milestone to take stock at.
* 7100 - tile: render string literalsKartik Agaram2020-10-251-0/+56
|
* 6742 - support for formatting in fake screensKartik Agaram2020-09-071-0/+2
| | | | | We still need a few primitives, but we can implement these as needed. I'm ready to call the fake screen done.
* 6687 - stream-empty? and stream-full?Kartik Agaram2020-07-301-2/+50
|
* 6684 - experimental primitives for streamsKartik Agaram2020-07-291-0/+108
This is a hacky special case. The alternative would be more general support for generics. One observation: we might be able to type-check some primitives using `sig`s. Only if they don't return anything, since primitives usually need to support arbitrary registers. I'm not doing that yet, though. It eliminates the possibility of writing tests for them in mu.subx, which can't see 400.mu. But it's an alternative: sig allocate out: (addr handle _) sig populate out: (addr handle array _), n: int sig populate-stream out: (addr handle stream _), n: int sig read-from-stream s: (addr stream _T), out: (addr _T) sig write-to-stream s: (addr stream _T), in: (addr _T) We could write the tests in Mu. But then we're testing behavior rather than the code generated. There are trade-offs. By performing type-checking in mu.subx I retain the option to write both kinds of tests.
nd-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 - 047jump_label.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<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: #d0d0d0; background-color: #000000; }
body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
* { font-size: 1em; }
.traceAbsent { color: #c00000; }
.Identifier { color: #008080; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.cSpecial { color: #008000; }
.traceContains { color: #008000; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Support jumps to labels.</span>
<span class="Comment">//: We'll also treat 'break' and 'continue' as jumps. The choice of name is</span>
<span class="Comment">//: just documentation about intent.</span>

<span class="Delimiter">:(scenario jump_to_label)</span>
recipe main [
  jump +target:label
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
  +target
]
<span class="traceAbsent">-mem: storing 0 in location 1</span>

<span class="Delimiter">:(before &quot;End Mu Types Initialization&quot;)</span>
Type_number[<span class="Constant">&quot;label&quot;</span>] = <span class="Constant">0</span><span class="Delimiter">;</span>

<span class="Delimiter">:(after &quot;int main&quot;)</span>
  Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_labels<span class="Delimiter">);</span>

<span class="Delimiter">:(code)</span>
void transform_labels<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  map&lt;string<span class="Delimiter">,</span> long long int&gt; offset<span class="Delimiter">;</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    const instruction&amp; inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
    if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>label<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> offset[inst<span class="Delimiter">.</span>label] = i<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    instruction&amp; inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
    if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;jump&quot;</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?       cerr &lt;&lt; inst.to_string() &lt;&lt; '\n'; //? 1</span>
      replace_offset<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;jump-if&quot;</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;jump-unless&quot;</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      replace_offset<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;loop&quot;</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;break&quot;</span>]<span class="Delimiter">)</span>
        &amp;&amp; SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      replace_offset<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;loop-if&quot;</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;loop-unless&quot;</span>]
            || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;break-if&quot;</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">&quot;break-unless&quot;</span>]<span class="Delimiter">)</span>
        &amp;&amp; SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      replace_offset<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
void replace_offset<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">const</span><span class="Comment">*/</span> map&lt;string<span class="Delimiter">,</span> long long int&gt;&amp; offset<span class="Delimiter">,</span> const long long int current_offset<span class="Delimiter">,</span> const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">));</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;BBB &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">);</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;CCC &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>  <span class="Comment">// non-labels will be handled like other number operands</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;DDD &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  if <span class="Delimiter">(</span>offset<span class="Delimiter">.</span>find<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == offset<span class="Delimiter">.</span>end<span class="Delimiter">())</span>
    raise &lt;&lt; <span class="Constant">&quot;can't find label &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot; in routine &quot;</span> &lt;&lt; Recipe[r]<span class="Delimiter">.</span>name &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>offset[x<span class="Delimiter">.</span>name]-current_offset<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario break_to_label)</span>
recipe main [
<span class="CommentedCode">#?   $print [aaa]</span>
  <span class="Delimiter">{</span>
    <span class="Delimiter">{</span>
      <span class="Identifier">break</span> +target:label
      <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  +target
]
<span class="traceAbsent">-mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario jump_if_to_label)</span>
recipe main [
  <span class="Delimiter">{</span>
    <span class="Delimiter">{</span>
      jump-if <span class="Constant">1</span>:literal<span class="Delimiter">,</span> +target:label
      <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  +target
]
<span class="traceAbsent">-mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario loop_unless_to_label)</span>
recipe main [
  <span class="Delimiter">{</span>
    <span class="Delimiter">{</span>
      loop-unless <span class="Constant">0</span>:literal<span class="Delimiter">,</span> +target:label  <span class="Comment"># loop/break with a label don't care about braces</span>
      <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  +target
]
<span class="traceAbsent">-mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario jump_runs_code_after_label)</span>
recipe main [
  <span class="Comment"># first a few lines of padding to exercise the offset computation</span>
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
  <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
  jump +target:label
  <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
  +target
  <span class="Constant">5</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 5</span>
<span class="traceAbsent">-mem: storing 0 in location 4</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->