Functions

Function calling

Function calling is simple, all you have to do is write the function name and it will get called

Example

func sayHi begin
    "hi" printlstr new_line
end

sayHi

Parameters are passed to functions through the stack (which you push to by just writing an integer, or variable identifier, or const identifier)

Example

2 2 +

Function definitions

Function definitions use this syntax:

func NAME PARAM_TYPE PARAM_NAME ... begin

end

Where NAME is the name of the function

There can be as many parameters as you want. You can also handle parameters manually if you want, which means leaving the parameters part blank.

Example:

func say_num cell num begin
    num printdec new_line
end

If you want the function to be inlined, you can replace the func keyword with inline. This also makes the function act like a macro, so words like return will return from whatever function the caller is in

Returning from functions

Callisto has a built in word called return, which will return from the function

Function pointers

You can get the address of a Callisto function using the only unary operator: &. It works like this:

func foo begin

end

&foo printdec

You can call function pointers that are on the stack with call, like this:

50 &printdec call

Raw functions

Usually in Callisto, functions get compiled with a certain prefix (__func__ or func__), you can disable this by adding raw after the func/inline keyword, like this:

func raw foo begin

end