blob: 8c601226bbea1c8c7fd6361434c8d651085e5756 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
Easy-to-use linear types
========================
Allow simple usage of linear types when using only local variables
and/or parameters and/or return values.
Have a "lock system" with automatic garbage collection (collected no later
than when the arena is destroyed) for more complex cases.
Assume that `open` create a linear/owned `File` type.
Trivial case:
func stuff
code
own File f = open "file.txt" .write
write f "hello" # uses `f` but does not take ownership
close f # takes ownership of `f`
end
Nested case:
func get_file
returns
own File f
code
# Allow simple usage when returning
return open "file.txt" .write
end
Complex case:
func maybe_open_file
code
if use_file
#
begin_ownership thefile
thefile = open "file.txt" .write
suspend_ownership thefile
# disallow changing the `file` variable when it is
# suspended?
end
end
func maybe_write_to_file
code
if use_file
resume_ownership file
write thefile "hello"
suspend_ownership file
end
end
func maybe_close_file
code
if use_file
resume_ownership thefile
close thefile
end_ownership thefile
end
end
|