diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-25 22:15:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-25 22:15:51 -0700 |
commit | 9542bb112419d575190a72baf7f964c3e32df223 (patch) | |
tree | f9edd69ee91c47d41d50dc1f86ae86dcf10e4428 /html/043new.cc.html | |
parent | 955a66a504aec3f106b415d271403b63d0d0e410 (diff) | |
download | mu-9542bb112419d575190a72baf7f964c3e32df223.tar.gz |
1853
Diffstat (limited to 'html/043new.cc.html')
-rw-r--r-- | html/043new.cc.html | 190 |
1 files changed, 100 insertions, 90 deletions
diff --git a/html/043new.cc.html b/html/043new.cc.html index 60ebb332..83bbbef2 100644 --- a/html/043new.cc.html +++ b/html/043new.cc.html @@ -13,15 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Constant { color: #00a0a0; } .SalientComment { color: #00ffff; } +.Constant { color: #00a0a0; } +.CommentedCode { color: #6c6c6c; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } +.traceContains { color: #008000; } --> </style> @@ -39,26 +40,26 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario new)</span> <span class="Comment"># call new two times with identical arguments; you should get back different results</span> recipe main [ - <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:number/<span class="Special">raw</span> ] <span class="traceContains">+mem: storing 0 in location 3</span> <span class="Delimiter">:(before "End Globals")</span> -long long int Reserved_for_tests = <span class="Constant">1000</span><span class="Delimiter">;</span> -long long int Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> -long long int Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Reserved_for_tests = <span class="Constant">1000</span><span class="Delimiter">;</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Fields")</span> -long long int alloc<span class="Delimiter">,</span> alloc_max<span class="Delimiter">;</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> alloc<span class="Delimiter">,</span> alloc_max<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> alloc = Memory_allocated_until<span class="Delimiter">;</span> Memory_allocated_until += Initial_memory_per_routine<span class="Delimiter">;</span> alloc_max = Memory_allocated_until<span class="Delimiter">;</span> -trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << alloc << <span class="Constant">" to "</span> << alloc_max<span class="Delimiter">;</span> +trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << alloc << <span class="Constant">" to "</span> << alloc_max << end<span class="Delimiter">();</span> <span class="SalientComment">//:: First handle 'type' operands.</span> @@ -66,20 +67,20 @@ trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimite Type_ordinal[<span class="Constant">"type"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "Per-recipe Transforms")</span> <span class="Comment">// replace type names with type_ordinals</span> -if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"new"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"new"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// End NEW Transform Special-cases</span> <span class="Comment">// first arg must be of type 'type'</span> - assert<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> >= <span class="Constant">1</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!is_literal<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> - raise << <span class="Constant">"expected literal, got "</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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> - if <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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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">"type"</span><span class="Delimiter">)</span> - raise << <span class="Constant">"tried to allocate non-type "</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>to_string<span class="Delimiter">()</span> << <span class="Constant">" in recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<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>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> - raise << <span class="Constant">"unknown type "</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>name << <span class="Constant">" in recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "type " << inst.ingredients.at(0).name << " => " << Type_ordinal[inst.ingredients.at(0).name] << '\n'; //? 1</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": 'new' expects one or two ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">if</span> <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>properties<span class="Delimiter">.</span>empty<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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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">"type"</span><span class="Delimiter">)</span> + raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": first ingredient of 'new' should be a type, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<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>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": unknown type "</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>name << <span class="cSpecial">'\n'</span> << end<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>set_value<span class="Delimiter">(</span>Type_ordinal[inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><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>name << <span class="Constant">" -> "</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>name<span class="Delimiter">;</span> - end_new_transform:<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><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>name << <span class="Constant">" -> "</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>name << end<span class="Delimiter">();</span> + <span class="Normal">end_new_transform</span>:<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: Now implement the primitive recipe.</span> @@ -90,22 +91,27 @@ NEW<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"new"</span>] = NEW<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -case NEW: <span class="Delimiter">{</span> +<span class="Normal">case</span> NEW: <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'new' requires one or two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'new' should be a type, but got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Comment">// compute the space we need</span> - long long int size = <span class="Constant">0</span><span class="Delimiter">;</span> - long long int array_length = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> array_length = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">{</span> vector<type_ordinal> type<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span> type<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>value<span class="Delimiter">);</span> -<span class="CommentedCode">//? trace(Primitive_recipe_depth, "mem") << "type " << current_instruction().ingredients.at(0).to_string() << ' ' << type.size() << ' ' << type.back() << " has size " << size_of(type); //? 1</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array</span> array_length = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"array size is "</span> << array_length<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"array size is "</span> << array_length << end<span class="Delimiter">();</span> size = array_length*size_of<span class="Delimiter">(</span>type<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">space for length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> + <span class="Normal">else</span> <span class="Delimiter">{</span> <span class="Comment">// scalar</span> size = size_of<span class="Delimiter">(</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -115,17 +121,16 @@ case NEW: <span class="Delimiter">{</span> <span class="Comment">// compute the region of memory to return</span> <span class="Comment">// really crappy at the moment</span> ensure_space<span class="Delimiter">(</span>size<span class="Delimiter">);</span> - const long long int result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"new alloc: "</span> << result<span class="Delimiter">;</span> -<span class="CommentedCode">//? trace(Primitive_recipe_depth, "mem") << "size: " << size << " locations"; //? 1</span> + <span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"new alloc: "</span> << result << end<span class="Delimiter">();</span> <span class="Comment">// save result</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Comment">// initialize allocated space</span> - for <span class="Delimiter">(</span>long long int address = result<span class="Delimiter">;</span> address < result+size<span class="Delimiter">;</span> ++address<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address = result<span class="Delimiter">;</span> address < result+size<span class="Delimiter">;</span> ++address<span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[address] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[result] = array_length<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// bump</span> @@ -145,18 +150,17 @@ case NEW: <span class="Delimiter">{</span> <span class="CommentedCode">//? :(before "End Teardown") //? 1</span> <span class="CommentedCode">//? cerr << Total_alloc << "/" << Num_alloc //? 1</span> <span class="CommentedCode">//? << " vs " << Total_free << "/" << Num_free << '\n'; //? 1</span> -<span class="CommentedCode">//? cerr << Memory.size() << '\n'; //? 1</span> +<span class="CommentedCode">//? cerr << SIZE(Memory) << '\n'; //? 1</span> <span class="Delimiter">:(code)</span> -void ensure_space<span class="Delimiter">(</span>long long int size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> ensure_space<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>size <= Initial_memory_per_routine<span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << Current_routine->alloc << " " << Current_routine->alloc_max << " " << size << '\n'; //? 1</span> - if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc + size > Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc + size > Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// waste the remaining space and create a new chunk</span> Current_routine<span class="Delimiter">-></span>alloc = Memory_allocated_until<span class="Delimiter">;</span> Memory_allocated_until += Initial_memory_per_routine<span class="Delimiter">;</span> Current_routine<span class="Delimiter">-></span>alloc_max = Memory_allocated_until<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << Current_routine<span class="Delimiter">-></span>alloc << <span class="Constant">" to "</span> << Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << Current_routine<span class="Delimiter">-></span>alloc << <span class="Constant">" to "</span> << Current_routine<span class="Delimiter">-></span>alloc_max << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -164,15 +168,15 @@ void ensure_space<span class="Delimiter">(</span>long long int size<span class=" <span class="Special">% Memory_allocated_until = 10;</span> <span class="Special">% Memory[Memory_allocated_until] = 1;</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type + <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/deref ] <span class="traceContains">+mem: storing 0 in location 2</span> <span class="Delimiter">:(scenario new_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">5</span>:literal - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">5</span>:literal + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type <span class="Constant">3</span>:number/<span class="Special">raw <- </span>subtract <span class="Constant">2</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:number/<span class="Special">raw</span> ] <span class="traceContains">+run: 1:address:array:number/raw <- new number:type, 5:literal</span> @@ -182,8 +186,8 @@ recipe main [ <span class="Delimiter">:(scenario new_empty_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">0</span>:literal - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">0</span>:literal + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type <span class="Constant">3</span>:number/<span class="Special">raw <- </span>subtract <span class="Constant">2</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:number/<span class="Special">raw</span> ] <span class="traceContains">+run: 1:address:array:number/raw <- new number:type, 0:literal</span> @@ -194,14 +198,14 @@ recipe main [ <span class="Delimiter">:(scenario new_concurrent)</span> recipe f1 [ start-running f2:recipe - <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type <span class="Comment"># wait for f2 to complete</span> <span class="Delimiter">{</span> loop-unless <span class="Constant">4</span>:number/<span class="Special">raw</span> <span class="Delimiter">}</span> ] recipe f2 [ - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type <span class="Comment"># hack: assumes scheduler implementation</span> <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:number/<span class="Special">raw</span> <span class="Comment"># signal f2 complete</span> @@ -213,8 +217,8 @@ recipe f2 [ <span class="Delimiter">:(scenario new_overflow)</span> <span class="Special">% Initial_memory_per_routine = 2;</span> recipe main [ - <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type - <span class="Constant">2</span>:address:point/<span class="Special">raw <- </span>new point:type <span class="Comment"># not enough room in initial page</span> + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <span class="Constant">2</span>:address:point/<span class="Special">raw <- </span><span class="Normal">new</span> point:type <span class="Comment"># not enough room in initial page</span> ] <span class="traceContains">+new: routine allocated memory from 1000 to 1002</span> <span class="traceContains">+new: routine allocated memory from 1002 to 1004</span> @@ -224,16 +228,16 @@ recipe main [ <span class="Delimiter">:(scenario new_reclaim)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type + <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type abandon <span class="Constant">1</span>:address:number - <span class="Constant">2</span>:address:number<span class="Special"> <- </span>new number:type <span class="Comment"># must be same size as abandoned memory to reuse</span> + <span class="Constant">2</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type <span class="Comment"># must be same size as abandoned memory to reuse</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number ] <span class="Comment"># both allocations should have returned the same address</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(before "End Globals")</span> -map<long long int<span class="Delimiter">,</span> long long int> Free_list<span class="Delimiter">;</span> +map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Free_list<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Free_list<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -242,15 +246,19 @@ ABANDON<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"abandon"</span>] = ABANDON<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -case ABANDON: <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"abandon's ingredient should be scalar</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span class="Normal">case</span> ABANDON: <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'abandon' requires one ingredient, but got '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'abandon' should be an address, but got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - long long int address = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> reagent types = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> - if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"abandon's ingredient should be an address</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>types<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'abandon' should be an address, but got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent target_type = deref<span class="Delimiter">(</span>types<span class="Delimiter">);</span> @@ -259,12 +267,12 @@ case ABANDON: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -void abandon<span class="Delimiter">(</span>long long int address<span class="Delimiter">,</span> long long int size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> abandon<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? Total_free += size; //? 1</span> <span class="CommentedCode">//? Num_free++; //? 1</span> <span class="CommentedCode">//? cerr << "abandon: " << size << '\n'; //? 2</span> <span class="Comment">// clear memory</span> - for <span class="Delimiter">(</span>long long int curr = address<span class="Delimiter">;</span> curr < address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = address<span class="Delimiter">;</span> curr < address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> Memory[curr] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// append existing free list to address</span> Memory[address] = Free_list[size]<span class="Delimiter">;</span> @@ -272,15 +280,18 @@ void abandon<span class="Delimiter">(</span>long long int address<span class="De <span class="Delimiter">}</span> <span class="Delimiter">:(before "ensure_space(size)" following "case NEW")</span> -if <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - long long int result = Free_list[size]<span class="Delimiter">;</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Free_list[size]<span class="Delimiter">;</span> Free_list[size] = Memory[result]<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int curr = result+<span class="Constant">1</span><span class="Delimiter">;</span> curr < result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> - if <span class="Delimiter">(</span>Memory[curr] != <span class="Constant">0</span><span class="Delimiter">)</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": memory in free list was not zeroed out: "</span> << curr << <span class="Constant">'/'</span> << result << <span class="Constant">"; somebody wrote to us after free!!!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = result+<span class="Constant">1</span><span class="Delimiter">;</span> curr < result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[curr] != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": memory in free list was not zeroed out: "</span> << curr << <span class="Constant">'/'</span> << result << <span class="Constant">"; somebody wrote to us after free!!!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// always fatal</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> Memory[result] = array_length<span class="Delimiter">;</span> - else + <span class="Normal">else</span> Memory[result] = <span class="Constant">0</span><span class="Delimiter">;</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> @@ -289,9 +300,9 @@ if <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</spa <span class="Delimiter">:(scenario new_differing_size_no_reclaim)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type + <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type abandon <span class="Constant">1</span>:address:number - <span class="Constant">2</span>:address:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal <span class="Comment"># different size</span> + <span class="Constant">2</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal <span class="Comment"># different size</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number ] <span class="Comment"># no reuse</span> @@ -299,9 +310,9 @@ recipe main [ <span class="Delimiter">:(scenario new_reclaim_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal abandon <span class="Constant">1</span>:address:array:number - <span class="Constant">2</span>:address:array:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">2</span>:address:array:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:array:number ] <span class="Comment"># reuse</span> @@ -311,7 +322,7 @@ recipe main [ <span class="Delimiter">:(scenario new_string)</span> recipe main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [abc def] + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [abc def] <span class="Constant">2</span>:character<span class="Special"> <- </span>index <span class="Constant">1</span>:address:array:character/deref<span class="Delimiter">,</span> <span class="Constant">5</span>:literal ] <span class="Comment"># number code for 'e'</span> @@ -319,7 +330,7 @@ recipe main [ <span class="Delimiter">:(scenario new_string_handles_unicode)</span> recipe main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [a«c] + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [a«c] <span class="Constant">2</span>:number<span class="Special"> <- </span>length <span class="Constant">1</span>:address:array:character/deref <span class="Constant">3</span>:character<span class="Special"> <- </span>index <span class="Constant">1</span>:address:array:character/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] @@ -328,7 +339,7 @@ recipe main [ <span class="traceContains">+mem: storing 171 in location 3</span> <span class="Delimiter">:(before "End NEW Transform Special-cases")</span> - if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<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>properties<span class="Delimiter">.</span>empty<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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -338,29 +349,28 @@ recipe main [ <span class="Delimiter">}</span> <span class="Delimiter">:(after "case NEW" following "Primitive Recipe Implementations")</span> -if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>new_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>new_mu_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -long long int new_string<span class="Delimiter">(</span>const string& contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> new_mu_string<span class="Delimiter">(</span><span class="Normal">const</span> string& contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// allocate an array just large enough for it</span> - long long int string_length = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> string_length = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << "string_length is " << string_length << '\n'; //? 1</span> <span class="CommentedCode">//? Total_alloc += string_length+1; //? 1</span> <span class="CommentedCode">//? Num_alloc++; //? 1</span> ensure_space<span class="Delimiter">(</span>string_length+<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// don't forget the extra location for array size</span> <span class="Comment">// initialize string</span> -<span class="CommentedCode">//? cout << "new string literal: " << current_instruction().ingredients.at(0).name << '\n'; //? 1</span> - long long int result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> Memory[Current_routine<span class="Delimiter">-></span>alloc++] = string_length<span class="Delimiter">;</span> - long long int curr = <span class="Constant">0</span><span class="Delimiter">;</span> - const char* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < string_length<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - uint32_t curr_character<span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">const</span> <span class="Normal">char</span>* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < string_length<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">uint32_t</span> curr_character<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>contents<span class="Delimiter">));</span> tb_utf8_char_to_unicode<span class="Delimiter">(</span>&curr_character<span class="Delimiter">,</span> &raw_contents[curr]<span class="Delimiter">);</span> Memory[Current_routine<span class="Delimiter">-></span>alloc] = curr_character<span class="Delimiter">;</span> @@ -375,19 +385,19 @@ long long int new_string<span class="Delimiter">(</span>const string& conten <span class="Delimiter">:(scenario new_string_overflow)</span> <span class="Special">% Initial_memory_per_routine = 2;</span> recipe main [ - <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type - <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new [a] <span class="Comment"># not enough room in initial page, if you take the array size into account</span> + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span><span class="Normal">new</span> [a] <span class="Comment"># not enough room in initial page, if you take the array size into account</span> ] <span class="traceContains">+new: routine allocated memory from 1000 to 1002</span> <span class="traceContains">+new: routine allocated memory from 1002 to 1004</span> <span class="Comment">//: helpers</span> <span class="Delimiter">:(code)</span> -long long int unicode_length<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const char* in = s<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> - long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> - long long int curr = <span class="Constant">0</span><span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// carefully bounds-check on the string</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> unicode_length<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> <span class="Normal">char</span>* in = s<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">while</span> <span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// carefully bounds-check on the string</span> <span class="Comment">// before accessing its raw pointer</span> ++result<span class="Delimiter">;</span> curr += tb_utf8_char_length<span class="Delimiter">(</span>in[curr]<span class="Delimiter">);</span> |