626 - start eliminating the memory-per-routine limit

This commit is contained in:
Kartik K. Agaram 2015-01-26 02:40:35 -08:00
parent be6eb09211
commit f9d8b661fb
2 changed files with 31 additions and 5 deletions

13
mu.arc
View File

@ -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)

View File

@ -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