diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-12-26 22:03:19 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-12-26 22:03:19 -0800 |
commit | 5c958813f9c2c0721b649cdb939855a40abebef8 (patch) | |
tree | 1e30faa9cc5fef2efdc3b454ad7948af42cf5d01 | |
parent | 19f02639b5f5c047d4e50c29a3774e36fa64316b (diff) | |
download | mu-5c958813f9c2c0721b649cdb939855a40abebef8.tar.gz |
447 - function invocations can share locals
This is the first step to creating closures. That requires specifying the lexical scope 'frame' to read a variable from.
-rw-r--r-- | mu.arc.t | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mu.arc.t b/mu.arc.t index b6788d9a..3bd58cc7 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -2002,6 +2002,33 @@ (prn "F - 'len' accesses length of array address")) ;? (quit) +(reset) +(new-trace "default-scope-shared") +(add-code + '((function init-counter [ + (default-scope:scope-address <- new scope:literal 30:literal) + (1:integer <- copy 3:literal) ; initialize to 3 + (reply default-scope:scope-address) + ]) + (function increment-counter [ + (default-scope:scope-address <- next-input) + (1:integer <- add 1:integer 1:literal) ; increment + (reply 1:integer) + ]) + (function main [ + (1:scope-address <- init-counter) + (2:integer <- increment-counter 1:scope-address) + (3:integer <- increment-counter 1:scope-address) + ]))) +(run 'main) +(each routine completed-routines* + (aif rep.routine!error (prn "error - " it))) +;? (prn memory*) +(if (or (~is memory*.2 4) + (~is memory*.3 5)) + (prn "F - multiple calls to a function can share locals")) +;? (quit) + ) ; section 20 (section 100 |