Rewrite manifestJson to execute "stacklessly" inside evaluate() #1142
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 gets rid of the mutual recursion between
manifestJson
andevaluate
, turning themanifestJson
processing into a part of the interpreter's main loop. It should remove one avenue for native stack overflows during execution. Of course, the runtime still tracks its own internal call stack depth and can safely abort.The Interpreter needed to be able to convert things to JSON anyway, as this is the behaviour of string coercion (for string concatenation), and also the behaviour when using the
error
operator/statement.Some general notes:
Interpreter::evaluate
was already a really long function; this makes it even longer.Frame
struct gets even bigger.TL;DR: This is not ready yet, and might never be ready. But hey, it's been fun to make. Consider it just a sketch or prototype for now.
Edit - Note that there is still potentially deep recursion in some other pieces of the interpreter code. For example, code dealing with
HeapExtendedObject
(e.g.,objectFieldsAux
,objectInvariants
,countLeaves
,findObject
) needs to recurse through the object inheritance tree. Not sure that's a problem though.