diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-04-25 22:27:19 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-04-25 22:27:19 -0700 |
commit | 32b8fac2799ac7cec613e84a3eb9c009141b6a3a (patch) | |
tree | 11f56c1a235abf7b626ea8983fff3d2edb1fcf98 /html/077stream.mu.html | |
parent | 224972ee9871fcb06ee285fa5f3d9528c034d414 (diff) | |
download | mu-32b8fac2799ac7cec613e84a3eb9c009141b6a3a.tar.gz |
2866
Diffstat (limited to 'html/077stream.mu.html')
-rw-r--r-- | html/077stream.mu.html | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/html/077stream.mu.html b/html/077stream.mu.html index 5bf82f66..9fcfa379 100644 --- a/html/077stream.mu.html +++ b/html/077stream.mu.html @@ -32,41 +32,40 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># new type to help incrementally read texts (arrays of characters)</span> <span class="muData">container</span> stream [ index:number - data:address:shared:array:character + data:address:array:character ] -<span class="muRecipe">def</span> new-stream s:address:shared:array:character<span class="muRecipe"> -> </span>result:address:shared:stream [ +<span class="muRecipe">def</span> new-stream s:address:array:character<span class="muRecipe"> -> </span>result:address:stream [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> result<span class="Special"> <- </span>new <span class="Constant">stream:type</span> - i:address:number<span class="Special"> <- </span>get-address *result, <span class="Constant">index:offset</span> - *i<span class="Special"> <- </span>copy <span class="Constant">0</span> - d:address:address:shared:array:character<span class="Special"> <- </span>get-address *result, <span class="Constant">data:offset</span> - *d<span class="Special"> <- </span>copy s + *result<span class="Special"> <- </span>put *result, <span class="Constant">index:offset</span>, <span class="Constant">0</span> + *result<span class="Special"> <- </span>put *result, <span class="Constant">data:offset</span>, s ] -<span class="muRecipe">def</span> rewind-stream in:address:shared:stream<span class="muRecipe"> -> </span>in:address:shared:stream [ +<span class="muRecipe">def</span> rewind-stream in:address:stream<span class="muRecipe"> -> </span>in:address:stream [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - x:address:number<span class="Special"> <- </span>get-address *in, <span class="Constant">index:offset</span> - *x<span class="Special"> <- </span>copy <span class="Constant">0</span> + *in<span class="Special"> <- </span>put *in, <span class="Constant">index:offset</span>, <span class="Constant">0</span> ] -<span class="muRecipe">def</span> read-line in:address:shared:stream<span class="muRecipe"> -> </span>result:address:shared:array:character, in:address:shared:stream [ +<span class="muRecipe">def</span> read-line in:address:stream<span class="muRecipe"> -> </span>result:address:array:character, in:address:stream [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - idx:address:number<span class="Special"> <- </span>get-address *in, <span class="Constant">index:offset</span> - s:address:shared:array:character<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - next-idx:number<span class="Special"> <- </span>find-next s, <span class="Constant">10/newline</span>, *idx - result<span class="Special"> <- </span>copy-range s, *idx, next-idx - *idx<span class="Special"> <- </span>add next-idx, <span class="Constant">1</span> <span class="Comment"># skip newline</span> + idx:number<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> + s:address:array:character<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> + next-idx:number<span class="Special"> <- </span>find-next s, <span class="Constant">10/newline</span>, idx + result<span class="Special"> <- </span>copy-range s, idx, next-idx + idx<span class="Special"> <- </span>add next-idx, <span class="Constant">1</span> <span class="Comment"># skip newline</span> + <span class="Comment"># write back</span> + *in<span class="Special"> <- </span>put *in, <span class="Constant">index:offset</span>, idx ] -<span class="muRecipe">def</span> end-of-stream? in:address:shared:stream<span class="muRecipe"> -> </span>result:boolean [ +<span class="muRecipe">def</span> end-of-stream? in:address:stream<span class="muRecipe"> -> </span>result:boolean [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> idx:number<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> - s:address:shared:array:character<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> + s:address:array:character<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> len:number<span class="Special"> <- </span>length *s result<span class="Special"> <- </span>greater-or-equal idx, len ] |