TC-I Samples

sub.tig
let
  function sub(i: int, j: int) :int = i + j
in
  sub(1, 2)
end

In this sample all function calls to sub can be inlined, i.e. replaced by the function body.

tc -X --inline -A sub.tig
$ tc -X --inline -A sub.tig
/* == Abstract Syntax Tree. == */

function _main() =
  (
    let
      function sub_2(i_0 : int, j_1 : int) : int =
        i_0 + j_1
    in
      let
        var i_0 : int := 1
        var j_1 : int := 2
        var res : int := i_0 + j_1
      in
        res
      end
    end;
    ()
  )
$ echo $?
0

The function call sub(1, 2) has been effectively replaced. Take care with nested function calls, note the variables in the inlined block.

Now that sub is inlined and no longer used, it can be pruned.

tc -X --inline --prune -A sub.tig
$ tc -X --inline --prune -A sub.tig
/* == Abstract Syntax Tree. == */

function _main() =
  (
    let
    in
      let
        var i_0 : int := 1
        var j_1 : int := 2
        var res : int := i_0 + j_1
      in
        res
      end
    end;
    ()
  )
$ echo $?
0

Recursive functions cannot be inlined.