c generator
This commit is contained in:
3
examples/hello-world/.gitignore
vendored
Normal file
3
examples/hello-world/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.build
|
||||
out.a
|
||||
out
|
||||
34
examples/hello-world/main.nub
Normal file
34
examples/hello-world/main.nub
Normal file
@@ -0,0 +1,34 @@
|
||||
module "main"
|
||||
|
||||
extern "puts" func puts(text: cstring)
|
||||
|
||||
struct Human
|
||||
{
|
||||
name: cstring
|
||||
|
||||
func print()
|
||||
{
|
||||
puts("human")
|
||||
}
|
||||
}
|
||||
|
||||
extern "main" func main(args: []cstring): i64
|
||||
{
|
||||
puts("test")
|
||||
let test: Human = {
|
||||
name = "uwu"
|
||||
}
|
||||
|
||||
if false
|
||||
{
|
||||
puts("uwu")
|
||||
}
|
||||
|
||||
while true
|
||||
{
|
||||
puts("count")
|
||||
}
|
||||
|
||||
test.print()
|
||||
return 0
|
||||
}
|
||||
15
examples/hello-world/makefile
Normal file
15
examples/hello-world/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
NUBC = ../../compiler/NubLang.CLI/bin/Debug/net9.0/nubc
|
||||
|
||||
out: .build/out.o
|
||||
gcc -nostartfiles -lm -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
|
||||
10
examples/hello-world/x86_64.s
Normal file
10
examples/hello-world/x86_64.s
Normal file
@@ -0,0 +1,10 @@
|
||||
.intel_syntax noprefix
|
||||
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
mov rdi, rsp
|
||||
call main
|
||||
mov rdi, rax
|
||||
mov rax, 60
|
||||
syscall
|
||||
Reference in New Issue
Block a user