Tests for memory allocation and linear typing
This commit is contained in:
parent
c70861b874
commit
caa149ac39
7 changed files with 158 additions and 0 deletions
6
test/bad/linear_causality.ept
Normal file
6
test/bad/linear_causality.ept
Normal file
|
@ -0,0 +1,6 @@
|
|||
node f(a:int^10 at r) returns (o:int^10 at r)
|
||||
var u:int^10 at r;
|
||||
let
|
||||
u = [a with [0] = 0];
|
||||
o = map<<10>> (+)(u, a);
|
||||
tel
|
35
test/good/linear.ept
Normal file
35
test/good/linear.ept
Normal file
|
@ -0,0 +1,35 @@
|
|||
const m:int = 3
|
||||
const n:int = 100
|
||||
|
||||
node f(a:int^10 at r) returns (o:int^10 at r)
|
||||
let
|
||||
o = [ a with [0]=0 ]
|
||||
tel
|
||||
|
||||
node g(a:int^10 at r) returns (o:int^10 at r)
|
||||
let
|
||||
o = f(a)
|
||||
tel
|
||||
|
||||
node linplus (a:int at r) returns (u:int at r)
|
||||
let
|
||||
u = a
|
||||
tel
|
||||
|
||||
fun swap<<s:int>>(i,j:int; a:float^s at r) returns (o:float^s at r)
|
||||
var u,v:float; a1:float^s at r;
|
||||
let
|
||||
u = a.[i] default 0.0;
|
||||
v = a.[j] default 0.0;
|
||||
a1 = [ a with [i] = v ];
|
||||
o = [ a1 with [j] = v];
|
||||
tel
|
||||
|
||||
node shuffle(i_arr, j_arr:int^m; q:int)
|
||||
returns (v : float)
|
||||
var t,t_next:float^n at r;
|
||||
let
|
||||
t_next = fold<<m>> (swap<<n>>)(i_arr, j_arr, t);
|
||||
init<<r>> t = (0.0^n) fby t_next;
|
||||
v = t_next.[q] default 0.0;
|
||||
tel
|
26
test/good/linear_automata.ept
Normal file
26
test/good/linear_automata.ept
Normal file
|
@ -0,0 +1,26 @@
|
|||
const n:int = 100
|
||||
|
||||
fun f(a:int^n at r) returns (o:int^n at r)
|
||||
let
|
||||
o = [ a with [0] = 0 ]
|
||||
tel
|
||||
|
||||
fun g(a:int^n at r) returns (o:int^n at r)
|
||||
let
|
||||
o = [ a with [n-1] = 0 ]
|
||||
tel
|
||||
|
||||
node autom(a:int^n at r) returns (o:int^n at r)
|
||||
let
|
||||
automaton
|
||||
state S1
|
||||
do
|
||||
o = f(a)
|
||||
until true then S2
|
||||
|
||||
state S2
|
||||
do
|
||||
o = g(a)
|
||||
until false then S1
|
||||
end
|
||||
tel
|
23
test/good/linear_init.ept
Normal file
23
test/good/linear_init.ept
Normal file
|
@ -0,0 +1,23 @@
|
|||
const n:int = 100
|
||||
|
||||
node pp(x:float) returns(o1,o2:float)
|
||||
let
|
||||
o1 = x;
|
||||
o2 = x
|
||||
tel
|
||||
|
||||
node f() returns (o:float)
|
||||
var u,v:float^n at r;
|
||||
let
|
||||
init<<r>> u = [1.0^n with [0] = 0.0];
|
||||
v = [u with [n-1] = 0.0];
|
||||
o = v[28]
|
||||
tel
|
||||
|
||||
node g() returns (o:float)
|
||||
var u,v:float^n at r; z:float^n;
|
||||
let
|
||||
(init<<r>> u, z) = map<<n>> pp(0.0^n);
|
||||
v = [u with [n-1] = 0.0];
|
||||
o = v[28]
|
||||
tel
|
11
test/good/linear_split.ept
Normal file
11
test/good/linear_split.ept
Normal file
|
@ -0,0 +1,11 @@
|
|||
const n:int = 100
|
||||
|
||||
type st = On | Off
|
||||
|
||||
node f(a:int^n at r; c:st) returns (o:int^n at r)
|
||||
var u,v,x:int^n at r;
|
||||
let
|
||||
(u, v) = split c (a);
|
||||
x = [ u with [0] = 0 ];
|
||||
o = merge c (On -> x) (Off -> v)
|
||||
tel
|
14
test/good/memalloc_record.ept
Normal file
14
test/good/memalloc_record.ept
Normal file
|
@ -0,0 +1,14 @@
|
|||
type array = { tab : int^100; size : int }
|
||||
|
||||
fun f(a:array) returns (o:array)
|
||||
let
|
||||
o = { a with .size = 0 }
|
||||
tel
|
||||
|
||||
node g(a:array) returns (o:array)
|
||||
var v, u : int^100;
|
||||
let
|
||||
v = [ a.tab with [0] = 0 ];
|
||||
u = [ v with [10] = 99 ];
|
||||
o = { a with .tab = u }
|
||||
tel
|
43
test/good/memalloc_simple.ept
Normal file
43
test/good/memalloc_simple.ept
Normal file
|
@ -0,0 +1,43 @@
|
|||
const n:int = 100
|
||||
const m:int = 3
|
||||
|
||||
fun swap<<s:int>>(i,j:int; a:float^s) returns (o:float^s)
|
||||
var u,v:float; a1:float^s;
|
||||
let
|
||||
u = a.[i] default 0.0;
|
||||
v = a.[j] default 0.0;
|
||||
a1 = [ a with [i] = v ];
|
||||
o = [ a1 with [j] = v];
|
||||
tel
|
||||
|
||||
node shuffle(i_arr, j_arr:int^m; q:int)
|
||||
returns (v : float)
|
||||
var t,t_next:float^n;
|
||||
let
|
||||
t_next = fold<<m>> (swap<<n>>)(i_arr, j_arr, t);
|
||||
t = (0.0^n) fby t_next;
|
||||
v = t_next.[q] default 0.0;
|
||||
tel
|
||||
|
||||
node p(a,b:int^n) returns (o:int^n)
|
||||
var x:int^n;
|
||||
let
|
||||
x = map<<n>> (+) (a, b);
|
||||
o = map<<n>> (-) (x, b)
|
||||
tel
|
||||
|
||||
fun clocked(x:bool; i,j:int; a:float^n) returns (o:float^n)
|
||||
var a1,a2:float^n;
|
||||
let
|
||||
a1 = [ (a when true(x)) with [i when true(x)] = 0.0 ];
|
||||
a2 = [ (a when false(x)) with [j when false(x)] = 0.0 ];
|
||||
o = merge x (true -> a1) (false -> a2);
|
||||
tel
|
||||
|
||||
node clocked_reg(x:bool; i,j:int; a:float^n) returns (o:float^n)
|
||||
var a1,a2:float^n;
|
||||
let
|
||||
o = merge x (true -> a1) (false -> a2);
|
||||
a1 = (0.0^n) fby [ a1 with [i when true(x)] = 0.0 ];
|
||||
a2 = (0.0^n) fby [ a2 with [j when false(x)] = 0.0 ];
|
||||
tel
|
Loading…
Reference in a new issue