blob: c2ae39da69e27253217d5b76390f9c6cfb514f24 (
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
|
#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
implement{vt} exec_void$fwork (v) = panic("Not overloaded")
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} {a} exec$fwork (v) = (
(panic("Not overloaded"));
$UN.ptr0_get<a>(the_null_ptr)
)
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
implement{vt} initialize$fwork (v) = let
prval () = opt_none v
in
false
end
|