Programming with regions in the ML Kit

integer 32 bits, untagged. Unboxed (i.e., not region allocated). real 64 bits, untagged. Boxed (i.e., allocated in region) string Unbounded size. Allocated in region. bool one 32 bit word. Unboxed. list nil and :: cells in one region; auxiliary pairs in one region; elements in one or more regions. Size of :: cell: two 32 bit words; size of auxiliary pair: two 32 bit words. tree A tree and its subtrees reside in one region. Elements in one region (if not unboxed). exn Nullary exception names are unboxed. A constructed exception value (i.e., a unary exception constructor applied to a value) is stored in a global region. fn pat => exp An anonymous function is represented by a boxed, untagged closure. Size (in 32 bit words): 1 plus the number of free variables of the function. (Free region variables also count as variables.) fun f : : : Mutually recursive region-polymorphic functions share the same closure, which is region-allocated, untagged and whose size (in words) is the number of variables that occur free in the recursive declaration. Finite (:n) Region whose size can be determined at compile time. During compilation , a nite region size is given as a non-negative integer. After multiplicity inference, this integer indicates the number of times a value (of the appropriate type) is written into the region. Later, after physical size inference, the integer indicates the physical region size in words. At runtime, a nite region is allocated on the runtime stack. Innnite (:INF) All other regions. At runtime, an innnite region consists of a region descripter on the stack which contains pointers to the beginning and the end of a linked list of xed size region pages. Storage Modes (only signiicant for innnite regions) atbot Reset region, then store value. sat Determine actual storage mode (attop/atbot) at runtime. attop Store at top of region, without destroying any values already in the region. Preface The ML Kit with Regions is a Standard ML compiler. It is intended for the development of stand-alone applications which must be small, reliable, fast and space eecient. There has always been a tension between high-level features in programming languages and the programmer's legitimate need to understand programs at the operational level. Very likely, if a resource conscious programmer is forced to make a choice between the two, he will choose the latter. The ML Kit with Regions is the result …