corrected me forcing c99 because i use strtok_r that isn't c99 compliant
This commit is contained in:
parent
378cae31a1
commit
fd2ba66124
8
Makefile
8
Makefile
@ -1,12 +1,12 @@
|
||||
NAME := Sterling
|
||||
NAME := SterlingCompiler
|
||||
|
||||
SRC := $(wildcard source/*.c)
|
||||
|
||||
OBJ := $(SRC:source/%.c=obj/%.o)
|
||||
|
||||
CC := gcc
|
||||
CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -O0 -std=c99 -fsignaling-nans
|
||||
LFLAG :=
|
||||
CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -Og -fsignaling-nans -fsanitize=address -fsanitize=undefined
|
||||
LDFLAG := -lasan -lubsan -lpthread
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
@ -14,7 +14,7 @@ obj/%.o : source/%.c | makedir
|
||||
$(CC) $(CFLAG) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
$(CC) $(OBJ) $(LFLAG) -o build/$(NAME)
|
||||
$(CC) $(OBJ) $(LDFLAG) -o build/$(NAME)
|
||||
|
||||
makedir:
|
||||
mkdir -p obj
|
||||
|
||||
BIN
build/SterlingCompiler
Normal file
BIN
build/SterlingCompiler
Normal file
Binary file not shown.
@ -1,81 +1,81 @@
|
||||
#ifndef STERLING_COMPILER_H
|
||||
# define STERLING_COMPILER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
//simd
|
||||
# ifdef __x86_64__
|
||||
# include <x86intrin.h>
|
||||
# endif
|
||||
|
||||
typedef enum {
|
||||
TOK_NONE = 1 << 0,
|
||||
TOK_RAW = 1 << 1,
|
||||
TOK_STRING = 1 << 2,//"asdfasf"; L"WideString"
|
||||
TOK_LITERAL = 1 << 3,//INT: 42, 0xff, 0777, 100L; FLOAT:3.14, 1e-5, 2.0f; ENUM; char CONST 'a' '\n' L'x'
|
||||
TOK_OP = 1 << 4,
|
||||
TOK_PREPROC = 1 << 5,
|
||||
TOK_COMMENT = 1 << 6,
|
||||
TOK_KEY = 1 << 7,
|
||||
TOK_ID = 1 << 8,
|
||||
TOK_NUM = 1 << 9
|
||||
} TKN_CTX;
|
||||
|
||||
typedef struct Token_s {
|
||||
size_t size;
|
||||
TKN_CTX ctx;
|
||||
char *data;
|
||||
} Token_t;
|
||||
|
||||
typedef struct {
|
||||
char *op;
|
||||
size_t len;
|
||||
} MultiOp;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
TKN_CTX ctx;
|
||||
} KeywordEntry;
|
||||
|
||||
|
||||
const char *SYMBOLS = ";(){}[]$%&*#@!?:,.<>|-+=~`^";
|
||||
|
||||
// Common C operators (Order matters: put longer ones first if you add 3-char ops)
|
||||
static const MultiOp MUNCH_TABLE[] = {
|
||||
{"%:%:", 4},
|
||||
{"<<=", 3}, {">>=", 3}, {"...", 3},
|
||||
{"\?\?=", 3}, {"\?\?/", 3}, {"\?\?'", 3}, {"\?\?(", 3},
|
||||
{"\?\?)", 3}, {"\?\?!", 3}, {"\?\?<", 3},
|
||||
{"\?\?>", 3}, {"\?\?-", 3}, //trigraph
|
||||
{"==", 2}, {"!=", 2}, {"<=", 2}, {">=", 2}, {"##", 2},
|
||||
{"++", 2}, {"--", 2}, {"->", 2}, {"+=", 2}, {"%=",2},
|
||||
{"-=", 2}, {"*=", 2}, {"/=", 2}, {"&&", 2}, {"||", 2},
|
||||
{"^=", 2}, {"<<", 2}, {">>", 2}, {"|=", 2}, {"&=", 2},//
|
||||
{"<:", 2}, {":>", 2}, {"<%", 2}, {"%>", 2}, {"%:", 2},//digraphs
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
// This can be expanded at runtime if you use a dynamic array instead of a static one
|
||||
static const KeywordEntry KEYWORD_TABLE[] = {
|
||||
{"if", TOK_KEY},
|
||||
{"else", TOK_KEY},
|
||||
{"while", TOK_KEY},
|
||||
{"return", TOK_KEY},
|
||||
{"var", TOK_KEY},
|
||||
{"int", TOK_KEY},
|
||||
{"float", TOK_KEY},
|
||||
{"void", TOK_KEY},
|
||||
{"include", TOK_PREPROC},
|
||||
{"define", TOK_PREPROC},
|
||||
{"comptime",TOK_KEY},
|
||||
{"reflect", TOK_KEY},
|
||||
{NULL, TOK_NONE}
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef STERLING_COMPILER_H
|
||||
# define STERLING_COMPILER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
//simd
|
||||
# ifdef __x86_64__
|
||||
# include <x86intrin.h>
|
||||
# endif
|
||||
|
||||
typedef enum {
|
||||
TOK_NONE = 1 << 0,
|
||||
TOK_RAW = 1 << 1,
|
||||
TOK_STRING = 1 << 2,//"asdfasf"; L"WideString"
|
||||
TOK_LITERAL = 1 << 3,//INT: 42, 0xff, 0777, 100L; FLOAT:3.14, 1e-5, 2.0f; ENUM; char CONST 'a' '\n' L'x'
|
||||
TOK_OP = 1 << 4,
|
||||
TOK_PREPROC = 1 << 5,
|
||||
TOK_COMMENT = 1 << 6,
|
||||
TOK_KEY = 1 << 7,
|
||||
TOK_ID = 1 << 8,
|
||||
TOK_NUM = 1 << 9
|
||||
} TKN_CTX;
|
||||
|
||||
typedef struct Token_s {
|
||||
size_t size;
|
||||
TKN_CTX ctx;
|
||||
char *data;
|
||||
} Token_t;
|
||||
|
||||
typedef struct {
|
||||
char *op;
|
||||
size_t len;
|
||||
} MultiOp;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
TKN_CTX ctx;
|
||||
} KeywordEntry;
|
||||
|
||||
|
||||
const char *SYMBOLS = ";(){}[]$%&*#@!?:,.<>|-+=~`^";
|
||||
|
||||
// Common C operators (Order matters: put longer ones first if you add 3-char ops)
|
||||
static const MultiOp MUNCH_TABLE[] = {
|
||||
{"%:%:", 4},
|
||||
{"<<=", 3}, {">>=", 3}, {"...", 3},
|
||||
{"\?\?=", 3}, {"\?\?/", 3}, {"\?\?'", 3}, {"\?\?(", 3},
|
||||
{"\?\?)", 3}, {"\?\?!", 3}, {"\?\?<", 3},
|
||||
{"\?\?>", 3}, {"\?\?-", 3}, //trigraph
|
||||
{"==", 2}, {"!=", 2}, {"<=", 2}, {">=", 2}, {"##", 2},
|
||||
{"++", 2}, {"--", 2}, {"->", 2}, {"+=", 2}, {"%=",2},
|
||||
{"-=", 2}, {"*=", 2}, {"/=", 2}, {"&&", 2}, {"||", 2},
|
||||
{"^=", 2}, {"<<", 2}, {">>", 2}, {"|=", 2}, {"&=", 2},//
|
||||
{"<:", 2}, {":>", 2}, {"<%", 2}, {"%>", 2}, {"%:", 2},//digraphs
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
// This can be expanded at runtime if you use a dynamic array instead of a static one
|
||||
static const KeywordEntry KEYWORD_TABLE[] = {
|
||||
{"if", TOK_KEY},
|
||||
{"else", TOK_KEY},
|
||||
{"while", TOK_KEY},
|
||||
{"return", TOK_KEY},
|
||||
{"var", TOK_KEY},
|
||||
{"int", TOK_KEY},
|
||||
{"float", TOK_KEY},
|
||||
{"void", TOK_KEY},
|
||||
{"include", TOK_PREPROC},
|
||||
{"define", TOK_PREPROC},
|
||||
{"comptime",TOK_KEY},
|
||||
{"reflect", TOK_KEY},
|
||||
{NULL, TOK_NONE}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
@ -1,66 +0,0 @@
|
||||
#ifndef ARRAY_H
|
||||
# define ARRAY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct Header_s{
|
||||
int size;
|
||||
int capacity;
|
||||
int type;
|
||||
} Header;
|
||||
|
||||
#ifndef memset
|
||||
|
||||
void *memset(void *src, char c, size_t size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
*(char *)(src + i) = c;
|
||||
}
|
||||
return (src);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef void *Array;
|
||||
|
||||
#define ARRAY_BASE_CAPACITY 64
|
||||
|
||||
#define ArraySize(arr) ((Header*)(arr) - 1)->size
|
||||
|
||||
#define ArrayFree(arr) free(((Header*)(arr) - 1))
|
||||
|
||||
#define ArrayPush(arr, x)\
|
||||
do {\
|
||||
Header *head = NULL;\
|
||||
if (!arr) { \
|
||||
head = malloc(sizeof(x) * ARRAY_BASE_CAPACITY + sizeof(Header));\
|
||||
head->size = 0;\
|
||||
head->type = sizeof(x);\
|
||||
head->capacity = ARRAY_BASE_CAPACITY;\
|
||||
arr = (void *)(head + 1);\
|
||||
}\
|
||||
head = (Header*)(arr)-1;\
|
||||
assert(sizeof(x) == head->type);\
|
||||
if (head->size >= head->capacity) {\
|
||||
head->capacity *= 2;\
|
||||
head = realloc(head, head->type *head->capacity + sizeof(Header));\
|
||||
arr = (void *)(head + 1);\
|
||||
}\
|
||||
(arr)[head->size++] = x;\
|
||||
} while(0)
|
||||
|
||||
#define ArrayClear(arr)\
|
||||
do {\
|
||||
assert(arr);\
|
||||
Header * head = (Header*)(arr)-1;\
|
||||
memset(arr, 0, head->size * head->type);\
|
||||
} while(0)\
|
||||
|
||||
|
||||
# ifdef ARRAY_IMPL
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@ -124,8 +124,11 @@ void ListFree(list_t *lst, void (*free_func)(void*)) {
|
||||
free(current);
|
||||
current = next;
|
||||
}
|
||||
//seems like i got a leak here, but may not be that bad since it is only called when closing
|
||||
lst->size = 0;
|
||||
lst->first = lst->last = NULL;
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
||||
|
||||
void *ListPeekK(const list_iter_t *it, size_t k) {
|
||||
|
||||
1164
source/main.c
1164
source/main.c
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user