diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-01-26 02:40:35 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-01-26 02:40:35 -0800 |
commit | f9d8b661fb73281d3b8d844833134fcc8098fc2c (patch) | |
tree | 2f722412962c9cdcaf072e554528dd39b70898ba | |
parent | be6eb09211ca8470836152a1aa9d1536ce753bc6 (diff) | |
download | mu-f9d8b661fb73281d3b8d844833134fcc8098fc2c.tar.gz |
626 - start eliminating the memory-per-routine limit
-rw-r--r-- | mu.arc | 13 | ||||
-rw-r--r-- | mu.arc.t | 23 |
2 files changed, 31 insertions, 5 deletions
diff --git a/mu.arc b/mu.arc index bd933a6e..688fc012 100644 --- a/mu.arc +++ b/mu.arc @@ -211,13 +211,14 @@ (on-init ;? (prn "-- resetting memory allocation") - (= Memory-allocated-until 1000)) + (= Memory-allocated-until 1000) + (= Allocation-chunk 100000)) ; routine = runtime state for a serial thread of execution (def make-routine (fn-name . args) (let curr-alloc Memory-allocated-until ;? (prn "-- allocating routine: @curr-alloc") - (++ Memory-allocated-until 100000) + (++ Memory-allocated-until Allocation-chunk) (annotate 'routine (obj alloc curr-alloc alloc-max Memory-allocated-until call-stack (list (obj fn-name fn-name pc 0 args args caller-arg-idx 0)))) @@ -226,7 +227,6 @@ ; limit: number of cycles this routine can use ; running-since: start of the clock for counting cycles this routine has used - ; todo: allow routines to expand past initial allocation ; todo: do memory management in mu )) @@ -1020,9 +1020,12 @@ (def new-scalar (type) ;? (tr "new scalar: @type") (ret result rep.routine*!alloc + (when (>= rep.routine*!alloc rep.routine*!alloc-max) + (let curr-alloc Memory-allocated-until + (= rep.routine*!alloc curr-alloc) + (++ Memory-allocated-until Allocation-chunk) + (= rep.routine*!alloc-max Memory-allocated-until))) (++ rep.routine*!alloc (sizeof `((_ ,type)))) -;? (tr "new-scalar: @result => @rep.routine*!alloc") - (assert (< rep.routine*!alloc rep.routine*!alloc-max) "allocation overflowed routine space @rep.routine*!alloc - @rep.routine*!alloc-max") )) (def new-array (type size) diff --git a/mu.arc.t b/mu.arc.t index b9a0aba7..0bb64788 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -1879,6 +1879,29 @@ (when (~iso rep.routine!alloc (+ before 6)) (prn "F - 'new' on primitive arrays increments high-water mark by their (variable) size")))) +(reset) +(new-trace "new-allocation-chunk") +(add-code + '((function main [ + (1:integer-address <- new integer:literal) + ]))) +; start allocating from address 30, in chunks of 10 locations each +(= Memory-allocated-until 30 + Allocation-chunk 10) +(let routine make-routine!main + (assert:is rep.routine!alloc 30) + (assert:is rep.routine!alloc-max 40) + ; pretend the current chunk is full + (= rep.routine!alloc 40) + (enq routine running-routines*) + (run) + (each routine completed-routines* + (aif rep.routine!error (prn "error - " it))) + (when (~is rep.routine!alloc 41) + (prn "F - 'new' can allocate past initial routine memory")) + (when (~is rep.routine!alloc-max 50) + (prn "F - 'new' updates upper bound for routine memory @rep.routine!alloc-max"))) + ; 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 |