diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/example.gn | 94 | ||||
| -rw-r--r-- | examples/test.gn | 11 |
2 files changed, 105 insertions, 0 deletions
diff --git a/examples/example.gn b/examples/example.gn new file mode 100644 index 0000000..35e2ce0 --- /dev/null +++ b/examples/example.gn @@ -0,0 +1,94 @@ +import fn puts(str: [u8]) -> i32; + +fn main() -> i32 { + return puts("Hello World!"); +} + +!use defaults->+ + +(add <- int <- int) -> int +add x -> y -> x + y + +-------------------------- + + +!use builtin -> universal -> Natural. +!use builtin -> universal -> Integer. +!use builtin -> universal -> Real. +!use builtin -> universal ->. +!use builtin -> x86 -> i32. +!use builtin -> x86_64 -> i128. +!use builtin -> x86 -> u32. +!use defaults -> +. +!use defaults -> println. +!use defaults -> map. +!entrypoint <- main. + + +(Vec3 <- a <- a <- Natural) -> (a, a, Natural). +Vec3 a b c -> (a, b, c). + +(I <- ) ->. +I a -> a. + +(K <- <-) ->. +K x -> y -> x. + +(`add` <- Natural <- Natural) -> Natural. +`add` x -> y -> x + y. + +(`+` <- Float <- Float) -> Float. + + +(doStuff <- Integer) -> Integer. +doStuff x -> 1.0 + x // Warning + +(main <- [String]) -> ? IO. +main args -> match (x <- len args) ( + (x = 0) -> println "No Args", + (x < 3) -> println (get 0 args), + -> map println args +). + +(println <- String) -> ? IO. +println str -> (print str, print "\n"). + +!use defaults -> x86 -> linux -> _stdout. +!use defaults -> write. + +(print <- String) -> ? IO. +print str -> write str _stdout. + +(World) -> (IO, MemAction). +(IO) -> (FileRead, FileWrite, FileOpen, FileClose, FileStat). +(MemAction) -> (MemRead, MemWrite, MemMap, Alloc, Free). + +(write <- String <- File a) -> (x86_64 -> i64) ? (FileAction a). +write str file -> !syscall_write (len str) str _stdout. +write str file -> !asm "syscall" ( + !reg "rax" 1, + !reg "rsi" str, + !reg "rdx" file, + !reg "rdi" (len str)) + ("rax"). + +!use defaults -> dlopen. +(somefunc <- Integer) -> Integer. +somefunc -> !deref (dlopen "SomeFunc") 0. + +!use builtin -> x86_64 -> ptr. +!use builtin -> x86_64 -> Pointer. +!setrule embedded. // Disables defaults, enables mutability underneath pointers + +(Byte) -> Type. +(Color) -> Type. +Byte -> (x86_64 -> u8). +Color -> Byte. +(cols) -> Integer. +cols -> 80. + +// (Byte, Byte) is packed +(framebuffer) -> (Pointer (Byte, Color)). +framebuffer -> ptr 0x8B000. +(buffset <- Natural <- Natural <- Byte <- Color) -> ? MemWrite. +buffset x y char col -> memwrite framebuffer (y * cols + x) (char, col). diff --git a/examples/test.gn b/examples/test.gn new file mode 100644 index 0000000..99e7ef6 --- /dev/null +++ b/examples/test.gn @@ -0,0 +1,11 @@ +!use defaults -> io -> println. +!use defaults -> effects. +!use defaults -> math -> +. +!use builtin -> block. +!use builtin -> return. +!entrypoint <- main. +(main) -> Int ? (effects -> IO). +main -> match (x <- println "Hello World") ( + (x >= 0) -> 0, + (x < 0)-> 1, +) |
