diff --git a/examples/add_args.cal b/examples/add_args.cal new file mode 100644 index 0000000..ade6f61 --- /dev/null +++ b/examples/add_args.cal @@ -0,0 +1,15 @@ +include "cores/select.cal" +include "std/args.cal" +include "std/conv.cal" +include "std/io.cal" + +if get_args_length 3 < then + "Required parameters: a b\n" printstr + 1 exit +end + +let Array arg +1 &arg get_arg &arg parse_int +2 &arg get_arg &arg parse_int ++ printdec new_line + diff --git a/source/backends/x86_64.d b/source/backends/x86_64.d index 149f5d6..b0238ec 100644 --- a/source/backends/x86_64.d +++ b/source/backends/x86_64.d @@ -198,7 +198,7 @@ class BackendX86_64 : CompilerBackend { break; } case "osx": { - ret ~= ["OSX", "IO", "Exit"]; + ret ~= ["OSX", "IO", "Args", "Exit"]; break; } default: break; @@ -337,7 +337,7 @@ class BackendX86_64 : CompilerBackend { } if (useLibc) output ~= "global main\n"; - else if (os == "osx") output ~= "global _main\n"; + else if (os == "osx") output ~= "default rel\nglobal _main\n"; else output ~= "global _start\n"; output ~= "section .text\n"; @@ -406,7 +406,6 @@ class BackendX86_64 : CompilerBackend { // run init function output ~= "__init:\n"; - output ~= "mov rsi, rsp\n"; if ("__x86_64_program_init" in words) { CallFunction("__x86_64_program_init"); } @@ -1137,8 +1136,9 @@ class BackendX86_64 : CompilerBackend { auto var = globals[node.func]; output ~= format( - "mov qword [r15], qword __global_%s\n", node.func.Sanitise() + "lea rax, qword [__global_%s]\n", node.func.Sanitise() ); + output ~= "mov [r15], rax\n"; output ~= "add r15, 8\n"; } else if (VariableExists(node.func)) { diff --git a/std b/std index 4f1b6f7..bbc9985 160000 --- a/std +++ b/std @@ -1 +1 @@ -Subproject commit 4f1b6f763b7045742e73ae98b87f258b86eaa720 +Subproject commit bbc9985a6479752845b00228168cb0502c72b61a