Intermediate commit before visitor refactor.

This commit is contained in:
2018-08-11 18:22:18 -07:00
parent 80e7c95915
commit f4ecb82c46
10 changed files with 172 additions and 91 deletions

View File

@@ -1,8 +1,8 @@
#ifndef LIBABACUS_GC_H
#define LIBABACUS_GC_H
struct libab_ref_s;
struct libab_ref_count_s;
#include "refcount.h"
#include "gc_functions.h"
/**
* Struct used to create an interface
@@ -10,18 +10,16 @@ struct libab_ref_count_s;
*/
struct libab_gc_list_s {
/**
* The head of the linked list.
* The head sentinel node.
*/
struct libab_ref_count_s* head;
struct libab_ref_count_s head_sentinel;
/**
* The tail of the linked list.
* The tail sentinel node.
*/
struct libab_ref_count_s* tail;
struct libab_ref_count_s tail_sentinel;
};
typedef struct libab_gc_list_s libab_gc_list;
typedef void (*libab_visitor_function_ptr)(struct libab_ref_count_s* , void*);
typedef void (*libab_visit_function_ptr)(void*, libab_visitor_function_ptr, void*);
/**
* Initializes a garbage collection tracking list.
@@ -34,7 +32,7 @@ void libab_gc_list_init(libab_gc_list* list);
* @param visitor the function to call for each child.
* @param data the data to pass to the visitor.
*/
void libab_gc_visit_chilren(struct libab_ref_s* ref, libab_visitor_function_ptr visitor, void* data);
void libab_gc_visit_children(struct libab_ref_s* ref, libab_visitor_function_ptr visitor, void* data);
/**
* Adds the given reference to the given garbage collection list,
* and specifies a function used to reach its children.

10
include/gc_functions.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef LIBABACUS_GC_FUNCTIONS_H
#define LIBABACUS_GC_FUNCTIONS_H
struct libab_ref_count_s;
struct libab_ref_s;
typedef void (*libab_visitor_function_ptr)(struct libab_ref_count_s* , void*);
typedef void (*libab_visit_function_ptr)(void*, libab_visitor_function_ptr, void*);
#endif

View File

@@ -9,6 +9,7 @@
#include "parser.h"
#include "result.h"
#include "table.h"
#include "gc.h"
/**
* The main struct of libabacus,
@@ -59,6 +60,12 @@ struct libab_s {
* The unit type instance.
*/
libab_ref type_unit;
/**
* List of containers references
* that should be tracked by the
* garbage collector for cycles.
*/
libab_gc_list containers;
/**
* Internal; the number basetype. This cannot be a static

View File

@@ -2,7 +2,7 @@
#define LIBABACUS_REFCOUNT_H
#include "result.h"
#include "gc.h"
#include "gc_functions.h"
/**
* A struct for holding

View File

@@ -7,6 +7,7 @@
#include "parsetype.h"
#include "result.h"
#include "table.h"
#include "libabacus.h"
#include <string.h>
/**
@@ -78,11 +79,12 @@ libab_result libab_instantiate_basetype(libab_basetype* to_instantiate,
libab_ref* into, size_t n, ...);
/**
* Creates a new libab_table, and stores it into the given reference.
* @param ab the libabacus instance in which the table is being created.
* @param into the reference to store the table into.
* @param parent the parent reference to store.
* @return the result of the instantiation.
*/
libab_result libab_create_table(libab_ref* into, libab_ref* parent);
libab_result libab_create_table(libab* ab, libab_ref* into, libab_ref* parent);
/**
* Allocates a new reference counted value with the given type and data.
* @param into the reference to store the allocated data into.
@@ -90,8 +92,8 @@ libab_result libab_create_table(libab_ref* into, libab_ref* parent);
* @param type the type to give the value.
* @return the result of necessary allocations.
*/
libab_result libab_create_value_ref(libab_ref* into, libab_ref* data,
libab_ref* type);
libab_result libab_create_value_ref(libab* ab, libab_ref* into,
libab_ref* data, libab_ref* type);
/**
* Allocates a new reference counted value with the given type and data.
* @param into the reference to store the allocated data into.
@@ -99,8 +101,8 @@ libab_result libab_create_value_ref(libab_ref* into, libab_ref* data,
* @param type the type to give the value.
* @return the result of necessary allocations.
*/
libab_result libab_create_value_raw(libab_ref* into, void* data,
libab_ref* type);
libab_result libab_create_value_raw(libab* ab, libab_ref* into,
void* data, libab_ref* type);
/**
* Allocates a function that uses internal code to run.
* @param into the reference into which to store the new function.
@@ -109,7 +111,7 @@ libab_result libab_create_value_raw(libab_ref* into, void* data,
* @param scope the scope in which this function was declared.
* @return libab_result the result of any necessary allocations.
*/
libab_result libab_create_function_internal(libab_ref* into,
libab_result libab_create_function_internal(libab* ab, libab_ref* into,
void (*free_function)(void*),
libab_function_ptr fun,
libab_ref* scope);
@@ -121,7 +123,7 @@ libab_result libab_create_function_internal(libab_ref* into,
* @param scope the scope in which this function was declared.
* @return libab_result the result of any necessary allocations.
*/
libab_result libab_create_function_tree(libab_ref* into,
libab_result libab_create_function_tree(libab* ab, libab_ref* into,
void (*free_function)(void*),
libab_tree* tree,
libab_ref* scope);
@@ -133,7 +135,7 @@ libab_result libab_create_function_tree(libab_ref* into,
* @param scope the scope in which this function was declared.
* @return libab_result the result of any necessary allocations.
*/
libab_result libab_create_function_behavior(libab_ref* into,
libab_result libab_create_function_behavior(libab* ab, libab_ref* into,
void (*free_function)(void*),
libab_behavior* behavior,
libab_ref* scope);
@@ -143,7 +145,7 @@ libab_result libab_create_function_behavior(libab_ref* into,
* @param the function_list type.
* @return the result of the allocations.
*/
libab_result libab_create_function_list(libab_ref* into, libab_ref* type);
libab_result libab_create_function_list(libab* ab, libab_ref* into, libab_ref* type);
/**
* Creates a new table entry that holds the given value.
* @param table the table to store the entry into.