Begin working on a table struct to hold information during runtime.

This commit is contained in:
Danila Fedorin 2018-02-10 17:53:07 -08:00
parent 3254f5741f
commit a27bdc37f5
3 changed files with 73 additions and 1 deletions

View File

@ -8,7 +8,7 @@ project(libabacus)
add_compile_options(-pedantic -Wall)
add_library(abacus STATIC src/lexer.c src/libabacus_util.c)
add_library(abacus STATIC src/lexer.c src/libabacus_util.c src/table.c)
add_executable(libabacus src/main.c)
add_subdirectory(external/liblex)

61
include/table.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef LIBABACUS_TABLE_H
#define LIBABACUS_TABLE_H
#include "ht.h"
#include "libabacus.h"
/**
* A struct that represents a structure
* similar to a symbol table. This structure
* is used to keep track of definitions such
* as types, functions, and variables in an
* environment with scopes.
*/
struct table {
/**
* The "parent" scope of this table.
*/
struct table* parent;
/**
* The hash table used to store the data.
*/
ht table;
};
/**
* Enum that represents the type of a table
* entry.
*/
enum table_entry_variant {
ENTRY_VALUE,
ENTRY_TYPE,
ENTRY_FUNCTION
};
/**
* An entry in the table.
*/
struct table_entry {
/**
* The type of this entry.
*/
enum table_entry_variant variant;
};
typedef struct table table;
typedef enum table_entry_variant table_entry_variant;
typedef struct table_entry table_entry;
/**
* Initializes the given table.
* @param table the table to initialize.
*/
void table_init(table* table);
/**
* Frees the resources allocated by the
* given table.
* @param table the table to free.
*/
void table_free(table* table);
#endif

11
src/table.c Normal file
View File

@ -0,0 +1,11 @@
#include "table.h"
#include <stdlib.h>
void table_init(table* table) {
ht_init(&table->table);
table->parent = NULL;
}
void table_free(table* table) {
ht_free(&table->table);
}