Use references instead of clones - #8
Merged
Merged
Conversation
These are considered mostly safe when proper cons pairs are added, although they don't work right now. More unsafe expressions were noted in commit 9ddd84d. * Change parameter types of 'env_bind' and 'env_bind_global', remove 'const' qualifier from 'val' parameter. * Store references instead of clones in 'env_bind' and 'env_bind_global'. * Return reference instead of clone in 'env_get'. * Don't clone self-evaluating expressions in 'eval'. * Don't clone returned expression in 'prim_print_str'.
* Don't clone expressions when cloning an environment. * Don't clone expressions of the body when cloning a lambda. * Don't mark 'g_nil', 'g_tru' and 'g_debug_trace_list' for garbage collection. * Don't clone expressions in 'cons', 'car', 'cdr' and 'nth' primitives. * Don't clone expressions when evaluating quoted (or backquoted) expressions.
The code of this commit is a bit messy, as explained in the comments. * Add 'is_used' member to 'Env', for storing whether or not it's being used somewhere else. * Unmark environments in 'gc_unmark_all'. * Mark environments in 'gc_mark_expr'. * Don't collect expressions if their associated environment is still in use.
This commit doesn't currently work, because we still work with copies.
From 'gc_mark_expr'.
Environment closures. Changes: * Add 'is_used' member to 'Env', for storing whether or not it's being used somewhere else. * Unmark environments in 'gc_unmark_all' (by setting 'is_used'). * Mark environments in 'gc_mark_expr' as used. * Don't collect expressions if their associated environment is marked as in use. * Set the parent environment on lambda creation, instead of on call. * Mark each expression of a lambda's environment whenever the lambda is marked for garbage collection. * Add 'pool_item_is_gcmarked', move 'pool_item_is_free' to 'expr_pool.h', make arguments of 'pool_item_flags' constant.
Before this commit, we just marked the lambda's environment and its contents. Now we also mark all parent environments, and their contents. After this commit, the Y combinator can be evaluated.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Work with references, instead of always returning copies. This change was possible thanks to #5 (which needed #4), #6 and #7. Some changes were merged into this
copy-referencesbranch in #7.Major changes:
expr_clone, for working with references instead of copies.car,cdr,cons,nth,quoteandbackquoteprimitives.is_usedmember toEnv. Mostly included in Environment closures #7, but not completely (see 5758c96).g_nil,g_truandg_debug_trace_list) for garbage collection, since their references are being stored in the environment.Minor changes:
gc_mark_envandgc_mark_env_and_parentsstatic functions togarbage_collector.c.Env*parameter tolambdactx_init, remove it fromlambdactx_eval_body.Expr*parameter ofenv_bindandenv_bind_globalconstant.test/lambdas.lisp. See Environment closures #7.