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)
|
SRC := $(wildcard source/*.c)
|
||||||
|
|
||||||
OBJ := $(SRC:source/%.c=obj/%.o)
|
OBJ := $(SRC:source/%.c=obj/%.o)
|
||||||
|
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -O0 -std=c99 -fsignaling-nans
|
CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -Og -fsignaling-nans -fsanitize=address -fsanitize=undefined
|
||||||
LFLAG :=
|
LDFLAG := -lasan -lubsan -lpthread
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ obj/%.o : source/%.c | makedir
|
|||||||
$(CC) $(CFLAG) -c $< -o $@
|
$(CC) $(CFLAG) -c $< -o $@
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
$(NAME): $(OBJ)
|
||||||
$(CC) $(OBJ) $(LFLAG) -o build/$(NAME)
|
$(CC) $(OBJ) $(LDFLAG) -o build/$(NAME)
|
||||||
|
|
||||||
makedir:
|
makedir:
|
||||||
mkdir -p obj
|
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
|
#ifndef STERLING_COMPILER_H
|
||||||
# define STERLING_COMPILER_H
|
# define STERLING_COMPILER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
//simd
|
//simd
|
||||||
# ifdef __x86_64__
|
# ifdef __x86_64__
|
||||||
# include <x86intrin.h>
|
# include <x86intrin.h>
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TOK_NONE = 1 << 0,
|
TOK_NONE = 1 << 0,
|
||||||
TOK_RAW = 1 << 1,
|
TOK_RAW = 1 << 1,
|
||||||
TOK_STRING = 1 << 2,//"asdfasf"; L"WideString"
|
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_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_OP = 1 << 4,
|
||||||
TOK_PREPROC = 1 << 5,
|
TOK_PREPROC = 1 << 5,
|
||||||
TOK_COMMENT = 1 << 6,
|
TOK_COMMENT = 1 << 6,
|
||||||
TOK_KEY = 1 << 7,
|
TOK_KEY = 1 << 7,
|
||||||
TOK_ID = 1 << 8,
|
TOK_ID = 1 << 8,
|
||||||
TOK_NUM = 1 << 9
|
TOK_NUM = 1 << 9
|
||||||
} TKN_CTX;
|
} TKN_CTX;
|
||||||
|
|
||||||
typedef struct Token_s {
|
typedef struct Token_s {
|
||||||
size_t size;
|
size_t size;
|
||||||
TKN_CTX ctx;
|
TKN_CTX ctx;
|
||||||
char *data;
|
char *data;
|
||||||
} Token_t;
|
} Token_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *op;
|
char *op;
|
||||||
size_t len;
|
size_t len;
|
||||||
} MultiOp;
|
} MultiOp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
TKN_CTX ctx;
|
TKN_CTX ctx;
|
||||||
} KeywordEntry;
|
} KeywordEntry;
|
||||||
|
|
||||||
|
|
||||||
const char *SYMBOLS = ";(){}[]$%&*#@!?:,.<>|-+=~`^";
|
const char *SYMBOLS = ";(){}[]$%&*#@!?:,.<>|-+=~`^";
|
||||||
|
|
||||||
// Common C operators (Order matters: put longer ones first if you add 3-char ops)
|
// Common C operators (Order matters: put longer ones first if you add 3-char ops)
|
||||||
static const MultiOp MUNCH_TABLE[] = {
|
static const MultiOp MUNCH_TABLE[] = {
|
||||||
{"%:%:", 4},
|
{"%:%:", 4},
|
||||||
{"<<=", 3}, {">>=", 3}, {"...", 3},
|
{"<<=", 3}, {">>=", 3}, {"...", 3},
|
||||||
{"\?\?=", 3}, {"\?\?/", 3}, {"\?\?'", 3}, {"\?\?(", 3},
|
{"\?\?=", 3}, {"\?\?/", 3}, {"\?\?'", 3}, {"\?\?(", 3},
|
||||||
{"\?\?)", 3}, {"\?\?!", 3}, {"\?\?<", 3},
|
{"\?\?)", 3}, {"\?\?!", 3}, {"\?\?<", 3},
|
||||||
{"\?\?>", 3}, {"\?\?-", 3}, //trigraph
|
{"\?\?>", 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},
|
{"-=", 2}, {"*=", 2}, {"/=", 2}, {"&&", 2}, {"||", 2},
|
||||||
{"^=", 2}, {"<<", 2}, {">>", 2}, {"|=", 2}, {"&=", 2},//
|
{"^=", 2}, {"<<", 2}, {">>", 2}, {"|=", 2}, {"&=", 2},//
|
||||||
{"<:", 2}, {":>", 2}, {"<%", 2}, {"%>", 2}, {"%:", 2},//digraphs
|
{"<:", 2}, {":>", 2}, {"<%", 2}, {"%>", 2}, {"%:", 2},//digraphs
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This can be expanded at runtime if you use a dynamic array instead of a static one
|
// This can be expanded at runtime if you use a dynamic array instead of a static one
|
||||||
static const KeywordEntry KEYWORD_TABLE[] = {
|
static const KeywordEntry KEYWORD_TABLE[] = {
|
||||||
{"if", TOK_KEY},
|
{"if", TOK_KEY},
|
||||||
{"else", TOK_KEY},
|
{"else", TOK_KEY},
|
||||||
{"while", TOK_KEY},
|
{"while", TOK_KEY},
|
||||||
{"return", TOK_KEY},
|
{"return", TOK_KEY},
|
||||||
{"var", TOK_KEY},
|
{"var", TOK_KEY},
|
||||||
{"int", TOK_KEY},
|
{"int", TOK_KEY},
|
||||||
{"float", TOK_KEY},
|
{"float", TOK_KEY},
|
||||||
{"void", TOK_KEY},
|
{"void", TOK_KEY},
|
||||||
{"include", TOK_PREPROC},
|
{"include", TOK_PREPROC},
|
||||||
{"define", TOK_PREPROC},
|
{"define", TOK_PREPROC},
|
||||||
{"comptime",TOK_KEY},
|
{"comptime",TOK_KEY},
|
||||||
{"reflect", TOK_KEY},
|
{"reflect", TOK_KEY},
|
||||||
{NULL, TOK_NONE}
|
{NULL, TOK_NONE}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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);
|
free(current);
|
||||||
current = next;
|
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->size = 0;
|
||||||
lst->first = lst->last = NULL;
|
lst->first = lst->last = NULL;
|
||||||
|
free(lst);
|
||||||
|
lst = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ListPeekK(const list_iter_t *it, size_t k) {
|
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