Skip to content

Commit

Permalink
Get the GC to work again and change the allocator
Browse files Browse the repository at this point in the history
Allocator subsystem works with a single contiguous chunk of memory.
Small object allocator uses fixed-size bins and never attempts to merge chunks,
and the large object allocator is a slightly-modified version of the SQLite
mem3.c allocator.
The GC uses the boundaries of this chunk of memory, plus a table of
flags, to determine if a Value refers to a heap allocation or not (we no longer have type information per-Value). The
current implementation requires storing the size of each heap object in
the GC header, but it should be possible to elide this requirement using flags (using 2 bits for each flag instead of 1, see golang GC implementation).
Should support expanding the heap via. sbrk or similar (will require
changing paw_Alloc to expand/contract the dynamic memory area, rather
than implement a realloc-like interface).
  • Loading branch information
andy-byers committed Aug 12, 2024
1 parent 7d55931 commit 469fdd3
Show file tree
Hide file tree
Showing 51 changed files with 1,658 additions and 1,184 deletions.
23 changes: 7 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,25 @@ else()
INTERFACE m)
endif()

include(FetchContent)
FetchContent_Declare(gc
GIT_REPOSITORY https://github.com/ivmai/bdwgc.git
GIT_TAG v8.2.6)
FetchContent_MakeAvailable(gc)

set(PAW_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)

add_library(paw STATIC)
target_sources(paw
PUBLIC ${PAW_SOURCE_DIR}/api.h
PUBLIC ${PAW_SOURCE_DIR}/alloc.h
${PAW_SOURCE_DIR}/api.h
${PAW_SOURCE_DIR}/ast.h
${PAW_SOURCE_DIR}/auxlib.h
${PAW_SOURCE_DIR}/call.h
${PAW_SOURCE_DIR}/code.h
${PAW_SOURCE_DIR}/compile.h
${PAW_SOURCE_DIR}/debug.h
${PAW_SOURCE_DIR}/env.h
${PAW_SOURCE_DIR}/gc_aux.h
${PAW_SOURCE_DIR}/gc.h
${PAW_SOURCE_DIR}/hir.h
${PAW_SOURCE_DIR}/lex.h
${PAW_SOURCE_DIR}/lib.h
${PAW_SOURCE_DIR}/map.h
${PAW_SOURCE_DIR}/mem.h
${PAW_SOURCE_DIR}/meta.h
${PAW_SOURCE_DIR}/opcode.h
${PAW_SOURCE_DIR}/os.h
${PAW_SOURCE_DIR}/parse.h
Expand All @@ -67,38 +61,35 @@ target_sources(paw
${PAW_SOURCE_DIR}/unify.h
${PAW_SOURCE_DIR}/util.h
${PAW_SOURCE_DIR}/value.h
PRIVATE ${PAW_SOURCE_DIR}/api.c
PRIVATE ${PAW_SOURCE_DIR}/alloc.c
${PAW_SOURCE_DIR}/api.c
${PAW_SOURCE_DIR}/ast.c
${PAW_SOURCE_DIR}/auxlib.c
${PAW_SOURCE_DIR}/call.c
${PAW_SOURCE_DIR}/check.c
${PAW_SOURCE_DIR}/code.c
${PAW_SOURCE_DIR}/codegen.c
${PAW_SOURCE_DIR}/compile.c
${PAW_SOURCE_DIR}/debug.c
${PAW_SOURCE_DIR}/env.c
${PAW_SOURCE_DIR}/gc_aux.c
${PAW_SOURCE_DIR}/gc.c
${PAW_SOURCE_DIR}/hir.c
#${PAW_SOURCE_DIR}/iolib.c
${PAW_SOURCE_DIR}/lex.c
${PAW_SOURCE_DIR}/lib.c
#${PAW_SOURCE_DIR}/mathlib.c
${PAW_SOURCE_DIR}/map.c
${PAW_SOURCE_DIR}/mem.c
${PAW_SOURCE_DIR}/meta.c
${PAW_SOURCE_DIR}/opcode.c
${PAW_SOURCE_DIR}/os.c
${PAW_SOURCE_DIR}/parse.c
${PAW_SOURCE_DIR}/resolve.c
${PAW_SOURCE_DIR}/rt.c
${PAW_SOURCE_DIR}/str.c
${PAW_SOURCE_DIR}/type.c
${PAW_SOURCE_DIR}/unify.c
${PAW_SOURCE_DIR}/util.c
${PAW_SOURCE_DIR}/value.c
${PAW_SOURCE_DIR}/vector.c)
target_link_libraries(paw
PRIVATE paw_context
PUBLIC gc)
target_include_directories(paw
PUBLIC ${PAW_SOURCE_DIR})
target_compile_definitions(paw
Expand Down
2 changes: 1 addition & 1 deletion GRAMMER.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Paw language grammer (EBNF)
**TODO: get rid of requirement that "break" | "return" | "continue" is the last statement in the block**
** just don't emit unreachable code**
** use a tool to validate this...**
** use a tool to validate this EBNF...**

## Module
```ebnf
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,14 @@ assert(status != 0)
+ [x] type inference for `struct` templates and builtin containers
+ [x] sum types/discriminated unions (`enum`)
+ [x] product types (tuple)
+ [ ] refactor user-provided allocation interface to allow heap expansion
+ [ ] module system and `import` keyword
+ [ ] methods using `impl` blocks
+ [ ] error handling
+ [ ] type inference for `enum` templates
+ [ ] pattern matching (`switch` construct)
+ [ ] pattern matching (`if let`, `let` bindings)
+ [ ] custom garbage collector (using Boehm GC for now)
+ [x] custom garbage collector (using Boehm GC for now)
+ [ ] split off UTF-8 stuff into `String` structure, where `str` is a byte array and `String` is always valid UTF-8
+ [ ] constness (`var` vs `let`)
+ [ ] compiler optimization passes
Expand Down
Loading

0 comments on commit 469fdd3

Please sign in to comment.