Skip to content

Commit

Permalink
Merge pull request #11 from soxfox42/tak_fixes
Browse files Browse the repository at this point in the history
fix init, fix macOS globals, add macOS args, add args + parse_int example
  • Loading branch information
yeti0904 authored Aug 12, 2024
2 parents fc17b29 + d83ea4d commit 4de92f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 15 additions & 0 deletions examples/add_args.cal
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class BackendX86_64 : CompilerBackend {
break;
}
case "osx": {
ret ~= ["OSX", "IO", "Exit"];
ret ~= ["OSX", "IO", "Args", "Exit"];
break;
}
default: break;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion std

0 comments on commit 4de92f8

Please sign in to comment.