diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-01-19 23:18:03 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-01-19 23:18:03 -0800 |
commit | 455fbac64f101b05f7eaca89b84470569e4df3fd (patch) | |
tree | 32cfd5b092ad86086e4d15992bb10fd06a12bf13 /076stream.mu | |
parent | 7163e18a774781c62f0c0542e4cb9037f6a71d22 (diff) | |
download | mu-455fbac64f101b05f7eaca89b84470569e4df3fd.tar.gz |
2576 - distinguish allocated addresses from others
This is the one major refinement on the C programming model I'm planning to introduce in mu. Instead of Rust's menagerie of pointer types and static checking, I want to introduce just one new type, and use it to perform ref-counting at runtime. So far all we're doing is updating new's interface. The actual ref-counting implementation is next. One implication: I might sometimes need duplicate implementations for a recipe with allocated vs vanilla addresses of the same type. So far it seems I can get away with just always passing in allocated addresses; the situations when you want to pass an unallocated address to a recipe should be few and far between.
Diffstat (limited to '076stream.mu')
-rw-r--r-- | 076stream.mu | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/076stream.mu b/076stream.mu index be60d855..aa11b773 100644 --- a/076stream.mu +++ b/076stream.mu @@ -1,41 +1,41 @@ # new type to help incrementally read texts (arrays of characters) container stream [ index:number - data:address:array:character + data:address:shared:array:character ] -recipe new-stream s:address:array:character -> result:address:stream [ +recipe new-stream s:address:shared:array:character -> result:address:shared:stream [ local-scope load-ingredients result <- new stream:type i:address:number <- get-address *result, index:offset *i <- copy 0 - d:address:address:array:character <- get-address *result, data:offset + d:address:address:shared:array:character <- get-address *result, data:offset *d <- copy s ] -recipe rewind-stream in:address:stream -> in:address:stream [ +recipe rewind-stream in:address:shared:stream -> in:address:shared:stream [ local-scope load-ingredients x:address:number <- get-address *in, index:offset *x <- copy 0 ] -recipe read-line in:address:stream -> result:address:array:character, in:address:stream [ +recipe read-line in:address:shared:stream -> result:address:shared:array:character, in:address:shared:stream [ local-scope load-ingredients idx:address:number <- get-address *in, index:offset - s:address:array:character <- get *in, data:offset + s:address:shared:array:character <- get *in, data:offset next-idx:number <- find-next s, 10/newline, *idx result <- copy-range s, *idx, next-idx *idx <- add next-idx, 1 # skip newline ] -recipe end-of-stream? in:address:stream -> result:boolean [ +recipe end-of-stream? in:address:shared:stream -> result:boolean [ local-scope load-ingredients idx:number <- get *in, index:offset - s:address:array:character <- get *in, data:offset + s:address:shared:array:character <- get *in, data:offset len:number <- length *s result <- greater-or-equal idx, len ] |