-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
vtest.flx
44 lines (37 loc) · 945 Bytes
/
vtest.flx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
println$ "Vtesty";
var x : uint = 1u;
var p : &uint = &x;
var pp : &(&uint) = &p;
println$ * (* pp);
var tup = 1,pp;
var vtup = &<<tup;
var dtup = * vtup;
var q = *(dtup.1);
//q <- 2u; // this should FAIL because the deref should modify the target to be a view pointer
println$ (* (* pp)).str;
begin
struct Node { a:int; next: opt[&Node]; }
var px = unbox (new Node (1, None[&Node] ));
px = unbox (new Node (2, Some (px)));
px = unbox (new Node (3, Some (px)));
fun pNode (var px:&<<Node) =>
(px*.a).str + ", " +
match px*.next with
| None => ";"
| Some px => pNode px
endmatch
;
println$ px.pNode;
end
noinline proc g () {
struct X { x:int; py: &Y; }
struct Y { y:int; }
var pw = new Y(42);
var px = unbox$ new X (99, pw);
println$ px -> py -> y;
px -> py . y <- 44;
println$ px -> py -> y;
var vpx : &<<X = px; // coerce to view pointer
//vpx -> py . y <- 48; // FAILS
}
g();