For my class project, I have to implement a (simple) Scheme compiler.
At this moment, I am brainstorming how I implement various functions.
Why are typical circuit implementations associated with complex GC? If the code is really functional (no side effects), then the function that is not currently executing cannot be held in allocated memory. Ever! (if it's not a leak!)
Therefore, why not just use the strategy followed by the most imperative languages, for example C, i.e. stack distribution. Each time a new lexical context is introduced (i.e., (define (foo ..)or (letrec ...), allocate the storage of variables on the stack, and then simply adjust the stack pointer after exiting the context.
Since the scheme does not have malloc()and allows you to select only predefined types, a simple implementation can use a pool of distribution or distribution of zones, so the "stack" should never fragment.
I don’t need to implement a closure, but I think that even those can be done in the same spirit by copying the bound values to a separate stack, which is used exclusively for tracking closure states.
Thoughts?
source
share