refactor: remove QBE backend, improve bootstrap compiler and stdlib
Bootstrap compiler improvements: - Extract findStdlibDir() to remove hardcoded path and deduplicate - Extract prepareProject()/mergeProject() to share code between cmdCheck/cmdBuild - Fix C backend to emit warning on unknown types instead of silent 'int' - Clean up all unused imports across 7 modules - Makefile: add strip, debug target, clean-all, selfhost strip QBE removal: - Remove vendor/qbe/ (74K lines) - Remove compiler/selfhost/qbe_backend.bux, nim_backend.bux Stdlib improvements: - Add Result.bux + Option.bux modules - Fix Json.bux memory leak (removed double String_Copy) - Add missing imports in Crypto.bux (Alloc/Free) and Test.bux (PrintLine/PrintInt) - Clean stale buxc_debug binary
This commit is contained in:
@@ -32,7 +32,7 @@ func Channel_Free<T>(ch: *Channel<T>) {
|
||||
bux_channel_free(ch.handle);
|
||||
}
|
||||
|
||||
/* Non-generic wrappers for common types (avoid monomorphization issues) */
|
||||
/* Convenience wrappers for common types */
|
||||
func Channel_SendInt(ch: *Channel<int>, value: int) {
|
||||
bux_channel_send(ch.handle, (&value) as *void);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
module Std::Crypto {
|
||||
import Std::Mem::{Alloc, Free};
|
||||
import Std::String::{String_Len};
|
||||
extern func bux_sha256(data: String, len: int, out: *void);
|
||||
extern func bux_hmac_sha256(key: String, keylen: int, msg: String, msglen: int, out: *void);
|
||||
extern func bux_random_bytes(buf: *void, len: int) -> int;
|
||||
|
||||
@@ -274,8 +274,7 @@ func JsonParser_ParseString(p: *JsonParser) -> String {
|
||||
return "";
|
||||
}
|
||||
JsonParser_Advance(p);
|
||||
let raw: String = StringBuilder_Build(&sb);
|
||||
let result: String = String_Copy(raw);
|
||||
let result: String = StringBuilder_Build(&sb);
|
||||
StringBuilder_Free(&sb);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
module Std::Option {
|
||||
import Std::Io::{PrintLine};
|
||||
|
||||
enum Option {
|
||||
Some(int),
|
||||
None,
|
||||
}
|
||||
|
||||
func Option_NewSome(value: int) -> Option {
|
||||
let o: Option = Option { tag: Option_Some };
|
||||
o.data.Some_0 = value;
|
||||
return o;
|
||||
}
|
||||
|
||||
func Option_NewNone() -> Option {
|
||||
return Option { tag: Option_None };
|
||||
}
|
||||
|
||||
func Option_IsSome(o: Option) -> bool {
|
||||
return o.tag == Option_Some;
|
||||
}
|
||||
|
||||
func Option_IsNone(o: Option) -> bool {
|
||||
return o.tag == Option_None;
|
||||
}
|
||||
|
||||
func Option_Unwrap(o: Option) -> int {
|
||||
if o.tag != Option_Some {
|
||||
PrintLine("panic: unwrap on None");
|
||||
return 0;
|
||||
}
|
||||
return o.data.Some_0;
|
||||
}
|
||||
|
||||
func Option_UnwrapOr(o: Option, fallback: int) -> int {
|
||||
if o.tag == Option_Some {
|
||||
return o.data.Some_0;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
module Std::Result {
|
||||
import Std::Io::{PrintLine};
|
||||
|
||||
enum Result {
|
||||
Ok(int),
|
||||
Err(String),
|
||||
}
|
||||
|
||||
func Result_NewOk(value: int) -> Result {
|
||||
let r: Result = Result { tag: Result_Ok };
|
||||
r.data.Ok_0 = value;
|
||||
return r;
|
||||
}
|
||||
|
||||
func Result_NewErr(msg: String) -> Result {
|
||||
let r: Result = Result { tag: Result_Err };
|
||||
r.data.Err_0 = msg;
|
||||
return r;
|
||||
}
|
||||
|
||||
func Result_IsOk(r: Result) -> bool {
|
||||
return r.tag == Result_Ok;
|
||||
}
|
||||
|
||||
func Result_IsErr(r: Result) -> bool {
|
||||
return r.tag == Result_Err;
|
||||
}
|
||||
|
||||
func Result_Unwrap(r: Result) -> int {
|
||||
if r.tag != Result_Ok {
|
||||
PrintLine("panic: unwrap on Err");
|
||||
return 0;
|
||||
}
|
||||
return r.data.Ok_0;
|
||||
}
|
||||
|
||||
func Result_UnwrapOr(r: Result, fallback: int) -> int {
|
||||
if r.tag == Result_Ok {
|
||||
return r.data.Ok_0;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
module Std::Test {
|
||||
import Std::Io::{PrintLine, PrintInt};
|
||||
|
||||
extern func bux_exit(code: int);
|
||||
extern func bux_assert(cond: int, file: String, line: int, expr: String);
|
||||
|
||||
Reference in New Issue
Block a user