Theory Shallow_Micro_Rust.Global_Store
theory Global_Store
imports Lenses_And_Other_Optics.Lenses_And_Other_Optics Misc.Array Misc.Vector
Core_Expression Result_Type
begin
section‹References, and the global store›
subsection‹References›
text‹References ∗‹references› are basically pointers that carry around an address that points-into a
global store, such as physical memory or a logical runtime heap.
References of this sort are familiar from functional programming languages like Standard ML and OCaml,
and allow us to introduce a structured form of mutability into our Micro Rust language without having
to deal with how values are encoded into a byte-addressable memory.
References come in two flavors: untyped and typed. ∗‹Untyped references› (or ∗‹raw references›) are essentially pointers
into a monomorphic global store, without information of how the global value behind the reference is to be
interpreted. For example, a raw reference to a memory-backed global store would dereference to a list
of raw bytes.
∗‹Typed references› are constructed as "focused raw references": They attach to a raw reference a focus
specifying how the raw global value behind the reference can be interpreted as a concrete value type.
For example, the focus attached to a typed reference into a memory-backed global store encapsulates
the byte-level presentation of the reference's value type.
Below, the fixed type typ‹'b› represents the "global" values that the global store holds, while the
typ‹'v› represents the type of the value actually stored by this reference. When creating a typed
reference one must provide a focus between \<^typ>‹'b› and \<^typ>‹'v›.›
text‹Untyped/raw references are just wrappers around raw addresses. The global value type is
encoded in the global reference's type.›