feat: enhance compiler
- Add comments and test for it - Add semicolon as required end of some expressions - Add new arguments parser - Add multi-file compilation - Add colors in output
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define FZL_READER_H
|
||||
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/utils/fzl_linked.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -19,16 +20,16 @@ typedef struct
|
||||
fzl_reader_ll_t *first;
|
||||
fzl_reader_ll_t *last;
|
||||
|
||||
fzl_linked_t *linked;
|
||||
|
||||
char *source;
|
||||
size_t size;
|
||||
|
||||
size_t position;
|
||||
size_t line_start;
|
||||
size_t line_n;
|
||||
} fzl_reader_t;
|
||||
|
||||
// Allocate new reader
|
||||
fzl_reader_t *fzl_mkreader(char *source);
|
||||
fzl_reader_t *fzl_mkreader(fzl_linked_t *linked);
|
||||
|
||||
// Read source file
|
||||
int fzl_read(fzl_reader_t *reader);
|
||||
|
||||
@@ -61,11 +61,12 @@ typedef struct
|
||||
bool store_value;
|
||||
void *value;
|
||||
uint16_t value_sz;
|
||||
char *filename;
|
||||
} fzl_token_t;
|
||||
|
||||
// Allocate new token
|
||||
fzl_token_t *fzl_mktoken(const fzl_toktype_t type, size_t line, size_t col,
|
||||
void *value, size_t value_sz);
|
||||
void *value, size_t value_sz, char *filename);
|
||||
|
||||
// Free token and its contents
|
||||
void fzl_freetoken(fzl_token_t *token);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef FZL_LINKED_H
|
||||
#define FZL_LINKED_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Linked file descriptor
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
size_t start;
|
||||
size_t end;
|
||||
} fzl_linked_entry_t;
|
||||
|
||||
// Linked descriptor
|
||||
typedef struct
|
||||
{
|
||||
fzl_linked_entry_t *entries;
|
||||
size_t entries_count;
|
||||
|
||||
char *source;
|
||||
size_t total_sz;
|
||||
} fzl_linked_t;
|
||||
|
||||
// Position in file
|
||||
typedef struct
|
||||
{
|
||||
size_t line;
|
||||
size_t col;
|
||||
|
||||
char *filename;
|
||||
} fzl_file_loc;
|
||||
|
||||
// Allocated new linked
|
||||
fzl_linked_t *fzl_mklinked();
|
||||
|
||||
// Read specified files
|
||||
bool fzl_linked_add_files(fzl_linked_t *l, char **files, size_t files_count);
|
||||
|
||||
// Get last error from linked
|
||||
char *fzl_linked_geterror();
|
||||
|
||||
// Get filename and position in it by reader cursor
|
||||
bool fzl_linked_getpos(fzl_linked_t *l, size_t pos, fzl_file_loc *res);
|
||||
|
||||
// Free linked obj
|
||||
void fzl_freelinked(fzl_linked_t *linked);
|
||||
|
||||
#endif // FZL_LINKED_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef FZL_OPTIONS_H
|
||||
#define FZL_OPTIONS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Compiler options
|
||||
typedef struct
|
||||
{
|
||||
char **files;
|
||||
size_t files_count;
|
||||
|
||||
char *outname;
|
||||
|
||||
bool should_continue;
|
||||
bool verbose;
|
||||
} fzl_options_t;
|
||||
|
||||
// Parse command line arguments
|
||||
fzl_options_t *fzl_mkoptions(int argc, char **argv);
|
||||
|
||||
// Free options
|
||||
void fzl_freeoptions(fzl_options_t *options);
|
||||
|
||||
#endif // FZL_OPTIONS_H
|
||||
Reference in New Issue
Block a user