mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 08:54:25 +00:00
Bootstrap: the Finch compiler written in Finch
boot/ is a second Finch compiler written in Finch (lexer, parser, type checker and an LLVM IR text generator, ~3k lines). Built by the C++ compiler it compiles itself; stage 2 and stage 3 produce byte-identical IR. It covers the core language: functions, structs, arrays, str, pointers, loops and modules (no C imports, sized numbers or defer), copies values like the main compiler and leaves freeing memory to the operating system. tests/boot.sh checks the fixpoint and runs the test programs it supports. Also: shell(cmd) built-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1dc976bd8f
commit
c7ddd4d8b6
8 changed files with 3153 additions and 1 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
typedef struct {
|
||||
char *ptr;
|
||||
|
|
@ -418,6 +419,15 @@ void finch_read_file(FStr *out, const FStr *path, const char *file, int64_t line
|
|||
out->cap = size + 1;
|
||||
}
|
||||
|
||||
// shell("ls -l"): run a command, give back its exit code
|
||||
int64_t finch_shell(const FStr *cmd) {
|
||||
fflush(stdout);
|
||||
int status = system(cmd->ptr ? cmd->ptr : "");
|
||||
if (status == -1) return -1;
|
||||
if (WIFEXITED(status)) return WEXITSTATUS(status);
|
||||
return 128 + (WIFSIGNALED(status) ? WTERMSIG(status) : 0);
|
||||
}
|
||||
|
||||
int finch_write_file(const FStr *path, const FStr *text) {
|
||||
FILE *f = fopen(path->ptr, "wb");
|
||||
if (!f) return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue