This commit is contained in:
MCorange 2025-06-24 21:09:26 +03:00
parent 77a1e74526
commit 7e95a9af34
6 changed files with 93 additions and 9 deletions

View File

@ -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)

View File

@ -5,6 +5,7 @@
#include <stddef.h>
#include <sys/types.h>
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

View File

@ -1,3 +1,13 @@
#include <util.h>
#include <tokeniser.h>
#include <stdio.h>
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;
}

61
src/token.c Normal file
View File

@ -0,0 +1,61 @@
#include <token.h>
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"
};

View File

@ -35,6 +35,7 @@ token_t* tokenise_string(char* file_path, char* str) {
buf[buf_counter++] = str[i];
}
buf = realloc(buf, strlen(buf) + 1);
}
}
}

5
test.mrph Normal file
View File

@ -0,0 +1,5 @@
fn main with void returs int do
34 35 add __print__
end