Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include(FetchContent)
FetchContent_Declare(
snlogger
GIT_REPOSITORY https://github.com/kshku/SnLogger.git
GIT_TAG v0.1.0
GIT_TAG v0.2.0
)
FetchContent_MakeAvailable(snlogger)

Expand All @@ -47,10 +47,17 @@ FetchContent_MakeAvailable(snfile)
FetchContent_Declare(
snmemory
GIT_REPOSITORY https://github.com/kshku/SnMemory.git
GIT_TAG v0.2.0
)

FetchContent_Declare(
sncontainer
GIT_REPOSITORY https://github.com/kshku/SnContainer.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(sncontainer)

target_link_libraries(snuk_configs INTERFACE snlogger snfile snmemory)
target_link_libraries(snuk_configs INTERFACE snlogger snfile snmemory sncontainer)

add_subdirectory(docs)
add_subdirectory(src)
Expand Down
144 changes: 0 additions & 144 deletions include/snuk/darray.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/snuk/interpreter/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct SnukInterpreter {
SnukValue *trash;
SnukSignal signal;
void *mem;
SnukAllocator allocator;
SnMemoryAllocator allocator;
SnLinearAllocator la;
SnukError err;
SnukSrcLoc cur_loc;
Expand Down
8 changes: 4 additions & 4 deletions include/snuk/interpreter/interpreter_helper.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "interpreter.h"
#include "snuk/darray.h"
#include "snuk/defines.h"
#include "snuk/snuk_error.h"
#include "snuk_scope.h"

#include <sncontainer/darray.h>
#include <stdarg.h>
#include <stdio.h>

Expand Down Expand Up @@ -164,11 +164,11 @@ SNUK_INLINE SnukEnv *interpreter_lookup(
}

SNUK_INLINE void interpreter_trash(SnukInterpreter *intpret, SnukValue value) {
snuk_darray_push(&intpret->trash, value);
sn_darray_push(&intpret->trash, value);
}

SNUK_INLINE void interpreter_clear_trash(SnukInterpreter *intpret) {
uint64_t count = snuk_darray_get_length(intpret->trash);
uint64_t count = sn_darray_get_length(intpret->trash);
for (uint64_t i = 0; i < count; ++i) snuk_value_free(intpret->trash[i]);
snuk_darray_clear(&intpret->trash);
sn_darray_clear(&intpret->trash);
}
1 change: 0 additions & 1 deletion include/snuk/interpreter/snuk_env.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "snuk/darray.h"
#include "snuk/defines.h"
#include "snuk/parser/snuk_type.h"
#include "snuk/string_view.h"
Expand Down
19 changes: 11 additions & 8 deletions include/snuk/interpreter/snuk_scope.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once

#include "snuk/defines.h"
#include "snuk/memory.h"
#include "snuk/refcount.h"
#include "snuk_env.h"

#include <sncontainer/darray.h>

extern uint64_t snuk_scope_seq;
#define GET_SCOPE(rc) ((SnukScope *)snuk_ref_counter_get(rc))
#define SCOPE_PARENT(rc) (GET_SCOPE(rc)->parent)
Expand All @@ -24,9 +27,9 @@ struct SnukScope {
};

SNUK_INLINE void snuk_scope_destroy_envs(SnukScope *scope) {
uint64_t count = snuk_darray_get_length(scope->vars);
uint64_t count = sn_darray_get_length(scope->vars);
for (uint64_t i = 0; i < count; ++i) snuk_env_free(scope->vars[i]);
snuk_darray_clear(&scope->vars);
sn_darray_clear(&scope->vars);
}

/**
Expand All @@ -47,7 +50,7 @@ SNUK_INLINE void snuk_scope_destroy(void *data, void *ptr) {
log_debug("scope destroyed (scope=%p)", ptr);
snuk_scope_destroy_envs(scope);

snuk_darray_destroy(scope->vars);
sn_darray_destroy(scope->vars);

if (scope->parent) {
if (scope->weak_ref) snuk_ref_counter_release_weak(&scope->parent);
Expand All @@ -72,7 +75,7 @@ SNUK_INLINE SnukRefCounter *snuk_scope_create(SnukRefCounter *parent, bool weak_
SnukScope *scope = (SnukScope *)snuk_alloc(sizeof(SnukScope), alignof(SnukScope));
uint64_t seq = ++snuk_scope_seq;
*scope = (SnukScope){
.vars = snuk_darray_create(SnukEnv *, NULL),
.vars = sn_darray_create(SnukEnv *, &snuk_global_allocator),
.parent = snuk_ref_counter_move(&parent),
.weak_ref = weak_ref,
.locked = locked,
Expand Down Expand Up @@ -113,7 +116,7 @@ SNUK_INLINE void snuk_scope_set_parent(SnukRefCounter *scope_rc, SnukRefCounter
SNUK_INLINE SnukEnv *snuk_scope_lookup(SnukRefCounter *scope_rc, SnukStringView name, bool *locked) {
SnukScope *scope = GET_SCOPE(scope_rc);
if (locked) *locked = scope->locked;
uint64_t count = snuk_darray_get_length(scope->vars);
uint64_t count = sn_darray_get_length(scope->vars);
for (uint64_t i = 0; i < count; ++i)
if (snuk_string_view_equal(scope->vars[i]->name, name)) return scope->vars[i];

Expand All @@ -139,17 +142,17 @@ SNUK_INLINE bool snuk_scope_add_env(SnukRefCounter *scope_rc, SnukEnv *env) {
snuk_env_free(env);
return false;
}
snuk_darray_push(&scope->vars, env);
sn_darray_push(&scope->vars, env);
return true;
}

SNUK_INLINE void snuk_scope_remove_env(SnukRefCounter *scope_rc, SnukStringView name) {
SnukScope *scope = GET_SCOPE(scope_rc);
uint64_t count = snuk_darray_get_length(scope->vars);
uint64_t count = sn_darray_get_length(scope->vars);
for (uint64_t i = 0; i < count; ++i) {
if (snuk_string_view_equal(scope->vars[i]->name, name)) {
SnukEnv *env = NULL;
snuk_darray_pop_at(&scope->vars, i, &env);
sn_darray_pop_at(&scope->vars, i, &env);
snuk_env_free(env);
return;
}
Expand Down
9 changes: 1 addition & 8 deletions include/snuk/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
#define MIB(x) (KIB((x) * 1024))
#define GIB(x) (MIB((x) * 1024))

typedef struct SnukAllocator {
void *data;
void *(*alloc)(void *data, uint64_t size, uint64_t align);
void *(*realloc)(void *data, void *ptr, uint64_t new_size, uint64_t align);
void (*free)(void *data, void *ptr);
} SnukAllocator;

/**
* @brief Retrieves the system page size.
*
Expand Down Expand Up @@ -98,4 +91,4 @@ SNUK_API void *snuk_realloc(void *ptr, uint64_t new_size, uint64_t align);
*/
SNUK_API void snuk_free(void *ptr);

extern SnukAllocator snuk_global_allocator;
extern SnMemoryAllocator snuk_global_allocator;
4 changes: 2 additions & 2 deletions include/snuk/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct SnukParser {
SnukToken current; /**< Current token. */
SnukToken next; /**< Next token. */

SnukAllocator *allocator;
SnMemoryAllocator *allocator;

bool panic_mode; /**< Error and recovery state flags. */
SnukError err;
Expand All @@ -50,7 +50,7 @@ typedef struct SnukParser {
* @note The source text must remain valid for the lifetime of parsed nodes that
* reference token text.
*/
SNUK_API void snuk_parser_init(SnukParser *parser, const char *src, SnukAllocator *allocator);
SNUK_API void snuk_parser_init(SnukParser *parser, const char *src, SnMemoryAllocator *allocator);

/**
* @brief Deinitialize a parser context.
Expand Down
7 changes: 4 additions & 3 deletions include/snuk/parser/snuk_expr.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include "parser_common.h"
#include "snuk/darray.h"
#include "snuk/defines.h"
#include "snuk/string_view.h"

#include <sncontainer/darray.h>

/**
* @brief Parser expression node kinds.
*/
Expand Down Expand Up @@ -501,10 +502,10 @@ SNUK_INLINE SnukExpr *build_block_expr(SnukParser *parser, SnukExpr *expr, SnukI
expr = parser_create_expr(parser);
*expr = (SnukExpr){
.type = SNUK_EXPR_BLOCK,
.block_items = snuk_darray_create(SnukItem *, parser->allocator),
.block_items = sn_darray_create(SnukItem *, parser->allocator),
};
}
if (item) snuk_darray_push(&expr->block_items, item);
if (item) sn_darray_push(&expr->block_items, item);
return expr;
}

Expand Down
11 changes: 6 additions & 5 deletions include/snuk/parser/snuk_item.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include "parser_common.h"
#include "snuk/darray.h"
#include "snuk/defines.h"
#include "snuk/snuk_error.h"
#include "snuk/string_view.h"
#include "snuk_type.h"

#include <sncontainer/darray.h>

/**
* @brief Parser items kinds.
*/
Expand Down Expand Up @@ -161,10 +162,10 @@ SNUK_INLINE SnukItem *build_print_item(SnukParser *parser, SnukItem *item, SnukE
item = parser_create_item(parser);
*item = (SnukItem){
.type = SNUK_ITEM_PRINT,
.print_exprs = snuk_darray_create(SnukExpr *, parser->allocator),
.print_exprs = sn_darray_create(SnukExpr *, parser->allocator),
};
}
if (expr) snuk_darray_push(&item->print_exprs, expr);
if (expr) sn_darray_push(&item->print_exprs, expr);
return item;
}

Expand All @@ -182,12 +183,12 @@ SNUK_INLINE SnukItem *build_extend_item(SnukParser *parser, SnukItem *item, Snuk
*item = (SnukItem){
.type = SNUK_ITEM_EXTEND,
.extend_item = {
.members = snuk_darray_create(SnukItem *, parser->allocator),
.members = sn_darray_create(SnukItem *, parser->allocator),
},
};
}
if (type) item->extend_item.type = type;
if (member) snuk_darray_push(&item->extend_item.members, member);
if (member) sn_darray_push(&item->extend_item.members, member);
return item;
}

Expand Down
Loading
Loading