meow
This commit is contained in:
parent
77a1e74526
commit
7e95a9af34
12
Makefile
12
Makefile
|
@ -1,11 +1,10 @@
|
||||||
BIN=cmplx
|
BIN=morph
|
||||||
|
|
||||||
BUILD_DIR?=build
|
BUILD_DIR?=build
|
||||||
|
|
||||||
COM_FLAGS = -fPIC -Isrc/include $(shell pkg-config --cflags libcx)
|
CC_FLAGS = -std=c23 -ggdb -Isrc/include
|
||||||
CC_FLAGS = -std=c23 -ggdb
|
CXX_FLAGS = -std=c++23 -ggdb
|
||||||
CXX_FLAGS = -std=c++23 -nostdinc++ -ggdb
|
LD_FLAGS = -ggdb
|
||||||
LD_FLAGS = -nostdlib++ -lsupc++ -ggdb $(shell pkg-config --libs libcx)
|
|
||||||
CC=clang
|
CC=clang
|
||||||
CXX=clang
|
CXX=clang
|
||||||
LD=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))
|
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)
|
$(BUILD_DIR)/$(BIN): $(objects)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
typedef enum token_type_e {
|
typedef enum token_type_e {
|
||||||
TT_NONE = 0,
|
TT_NONE = 0,
|
||||||
TT_KW,
|
TT_KW,
|
||||||
|
@ -31,7 +32,8 @@ typedef enum kw_type_e {
|
||||||
KW_ELSE,
|
KW_ELSE,
|
||||||
KW_WHILE,
|
KW_WHILE,
|
||||||
KW_CONST,
|
KW_CONST,
|
||||||
KW_MEMORY
|
KW_MEMORY,
|
||||||
|
KW_COUNT__,
|
||||||
} kw_type_t;
|
} kw_type_t;
|
||||||
|
|
||||||
typedef enum op_type_e {
|
typedef enum op_type_e {
|
||||||
|
@ -93,6 +95,7 @@ typedef enum op_type_e {
|
||||||
OP_CAST_BOOL,
|
OP_CAST_BOOL,
|
||||||
OP_HERE,
|
OP_HERE,
|
||||||
OP_PRINT,
|
OP_PRINT,
|
||||||
|
OP_COUNT__
|
||||||
} op_type_t;
|
} op_type_t;
|
||||||
|
|
||||||
typedef struct token_s {
|
typedef struct token_s {
|
||||||
|
@ -114,4 +117,8 @@ typedef struct token_s {
|
||||||
};
|
};
|
||||||
} token_t;
|
} token_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern const char* OP_LIST[];
|
||||||
|
extern const char* KW_LIST[];
|
||||||
#endif // _H_MORPH_TOKEN
|
#endif // _H_MORPH_TOKEN
|
||||||
|
|
14
src/main.c
14
src/main.c
|
@ -1,3 +1,13 @@
|
||||||
|
#include <util.h>
|
||||||
|
#include <tokeniser.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, const char **argv) {
|
||||||
int main(int argc, const char **argv) { return 0; }
|
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
61
src/token.c
Normal 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"
|
||||||
|
};
|
|
@ -35,6 +35,7 @@ token_t* tokenise_string(char* file_path, char* str) {
|
||||||
buf[buf_counter++] = str[i];
|
buf[buf_counter++] = str[i];
|
||||||
}
|
}
|
||||||
buf = realloc(buf, strlen(buf) + 1);
|
buf = realloc(buf, strlen(buf) + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user