diff --git a/Makefile b/Makefile index 7ab6c87..0c632fc 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -BIN=cmplx +BIN=morph BUILD_DIR?=build -COM_FLAGS = -fPIC -Isrc/include $(shell pkg-config --cflags libcx) -CC_FLAGS = -std=c23 -ggdb -CXX_FLAGS = -std=c++23 -nostdinc++ -ggdb -LD_FLAGS = -nostdlib++ -lsupc++ -ggdb $(shell pkg-config --libs libcx) +CC_FLAGS = -std=c23 -ggdb -Isrc/include +CXX_FLAGS = -std=c++23 -ggdb +LD_FLAGS = -ggdb CC=clang CXX=clang LD=clang @@ -16,7 +15,8 @@ c_sources=$(wildcard src/*.c) objects=$(patsubst src/%.cpp,$(BUILD_DIR)/obj/%.cpp.o,$(cxx_sources)) $(patsubst src/%.c,$(BUILD_DIR)/obj/%.c.o,$(c_sources)) -all: $(BUILD_DIR)/$(BIN) compile_commands.json +all: $(BUILD_DIR)/$(BIN) +# compile_commands.json $(BUILD_DIR)/$(BIN): $(objects) diff --git a/src/include/token.h b/src/include/token.h index 002d110..59523a3 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -5,6 +5,7 @@ #include #include + typedef enum token_type_e { TT_NONE = 0, TT_KW, @@ -31,7 +32,8 @@ typedef enum kw_type_e { KW_ELSE, KW_WHILE, KW_CONST, - KW_MEMORY + KW_MEMORY, + KW_COUNT__, } kw_type_t; typedef enum op_type_e { @@ -93,6 +95,7 @@ typedef enum op_type_e { OP_CAST_BOOL, OP_HERE, OP_PRINT, + OP_COUNT__ } op_type_t; typedef struct token_s { @@ -114,4 +117,8 @@ typedef struct token_s { }; } token_t; + + +extern const char* OP_LIST[]; +extern const char* KW_LIST[]; #endif // _H_MORPH_TOKEN diff --git a/src/main.c b/src/main.c index e2c0387..7032284 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,13 @@ +#include +#include +#include - -int main(int argc, const char **argv) { return 0; } +int main(int argc, const char **argv) { + if (argc < 2) { + printf("Usage: %s [source]\n", argv[0]); + return 1; + } + char* str = read_to_string(argv[1]); + tokenise_string(argv[1], str); + return 0; +} diff --git a/src/token.c b/src/token.c new file mode 100644 index 0000000..cb98f31 --- /dev/null +++ b/src/token.c @@ -0,0 +1,61 @@ +#include + +const char* OP_LIST[] = { + [OP_ADD] = "add", + [OP_SUB] = "sub", + [OP_MUL] = "mul", + [OP_DIV] = "div", + [OP_MOD] = "mod", + [OP_EQ] = "eq", + [OP_GT] = "gt", + [OP_LT] = "lt", + [OP_GE] = "ge", + [OP_LE] = "le", + [OP_NE] = "ne", + [OP_SHR] = "shr", + [OP_SHL] = "shl", + [OP_OR] = "or", + [OP_AND] = "and", + [OP_NOT] = "not", + [OP_DUP] = "dup", + [OP_SWAP] = "swap", + [OP_DROP] = "drop", + [OP_OVER] = "over", + [OP_ROT] = "rot", + [OP_LOAD8] = "load8", + [OP_STORE8] = "store8", + [OP_LOAD16] = "load16", + [OP_STORE16] = "store16", + [OP_LOAD32] = "load32", + [OP_STORE32] = "store32", + [OP_LOAD64] = "load64", + [OP_STORE64] = "store64", + [OP_SYSCALL0] = "syscall0", + [OP_SYSCALL1] = "syscall1", + [OP_SYSCALL2] = "syscall2", + [OP_SYSCALL3] = "syscall3", + [OP_SYSCALL4] = "syscall4", + [OP_SYSCALL5] = "syscall5", + [OP_SYSCALL6] = "syscall6", + [OP_ARGC] = "__argv__", + [OP_ARGV] = "__argv__", + [OP_CAST_PTR] = "cast(ptr)", + [OP_CAST_INT] = "cast(int)", + [OP_CAST_BOOL] = "cast(bool)", + [OP_HERE] = "__here__", + [OP_PRINT] = "__print__" +}; +const char* KW_LIST[] = { + [KW_FN] = "fn", + [KW_DO] = "do", + [KW_END] = "end", + [KW_WITH] = "with", + [KW_RETURNS] = "returns", + [KW_STRUCT] = "struct", + [KW_ENUM] = "enum", + [KW_IF] = "if", + [KW_ELSE] = "else", + [KW_WHILE] = "while", + [KW_CONST] = "const", + [KW_MEMORY] = "memory" +}; diff --git a/src/tokeniser.c b/src/tokeniser.c index 3f92f3d..ee318c5 100644 --- a/src/tokeniser.c +++ b/src/tokeniser.c @@ -35,6 +35,7 @@ token_t* tokenise_string(char* file_path, char* str) { buf[buf_counter++] = str[i]; } buf = realloc(buf, strlen(buf) + 1); + } } } diff --git a/test.mrph b/test.mrph new file mode 100644 index 0000000..f0b6a76 --- /dev/null +++ b/test.mrph @@ -0,0 +1,5 @@ + + +fn main with void returs int do + 34 35 add __print__ +end