blob: 206dc6f3bffa537d6f15fe9fb09680f574f16d1e (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "share/atspre_staload.hats"
staload "lib/SATS/init.sats"
staload "lib/SATS/panic.sats"
staload UN = "prelude/SATS/unsafe.sats"
#define ATS_DYNLOADFLAG 0
implement {vt:viewt@ype} uninitialized (v) =
let
in
@{initialized = false, obj = v}: initializable vt
end
implement{vt} exec_void (r) = let
val (vbox pf | p) = ref_get_viewptr{initializable vt}(r)
in
if p->initialized then
let
prval () = opt_unsome p->obj
val () = exec_void$fwork (p->obj)
prval () = opt_some p->obj
in
end
else
panic("Not initialized")
end
//NOTE: lot of duplicate code
implement{vt} exec_init (r) = let
val (vbox pf | p) = ref_get_viewptr{initializable vt}(r)
in
if p->initialized then
let
prval () = opt_unsome p->obj
val () = exec_void$fwork<vt>(p->obj)
prval () = opt_some p->obj
in
end
else (
$effmask_ref(initialize<vt>(r));
if p->initialized then
$effmask_ref(exec_void<vt>(r))
else
panic("Not inialized");
)
end
implement{vt} {a} exec (r) = let
val (vbox pf | p) = ref_get_viewptr{initializable vt}(r)
in
if p->initialized then
let
prval () = opt_unsome p->obj
val out = exec$fwork<vt><a> (p->obj)
prval () = opt_some p->obj
in
out
end
else (
panic("Not inialized");
$UN.ptr0_get<a>(the_null_ptr)
)
end
implement{vt} initialize (r) = let
val (vbox pf | p) = ref_get_viewptr{initializable vt}(r)
in
if (not p->initialized) then
let
prval () = opt_unnone p->obj
val () = p->initialized := initialize$fwork(p->obj)
in end
end
|