fixed: tests

This commit is contained in:
Sven Vogel 2024-07-02 16:43:59 +02:00
parent 09ac2251dc
commit 0936ab39c0
6 changed files with 36 additions and 36 deletions

View File

@ -7,22 +7,22 @@
#include <mem/cache.h> #include <mem/cache.h>
void generate_statement(const AST_NODE_PTR stmt) { void generate_statement(const AST_NODE_PTR stmt) {
const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL); const AST_NODE_PTR add = AST_new_node(empty_location(NULL), AST_Add, NULL);
AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "3"));
AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "6"));
AST_push_node(stmt, add); AST_push_node(stmt, add);
} }
void generate_branch(const AST_NODE_PTR stmt) { void generate_branch(const AST_NODE_PTR stmt) {
const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); const AST_NODE_PTR branch = AST_new_node(empty_location(NULL), AST_If, NULL);
const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); const AST_NODE_PTR gt = AST_new_node(empty_location(NULL), AST_Greater, NULL);
AST_push_node(branch, gt); AST_push_node(branch, gt);
AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3")); AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "2.3"));
AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "0.79"));
AST_push_node(stmt, branch); AST_push_node(stmt, branch);
@ -32,7 +32,7 @@ void generate_branch(const AST_NODE_PTR stmt) {
int main(void) { int main(void) {
mem_init(); mem_init();
const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL); const AST_NODE_PTR root = AST_new_node(empty_location(NULL), AST_Stmt, NULL);
generate_branch(root); generate_branch(root);

View File

@ -9,15 +9,15 @@
int main(void) { int main(void) {
mem_init(); mem_init();
struct AST_Node_t* node = AST_new_node(empty_location(), AST_If, NULL); struct AST_Node_t* node = AST_new_node(empty_location(NULL), AST_If, NULL);
struct AST_Node_t* child = AST_new_node(empty_location(), AST_Add, NULL); struct AST_Node_t* child = AST_new_node(empty_location(NULL), AST_Add, NULL);
AST_push_node(child, AST_new_node(empty_location(), AST_Int, "43")); AST_push_node(child, AST_new_node(empty_location(NULL), AST_Int, "43"));
AST_push_node(child, AST_new_node(empty_location(), AST_Int, "9")); AST_push_node(child, AST_new_node(empty_location(NULL), AST_Int, "9"));
AST_push_node(node, child); AST_push_node(node, child);
AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL)); AST_push_node(node, AST_new_node(empty_location(NULL), AST_Expr, NULL));
AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL)); AST_push_node(node, AST_new_node(empty_location(NULL), AST_Expr, NULL));
FILE* out = fopen("ast.gv", "w+"); FILE* out = fopen("ast.gv", "w+");
// convert this file ^^^^^^ // convert this file ^^^^^^

View File

@ -7,22 +7,22 @@
#include <mem/cache.h> #include <mem/cache.h>
void generate_statement(const AST_NODE_PTR stmt) { void generate_statement(const AST_NODE_PTR stmt) {
const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL); const AST_NODE_PTR add = AST_new_node(empty_location(NULL), AST_Add, NULL);
AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "3"));
AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "6"));
AST_push_node(stmt, add); AST_push_node(stmt, add);
} }
void generate_branch(const AST_NODE_PTR stmt) { void generate_branch(const AST_NODE_PTR stmt) {
const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); const AST_NODE_PTR branch = AST_new_node(empty_location(NULL), AST_If, NULL);
const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); const AST_NODE_PTR gt = AST_new_node(empty_location(NULL), AST_Greater, NULL);
AST_push_node(branch, gt); AST_push_node(branch, gt);
AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3")); AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "2.3"));
AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "0.79"));
AST_push_node(stmt, branch); AST_push_node(stmt, branch);
@ -33,7 +33,7 @@ int main(void) {
mem_init(); mem_init();
AST_init(); AST_init();
const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL); const AST_NODE_PTR root = AST_new_node(empty_location(NULL), AST_Stmt, NULL);
generate_branch(root); generate_branch(root);

View File

