#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