TC-R Samples

Note that the transformation does not apply to field names and primitive.

as.tig
let
  type a = { a: int }
  function a(a: a): a = a{ a = a + a }
  var a : a := a(1, 2)
in
  a.a
end
tc --rename -A as.tig
$ tc --rename -A as.tig
/* == Abstract Syntax Tree. == */

primitive print(string_0 : string)
primitive print_err(string_1 : string)
primitive print_int(int_2 : int)
primitive flush()
primitive getchar() : string
primitive ord(string_3 : string) : int
primitive chr(code_4 : int) : string
primitive size(string_5 : string) : int
primitive streq(s1_6 : string, s2_7 : string) : int
primitive strcmp(s1_8 : string, s2_9 : string) : int
primitive substring(string_10 : string, start_11 : int, length_12 : int) : string
primitive concat(fst_13 : string, snd_14 : string) : string
primitive not(boolean_15 : int) : int
primitive exit(status_16 : int)
function _main() =
  (
    let
      type a_17 = { a : int }
      function a_19(a_18 : a_17) : a_17 =
        a_17 { a = a_18 + a_18 }
      var a_20 : a_17 := a_19(1, 2)
    in
      a_20.a
    end;
    ()
  )
$ echo $?
0

Warning

The sample below concern the object renaming

object-renamer.tig
let
  class A
  {
      var a := 1
      method k(b : int) : int = b
      method toto(b : int) : int = self.a + b
  }

  class B extends A
  {
      var c : string := "salut"
      method k(b : int) : int = b + 2
      method t(b : int) : int = (print(self.c); self.a)
  }

  var a : A := new A
  var b : B := new B
in
  a.k(1) + b.k(4);
  b.t(1);
  b.toto(2);
  a.a;
  b.c;
  b.a
end
tc --object-rename -A object-renamer.tig
$ tc --object-rename -A object-renamer.tig
/* == Abstract Syntax Tree. == */

primitive print(string_0 : string)
primitive print_err(string_1 : string)
primitive print_int(int_2 : int)
primitive flush()
primitive getchar() : string
primitive ord(string_3 : string) : int
primitive chr(code_4 : int) : string
primitive size(string_5 : string) : int
primitive streq(s1_6 : string, s2_7 : string) : int
primitive strcmp(s1_8 : string, s2_9 : string) : int
primitive substring(string_10 : string, start_11 : int, length_12 : int) : string
primitive concat(fst_13 : string, snd_14 : string) : string
primitive not(boolean_15 : int) : int
primitive exit(status_16 : int)
function _main() =
  (
    let
      type A_21 = 
      class extends Object
      {
        var a := 1
        method k_18(b_17 : int) : int =
          b_17
        method toto_20(b_19 : int) : int =
          self.a + b_19
      }
      type B_26 = 
      class extends A_21
      {
        var c : string := "salut"
        method k_23(b_22 : int) : int =
          b_22 + 2
        method t_25(b_24 : int) : int =
          (
            print(self.c);
            self.a
          )
      }
      var a_27 : A_21 := new A_21
      var b_28 : B_26 := new B_26
    in
      (
        a_27.k_18(1) + b_28.k_23(4);
        b_28.t_25(1);
        b_28.toto_20(2);
        a_27.a;
        b_28.c;
        b_28.a
      )
    end;
    ()
  )
$ echo $?
0