From d1c12218229989dc9a6e15b0190ae0ca05ecb20f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 2 Jan 2015 18:13:04 -0800 Subject: 497 - strengthen the concept of 'space' 'default-scope' is now 'default-space' 'closure-generator' is now 'next-space-generator' The connection to high-level syntax for closures is now tenuous, so we'll call the 'outer scope' the 'next space'. So, let's try to create a few sentences with all these related ideas: Names map to addresses offset from a default-space when it's provided. Spaces can be strung together. The zeroth variable points to the next space, the one that is accessed when a variable has /space:1. To map a name to an address in the next space, you need to know what function generated that space. A corollary is that the space passed in to a function should always be generated by a single function. Spaces can be used to construct lexical scopes and objects. --- channel.mu | 4 +- chessboard-rawterm.mu | 10 +-- chessboard.mu | 8 +-- counters.mu | 33 ++++++++++ edit.mu | 2 +- factorial.mu | 2 +- fork.mu | 4 +- generic.mu | 2 +- mu.arc | 73 +++++++++++----------- mu.arc.t | 166 +++++++++++++++++++++++++------------------------- tangle.mu | 2 +- 11 files changed, 170 insertions(+), 136 deletions(-) create mode 100644 counters.mu diff --git a/channel.mu b/channel.mu index cb1721af..854ab858 100644 --- a/channel.mu +++ b/channel.mu @@ -1,6 +1,6 @@ (function producer [ ; produce numbers 1 to 5 on a channel - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- next-input) ; n = 0 (n:integer <- copy 0:literal) @@ -24,7 +24,7 @@ (function consumer [ ; consume and print integers from a channel - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- next-input) { begin ; read a tagged value from the channel diff --git a/chessboard-rawterm.mu b/chessboard-rawterm.mu index 03cb867e..36ad5ad6 100644 --- a/chessboard-rawterm.mu +++ b/chessboard-rawterm.mu @@ -8,7 +8,7 @@ (address board-address (board)) (function read-board [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (initial-position:list-address <- init-list R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal @@ -36,7 +36,7 @@ ]) (function read-file [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (cursor:list-address <- next-input) (result:file-address <- new file:literal 8:literal) (row:integer <- copy 0:literal) @@ -54,7 +54,7 @@ ]) (function print-board [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (b:board-address <- next-input) (row:integer <- copy 7:literal) ; print each row @@ -167,7 +167,7 @@ ]) (function make-move [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (b:board-address <- next-input) (m:move-address <- next-input) (x:integer-integer-pair <- get m:move-address/deref from:offset) @@ -186,7 +186,7 @@ ]) (function main [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (b:board-address <- read-board) (console-on) { begin diff --git a/chessboard.mu b/chessboard.mu index 71e3da92..e9fbd101 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -8,7 +8,7 @@ (address board-address (board)) (function read-board [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (initial-position:list-address <- init-list R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal @@ -39,7 +39,7 @@ ]) (function read-file [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (cursor:list-address <- next-input) (result:file-address <- new file:literal 8:literal) (row:integer <- copy 0:literal) @@ -60,7 +60,7 @@ ]) (function print-board [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (b:board-address <- next-input) (row:integer <- copy 7:literal) ; print each row @@ -87,7 +87,7 @@ (function main [ ;? (print-primitive (("\u2654 \u265a" literal))) - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (b:board-address <- read-board) (print-board b:board-address) ]) diff --git a/counters.mu b/counters.mu new file mode 100644 index 00000000..cd8825ce --- /dev/null +++ b/counters.mu @@ -0,0 +1,33 @@ +(function init-counter [ + (default-space:space-address <- new space:literal 30:literal) + (n:integer <- next-input) + (reply default-space:space-address) + ]) + +(function increment-counter [ + (default-space:space-address <- new space:literal 30:literal) + (0:space-address/names:init-counter <- next-input) ; setup outer space + (x:integer <- next-input) + (n:integer/space:1 <- add n:integer/space:1 x:integer) + (reply n:integer/space:1) + ]) + +(function main [ + (default-space:space-address <- new space:literal 30:literal) + ; counter A + (a:space-address <- init-counter 34:literal) + ; counter B + (b:space-address <- init-counter 23:literal) + ; increment both by 2 but in different ways + (increment-counter a:space-address 1:literal) + (bres:integer <- increment-counter b:space-address 2:literal) + (ares:integer <- increment-counter a:space-address 1:literal) + ; check results + (print-primitive (("Contents of counters a: " literal))) + (print-primitive ares:integer) + (print-primitive ((" b: " literal))) + (print-primitive bres:integer) + (print-primitive (("\n" literal))) + ]) + +; compare http://www.paulgraham.com/accgen.html diff --git a/edit.mu b/edit.mu index 706d5de4..ebf43161 100644 --- a/edit.mu +++ b/edit.mu @@ -1,7 +1,7 @@ ; a screen is an array of pointers to lines, in turn arrays of characters (function new-screen [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (nrows:integer <- next-input) (ncols:integer <- next-input) (result:screen-address <- new screen:literal nrows:integer) diff --git a/factorial.mu b/factorial.mu index 580b30d4..e1c6007f 100644 --- a/factorial.mu +++ b/factorial.mu @@ -1,5 +1,5 @@ (function factorial [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (n:integer <- next-input) { begin ; if n=0 return 1 diff --git a/fork.mu b/fork.mu index 1cf7aa71..ba19e3af 100644 --- a/fork.mu +++ b/fork.mu @@ -1,6 +1,6 @@ (function main [ (fork thread2:fn) - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (x:integer <- copy 34:literal) { begin (print-primitive x:integer) @@ -9,7 +9,7 @@ ]) (function thread2 [ - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (y:integer <- copy 35:literal) { begin (print-primitive y:integer) diff --git a/generic.mu b/generic.mu index 2a487a96..4486e8bc 100644 --- a/generic.mu +++ b/generic.mu @@ -3,7 +3,7 @@ ; factorial n = n*factorial(n-1) (function factorial [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (n:integer <- input 0:literal) more-clauses (x:integer <- subtract n:integer 1:literal) diff --git a/mu.arc b/mu.arc index e574f65f..cb18200f 100644 --- a/mu.arc +++ b/mu.arc @@ -111,8 +111,9 @@ (= type* (table)) ; name -> type info (= memory* (table)) ; address -> value (= function* (table)) ; name -> [instructions] - (= location* (table)) ; function -> {name -> index into default-scope} - (= closure-generator* (table)) ; function -> name of function generating scope for the scope passed into it + (= location* (table)) ; function -> {name -> index into default-space} + (= next-space-generator* (table)) ; function -> name of function generating next space + ; each function's next space will usually always come from a single function ) (enq clear initialization-fns*) @@ -138,8 +139,8 @@ character (obj size 1) ; int32 like a Go rune character-address (obj size 1 address t elem '(character)) ; isolating function calls - scope (obj array t elem '(location)) ; by convention index 0 points to outer scope - scope-address (obj size 1 address t elem '(scope)) + space (obj array t elem '(location)) ; by convention index 0 points to outer space + space-address (obj size 1 address t elem '(space)) ; arrays consist of an integer length followed by that many ; elements, all of the same type integer-array (obj array t elem '(integer)) @@ -693,14 +694,14 @@ ; immediate addressing - 'literal' and 'offset' ; direct addressing - default ; indirect addressing - 'deref' -; relative addressing - if routine* has 'default-scope' +; relative addressing - if routine* has 'default-space' (def m (loc) ; read memory, respecting metadata (point return (when (literal? loc) (return v.loc)) - (when (is v.loc 'default-scope) - (return rep.routine*!call-stack.0!default-scope)) + (when (is v.loc 'default-space) + (return rep.routine*!call-stack.0!default-space)) (trace "m" loc) (assert (isa v.loc 'int) "addresses must be numeric (problem in convert-names?) @loc") (with (n sizeof.loc @@ -714,9 +715,9 @@ (def setm (loc val) ; set memory, respecting metadata (point return - (when (is v.loc 'default-scope) - (assert (is 1 sizeof.loc) "can't store compounds in default-scope @loc") - (= rep.routine*!call-stack.0!default-scope val) + (when (is v.loc 'default-space) + (assert (is 1 sizeof.loc) "can't store compounds in default-space @loc") + (= rep.routine*!call-stack.0!default-space val) (return)) (assert (isa v.loc 'int) "can't store to non-numeric address (problem in convert-names?)") (trace "setm" loc " <= " val) @@ -813,7 +814,7 @@ (raw)) (die "routine has no globals: @operand")) :else - (iflet base rep.routine*!call-stack.0!default-scope + (iflet base rep.routine*!call-stack.0!default-space (lookup-space (rem [caris _ 'space] operand) base space.operand) @@ -828,7 +829,7 @@ (raw)) (die "no room for var @operand in routine of size @memory*.base")) ; recursive case - (lookup-space operand (memory* (+ base 1)) ; location 0 points to parent space + (lookup-space operand (memory* (+ base 1)) ; location 0 points to next space (- space 1)))) (def space (operand) @@ -992,7 +993,7 @@ ;; convert symbolic names to raw memory locations -(def add-closure-generator (instrs name) +(def add-next-space-generator (instrs name) ;? (prn "== @name") (each instr instrs (when acons.instr @@ -1000,10 +1001,10 @@ (each oarg oargs (when (and (nondummy oarg) (is v.oarg 0) - (iso ty.oarg '(scope-address))) - (assert (no closure-generator*.name) "function can have only one closure-generator environment") - (tr "closure-generator of @name is @(alref oarg 'names)") - (= closure-generator*.name (alref oarg 'names)))))))) + (iso ty.oarg '(space-address))) + (assert (no next-space-generator*.name) "function can have only one next-space-generator environment") + (tr "next-space-generator of @name is @(alref oarg 'names)") + (= next-space-generator*.name (alref oarg 'names)))))))) ; just a helper for testing; in practice we unbundle assign-names-to-location ; and replace-names-with-location. @@ -1018,7 +1019,7 @@ (def assign-names-to-location (instrs name) (ret location (table) (with (isa-field (table) - idx 1) ; 0 always reserved for parent scope + idx 1) ; 0 always reserved for next space (each instr instrs (point continue (when atom.instr @@ -1083,7 +1084,7 @@ (~literal? arg) (~location v.arg) (isa v.arg 'sym) - (~in v.arg 'nil 'default-scope) + (~in v.arg 'nil 'default-space) (~pos '(raw) metadata.arg)) (= (location v.arg) idx))) @@ -1107,7 +1108,7 @@ (ret name default-name (when (~is space.arg 'global) (repeat space.arg - (zap closure-generator* name))))) + (zap next-space-generator* name))))) ;; literate tangling system for reordering code @@ -1241,7 +1242,7 @@ ;? (prn "freeze " name) (= function-table.name (convert-labels:convert-braces:tokenize-args:insert-code body name))) (each (name body) canon.function-table - (add-closure-generator body name)) + (add-next-space-generator body name)) (each (name body) canon.function-table (= location*.name (assign-names-to-location body name))) (each (name body) canon.function-table @@ -1329,7 +1330,7 @@ (section 100 (init-fn maybe-coerce - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (x:tagged-value-address <- new tagged-value:literal) (x:tagged-value-address/deref <- next-input) (p:type <- next-input) @@ -1343,7 +1344,7 @@ (reply xvalue:location match?:boolean)) (init-fn init-tagged-value - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) ; assert sizeof:arg.0 == 1 (xtype:type <- next-input) (xtypesize:integer <- sizeof xtype:type) @@ -1360,19 +1361,19 @@ (reply result:tagged-value-address)) (init-fn list-next ; list-address -> list-address - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (base:list-address <- next-input) (result:list-address <- get base:list-address/deref cdr:offset) (reply result:list-address)) (init-fn list-value-address ; list-address -> tagged-value-address - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (base:list-address <- next-input) (result:tagged-value-address <- get-address base:list-address/deref car:offset) (reply result:tagged-value-address)) (init-fn init-list - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) ; new-list = curr = new list (result:list-address <- new list:literal) (curr:list-address <- copy result:list-address) @@ -1395,7 +1396,7 @@ (reply result:list-address)) (init-fn list-length - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (curr:list-address <- next-input) ;? ; recursive ;? { begin @@ -1429,7 +1430,7 @@ (reply result:integer)) (init-fn init-channel - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) ; result = new channel (result:channel-address <- new channel:literal) ; result.first-full = 0 @@ -1446,14 +1447,14 @@ (reply result:channel-address)) (init-fn capacity - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel <- next-input) (q:tagged-value-array-address <- get chan:channel circular-buffer:offset) (qlen:integer <- length q:tagged-value-array-address/deref) (reply qlen:integer)) (init-fn write - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- next-input) (val:tagged-value <- next-input) { begin @@ -1480,7 +1481,7 @@ (reply chan:channel-address/deref)) (init-fn read - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- next-input) { begin ; block if chan is empty @@ -1506,7 +1507,7 @@ ; An empty channel has first-empty and first-full both at the same value. (init-fn empty? - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) ; return arg.first-full == arg.first-free (chan:channel <- next-input) (full:integer <- get chan:channel first-full:offset) @@ -1517,7 +1518,7 @@ ; A full channel has first-empty just before first-full, wasting one slot. ; (Other alternatives: https://en.wikipedia.org/wiki/Circular_buffer#Full_.2F_Empty_Buffer_Distinction) (init-fn full? - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel <- next-input) ; curr = chan.first-free + 1 (curr:integer <- get chan:channel first-free:offset) @@ -1535,7 +1536,7 @@ (reply result:boolean)) (init-fn strcat - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) ; result = new string[a.length + b.length] (a:string-address <- next-input) (a-len:integer <- length a:string-address/deref) @@ -1580,7 +1581,7 @@ ; replace underscores in first with remaining args (init-fn interpolate ; string-address template, string-address a.. - (default-scope:scope-address <- new scope:literal 60:literal) + (default-space:space-address <- new space:literal 60:literal) (template:string-address <- next-input) ; compute result-len, space to allocate for result (tem-len:integer <- length template:string-address/deref) @@ -1703,7 +1704,7 @@ (reply idx:integer)) (init-fn split ; string, character -> string-address-array-address - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (s:string-address <- next-input) (delim:character <- next-input) ; todo: unicode chars ; empty string? return empty array diff --git a/mu.arc.t b/mu.arc.t index 0c62899e..b880ea7e 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -1844,21 +1844,21 @@ ; Even though our memory locations can now have names, the names are all ; globals, accessible from any function. To isolate functions from their ; callers we need local variables, and mu provides them using a special -; variable called default-scope. When you initialize such a variable (likely +; variable called default-space. When you initialize such a variable (likely ; with a call to our just-defined memory allocator) mu interprets memory -; locations as offsets from its value. If default-scope is set to 1000, for +; locations as offsets from its value. If default-space is set to 1000, for ; example, reads and writes to memory location 1 will really go to 1001. ; -; 'default-scope' is itself hard-coded to be function-local; it's nil in a new +; 'default-space' is itself hard-coded to be function-local; it's nil in a new ; function, and it's restored when functions return to their callers. But the -; actual scope allocation is independent. So you can define closures, or do +; actual space allocation is independent. So you can define closures, or do ; even more funky things like share locals between two coroutines. (reset) -(new-trace "set-default-scope") +(new-trace "set-default-space") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (1:integer <- copy 23:literal) ]))) (let routine make-routine!main @@ -1869,14 +1869,14 @@ ;? (prn memory*) (if (~and (~is 23 memory*.1) (is 23 (memory* (+ before 2)))) - (prn "F - default-scope implicitly modifies variable locations")))) + (prn "F - default-space implicitly modifies variable locations")))) ;? (quit) (reset) -(new-trace "set-default-scope-skips-offset") +(new-trace "set-default-space-skips-offset") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (1:integer <- copy 23:offset) ]))) (let routine make-routine!main @@ -1887,13 +1887,13 @@ ;? (prn memory*) (if (~and (~is 23 memory*.1) (is 23 (memory* (+ before 2)))) - (prn "F - default-scope skips 'offset' types just like literals")))) + (prn "F - default-space skips 'offset' types just like literals")))) (reset) -(new-trace "default-scope-bounds-check") +(new-trace "default-space-bounds-check") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (2:integer <- copy 23:literal) ]))) ;? (set dump-trace*) @@ -1901,13 +1901,13 @@ ;? (prn memory*) (let routine (car completed-routines*) (if (no rep.routine!error) - (prn "F - default-scope checks bounds"))) + (prn "F - default-space checks bounds"))) (reset) -(new-trace "default-scope-and-get-indirect") +(new-trace "default-space-and-get-indirect") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 5:literal) + (default-space:space-address <- new space:literal 5:literal) (1:integer-boolean-pair-address <- new integer-boolean-pair:literal) (2:integer-address <- get-address 1:integer-boolean-pair-address/deref 0:offset) (2:integer-address/deref <- copy 34:literal) @@ -1920,14 +1920,14 @@ (each routine completed-routines* (aif rep.routine!error (prn "error - " it))) (if (~is 34 memory*.3) - (prn "F - indirect 'get' works in the presence of default-scope")) + (prn "F - indirect 'get' works in the presence of default-space")) ;? (quit) (reset) -(new-trace "default-scope-and-index-indirect") +(new-trace "default-space-and-index-indirect") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 5:literal) + (default-space:space-address <- new space:literal 5:literal) (1:integer-array-address <- new integer-array:literal 4:literal) (2:integer-address <- index-address 1:integer-array-address/deref 2:offset) (2:integer-address/deref <- copy 34:literal) @@ -1940,27 +1940,27 @@ (each routine completed-routines* (aif rep.routine!error (prn "error - " it))) (if (~is 34 memory*.3) - (prn "F - indirect 'index' works in the presence of default-scope")) + (prn "F - indirect 'index' works in the presence of default-space")) ;? (quit) (reset) -(new-trace "convert-names-default-scope") +(new-trace "convert-names-default-space") (= traces* (queue)) (if (~iso (convert-names '((((x integer)) <- ((copy)) ((4 literal))) (((y integer)) <- ((copy)) ((2 literal))) - ; unsafe in general; don't write random values to 'default-scope' - (((default-scope integer)) <- ((add)) ((x integer)) ((y integer))))) + ; unsafe in general; don't write random values to 'default-space' + (((default-space integer)) <- ((add)) ((x integer)) ((y integer))))) '((((1 integer)) <- ((copy)) ((4 literal))) (((2 integer)) <- ((copy)) ((2 literal))) - (((default-scope integer)) <- ((add)) ((1 integer)) ((2 integer))))) - (prn "F - convert-names never renames default-scope")) + (((default-space integer)) <- ((add)) ((1 integer)) ((2 integer))))) + (prn "F - convert-names never renames default-space")) (reset) -(new-trace "suppress-default-scope") +(new-trace "suppress-default-space") (add-code '((function main [ - (default-scope:scope-address <- new scope:literal 2:literal) + (default-space:space-address <- new space:literal 2:literal) (1:integer/raw <- copy 23:literal) ]))) (let routine make-routine!main @@ -1971,7 +1971,7 @@ ;? (prn memory*) (if (~and (is 23 memory*.1) (~is 23 (memory* (+ before 1)))) - (prn "F - default-scope skipped for locations with metadata 'raw'")))) + (prn "F - default-space skipped for locations with metadata 'raw'")))) ;? (quit) (reset) @@ -1979,7 +1979,7 @@ (add-code '((function main [ (10:integer <- copy 30:literal) ; pretend allocation - (default-scope:scope-address <- copy 10:literal) ; unsafe + (default-space:space-address <- copy 10:literal) ; unsafe (1:integer <- copy 2:literal) ; raw location 12 (2:integer <- copy 23:literal) (3:boolean <- copy nil:literal) @@ -1995,7 +1995,7 @@ (each routine completed-routines* (aif rep.routine!error (prn "error - " it))) (if (~iso memory*.18 2) ; variable 7 - (prn "F - indirect array copy in the presence of 'default-scope'")) + (prn "F - indirect array copy in the presence of 'default-space'")) ;? (quit) (reset) @@ -2003,7 +2003,7 @@ (add-code '((function main [ (10:integer <- copy 30:literal) ; pretend allocation - (default-scope:scope-address <- copy 10:literal) ; unsafe + (default-space:space-address <- copy 10:literal) ; unsafe (1:integer <- copy 2:literal) ; raw location 12 (2:integer <- copy 23:literal) (3:boolean <- copy nil:literal) @@ -2020,22 +2020,22 @@ ;? (quit) (reset) -(new-trace "default-scope-shared") +(new-trace "default-space-shared") (add-code '((function init-counter [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (1:integer <- copy 3:literal) ; initialize to 3 - (reply default-scope:scope-address) + (reply default-space:space-address) ]) (function increment-counter [ - (default-scope:scope-address <- next-input) + (default-space:space-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) + (1:space-address <- init-counter) + (2:integer <- increment-counter 1:space-address) + (3:integer <- increment-counter 1:space-address) ]))) (run 'main) (each routine completed-routines* @@ -2047,24 +2047,24 @@ ;? (quit) (reset) -(new-trace "default-scope-closure") +(new-trace "default-space-closure") (add-code '((function init-counter [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (1:integer <- copy 3:literal) ; initialize to 3 - (reply default-scope:scope-address) + (reply default-space:space-address) ]) (function increment-counter [ - (default-scope:scope-address <- new scope:literal 30:literal) - (0:scope-address <- next-input) ; share outer scope + (default-space:space-address <- new space:literal 30:literal) + (0:space-address <- next-input) ; share outer space (1:integer/space:1 <- add 1:integer/space:1 1:literal) ; increment (1:integer <- copy 34:literal) ; dummy (reply 1:integer/space:1) ]) (function main [ - (1:scope-address <- init-counter) - (2:integer <- increment-counter 1:scope-address) - (3:integer <- increment-counter 1:scope-address) + (1:space-address <- init-counter) + (2:integer <- increment-counter 1:space-address) + (3:integer <- increment-counter 1:space-address) ]))) ;? (set dump-trace*) (run 'main) @@ -2077,25 +2077,25 @@ ;? (quit) (reset) -(new-trace "default-scope-closure-with-names") +(new-trace "default-space-closure-with-names") (add-code '((function init-counter [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (x:integer <- copy 23:literal) (y:integer <- copy 3:literal) ; correct copy of y - (reply default-scope:scope-address) + (reply default-space:space-address) ]) (function increment-counter [ - (default-scope:scope-address <- new scope:literal 30:literal) - (0:scope-address/names:init-counter <- next-input) ; outer scope must be created by 'init-counter' above + (default-space:space-address <- new space:literal 30:literal) + (0:space-address/names:init-counter <- next-input) ; outer space must be created by 'init-counter' above (y:integer/space:1 <- add y:integer/space:1 1:literal) ; increment (y:integer <- copy 34:literal) ; dummy (reply y:integer/space:1) ]) (function main [ - (1:scope-address/names:init-counter <- init-counter) - (2:integer <- increment-counter 1:scope-address/names:init-counter) - (3:integer <- increment-counter 1:scope-address/names:init-counter) + (1:space-address/names:init-counter <- init-counter) + (2:integer <- increment-counter 1:space-address/names:init-counter) + (3:integer <- increment-counter 1:space-address/names:init-counter) ]))) ;? (set dump-trace*) (run 'main) @@ -2124,7 +2124,7 @@ ; doesn't matter too much how many locals you allocate space for (here 20) ; if it's slightly too many -- memory is plentiful ; if it's too few -- mu will raise an error - (default-scope:scope-address <- new scope:literal 20:literal) + (default-space:space-address <- new space:literal 20:literal) (first-arg-box:tagged-value-address <- next-input) ; if given integers, add them { begin @@ -2153,7 +2153,7 @@ ;? (set dump-trace*) (add-code '((function test1 [ - (default-scope:scope-address <- new scope:literal 20:literal) + (default-space:space-address <- new space:literal 20:literal) (first-arg-box:tagged-value-address <- next-input) ; if given integers, add them { begin @@ -2193,7 +2193,7 @@ (new-trace "dispatch-multiple-calls") (add-code '((function test1 [ - (default-scope:scope-address <- new scope:literal 20:literal) + (default-space:space-address <- new space:literal 20:literal) (first-arg-box:tagged-value-address <- next-input) ; if given integers, add them { begin @@ -2627,7 +2627,7 @@ '((function f1 [ ; waits for memory location 1 to be changed, before computing its successor (10:integer <- copy 5:literal) ; array of locals - (default-scope:scope-address <- copy 10:literal) + (default-space:space-address <- copy 10:literal) (1:integer <- copy 23:literal) ; really location 12 (sleep 1:integer) (2:integer <- add 1:integer 1:literal) @@ -2672,7 +2672,7 @@ (new-trace "fork-copies-args") (add-code '((function f1 [ - (default-scope:scope-address <- new scope:literal 5:literal) + (default-space:space-address <- new space:literal 5:literal) (x:integer <- copy 4:literal) (fork f2:fn nil:literal x:integer) (x:integer <- copy 0:literal) ; should be ignored @@ -2691,9 +2691,9 @@ (1:integer/raw <- copy 2:integer/space:global) ]) (function main [ - (default-scope:scope-address <- new scope:literal 5:literal) + (default-space:space-address <- new space:literal 5:literal) (2:integer <- copy 4:literal) - (fork f1:fn default-scope:scope-address) + (fork f1:fn default-space:space-address) ]))) (run 'main) (each routine completed-routines* @@ -3017,13 +3017,13 @@ (new-trace "channel-handoff") (add-code '((function consumer [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- init-channel 3:literal) ; create a channel (fork producer:fn nil:literal chan:channel-address) ; fork a routine to produce a value in it (1:tagged-value/raw <- read chan:channel-address) ; wait for input on channel ]) (function producer [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (n:integer-address <- new integer:literal) (n:integer-address/deref <- copy 24:literal) (ochan:channel-address <- next-input) @@ -3045,13 +3045,13 @@ (new-trace "channel-handoff-routine") (add-code '((function consumer [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (1:channel-address <- init-channel 3:literal) ; create a channel - (fork producer:fn default-scope:address) ; pass it as a global to another routine + (fork producer:fn default-space:address) ; pass it as a global to another routine (1:tagged-value/raw <- read 1:channel-address) ; wait for input on channel ]) (function producer [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (n:integer-address <- new integer:literal) (n:integer-address/deref <- copy 24:literal) (x:tagged-value <- save-type n:integer-address) @@ -3783,21 +3783,21 @@ (tokenize-arg 'a:b/c:d)) ; support labels -(assert:iso '((((default-scope scope-address)) <- ((new)) ((scope literal)) ((30 literal))) +(assert:iso '((((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) foo) (tokenize-args - '((default-scope:scope-address <- new scope:literal 30:literal) + '((default-space:space-address <- new space:literal 30:literal) foo))) ; support braces -(assert:iso '((((default-scope scope-address)) <- ((new)) ((scope literal)) ((30 literal))) +(assert:iso '((((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) foo { begin bar (((a b)) <- ((op)) ((c d)) ((e f))) }) (tokenize-args - '((default-scope:scope-address <- new scope:literal 30:literal) + '((default-space:space-address <- new space:literal 30:literal) foo { begin bar @@ -3821,15 +3821,15 @@ (prn "F - 'absolutize' works without routine")) (= routine* make-routine!foo) (if (~iso '((4 integer)) (absolutize '((4 integer)))) - (prn "F - 'absolutize' works without default-scope")) -(= rep.routine*!call-stack.0!default-scope 10) -(= memory*.10 5) ; bounds check for default-scope + (prn "F - 'absolutize' works without default-space")) +(= rep.routine*!call-stack.0!default-space 10) +(= memory*.10 5) ; bounds check for default-space (if (~iso '((15 integer) (raw)) (absolutize '((4 integer)))) - (prn "F - 'absolutize' works with default-scope")) + (prn "F - 'absolutize' works with default-space")) (absolutize '((5 integer))) (if (~posmatch "no room" rep.routine*!error) - (prn "F - 'absolutize' checks against default-scope bounds")) + (prn "F - 'absolutize' checks against default-space bounds")) (if (~iso '((_ integer)) (absolutize '((_ integer)))) (prn "F - 'absolutize' passes dummy args right through")) @@ -3899,20 +3899,20 @@ (prn "F - 'addr' works with indirectly-addressed 'deref' inside routines")) ;? (prn 301) -(= rep.routine*!call-stack.0!default-scope 10) +(= rep.routine*!call-stack.0!default-space 10) ;? (prn 302) -(= memory*.10 5) ; bounds check for default-scope +(= memory*.10 5) ; bounds check for default-space ;? (prn 303) (if (~is 15 (addr '((4 integer)))) - (prn "F - directly addressed operands in routines add default-scope")) + (prn "F - directly addressed operands in routines add default-space")) ;? (quit) (if (~is 15 (addr '((4 integer-address)))) - (prn "F - directly addressed operands in routines add default-scope - 2")) + (prn "F - directly addressed operands in routines add default-space - 2")) (if (~is 15 (addr '((4 literal)))) (prn "F - 'addr' doesn't understand literals")) (= memory*.15 23) (if (~is 23 (addr '((4 integer-address) (deref)))) - (prn "F - 'addr' adds default-scope before 'deref', not after")) + (prn "F - 'addr' adds default-space before 'deref', not after")) ;? (quit) ; array-len @@ -3969,16 +3969,16 @@ (= routine* make-routine!foo) (if (~is 24 (sizeof '((4 integer-array)))) (prn "F - 'sizeof' reads array lengths from memory inside routines")) -(= rep.routine*!call-stack.0!default-scope 10) -(= memory*.10 5) ; bounds check for default-scope +(= rep.routine*!call-stack.0!default-space 10) +(= memory*.10 5) ; bounds check for default-space (if (~is 35 (sizeof '((4 integer-array)))) - (prn "F - 'sizeof' reads array lengths from memory using default-scope")) + (prn "F - 'sizeof' reads array lengths from memory using default-space")) (= memory*.35 4) ; size of array (= memory*.15 35) ;? (= dump-trace* (obj whitelist '("sizeof"))) (aif rep.routine*!error (prn "error - " it)) (if (~is 9 (sizeof '((4 integer-boolean-pair-array-address) (deref)))) - (prn "F - 'sizeof' works on pointers to arrays using default-scope")) + (prn "F - 'sizeof' works on pointers to arrays using default-space")) ;? (quit) ; m diff --git a/tangle.mu b/tangle.mu index 7580c328..b975fd2a 100644 --- a/tangle.mu +++ b/tangle.mu @@ -4,7 +4,7 @@ ; possibilities. (function factorial [ - (default-scope:scope-address <- new scope:literal 30:literal) + (default-space:space-address <- new space:literal 30:literal) (n:integer <- next-input) { begin base-case -- cgit 1.4.1-2-gfad0