Skip to content

Pool allocator - #4

Merged
8dcc merged 9 commits into
garbage-collectionfrom
pool-allocator
Jan 7, 2025
Merged

Pool allocator#4
8dcc merged 9 commits into
garbage-collectionfrom
pool-allocator

Conversation

@8dcc

@8dcc 8dcc commented Jan 7, 2025

Copy link
Copy Markdown
Owner

Add a pool allocator for Expr structures, meant for garbage collection.

8dcc and others added 9 commits January 6, 2025 23:40
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'.
@8dcc
8dcc merged commit ff652a9 into garbage-collection Jan 7, 2025
@8dcc
8dcc deleted the pool-allocator branch January 7, 2025 22:06
@8dcc 8dcc mentioned this pull request Jan 12, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant