From 16d27c76ab5ef8b213d1c81576d8476def7dce7c Mon Sep 17 00:00:00 2001 From: nub31 Date: Sat, 28 Feb 2026 23:19:57 +0100 Subject: [PATCH] ... --- TODO.txt | 6 ++++++ compiler/Program.cs | 4 ++-- examples/build.sh | 2 +- examples/core/file.nub | 24 ++++++++++++++++++++++++ examples/core/print.nub | 9 ++++++--- examples/core/sys.nub | 5 +++++ examples/program/main.nub | 19 +++---------------- 7 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 TODO.txt create mode 100644 examples/core/file.nub create mode 100644 examples/core/sys.nub diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..486807c --- /dev/null +++ b/TODO.txt @@ -0,0 +1,6 @@ +Comma seperated function parameters and struct/enum mebers +Converting ^u8 to string +string formatting +string concatination +Dynamic arrays +C-style arrays \ No newline at end of file diff --git a/compiler/Program.cs b/compiler/Program.cs index c0bb509..11b4a84 100644 --- a/compiler/Program.cs +++ b/compiler/Program.cs @@ -158,13 +158,13 @@ File.WriteAllText(".build/out.c", output); if (compileLib) { - Process.Start("gcc", ["-Og", "-fno-builtin", "-c", "-o", ".build/out.o", ".build/out.c", .. archivePaths]).WaitForExit(); + Process.Start("gcc", ["-Og", "-g", "-fno-builtin", "-c", "-o", ".build/out.o", ".build/out.c", .. archivePaths]).WaitForExit(); Process.Start("ar", ["rcs", ".build/out.a", ".build/out.o"]).WaitForExit(); NubLib.Pack(".build/out.nublib", ".build/out.a", Manifest.Create(moduleGraph)); } else { - Process.Start("gcc", ["-Og", "-fno-builtin", "-o", ".build/out", ".build/out.c", .. archivePaths]).WaitForExit(); + Process.Start("gcc", ["-Og", "-g", "-fno-builtin", "-o", ".build/out", ".build/out.c", .. archivePaths]).WaitForExit(); } return 0; diff --git a/examples/build.sh b/examples/build.sh index b3728d7..8c85818 100755 --- a/examples/build.sh +++ b/examples/build.sh @@ -1,7 +1,7 @@ set -e pushd core -dotnet run --project ../../compiler print.nub --type=lib +dotnet run --project ../../compiler sys.nub print.nub file.nub --type=lib popd pushd program diff --git a/examples/core/file.nub b/examples/core/file.nub new file mode 100644 index 0000000..95f28b0 --- /dev/null +++ b/examples/core/file.nub @@ -0,0 +1,24 @@ +module file + +export func read_text(path: string): ^u8 { + let fd = sys::open(path.ptr 0 0o644) + if fd < 0 { + return ^u8(0) // failed to open + } + + let buf_size: u64 = 4096 + let buf = c::malloc(buf_size) as ^u8 + if buf == ^u8(0) { + return ^u8(0) + } + + let bytes_read = sys::read(fd, buf, buf_size) + if bytes_read < 0 { + c::free(buf) + return ^u8(0) + } + + buf[bytes_read] = 0 + + return buf +} \ No newline at end of file diff --git a/examples/core/print.nub b/examples/core/print.nub index 15897a0..8409a87 100644 --- a/examples/core/print.nub +++ b/examples/core/print.nub @@ -1,7 +1,10 @@ module core -extern func puts(text: ^u8) - export func print(text: string) { - puts(text.ptr) + sys::write(0 text.ptr text.length) +} + +export func println(text: string) { + print(text) + print("\n") } \ No newline at end of file diff --git a/examples/core/sys.nub b/examples/core/sys.nub new file mode 100644 index 0000000..d9a894f --- /dev/null +++ b/examples/core/sys.nub @@ -0,0 +1,5 @@ +module sys + +export extern func read(fd: u32 buf: ^u8 count: u64): i64 +export extern func write(fd: u32 buf: ^u8 count: u64): i64 +export extern func open(fileName: ^u8 flags: i32 mode: u16): i64 \ No newline at end of file diff --git a/examples/program/main.nub b/examples/program/main.nub index eb1593b..6a48019 100644 --- a/examples/program/main.nub +++ b/examples/program/main.nub @@ -2,24 +2,11 @@ module main extern func puts(text: ^u8) -export func print(text: string) { - puts(text.ptr) -} - -enum Message { - Tell: string -} - func main(): i32 { - let x = "test" + core::println("Hello, world!") - let y = { - abc = x - } - - let a: Message = enum Message::Tell x - - core::print(x) + let file = file::read_text("file.nub") + puts(file) return 0 } \ No newline at end of file