Examples

calls.mul

Parameters and calls (RFC-002): main calls sub before its definition.

Source

examples/calls.mul is stored in the compact layout, as AI agents write it: a space only between two words, no other whitespace. The page lays it out for reading; the Compact button shows the stored text, and Copy always copies it.

// Parameters and calls (RFC-002): `main` calls `sub` before its definition.
module demo pub fn main()->i32{return sub(10,3)*100+sub(sub(5,1),1)}fn sub(a:i32,b:i32)->i32{return a-b}

Verified IR

What mul ir prints after the verifier has accepted the program.

module demo

fn @main() -> i32 {
b0:
  %0 = const.i32 10
  %1 = const.i32 3
  %2 = call.i32 @sub(%0, %1)
  %3 = const.i32 100
  %4 = mul.i32 %2, %3
  %5 = const.i32 5
  %6 = const.i32 1
  %7 = call.i32 @sub(%5, %6)
  %8 = const.i32 1
  %9 = call.i32 @sub(%7, %8)
  %10 = add.i32 %4, %9
  return %10
}

fn @sub(%0: i32, %1: i32) -> i32 {
b0:
  %2 = sub.i32 %0, %1
  return %2
}

Run

The value main returns is the exit code of the process.

$ mul run examples/calls.mul; echo "exit code $?"
exit code 191