diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-17 15:01:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-17 15:01:51 -0700 |
commit | f344b250f6f062a1a1902bf69b23ebf9b565de0e (patch) | |
tree | 199bd32a9aee198d5028b1c21b83d2cf0944b2b6 /html/038new_text.cc.html | |
parent | 897ae8c1855f830d8819759ea327d147f28a09bf (diff) | |
download | mu-f344b250f6f062a1a1902bf69b23ebf9b565de0e.tar.gz |
3395
Diffstat (limited to 'html/038new_text.cc.html')
-rw-r--r-- | html/038new_text.cc.html | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html index f9565ba4..81b50bde 100644 --- a/html/038new_text.cc.html +++ b/html/038new_text.cc.html @@ -32,40 +32,44 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color </head> <body> <pre id='vimCodeElement'> -<span class="Comment">//: Extend 'new' to handle a unicode string literal argument.</span> +<span class="Comment">//: Extend 'new' to handle a unicode string literal argument or 'text'.</span> + +<span class="Comment">//: A Mu text is an address to an array of characters.</span> +<span class="Delimiter">:(before "End Mu Types Initialization")</span> +put<span class="Delimiter">(</span>Type_abbreviations<span class="Delimiter">,</span> <span class="Constant">"text"</span><span class="Delimiter">,</span> new_type_tree<span class="Delimiter">(</span><span class="Constant">"address:array:character"</span><span class="Delimiter">));</span> <span class="Delimiter">:(scenario new_string)</span> def main [ - <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<span class="Delimiter">,</span> <span class="Constant">5</span> + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [abc def] + <span class="Constant">2</span>:<span class="Normal">char</span><span class="Special"> <- </span>index *<span class="Constant">1</span>:text<span class="Delimiter">,</span> <span class="Constant">5</span> ] <span class="Comment"># number code for 'e'</span> <span class="traceContains">+mem: storing 101 in location 2</span> <span class="Delimiter">:(scenario new_string_handles_unicode)</span> def main [ - <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 - <span class="Constant">3</span>:character<span class="Special"> <- </span>index *<span class="Constant">1</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">1</span> + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [a«c] + <span class="Constant">2</span>:num<span class="Special"> <- </span>length *<span class="Constant">1</span>:text + <span class="Constant">3</span>:<span class="Normal">char</span><span class="Special"> <- </span>index *<span class="Constant">1</span>:text<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 3 in location 2</span> <span class="Comment"># unicode for '«'</span> <span class="traceContains">+mem: storing 171 in location 3</span> <span class="Delimiter">:(before "End NEW Check Special-cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>is_literal_string<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> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>is_literal_text<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> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "Convert 'new' To 'allocate'")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"new"</span> && is_literal_string<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> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"new"</span> && is_literal_text<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> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "case NEW" following "Primitive Recipe Implementations")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal_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> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal_text<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="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_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> + 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_text<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> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"new string alloc: "</span> << products<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> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</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="Normal">int</span> new_mu_text<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> <span class="Normal">int</span> string_length = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> <span class="CommentedCode">//? Total_alloc += string_length+1;</span> @@ -96,48 +100,48 @@ def main [ <span class="Delimiter">:(scenario stash_string)</span> def main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [abc] - stash [foo:]<span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:character + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [abc] + stash [foo:]<span class="Delimiter">,</span> <span class="Constant">1</span>:text ] <span class="traceContains">+app: foo: abc</span> <span class="Delimiter">:(before "End print Special-cases(r, data)")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_string<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_text<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>data<span class="Delimiter">));</span> - <span class="Identifier">return</span> read_mu_string<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + <span class="Identifier">return</span> read_mu_text<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario unicode_string)</span> def main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [♠] - stash [foo:]<span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:character + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [♠] + stash [foo:]<span class="Delimiter">,</span> <span class="Constant">1</span>:text ] <span class="traceContains">+app: foo: ♠</span> <span class="Delimiter">:(scenario stash_space_after_string)</span> def main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [abc] - stash <span class="Constant">1</span>:address:array:character<span class="Delimiter">,</span> [foo] + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [abc] + stash <span class="Constant">1</span>:text<span class="Delimiter">,</span> [foo] ] <span class="traceContains">+app: abc foo</span> <span class="Delimiter">:(scenario stash_string_as_array)</span> def main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [abc] - stash *<span class="Constant">1</span>:address:array:character + <span class="Constant">1</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [abc] + stash *<span class="Constant">1</span>:text ] <span class="traceContains">+app: 3 97 98 99</span> <span class="Comment">//: fixes way more than just stash</span> -<span class="Delimiter">:(before "End Preprocess is_mu_string(reagent x)")</span> +<span class="Delimiter">:(before "End Preprocess is_mu_text(reagent x)")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<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">//: Allocate more to routine when initializing a literal string</span> <span class="Delimiter">:(scenario new_string_overflow)</span> <span class="Special">% Initial_memory_per_routine = 3;</span> def main [ - <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 refcount and array length into account</span> + <span class="Constant">1</span>:address:num/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <span class="Constant">2</span>:text/<span class="Special">raw <- </span><span class="Normal">new</span> [a] <span class="Comment"># not enough room in initial page, if you take the refcount and array length into account</span> ] <span class="traceContains">+new: routine allocated memory from 1000 to 1003</span> <span class="traceContains">+new: routine allocated memory from 1003 to 1006</span> @@ -156,7 +160,7 @@ def main [ <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -string read_mu_string<span class="Delimiter">(</span><span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string read_mu_text<span class="Delimiter">(</span><span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> ++address<span class="Delimiter">;</span> <span class="Comment">// skip refcount</span> <span class="Normal">int</span> size = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address<span class="Delimiter">);</span> |