#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(p->obj) prval () = opt_some p->obj in end else ( $effmask_ref(initialize(r)); if p->initialized then $effmask_ref(exec_void(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 (p->obj) prval () = opt_some p->obj in out end else ( panic("Not inialized"); $UN.ptr0_get(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