Merge remote-tracking branch 'origin/90-implement-the-struct-tree-for-the-parser' into 85-implement-llvm-backend
# Conflicts: # src/cfg/opt.c # src/set/types.h
This commit is contained in:
commit
98ecd8a6ae
|
@ -226,14 +226,13 @@ void print_help(void) {
|
||||||
" --lld-fatal-warnings treat linker warnings as errors",
|
" --lld-fatal-warnings treat linker warnings as errors",
|
||||||
" --gsc-fatal-warnings treat parser warnings as errors",
|
" --gsc-fatal-warnings treat parser warnings as errors",
|
||||||
"Options:",
|
"Options:",
|
||||||
" --verbose print logs with level information or higher",
|
" --verbose print logs with level information or higher",
|
||||||
" --debug print debug logs (if not disabled at compile time)",
|
" --debug print debug logs (if not disabled at compile time)",
|
||||||
" --version print the version",
|
" --version print the version",
|
||||||
" --list-targets print a list of all available targets supported",
|
" --list-targets print a list of all available targets supported",
|
||||||
" --help print this help dialog",
|
" --help print this help dialog",
|
||||||
" --color-always always colorize output",
|
" --color-always always colorize output",
|
||||||
" --version print the version",
|
" --print-gc-stats print statistics of the garbage collector"
|
||||||
" --print-memory-stats print statistics of the garbage collector"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(lines) / sizeof(const char *); i++) {
|
for (unsigned int i = 0; i < sizeof(lines) / sizeof(const char *); i++) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <codegen/backend.h>
|
#include <codegen/backend.h>
|
||||||
#include <llvm/backend.h>
|
#include <llvm/backend.h>
|
||||||
#include <mem/cache.h>
|
#include <mem/cache.h>
|
||||||
|
#include <set/set.h>
|
||||||
|
|
||||||
#define GRAPHVIZ_FILE_EXTENSION "gv"
|
#define GRAPHVIZ_FILE_EXTENSION "gv"
|
||||||
|
|
||||||
|
@ -178,6 +179,7 @@ static void build_target(ModuleFileStack *unit, const TargetConfig *target) {
|
||||||
if (setup_target_environment(target) == 0) {
|
if (setup_target_environment(target) == 0) {
|
||||||
|
|
||||||
print_ast_to_file(ast, target);
|
print_ast_to_file(ast, target);
|
||||||
|
Module* test = create_set(ast);
|
||||||
|
|
||||||
// TODO: parse AST to semantic values
|
// TODO: parse AST to semantic values
|
||||||
Module* module = NULL;
|
Module* module = NULL;
|
||||||
|
@ -190,6 +192,7 @@ static void build_target(ModuleFileStack *unit, const TargetConfig *target) {
|
||||||
|
|
||||||
mem_purge_namespace(MemoryNamespaceLex);
|
mem_purge_namespace(MemoryNamespaceLex);
|
||||||
mem_purge_namespace(MemoryNamespaceAst);
|
mem_purge_namespace(MemoryNamespaceAst);
|
||||||
|
mem_purge_namespace(MemoryNamespaceSet);
|
||||||
|
|
||||||
print_file_statistics(file);
|
print_file_statistics(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <io/files.h>
|
#include <io/files.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/col.h>
|
#include <sys/col.h>
|
||||||
|
@ -82,7 +84,7 @@ static void custom_fgets(char *buffer, size_t n, FILE *stream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message) {
|
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message, ...) {
|
||||||
assert(file->handle != NULL);
|
assert(file->handle != NULL);
|
||||||
assert(location != NULL);
|
assert(location != NULL);
|
||||||
assert(message != NULL);
|
assert(message != NULL);
|
||||||
|
@ -120,8 +122,16 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
|
|
||||||
const char *absolute_path = get_absolute_path(file->path);
|
const char *absolute_path = get_absolute_path(file->path);
|
||||||
|
|
||||||
printf("%s%s:%ld:%s %s%s:%s %s\n", BOLD, absolute_path, location->line_start, RESET, accent_color, kind_text, RESET,
|
printf("%s%s:%ld:%s %s%s:%s ", BOLD, absolute_path, location->line_start, RESET, accent_color, kind_text, RESET);
|
||||||
message);
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
|
||||||
|
vprintf(message, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
mem_free((void *) absolute_path);
|
mem_free((void *) absolute_path);
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ TokenLocation empty_location(void);
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
[[gnu::nonnull(1), gnu::nonnull(2)]]
|
[[gnu::nonnull(1), gnu::nonnull(2)]]
|
||||||
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message);
|
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message, ...);
|
||||||
|
|
||||||
[[gnu::nonnull(2)]]
|
[[gnu::nonnull(2)]]
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = mem_strdup(MemoryNamespaceLex, yytext); return(ValStr);};
|
DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = mem_strdup(MemoryNamespaceLex, yytext); return(ValStr);};
|
||||||
\"\"\"[^\"]*\"\"\" {
|
\"\"\"[^\"]*\"\"\" {
|
||||||
yytext = yytext +3;
|
yytext = yytext +3;
|
||||||
yytext[yyleng - 4] = 0;
|
yytext[yyleng - 6] = 0;
|
||||||
|
|
||||||
DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = mem_strdup(MemoryNamespaceLex, yytext); return(ValMultistr);};
|
DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = mem_strdup(MemoryNamespaceLex, yytext); return(ValMultistr);};
|
||||||
[ \r\t] { /* ignore whitespace */ };
|
[ \r\t] { /* ignore whitespace */ };
|
||||||
|
|
|
@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
run_compiler();
|
run_compiler();
|
||||||
|
|
||||||
if (is_option_set("print-memory-stats")) {
|
if (is_option_set("print-gc-stats")) {
|
||||||
print_memory_statistics();
|
print_memory_statistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
104
src/mem/cache.c
104
src/mem/cache.c
|
@ -7,6 +7,7 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
static GHashTable* namespaces = NULL;
|
static GHashTable* namespaces = NULL;
|
||||||
|
|
||||||
|
@ -20,6 +21,17 @@ typedef struct MemoryNamespaceStatistic_t {
|
||||||
size_t purged_free_count;
|
size_t purged_free_count;
|
||||||
} MemoryNamespaceStatistic;
|
} MemoryNamespaceStatistic;
|
||||||
|
|
||||||
|
typedef enum MemoryBlockType_t {
|
||||||
|
GenericBlock,
|
||||||
|
GLIB_Array,
|
||||||
|
GLIB_HashTable
|
||||||
|
} MemoryBlockType;
|
||||||
|
|
||||||
|
typedef struct MemoryBlock_t {
|
||||||
|
void* block_ptr;
|
||||||
|
MemoryBlockType kind;
|
||||||
|
} MemoryBlock;
|
||||||
|
|
||||||
typedef struct MemoryNamespace_t {
|
typedef struct MemoryNamespace_t {
|
||||||
MemoryNamespaceStatistic statistic;
|
MemoryNamespaceStatistic statistic;
|
||||||
GArray* blocks;
|
GArray* blocks;
|
||||||
|
@ -44,9 +56,11 @@ static void* namespace_malloc(MemoryNamespaceRef memoryNamespace, size_t size) {
|
||||||
assert(memoryNamespace != NULL);
|
assert(memoryNamespace != NULL);
|
||||||
assert(size != 0);
|
assert(size != 0);
|
||||||
|
|
||||||
void* block = malloc(size);
|
MemoryBlock block;
|
||||||
|
block.block_ptr = malloc(size);
|
||||||
|
block.kind = GenericBlock;
|
||||||
|
|
||||||
if (block == NULL) {
|
if (block.block_ptr == NULL) {
|
||||||
memoryNamespace->statistic.faulty_allocations ++;
|
memoryNamespace->statistic.faulty_allocations ++;
|
||||||
} else {
|
} else {
|
||||||
g_array_append_val(memoryNamespace->blocks, block);
|
g_array_append_val(memoryNamespace->blocks, block);
|
||||||
|
@ -55,20 +69,36 @@ static void* namespace_malloc(MemoryNamespaceRef memoryNamespace, size_t size) {
|
||||||
memoryNamespace->statistic.bytes_allocated += size;
|
memoryNamespace->statistic.bytes_allocated += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return block;
|
return block.block_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void namespace_free_block(MemoryBlock block) {
|
||||||
|
switch (block.kind) {
|
||||||
|
case GenericBlock:
|
||||||
|
free(block.block_ptr);
|
||||||
|
break;
|
||||||
|
case GLIB_Array:
|
||||||
|
g_array_free(block.block_ptr, TRUE);
|
||||||
|
break;
|
||||||
|
case GLIB_HashTable:
|
||||||
|
g_hash_table_destroy(block.block_ptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean namespace_free(MemoryNamespaceRef memoryNamespace, void* block) {
|
static gboolean namespace_free(MemoryNamespaceRef memoryNamespace, void* block) {
|
||||||
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
||||||
void* current_block = g_array_index(memoryNamespace->blocks, void*, i);
|
MemoryBlock current_block = g_array_index(memoryNamespace->blocks, MemoryBlock, i);
|
||||||
|
|
||||||
if (current_block == block) {
|
if (current_block.block_ptr == block) {
|
||||||
assert(block != NULL);
|
assert(block != NULL);
|
||||||
|
|
||||||
free(block);
|
namespace_free_block(current_block);
|
||||||
|
|
||||||
g_array_remove_index(memoryNamespace->blocks, i);
|
g_array_remove_index(memoryNamespace->blocks, i);
|
||||||
|
|
||||||
memoryNamespace->statistic.manual_free_count++;
|
memoryNamespace->statistic.manual_free_count++;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,13 +109,13 @@ static void* namespace_realloc(MemoryNamespaceRef memoryNamespace, void* block,
|
||||||
void* reallocated_block = NULL;
|
void* reallocated_block = NULL;
|
||||||
|
|
||||||
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
||||||
void* current_block = g_array_index(memoryNamespace->blocks, void*, i);
|
MemoryBlock current_block = g_array_index(memoryNamespace->blocks, MemoryBlock, i);
|
||||||
|
|
||||||
if (current_block == block) {
|
if (current_block.block_ptr == block) {
|
||||||
reallocated_block = realloc(block, size);
|
reallocated_block = realloc(current_block.block_ptr, size);
|
||||||
|
|
||||||
if (reallocated_block != NULL) {
|
if (reallocated_block != NULL) {
|
||||||
g_array_index(memoryNamespace->blocks, void*, i) = reallocated_block;
|
g_array_index(memoryNamespace->blocks, MemoryBlock, i).block_ptr = reallocated_block;
|
||||||
memoryNamespace->statistic.bytes_allocated += size;
|
memoryNamespace->statistic.bytes_allocated += size;
|
||||||
memoryNamespace->statistic.reallocation_count ++;
|
memoryNamespace->statistic.reallocation_count ++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,9 +137,9 @@ static void namespace_delete(MemoryNamespaceRef memoryNamespace) {
|
||||||
static void namespace_purge(MemoryNamespaceRef memoryNamespace) {
|
static void namespace_purge(MemoryNamespaceRef memoryNamespace) {
|
||||||
|
|
||||||
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
for (guint i = 0; i < memoryNamespace->blocks->len; i++) {
|
||||||
void* current_block = g_array_index(memoryNamespace->blocks, void*, i);
|
MemoryBlock current_block = g_array_index(memoryNamespace->blocks, MemoryBlock, i);
|
||||||
|
|
||||||
free(current_block);
|
namespace_free_block(current_block);
|
||||||
|
|
||||||
memoryNamespace->statistic.purged_free_count ++;
|
memoryNamespace->statistic.purged_free_count ++;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +150,7 @@ static void namespace_purge(MemoryNamespaceRef memoryNamespace) {
|
||||||
static MemoryNamespaceRef namespace_new() {
|
static MemoryNamespaceRef namespace_new() {
|
||||||
MemoryNamespaceRef memoryNamespace = malloc(sizeof(MemoryNamespace));
|
MemoryNamespaceRef memoryNamespace = malloc(sizeof(MemoryNamespace));
|
||||||
|
|
||||||
memoryNamespace->blocks = g_array_new(FALSE, FALSE, sizeof(void*));
|
memoryNamespace->blocks = g_array_new(FALSE, FALSE, sizeof(MemoryBlock));
|
||||||
memoryNamespace->statistic.bytes_allocated = 0;
|
memoryNamespace->statistic.bytes_allocated = 0;
|
||||||
memoryNamespace->statistic.allocation_count = 0;
|
memoryNamespace->statistic.allocation_count = 0;
|
||||||
memoryNamespace->statistic.manual_free_count = 0;
|
memoryNamespace->statistic.manual_free_count = 0;
|
||||||
|
@ -132,6 +162,30 @@ static MemoryNamespaceRef namespace_new() {
|
||||||
return memoryNamespace;
|
return memoryNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GArray *namespace_new_g_array(MemoryNamespaceRef namespace, guint size) {
|
||||||
|
MemoryBlock block;
|
||||||
|
block.block_ptr = g_array_new(FALSE, FALSE, size);
|
||||||
|
block.kind = GLIB_Array;
|
||||||
|
|
||||||
|
g_array_append_val(namespace->blocks, block);
|
||||||
|
namespace->statistic.bytes_allocated += sizeof(GArray*);
|
||||||
|
namespace->statistic.allocation_count ++;
|
||||||
|
|
||||||
|
return block.block_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHashTable *namespace_new_g_hash_table(MemoryNamespaceRef namespace, GHashFunc hash_func, GEqualFunc key_equal_func) {
|
||||||
|
MemoryBlock block;
|
||||||
|
block.block_ptr = g_hash_table_new(hash_func, key_equal_func);
|
||||||
|
block.kind = GLIB_HashTable;
|
||||||
|
|
||||||
|
g_array_append_val(namespace->blocks, block);
|
||||||
|
namespace->statistic.bytes_allocated += sizeof(GHashTable*);
|
||||||
|
namespace->statistic.allocation_count ++;
|
||||||
|
|
||||||
|
return block.block_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
static void cleanup() {
|
static void cleanup() {
|
||||||
if (namespaces == NULL) {
|
if (namespaces == NULL) {
|
||||||
printf("==> Memory cache was unused <==\n");
|
printf("==> Memory cache was unused <==\n");
|
||||||
|
@ -221,7 +275,7 @@ void mem_purge_namespace(MemoryNamespaceName name) {
|
||||||
|
|
||||||
namespace_purge(cache);
|
namespace_purge(cache);
|
||||||
} else {
|
} else {
|
||||||
PANIC("purging invalid namespace: %s", name);
|
WARN("purging invalid namespace: %s", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,5 +321,25 @@ void print_memory_statistics() {
|
||||||
|
|
||||||
namespace_statistics_print(&total, "summary");
|
namespace_statistics_print(&total, "summary");
|
||||||
|
|
||||||
printf("Note: untracked are memory allocations from external libraries.\n");
|
printf("Note: untracked are memory allocations from external libraries and non-gc managed components.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
GArray* mem_new_g_array(MemoryNamespaceName name, guint element_size) {
|
||||||
|
MemoryNamespaceRef cache = check_namespace(name);
|
||||||
|
|
||||||
|
if (cache == NULL) {
|
||||||
|
PANIC("memory namespace not created");
|
||||||
|
}
|
||||||
|
|
||||||
|
return namespace_new_g_array(cache, element_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
GHashTable* mem_new_g_hash_table(MemoryNamespaceName name, GHashFunc hash_func, GEqualFunc key_equal_func) {
|
||||||
|
MemoryNamespaceRef cache = check_namespace(name);
|
||||||
|
|
||||||
|
if (cache == NULL) {
|
||||||
|
PANIC("memory namespace not created");
|
||||||
|
}
|
||||||
|
|
||||||
|
return namespace_new_g_hash_table(cache, hash_func, key_equal_func);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <mem/cache.h>
|
#include <mem/cache.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
typedef char* MemoryNamespaceName;
|
typedef char* MemoryNamespaceName;
|
||||||
|
|
||||||
|
@ -87,4 +88,8 @@ void* mem_clone(MemoryNamespaceName name, void* data, size_t size);
|
||||||
|
|
||||||
void print_memory_statistics();
|
void print_memory_statistics();
|
||||||
|
|
||||||
|
GArray* mem_new_g_array(MemoryNamespaceName name, guint element_size);
|
||||||
|
|
||||||
|
GHashTable* mem_new_g_hash_table(MemoryNamespaceName name, GHashFunc hash_func, GEqualFunc key_equal_func);
|
||||||
|
|
||||||
#endif //GEMSTONE_CACHE_H
|
#endif //GEMSTONE_CACHE_H
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef _SET_H_
|
||||||
|
#define _SET_H_
|
||||||
|
|
||||||
|
#include <ast/ast.h>
|
||||||
|
#include <set/types.h>
|
||||||
|
|
||||||
|
#define SEMANTIC_OK 0
|
||||||
|
#define SEMANTIC_ERROR 1
|
||||||
|
|
||||||
|
Module * create_set(AST_NODE_PTR rootNodePtr );
|
||||||
|
|
||||||
|
void delete_set(Module* module);
|
||||||
|
|
||||||
|
#endif
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Primitive types form the basis of all other types.
|
* @brief Primitive types form the basis of all other types.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum PrimitiveType_t {
|
typedef enum PrimitiveType_t {
|
||||||
// 4 byte signed integer in two's complement
|
// 4 byte signed integer in two's complement
|
||||||
|
@ -21,7 +21,7 @@ typedef enum PrimitiveType_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the sign of a composite type.
|
* @brief Represents the sign of a composite type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum Sign_t {
|
typedef enum Sign_t {
|
||||||
// type has no sign bit
|
// type has no sign bit
|
||||||
|
@ -34,13 +34,13 @@ typedef enum Sign_t {
|
||||||
* @brief Represents the scale of composite type which is multiplied
|
* @brief Represents the scale of composite type which is multiplied
|
||||||
* with the base size in order to retrieve the the composites size.
|
* with the base size in order to retrieve the the composites size.
|
||||||
* @attention Valid value are: { 1/8, 1/4, 1/2, 1, 2, 4, 8 }
|
* @attention Valid value are: { 1/8, 1/4, 1/2, 1, 2, 4, 8 }
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef double Scale;
|
typedef double Scale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A composite type is an extended definition of a primitive type.
|
* @brief A composite type is an extended definition of a primitive type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct CompositeType_t {
|
typedef struct CompositeType_t {
|
||||||
// sign of composite
|
// sign of composite
|
||||||
|
@ -52,7 +52,7 @@ typedef struct CompositeType_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Specifies the specific type of the generic type struct.
|
* @brief Specifies the specific type of the generic type struct.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum TypeKind_t {
|
typedef enum TypeKind_t {
|
||||||
TypeKindPrimitive,
|
TypeKindPrimitive,
|
||||||
|
@ -66,7 +66,7 @@ typedef struct Type_t Type;
|
||||||
/**
|
/**
|
||||||
* @brief Reference points to a type.
|
* @brief Reference points to a type.
|
||||||
* @attention Can be nested. A reference can point to another reference: REF -> REF -> REF -> Primitive
|
* @attention Can be nested. A reference can point to another reference: REF -> REF -> REF -> Primitive
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef Type* ReferenceType;
|
typedef Type* ReferenceType;
|
||||||
|
|
||||||
|
@ -86,11 +86,11 @@ typedef struct BoxMember_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Essentially a g lorified struct
|
* @brief Essentially a g lorified struct
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct BoxType_t {
|
typedef struct BoxType_t {
|
||||||
// hashtable of members.
|
// hashtable of members.
|
||||||
// Associates the memebers name (const char*) with its type (BoxMember)
|
// Associates the memebers name (const char*) with its type (BoxMember)
|
||||||
GHashTable* member; //BoxMember Pointer
|
GHashTable* member; //BoxMember Pointer
|
||||||
AST_NODE_PTR nodePtr;
|
AST_NODE_PTR nodePtr;
|
||||||
} BoxType;
|
} BoxType;
|
||||||
|
@ -114,7 +114,7 @@ typedef struct Type_t {
|
||||||
union TypeImplementation_t {
|
union TypeImplementation_t {
|
||||||
PrimitiveType primitive;
|
PrimitiveType primitive;
|
||||||
CompositeType composite;
|
CompositeType composite;
|
||||||
BoxType box;
|
BoxType* box;
|
||||||
ReferenceType reference;
|
ReferenceType reference;
|
||||||
} impl;
|
} impl;
|
||||||
AST_NODE_PTR nodePtr;
|
AST_NODE_PTR nodePtr;
|
||||||
|
@ -130,7 +130,7 @@ typedef struct Typedefine_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reprents the value of type. Can be used to definitions, initialization and for expressions contants.
|
* @brief Reprents the value of type. Can be used to definitions, initialization and for expressions contants.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct TypeValue_t {
|
typedef struct TypeValue_t {
|
||||||
// the type
|
// the type
|
||||||
|
@ -146,7 +146,7 @@ typedef struct TypeValue_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Specifies a parameters I/O properties
|
* @brief Specifies a parameters I/O properties
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum IO_Qualifier_t {
|
typedef enum IO_Qualifier_t {
|
||||||
// Can be read from but not written to.
|
// Can be read from but not written to.
|
||||||
|
@ -162,7 +162,7 @@ typedef enum IO_Qualifier_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A functions parameter declaration.
|
* @brief A functions parameter declaration.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct ParameterDeclaration_t {
|
typedef struct ParameterDeclaration_t {
|
||||||
Type *type;
|
Type *type;
|
||||||
|
@ -172,7 +172,7 @@ typedef struct ParameterDeclaration_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A functions parameter.
|
* @brief A functions parameter.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct ParameterDefinition_t {
|
typedef struct ParameterDefinition_t {
|
||||||
ParameterDeclaration declaration;
|
ParameterDeclaration declaration;
|
||||||
|
@ -189,11 +189,11 @@ typedef enum ParameterKind_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A parameter can either be a declaration or a definition
|
* @brief A parameter can either be a declaration or a definition
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct Parameter_t {
|
typedef struct Parameter_t {
|
||||||
const char* name;
|
const char* name;
|
||||||
|
|
||||||
ParameterKind kind;
|
ParameterKind kind;
|
||||||
union ParameterImplementation {
|
union ParameterImplementation {
|
||||||
ParameterDeclaration declaration;
|
ParameterDeclaration declaration;
|
||||||
|
@ -254,9 +254,9 @@ typedef struct VariableDeclaration_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Definition of a variable
|
* @brief Definition of a variable
|
||||||
*
|
*
|
||||||
* @attention NOTE: The types of the initializer and the declaration must be equal
|
* @attention NOTE: The types of the initializer and the declaration must be equal
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct VariableDefiniton_t {
|
typedef struct VariableDefiniton_t {
|
||||||
VariableDeclaration declaration;
|
VariableDeclaration declaration;
|
||||||
|
@ -281,17 +281,28 @@ typedef struct Variable_t {
|
||||||
AST_NODE_PTR nodePtr;
|
AST_NODE_PTR nodePtr;
|
||||||
} Variable;
|
} Variable;
|
||||||
|
|
||||||
|
typedef struct Dereference_t {
|
||||||
|
Expression* index;
|
||||||
|
Expression* variable;
|
||||||
|
AST_NODE_PTR nodePtr;
|
||||||
|
}Dereference;
|
||||||
|
|
||||||
|
typedef struct AddressOf_t {
|
||||||
|
Expression* variable;
|
||||||
|
AST_NODE_PTR node_ptr;
|
||||||
|
}AddressOf;
|
||||||
|
|
||||||
// .------------------------------------------------.
|
// .------------------------------------------------.
|
||||||
// | Casts |
|
// | Casts |
|
||||||
// '------------------------------------------------'
|
// '------------------------------------------------'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a type cast, converting a value to different type whilest preserving as much of the original
|
* @brief Perform a type cast, converting a value to different type whilest preserving as much of the original
|
||||||
* values information.
|
* values information.
|
||||||
*
|
*
|
||||||
* @attention NOTE: Must check wether the given value's type can be parsed into
|
* @attention NOTE: Must check wether the given value's type can be parsed into
|
||||||
* the target type without loss.
|
* the target type without loss.
|
||||||
* Lossy mean possibly loosing information such when casting a float into an int (no fraction anymore).
|
* Lossy mean possibly loosing information such when casting a float into an int (no fraction anymore).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct TypeCast_t {
|
typedef struct TypeCast_t {
|
||||||
|
@ -305,7 +316,7 @@ typedef struct TypeCast_t {
|
||||||
*
|
*
|
||||||
* @attention NOTE: The given value's type must have the size in bytes as the target type.
|
* @attention NOTE: The given value's type must have the size in bytes as the target type.
|
||||||
* Transmuting a short int into a float should yield an error.
|
* Transmuting a short int into a float should yield an error.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct Transmute_t {
|
typedef struct Transmute_t {
|
||||||
Type *targetType;
|
Type *targetType;
|
||||||
|
@ -319,7 +330,7 @@ typedef struct Transmute_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the arithmetic operator.
|
* @brief Represents the arithmetic operator.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum ArithmeticOperator_t {
|
typedef enum ArithmeticOperator_t {
|
||||||
Add,
|
Add,
|
||||||
|
@ -335,7 +346,7 @@ typedef enum ArithmeticOperator_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the relational operator.
|
* @brief Represents the relational operator.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum RelationalOperator_t {
|
typedef enum RelationalOperator_t {
|
||||||
Equal,
|
Equal,
|
||||||
|
@ -395,7 +406,7 @@ typedef struct Operation_t {
|
||||||
union OperationImplementation {
|
union OperationImplementation {
|
||||||
ArithmeticOperator arithmetic;
|
ArithmeticOperator arithmetic;
|
||||||
RelationalOperator relational;
|
RelationalOperator relational;
|
||||||
BooleanOperator boolean;
|
BooleanOperator boolean;
|
||||||
LogicalOperator logical;
|
LogicalOperator logical;
|
||||||
BitwiseOperator bitwise;
|
BitwiseOperator bitwise;
|
||||||
} impl;
|
} impl;
|
||||||
|
@ -412,7 +423,9 @@ typedef enum ExpressionKind_t {
|
||||||
ExpressionKindTypeCast,
|
ExpressionKindTypeCast,
|
||||||
ExpressionKindTransmute,
|
ExpressionKindTransmute,
|
||||||
ExpressionKindConstant,
|
ExpressionKindConstant,
|
||||||
ExpressionKindVariable
|
ExpressionKindVariable,
|
||||||
|
ExpressionKindDereference,
|
||||||
|
ExpressionKindAddressOf,
|
||||||
} ExpressionKind;
|
} ExpressionKind;
|
||||||
|
|
||||||
typedef struct Expression_t {
|
typedef struct Expression_t {
|
||||||
|
@ -425,6 +438,8 @@ typedef struct Expression_t {
|
||||||
Transmute transmute;
|
Transmute transmute;
|
||||||
TypeValue constant;
|
TypeValue constant;
|
||||||
Variable* variable;
|
Variable* variable;
|
||||||
|
Dereference dereference;
|
||||||
|
AddressOf addressOf;
|
||||||
} impl;
|
} impl;
|
||||||
AST_NODE_PTR nodePtr;
|
AST_NODE_PTR nodePtr;
|
||||||
} Expression;
|
} Expression;
|
||||||
|
@ -543,4 +558,39 @@ typedef struct Module_t {
|
||||||
GArray* imports;
|
GArray* imports;
|
||||||
} Module;
|
} Module;
|
||||||
|
|
||||||
|
|
||||||
|
// .------------------------------------------------.
|
||||||
|
// | Cleanup Code |
|
||||||
|
// '------------------------------------------------'
|
||||||
|
|
||||||
|
void delete_box_access(BoxAccess* access);
|
||||||
|
|
||||||
|
void delete_variable(Variable* variable);
|
||||||
|
|
||||||
|
void delete_type(Type* type);
|
||||||
|
|
||||||
|
void delete_box(BoxType* box);
|
||||||
|
|
||||||
|
void delete_declaration(VariableDeclaration* decl);
|
||||||
|
|
||||||
|
void delete_definition(VariableDefiniton* definition);
|
||||||
|
|
||||||
|
void delete_expression(Expression* expr);
|
||||||
|
|
||||||
|
void delete_operation(Operation* operation);
|
||||||
|
|
||||||
|
void delete_type_value(TypeValue* value);
|
||||||
|
|
||||||
|
void delete_transmute(Transmute* trans);
|
||||||
|
|
||||||
|
void delete_typecast(TypeCast* cast);
|
||||||
|
|
||||||
|
void delete_box_member(BoxMember* member);
|
||||||
|
|
||||||
|
void delete_box_type(BoxType *box_type);
|
||||||
|
|
||||||
|
void delete_composite([[maybe_unused]] CompositeType* composite);
|
||||||
|
|
||||||
|
void delete_module(Module* module);
|
||||||
|
|
||||||
#endif // SET_TYPES_H_
|
#endif // SET_TYPES_H_
|
||||||
|
|
|
@ -135,7 +135,8 @@
|
||||||
%left '(' ')' '[' ']'
|
%left '(' ')' '[' ']'
|
||||||
|
|
||||||
%%
|
%%
|
||||||
program: program programbody {AST_push_node(root, $2);}
|
program: program programbody {AST_push_node(root, $2);
|
||||||
|
}
|
||||||
| programbody {AST_push_node(root, $1);};
|
| programbody {AST_push_node(root, $1);};
|
||||||
|
|
||||||
programbody: moduleimport {$$ = $1;}
|
programbody: moduleimport {$$ = $1;}
|
||||||
|
@ -376,7 +377,7 @@ decl: type ':' identlist {AST_NODE_PTR decl = AST_new_node(new_loc(), AST_Decl,
|
||||||
AST_push_node(decl, $1);
|
AST_push_node(decl, $1);
|
||||||
AST_push_node(decl, $2);
|
AST_push_node(decl, $2);
|
||||||
AST_push_node(decl, $4);
|
AST_push_node(decl, $4);
|
||||||
$$ = decl;}
|
$$ = decl;};
|
||||||
|
|
||||||
|
|
||||||
definition: decl '=' expr { AST_NODE_PTR def = AST_new_node(new_loc(), AST_Def, NULL);
|
definition: decl '=' expr { AST_NODE_PTR def = AST_new_node(new_loc(), AST_Def, NULL);
|
||||||
|
|
Loading…
Reference in New Issue