@ -9,7 +9,7 @@ int main(void) {
mem_init(); mem_init();
AST_init(); AST_init();
const AST_NODE_PTR node = AST_new_node(empty_location(), 0, "value"); const AST_NODE_PTR node = AST_new_node(empty_location(NULL), 0, "value");
for (size_t i = 0; i < AST_ELEMENT_COUNT; i++) { for (size_t i = 0; i < AST_ELEMENT_COUNT; i++) {
// set kind // set kind

View File

@ -36,8 +36,11 @@ add_executable(global_vars
${PROJECT_SOURCE_DIR}/src/codegen/backend.c ${PROJECT_SOURCE_DIR}/src/codegen/backend.c
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/sys/col.c ${PROJECT_SOURCE_DIR}/src/sys/col.c
${PROJECT_SOURCE_DIR}/src/set/set.c
${PROJECT_SOURCE_DIR}/src/ast/ast.c
${PROJECT_SOURCE_DIR}/src/cfg/opt.c ${PROJECT_SOURCE_DIR}/src/cfg/opt.c
${PROJECT_SOURCE_DIR}/src/io/files.c ${PROJECT_SOURCE_DIR}/src/io/files.c
${PROJECT_SOURCE_DIR}/src/mem/cache.c
global_vars.c global_vars.c
${SOURCE_FILES}) ${SOURCE_FILES})
set_target_properties(global_vars set_target_properties(global_vars

View File

@ -6,8 +6,7 @@
#include <set/types.h> #include <set/types.h>
[[gnu::always_inline]] [[gnu::always_inline]]
[[clang::always_inline]] inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type* type) {
inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type type) {
Variable* variable = alloca(sizeof(Variable)); Variable* variable = alloca(sizeof(Variable));
variable->name = name; variable->name = name;
@ -20,10 +19,8 @@ inline Variable* create_variable_decl(const char* name, StorageQualifier qualifi
return variable; return variable;
} }
[[gnu::always_inline]] Module* create_module() {
[[clang::always_inline]] Module* module = malloc(sizeof(Module));
inline Module* create_module() {
Module* module = alloca(sizeof(Module));
module->boxes = g_hash_table_new(g_str_hash, g_str_equal); module->boxes = g_hash_table_new(g_str_hash, g_str_equal);
module->functions = g_hash_table_new(g_str_hash, g_str_equal); module->functions = g_hash_table_new(g_str_hash, g_str_equal);
@ -35,7 +32,7 @@ inline Module* create_module() {
type_int.kind = TypeKindPrimitive; type_int.kind = TypeKindPrimitive;
type_int.impl.primitive = Int; type_int.impl.primitive = Int;
g_hash_table_insert(module->variables, "a", create_variable_decl("a", Global, type_int)); g_hash_table_insert(module->variables, "a", create_variable_decl("a", Global, &type_int));
Type type_composite; Type type_composite;
type_composite.kind = TypeKindComposite; type_composite.kind = TypeKindComposite;
@ -43,11 +40,11 @@ inline Module* create_module() {
type_composite.impl.composite.scale = 2.0; type_composite.impl.composite.scale = 2.0;
type_composite.impl.composite.sign = Signed; type_composite.impl.composite.sign = Signed;
g_hash_table_insert(module->variables, "b", create_variable_decl("b", Global, type_composite)); g_hash_table_insert(module->variables, "b", create_variable_decl("b", Global, &type_composite));
Type type_box; Type type_box;
type_box.kind = TypeKindBox; type_box.kind = TypeKindBox;
type_box.impl.box.member = g_hash_table_new(g_str_hash, g_str_equal); type_box.impl.box->member = g_hash_table_new(g_str_hash, g_str_equal);
BoxMember* member1 = alloca(sizeof(BoxMember)); BoxMember* member1 = alloca(sizeof(BoxMember));
member1->box = NULL; member1->box = NULL;
@ -55,7 +52,7 @@ inline Module* create_module() {
member1->type = alloca(sizeof(Type)); member1->type = alloca(sizeof(Type));
*(member1->type) = type_int; *(member1->type) = type_int;
g_hash_table_insert(type_box.impl.box.member, "foo", member1); g_hash_table_insert(type_box.impl.box->member, "foo", member1);
Type type_half; Type type_half;
type_half.kind = TypeKindComposite; type_half.kind = TypeKindComposite;
@ -69,15 +66,15 @@ inline Module* create_module() {
member2->type = alloca(sizeof(Type)); member2->type = alloca(sizeof(Type));
*(member2->type) = type_half; *(member2->type) = type_half;
g_hash_table_insert(type_box.impl.box.member, "bar", member2); g_hash_table_insert(type_box.impl.box->member, "bar", member2);
g_hash_table_insert(module->variables, "c", create_variable_decl("c", Global, type_box)); g_hash_table_insert(module->variables, "c", create_variable_decl("c", Global, &type_box));
Type type_reference; Type type_reference;
type_reference.kind = TypeKindReference; type_reference.kind = TypeKindReference;
type_reference.impl.reference = &type_box; type_reference.impl.reference = &type_box;
g_hash_table_insert(module->variables, "d", create_variable_decl("d", Global, type_reference)); g_hash_table_insert(module->variables, "d", create_variable_decl("d", Global, &type_reference));
return module; return module;
} }