about summary refs log tree commit diff stats
path: root/edit
Commit message (Expand)AuthorAgeFilesLines
* 5856Kartik Agaram2020-01-011-7/+2
* 5485 - promote SubX to top-levelKartik Agaram2019-07-2714-12404/+23
* 4266 - space for alloc-id in heap allocationsKartik Agaram2018-06-241-10/+12
* 4262 - literal 'null'Kartik Agaram2018-06-1710-38/+38
* 4261 - start using literals for 'true' and 'false'Kartik Agaram2018-06-179-94/+107
* 4258 - undo 4257Kartik Agaram2018-06-153-39/+10
* 4257 - abortive attempt at safe fat pointersKartik Agaram2018-06-153-10/+39
* 4208Kartik K. Agaram2018-02-171-6/+42
* 4207Kartik K. Agaram2018-02-151-1/+0
* 4206 - edit/ app: consistent cursor positioningKartik K. Agaram2018-02-154-9/+3
* 4205Kartik K. Agaram2018-02-151-45/+45
* 4169Kartik K. Agaram2017-12-301-7/+5
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-0312-92/+92
* 3984 - bugfix: display errors when scrolling recipe sideKartik K. Agaram2017-08-251-0/+38
* 3982 - bugfix: clear old recipe errors on F4Kartik K. Agaram2017-08-222-0/+60
* 3981Kartik K. Agaram2017-08-222-7/+4
* 3980Kartik K. Agaram2017-08-226-68/+68
* 3979Kartik K. Agaram2017-08-221-4/+4
* 3978Kartik K. Agaram2017-08-221-13/+18
* 3977Kartik K. Agaram2017-08-221-1/+1
* 3962Kartik K. Agaram2017-06-271-6/+13
* 3960Kartik K. Agaram2017-06-251-14/+38
* 3959Kartik K. Agaram2017-06-251-2/+13
* 3958Kartik K. Agaram2017-06-252-13/+19
* 3957Kartik K. Agaram2017-06-251-0/+2
* 3955Kartik K. Agaram2017-06-252-36/+32
* 3954Kartik K. Agaram2017-06-253-110/+39
* 3953Kartik K. Agaram2017-06-241-24/+51
* 3952Kartik K. Agaram2017-06-241-11/+10
* 3950Kartik K. Agaram2017-06-241-2/+43
* 3946Kartik K. Agaram2017-06-231-3/+3
* 3944Kartik K. Agaram2017-06-231-1/+25
* 3943Kartik K. Agaram2017-06-234-45/+0
* 3942Kartik K. Agaram2017-06-234-18/+18
* 3941Kartik K. Agaram2017-06-234-13/+29
* 3940Kartik K. Agaram2017-06-221-1/+1
* 3939Kartik K. Agaram2017-06-222-3/+9
* 3938Kartik K. Agaram2017-06-221-2/+32
* 3935Kartik K. Agaram2017-06-223-3/+3
* 3928Kartik K. Agaram2017-06-191-4/+5
* 3926Kartik K. Agaram2017-06-191-2/+57
* 3925Kartik K. Agaram2017-06-191-0/+292
* 3924Kartik K. Agaram2017-06-181-1/+1
* 3923Kartik K. Agaram2017-06-181-15/+91
* 3922Kartik K. Agaram2017-06-172-7/+4
* 3921Kartik K. Agaram2017-06-162-4/+6
* 3919Kartik K. Agaram2017-06-162-5/+89
* 3918Kartik K. Agaram2017-06-161-3/+47
* 3916 - minimal prints when commenting linesKartik K. Agaram2017-06-161-11/+139
* 3915Kartik K. Agaram2017-06-161-4/+2
> color: #6c6c6c; } --> </style> <script type='text/javascript'> <!-- --> </script> </head> <body> <pre id='vimCodeElement'> <span class="Comment">// So far we have local variables, and we can nest local variables of short</span> <span class="Comment">// lifetimes inside longer ones. Now let's support 'global' variables that</span> <span class="Comment">// last for the life of a routine. If we create multiple routines they won't</span> <span class="Comment">// have access to each other's globals.</span> <span class="Delimiter">:(scenario global_space)</span> recipe main [ <span class="Comment"># pretend arrays; in practice we'll use new</span> <span class="Constant">10</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>:literal <span class="Constant">20</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># actual start of this recipe</span> global-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">20</span>:literal default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>:literal <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal <span class="Constant">1</span>:number/space:global<span class="Special"> &lt;- </span>copy <span class="Constant">24</span>:literal ] <span class="traceContains">+mem: storing 23 in location 12</span> <span class="traceContains">+mem: storing 24 in location 22</span> <span class="Comment">//: to support it, create another special variable called global space</span> <span class="Delimiter">:(before &quot;End Disqualified Reagents&quot;)</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;global-space&quot;</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before &quot;End is_special_name Cases&quot;)</span> if <span class="Delimiter">(</span>s == <span class="Constant">&quot;global-space&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">//: writes to this variable go to a field in the current routine</span> <span class="Delimiter">:(before &quot;End routine Fields&quot;)</span> long long int global_space<span class="Delimiter">;</span> <span class="Delimiter">:(before &quot;End routine Constructor&quot;)</span> global_space = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after &quot;void write_memory(reagent x, vector&lt;double&gt; data)&quot;)</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;global-space&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>data<span class="Delimiter">));</span> if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>global_space<span class="Delimiter">)</span> raise &lt;&lt; <span class="Constant">&quot;routine already has a global-space; you can't over-write your globals&quot;</span><span class="Delimiter">;</span> Current_routine<span class="Delimiter">-&gt;</span>global_space = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: now marking variables as /space:global looks them up inside this field</span> <span class="Delimiter">:(after &quot;long long int space_base(const reagent&amp; x)&quot;)</span> if <span class="Delimiter">(</span>is_global<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-&gt;</span>global_space<span class="Delimiter">)</span> raise &lt;&lt; <span class="Constant">&quot;routine has no global space</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; die<span class="Delimiter">();</span> <span class="Identifier">return</span> Current_routine<span class="Delimiter">-&gt;</span>global_space<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: for now let's not bother giving global variables names.</span> <span class="Comment">//: don't want to make them too comfortable to use.</span> <span class="Delimiter">:(scenario global_space_with_names)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ global-space:address:array:location<span class="Special"> &lt;- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">10</span>:literal x:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal <span class="Constant">1</span>:number/space:global<span class="Special"> &lt;- </span>copy <span class="Constant">24</span>:literal ] <span class="Comment"># don't warn that we're mixing numeric addresses and names</span> $warn: <span class="Constant">0</span> <span class="Delimiter">:(after &quot;bool is_numeric_location(const reagent&amp; x)&quot;)</span> if <span class="Delimiter">(</span>is_global<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">//: helpers</span> <span class="Delimiter">:(code)</span> bool is_global<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span> for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">&quot;space&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> !x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> &amp;&amp; x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">&quot;global&quot;</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> </body> </html> <!-- vim: set foldmethod=manual : -->