The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

IMCC - calling conventions

VERSION

0.1 initial proposal
0.2 initial, checked in

OVERVIEW

This document describes subroutine calling conventions.

DESCRIPTION

A imcc does register allocation, it has to track the life span of variables. This includes the (possible) data flow in and out of subroutines.

Stack calling conventions

Arguments are saved in reverse order onto the user stack:

   .arg y       # save args in reversed order
   .arg x
   call _foo    #(r, s) = _foo(x,y)
   .local int r
   .local int s
   .result s    # restore results in reversed order
   .result r    # [1]

and return values are restored in reversed order from there.

The subroutine is responsible for preserving registers.

 .sub _foo              # sub foo(int a, int b)
   saveall
   .param int a
   .param int b
   ...

   .return pl           # return (pl, mi)
   .return mi           # [1]
   restoreall
   ret
 .end

[1] or vice versa?

Status

Implemented. When the subroutine is in the same compilation unit, the callee can saveall registers, when the subroutine is in a different compilation unit, the callee must preserve all used registers.

Parrot calling conventions (NCI)

Proposed syntax:

  $P0 = load_lib "libname"
  $P1 = dlfunc $P0, "funcname", "signature"
  .nciarg z     # I5
  .nciarg y     # I6
  .nciarg x     # I7
  ncicall $P1   # r = funcname(x, y, z)
  .local int r
  .nciresult r

This prepares parameters like described in pdd03_calling_conventions.pod, saves the registers and invokes the function. The .nciarg pseudo ops put the given argument into increasing registers of the appropriate type. They have to be in reversed argument order.

Status

Unimplemented.

Continuations

TBD.

Coroutines

TBD.

Exception handlers

TBD.

Parrot calling conventions (Method calls)

TBD.

Namespaces and lexicals

 - Should imcc keep track of pad opcodes?
 - Should imcc even emit such opcodes from e.g. .local directives?

FILES

imcc.y, t/syn/bsr.t

AUTHOR

Leopold Toetsch <lt@toetsch.at>