diff --git a/examples/array/.build/out.asm b/examples/array/.build/out.asm new file mode 100644 index 0000000..89bcb17 --- /dev/null +++ b/examples/array/.build/out.asm @@ -0,0 +1,79 @@ +.text +.cstring_len: + pushq %rbp + movq %rsp, %rbp + movl $0, %eax +.Lbb2: + movzbl (%rdi, %rax, 1), %ecx + cmpl $0, %ecx + jz .Lbb4 + addq $1, %rax + jmp .Lbb2 +.Lbb4: + leave + ret +.type .cstring_len, @function +.size .cstring_len, .-.cstring_len +/* end function .cstring_len */ + +.text +.memcpy: + pushq %rbp + movq %rsp, %rbp + movl $0, %eax +.Lbb7: + cmpq %rdx, %rax + jae .Lbb9 + movzbl (%rdi, %rax, 1), %ecx + movb %cl, (%rsi, %rax, 1) + addq $1, %rax + jmp .Lbb7 +.Lbb9: + leave + ret +.type .memcpy, @function +.size .memcpy, .-.memcpy +/* end function .memcpy */ + +.text +.memset: + pushq %rbp + movq %rsp, %rbp + movl $0, %eax +.Lbb12: + cmpq %rdx, %rax + jae .Lbb14 + movb %sil, (%rdi, %rax, 1) + addq $1, %rax + jmp .Lbb12 +.Lbb14: + leave + ret +.type .memset, @function +.size .memset, .-.memset +/* end function .memset */ + +.text +.array_size: + pushq %rbp + movq %rsp, %rbp + movq (%rdi), %rax + leave + ret +.type .array_size, @function +.size .array_size, .-.array_size +/* end function .array_size */ + +.text +.globl main +main: + pushq %rbp + movq %rsp, %rbp + movl $0, %eax + leave + ret +.type main, @function +.size main, .-main +/* end function main */ + +.section .note.GNU-stack,"",@progbits diff --git a/examples/array/.build/out.o b/examples/array/.build/out.o new file mode 100644 index 0000000..8e945ec Binary files /dev/null and b/examples/array/.build/out.o differ diff --git a/examples/array/.build/out.ssa b/examples/array/.build/out.ssa new file mode 100644 index 0000000..c647a88 --- /dev/null +++ b/examples/array/.build/out.ssa @@ -0,0 +1,65 @@ +# ========== Builtin functions ========== +function l $.cstring_len(l %str) { +@start + %count =l copy 0 +@loop + %address =l add %str, %count + %value =w loadub %address + jnz %value, @continue, @end +@continue + %count =l add %count, 1 + jmp @loop +@end + ret %count +} + +function $.memcpy(l %source, l %destination, l %length) { +@start + %count =l copy 0 +@loop + %condition =w cultl %count, %length + jnz %condition, @continue, @end +@continue + %source_address =l add %source, %count + %destination_address =l add %destination, %count + %value =w loadub %source_address + storeb %value, %destination_address + %count =l add %count, 1 + jmp @loop +@end + ret +} + +function $.memset(l %destination, l %value, l %length) { +@start + %count =l copy 0 +@loop + %condition =w cultl %count, %length + jnz %condition, @continue, @end +@continue + %destination_address =l add %destination, %count + storeb %value, %destination_address + %count =l add %count, 1 + jmp @loop +@end + ret +} + +function l $.array_size(l %array) { +@start + %size =l loadl %array + ret %size +} + +# ========== Referenced structs ========== + +# ========== Struct definitions ========== +# ========== Function definitions ========== +export function l $main(l %args) { +@start + ret 0 +} + +# ========== cstring literals ========== + +# ========== string literals ========== diff --git a/examples/array/main.nub b/examples/array/main.nub new file mode 100644 index 0000000..23a0b21 --- /dev/null +++ b/examples/array/main.nub @@ -0,0 +1,6 @@ +module "main" + +extern "main" func main(args: []cstring): i64 +{ + return 0 +} \ No newline at end of file diff --git a/examples/array/makefile b/examples/array/makefile new file mode 100644 index 0000000..df44fc1 --- /dev/null +++ b/examples/array/makefile @@ -0,0 +1,15 @@ +NUBC = ../../compiler/NubLang.CLI/bin/Debug/net9.0/nubc + +out: .build/out.o + gcc -nostartfiles -o out x86_64.s .build/out.o + +.build/out.o: $(NUBC) main.nub + $(NUBC) main.nub + +.PHONY: $(NUBC) +$(NUBC): + dotnet build ../../compiler/NubLang.CLI/NubLang.CLI.csproj + +clean: + @rm -r .build 2>/dev/null || true + @rm out 2>/dev/null || true diff --git a/examples/array/out b/examples/array/out new file mode 100755 index 0000000..9c0edeb Binary files /dev/null and b/examples/array/out differ diff --git a/examples/array/x86_64.s b/examples/array/x86_64.s new file mode 100644 index 0000000..f55a1d0 --- /dev/null +++ b/examples/array/x86_64.s @@ -0,0 +1,10 @@ +.intel_syntax noprefix + +.text +.globl _start +_start: + mov rdi, rsp + call main + mov rdi, rax + mov rax, 60 + syscall diff --git a/examples/raylib/main.nub b/examples/raylib/main.nub index a52d142..90710f8 100644 --- a/examples/raylib/main.nub +++ b/examples/raylib/main.nub @@ -1,4 +1,3 @@ -import "core" import "raylib" module "main"