diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-04-10 20:47:44 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-04-10 20:55:10 -0700 |
commit | 5f141f6a461bfaf23cb75603b18c09d65a8d79af (patch) | |
tree | e246faa3c58ef1a4db34b8739ad1bb249b62f230 /070text.mu | |
parent | 5939c226b41d6876aa7a36833a01a241925ddd00 (diff) | |
download | mu-5f141f6a461bfaf23cb75603b18c09d65a8d79af.tar.gz |
2829 - issues while switching to 'put'
1. It turns out we couldn't overload 'get' and 'get-address' until now, because transform_names looks for those names, and the resolve_ambiguous_calls transform happens before transform_names. Why does resolve_ambiguous_calls happen before transform_names? Because if my students made mistakes in the ingredients to an instruction they got overzealous errors from resolve_ambiguous_calls. Now this impacts 'put' as well, which is already overloaded for tables. Not sure what to do about this; I'm going to go back to the overzealous errors, and just teach students to visually scan past them for now. 2. I need addresses in a third place besides storing to containers and arrays, and managing the heap -- to synchronize routines. wait-for-location requires an address. Not sure what to do about this..
Diffstat (limited to '070text.mu')
-rw-r--r-- | 070text.mu | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/070text.mu b/070text.mu index 24317a59..386fee22 100644 --- a/070text.mu +++ b/070text.mu @@ -128,10 +128,9 @@ def new-buffer capacity:number -> result:address:shared:buffer [ local-scope load-ingredients result <- new buffer:type - len:address:number <- get-address *result, length:offset - *len:address:number <- copy 0 - s:address:address:shared:array:character <- get-address *result, data:offset - *s <- new character:type, capacity + *result <- put *result, length:offset, 0 + data:address:shared:array:character <- new character:type, capacity + *result <- put *result, data:offset, data return result ] @@ -139,18 +138,18 @@ def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [ local-scope load-ingredients # double buffer size - x:address:address:shared:array:character <- get-address *in, data:offset - oldlen:number <- length **x + olddata:address:shared:array:character <- get *in, data:offset + oldlen:number <- length *olddata newlen:number <- multiply oldlen, 2 - olddata:address:shared:array:character <- copy *x - *x <- new character:type, newlen + newdata:address:shared:array:character <- new character:type, newlen + *in <- put *in, data:offset, newdata # copy old contents i:number <- copy 0 { done?:boolean <- greater-or-equal i, oldlen break-if done? src:character <- index *olddata, i - dest:address:character <- index-address **x, i + dest:address:character <- index-address *newdata, i *dest <- copy src i <- add i, 1 loop @@ -186,14 +185,15 @@ def append buf:address:shared:buffer, x:_elem -> buf:address:shared:buffer [ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ local-scope load-ingredients - len:address:number <- get-address *in, length:offset + len:number <- get *in, length:offset { # backspace? just drop last character if it exists and return backspace?:boolean <- equal c, 8/backspace break-unless backspace? - empty?:boolean <- lesser-or-equal *len, 0 + empty?:boolean <- lesser-or-equal len, 0 return-if empty? - *len <- subtract *len, 1 + len <- subtract len, 1 + put *in, length:offset, len return } { @@ -203,9 +203,10 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ in <- grow-buffer in } s:address:shared:array:character <- get *in, data:offset - dest:address:character <- index-address *s, *len + dest:address:character <- index-address *s, len *dest <- copy c - *len <- add *len, 1 + len <- add len, 1 + put *in, length:offset, len ] scenario buffer-append-works [ |