aboutsummaryrefslogtreecommitdiff
path: root/lib/DATS/init.dats
blob: cfdc12eefc895fcc772eb054e4332d5956635acb (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
#include "share/atspre_staload.hats"
staload "lib/SATS/init.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
end

implement{vt} exec_void$fwork (v) = ()

implement{vt} {a} exec  (r,default) = let
  val (vbox pf | p) = ref_get_viewptr{initializable vt}(r)
in
  if p->initialized then
    let
      prval () = opt_unsome p->obj
      val a = exec$fwork (p->obj,default)
      prval () = opt_some  p->obj
    in
      a
    end
  else
    default
end

implement{vt} {a} exec$fwork (v,default) = default

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