summaryrefslogtreecommitdiff
path: root/examples/main.pipa
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-10 22:24:14 -0300
committerCarlos Maniero <carlos@maniero.me>2023-05-10 22:45:31 -0300
commit5042a4ffc1363d6f0f99a3afd79f76cf2da738d6 (patch)
tree90c31d77ddf6b9051669fafdc6dfe0fc3b1f35eb /examples/main.pipa
parent6f187a71cbe3aa4ebb32ba287c75562d96c7a3f4 (diff)
gas: implement function calls
For now function calls are following the C's calling convention, which means they are using the following registers to pass functions' arguments: rdi, rsi, rdx, rcx, r8, r9 If a function has more then 6 parameters, the compilation will fail. To enable function with more than 6 parameters we will need to save the extra arguments on stack. Naming: parameters: function parameters are the variables a function receives. arguments: Arguments are the values passed to a function when calling it. Calling mechanism: When a function is called, all the expressions passed as argument are evaluated, after the evaluation, the result is stored on the register that represents its argument position, the first argument will be stored on rdi, the second on rsi and so on. Receiving mechanism: When a function starts, the first thing it does is store all the registers onto the stack. So rdi will be stored on -8(rbp), rsi on -16(rbp) and so on. And, a ref_entry is created making the relationship parameter-stack_offset. Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'examples/main.pipa')
-rw-r--r--examples/main.pipa6
1 files changed, 1 insertions, 5 deletions
diff --git a/examples/main.pipa b/examples/main.pipa
index 5ea0077..2da2231 100644
--- a/examples/main.pipa
+++ b/examples/main.pipa
@@ -1,7 +1,3 @@
-fn give_me_the_number(): i32 {
- return 69;
-}
-
fn main(): i32 {
- return give_me_the_number();
+ return 69;
}