Function Calls

Function Calls

Part of the Sun ABI draft. These are proposed requirements, not guarantees of current releases. Open decisions must be resolved before stabilization.

Function calls

Suppose area takes a rectangle and returns an integer. These are illustrative calling rules, not a chosen Sun calling convention:

caller: puts rectangle fields into two argument registers
callee: expects a pointer to rectangle storage
result: the callee interprets a field value as an address; reject the mismatch

Both sides knowing the fields is insufficient: they must agree on how the fields reach the function. This translation is called signature lowering.

Minimal exampleLevelRequirement
A direct call and a callback invoke the same area function.MUSTUse one defined lowering procedure for definitions, declarations, direct and indirect calls, interface methods, callbacks, and returns.
The caller sends (width, height); the callee must not read (height, width).MUSTSpecify the order of parameters, including receivers, closure arguments, and result-storage arguments.
A small signed integer must arrive with the same sign.MUSTSpecify scalar extension rules and Boolean handling.
A rectangle is passed as fields or through a storage pointer.MUSTSpecify whether each value is passed directly, split into scalars, or passed through storage.
The caller provides the memory where the result is written.MUSTSpecify alignment and aliasing rules for arguments and results.
Specializing a parameter pack produces three arguments.MUSTSpecify how empty parameters and results are passed and how specialized parameter packs expand.
A moved resource is returned or destroyed after a failed call.MUSTDefine ownership and lifetimes on normal and exceptional exits, including who owns caller-provided storage.
The caller and callee disagree about which register holds the result.MUSTSpecify the calling convention and all function attributes that affect the ABI.
Passing an argument by address must not secretly clone or heap-allocate it.MUST NOTIntroduce an implicit Sun copy or a hidden heap allocation.

Proposed implementation

The implementation shares Sun call descriptors with ABI validation; this draft still needs the stable rules those descriptors promise. For example, if area uses caller-provided storage, both the call emitter and the checker must agree on its alignment and ownership. An LLVM structure type alone does not settle those choices.

Open decisions

Choose aggregate passing rules for each initial CPU target. Options include platform C rules applied to lowered Sun types, or a Sun convention that passes aggregates through storage. This draft chooses neither. LLVM structure types alone do not specify how machine code passes values.