/ tests / tests / compiler / modules / generics.adl
generics.adl
 1  program multifile.alpha {
 2      struct QQ {
 3          y: dep::Baz::[3],
 4      }
 5  
 6      transition main() -> u32 {
 7          let x = dep::X;
 8          let inner_x = inner::dep::X;
 9          let f = dep::Foo::[dep::X] {
10              a: [42; dep::X],
11          };
12          let inner_f = inner::dep::Foo {
13              a: [69; inner::dep::X],
14          };
15          return x + inner_x
16                + f.a[dep::X / 2] + inner_f.a[inner::dep::X / 3]
17                + dep::bar() + inner::dep::bar() + goo::[30]()
18                + dep::goo::[31]() + dep::other_dep::Y;
19      }
20  
21      inline goo::[M: u32]() -> u32 { 
22          let b = dep::Bar::[M] {
23              a: [43; M],
24              c: dep::Baz::[M] {
25                  x: 169, 
26              }
27          };
28          b.a[M/M] = 999999;
29          return M + dep::X + b.a[M/2]; 
30      }
31  }
32  
33  // --- Next Module: dep.leo --- //
34  
35  struct Baz::[Q: u32] {
36      x: u32,
37  }
38  
39  const X: u32 = 6;
40  
41  struct Foo::[N: u32] {
42      a: [u32; N],
43  }
44  
45  
46  struct Bar::[N: u32] {
47      a: [u32; N],
48      c: Baz::[N],
49  }
50  
51  inline bar() -> u32 {
52      let c = Foo::[X] {
53          a: [66; X]
54      };
55      let b:[u32; 3] = [1, 2, 3];
56      b[2] = 4;
57      c.a[0] = 1000000 + b[2];
58      return c.a[0] + goo::[29]() + X + other_dep::Y;
59  }
60  
61  inline goo::[M: u32]() -> u32 { 
62      let c = Baz::[M] {
63          x: 69,
64      };
65      let b = Bar::[M] {
66          a: [43; M],
67          c,
68      };
69      b.a[M/2] = 333333;
70      return M + X + b.a[M/2]; 
71  }
72  
73  // --- Next Module: dep/other_dep.leo --- //
74  const Y: u32 = 999999;
75  
76  // --- Next Module: inner/dep.leo --- //
77  const X: u32 = 11;
78  
79  struct Foo {
80      a: [u32; X],
81  }
82  
83  struct Bar::[N: u32] {
84      a: [u32; N],
85  }
86  
87  inline bar() -> u32 {
88      let c = Foo {
89          a: [6; X]
90      };
91      return c.a[0] + goo::[99]() + X;
92  }
93  
94  inline goo::[N: u32]() -> u32 { return N + X; }