Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this PR builds on #33, as explained in #33.
summary of changes
this is a preliminary PR which adds a
Sto
(short for store) to the strict interpreter. this is another layer of indirection. theTermEnv
now mapsName
s to indices in theSto
, which in turn maps indices toValue
s (before, theTermEnv
mappedName
s directly toValue
s).Value
in order to make this change we must parameterize
Value
by the type it recursively contains. it no longer simply wraps itself, because there are now two cases forValue
: (1) a value whose recursion is "mediated by theSto
", and therefore requires aSto
to be semantically meaningful/coherent; (2) a value whose recursion is self-contained (this is whatValue
was prior to these changes). (1) isValue<VRef>
, (2) isFlatValue
. since VRef is essentially a pointer to a memory address, we are now mediating recursion through the Sto.old
Value
:new
Value
and associated types (clipped down a bit from the code ineval.rs
):we observe that
Value
no longer directly recurs on itself. and because it is polymorphic inR
, we can instantiate in the ways described above as (1) and (2).de-duplication
another interesting change here is de-duplication of Sto values based on
Hash
es. when Values were mapped in the TermEnv directly, a program could end up doing a lot of cloning/copying. let-binding a variable, for example, would copy the whole Value.since we have purity & referential transparency in our language, we can instead do sharing of values in the Sto. in the example above, both
a
andb
would be mapped by the TermEnv to the same memory address, which would containVBool(true)
.de-duplication essentially hashes each value that goes into the Sto, and checks whether we have already mapped that value in the Sto. if it is already present, instead of allocating a new address to house that value, we simply return the existing address. there is a tradeoff here between computation (hashing) and memory - my hunch is that it's worth it.