about summary refs log tree commit diff
path: root/src/main.pry
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-07-15 17:34:39 +0200
committerBaitinq <[email protected]>2025-07-15 18:00:31 +0200
commitcc56ed42486c2636af50bae451825ad90cfd4b6c (patch)
tree2307d6ced51f427405e4152b4ff1493e245a6b30 /src/main.pry
parentBoostrap: Support generating LLVM IR file (diff)
downloadpry-lang-cc56ed42486c2636af50bae451825ad90cfd4b6c.tar.gz
pry-lang-cc56ed42486c2636af50bae451825ad90cfd4b6c.tar.bz2
pry-lang-cc56ed42486c2636af50bae451825ad90cfd4b6c.zip
Finish bootstrapping :^)
Diffstat (limited to 'src/main.pry')
-rw-r--r--src/main.pry80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main.pry b/src/main.pry
new file mode 100644
index 0000000..a564965
--- /dev/null
+++ b/src/main.pry
@@ -0,0 +1,80 @@
+import "!stdlib.pry";
+import "!mem.pry";
+
+let slice = struct {
+	data: *void,
+	data_len: i64,
+};
+
+import "tokenizer.pry";
+import "parser.pry";
+import "codegen.pry";
+
+let read_file = (filename: *i8, alloc: *arena) => slice {
+	let file = fopen(filename, "r");
+
+	fseek(file, 0, 2);
+	let file_size = ftell(file);
+	fseek(file, 0, 0);
+
+	let buf = cast(*i8, arena_alloc(alloc, file_size + 1));
+
+	let bytes_read = fread(buf, 1, file_size, file);
+	(*(buf + cast(*i8, bytes_read))) = '\0';
+
+	fclose(file);
+
+	let sl = slice{};
+	sl.data = cast(*void, buf);
+	sl.data_len = file_size;
+	return sl;
+};
+
+let main = (argc: i64, argv: **i8) => i64 {
+	if argc < 2 {
+		printf("Need filename!\n");
+		return 1;
+	};
+
+	let generate_ir = false;
+	let filename = cast(*i8, null);
+
+	let i = 0;
+	while i < (argc - 1) {
+		i = i + 1;
+		let arg = *(argv + cast(**i8, i));
+
+		if strcmp(arg, "--generate-ir") {
+		    generate_ir = true;
+		    continue;
+		};
+
+		if filename == cast(*i8, null) {
+		    filename = arg;
+		    continue;
+		};
+
+		assert(false);
+	};
+
+	printf("%s\n", filename);
+
+	let alloc = arena_init(1024 * 1024 * 1024);
+
+	let file = read_file(filename, alloc);
+
+	let t = tokenizer_init(alloc, file);
+	let ts = tokenizer_tokenize(t);
+
+	let p = parser_init(cast(*token, ts.data), ts.data_len, alloc, filename);
+	let ast = parse(p);
+
+	let c = codegen_init(alloc);
+	let res = codegen_generate(c, ast);
+	let res = codegen_compile(c, generate_ir);
+	codegen_deinit(c);
+
+	arena_free(alloc);
+
+	return 0;
+};