...
This commit is contained in:
6
TODO.txt
Normal file
6
TODO.txt
Normal 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
|
||||||
@@ -158,13 +158,13 @@ File.WriteAllText(".build/out.c", output);
|
|||||||
|
|
||||||
if (compileLib)
|
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();
|
Process.Start("ar", ["rcs", ".build/out.a", ".build/out.o"]).WaitForExit();
|
||||||
NubLib.Pack(".build/out.nublib", ".build/out.a", Manifest.Create(moduleGraph));
|
NubLib.Pack(".build/out.nublib", ".build/out.a", Manifest.Create(moduleGraph));
|
||||||
}
|
}
|
||||||
else
|
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;
|
return 0;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
pushd core
|
pushd core
|
||||||
dotnet run --project ../../compiler print.nub --type=lib
|
dotnet run --project ../../compiler sys.nub print.nub file.nub --type=lib
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd program
|
pushd program
|
||||||
|
|||||||
24
examples/core/file.nub
Normal file
24
examples/core/file.nub
Normal 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
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
module core
|
module core
|
||||||
|
|
||||||
extern func puts(text: ^u8)
|
|
||||||
|
|
||||||
export func print(text: string) {
|
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
5
examples/core/sys.nub
Normal 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
|
||||||
@@ -2,24 +2,11 @@ module main
|
|||||||
|
|
||||||
extern func puts(text: ^u8)
|
extern func puts(text: ^u8)
|
||||||
|
|
||||||
export func print(text: string) {
|
|
||||||
puts(text.ptr)
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Message {
|
|
||||||
Tell: string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main(): i32 {
|
func main(): i32 {
|
||||||
let x = "test"
|
core::println("Hello, world!")
|
||||||
|
|
||||||
let y = {
|
let file = file::read_text("file.nub")
|
||||||
abc = x
|
puts(file)
|
||||||
}
|
|
||||||
|
|
||||||
let a: Message = enum Message::Tell x
|
|
||||||
|
|
||||||
core::print(x)
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user