# Compiler memory management

Compilers in Dusk have common challenges to solve regarding memory.

First, there's the fact that compilation of binary code happens directly to HERE
and that while it happens, allocation of permanent memory cannot happen because
otherwise we corrupt compiled code.

Second, there's temporary data needed to be created, mostly about types
[lib/type], and there needs to be a place for these.

The answer to these challenges offered by this unit is a pair of locked arenas
[mem/arena] called parena (permanent) and tarena (temporary).

The broad principle is that whenever we're about to begin compiling a new piece
of binary code, we reset the tarena and call "ensurenext" on both of them,
ensuring we have enough leeway for a reasonably sized piece of code.

The permanent arena is never cleared and is mostly for putting literal data that
is encountered during compilation. The temporary arena is cleared regularly and
is for data that won't be needed past the compilation of a function.

## API

### Words

compmem$ ( -- )
  Call "ensurenext" on both parena and tarena and then clear tarena.

parena[
parena1
parena1@
parena1r
  [mem/alloc] bindings for the parena.

tarena[
tarena1
tarena1@
tarena1r
  [mem/alloc] bindings for the tarena.

tmppointer ( type -- type )
  An equivalent to "newpointer" from [lib/type] within the tarena, but with a
  very crude caching system that sometimes saves us a memory allocation in some
  conditions, relieving some pressure on the tarena.
