This commit is contained in:
nub31
2026-02-28 23:19:57 +01:00
parent 270be1f740
commit 16d27c76ab
7 changed files with 47 additions and 22 deletions

6
TODO.txt Normal file
View File

@@ -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

View File

@@ -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;

View File

@@ -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

24
examples/core/file.nub Normal file
View File

@@ -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
}

View File

@@ -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")
}

5
examples/core/sys.nub Normal file
View File

@@ -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

View File

@@ -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
}