Pool allocator - #4
Merged
Merged
Conversation
Instead of returning and receiving 'Pool' structures (like in my 'libpool' project), it initializes and operates on a single global expression pool. This should make the interface simpler, specially when integrating it with the garbage collector and the 'expr_new' function.
Tests succeeded with no memory leaks. * Move old body of 'expr_free' to new 'free_expr_members' static function, call it from 'pool_free'. * Add 'BASE_POOL_SZ' macro to 'expr_pool.h'. * Initialize and close pool from 'main'.
Merged
8dcc
added a commit
that referenced
this pull request
Jan 13, 2025
Some changes were merged into this 'garbage-collection' branch in #4. Major changes: * Move memory-related functions to 'memory.c' (this should have been done in main). * Add pool allocator for expressions ('Expr' structures). * Add garbage collector that marks expressions from the pool, and frees the non-marked ones. * Replace 'expr_free' with 'pool_free', remove 'expr_list_free'. Minor changes: * Remove most calls to 'expr_free', only call manually from 'parse' (other calls are currently from the garbage collector or the pool itself). * Don't use stack variables from 'env_init_defaults' (and therefore from the 'BIND_PRIM_FLAGS' macro). * Rename 'tru' and 'nil' C globals to 'g_tru' and 'g_nil' (this should have been done in 'main', after merging). * Add 'g_debug_trace_list' global variable to 'env.c'. * Add 'CPPFLAGS' to Makefile (this should have been done in 'main', after merging). * Improve documentation of 'EExprType' enum and 'Expr' structure in comments. * Add many TODO comments. Changes not included in this PR (currently in a 'copy-references' branch): * Use references instead of clones in most places.
8dcc
added a commit
that referenced
this pull request
Feb 16, 2025
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-references' branch in #7. Major changes: * Remove most calls to 'expr_clone', for working with references instead of copies. * Return or store references in 'car', 'cdr', 'cons', 'nth', 'quote' and 'backquote' primitives. * Add proper environment closures, setting the parent environments whenever a lambda is created, not when it's called. See #7. * Change how GC handles lambdas, add 'is_used' member to 'Env'. Mostly included in #7, but not completely (see 5758c96). * Don't mark globals ('g_nil', 'g_tru' and 'g_debug_trace_list') for garbage collection, since their references are being stored in the environment. Minor changes: * Add 'gc_mark_env' and 'gc_mark_env_and_parents' static functions to 'garbage_collector.c'. * Add an 'Env*' parameter to 'lambdactx_init', remove it from 'lambdactx_eval_body'. * Don't make the 'Expr*' parameter of 'env_bind' and 'env_bind_global' constant. * Add closure test to 'test/lambdas.lisp'. See #7.
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.
Add a pool allocator for
Exprstructures, meant for garbage collection.