#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 (p->obj) prval () = opt_some p->obj in out end else ( panic("Not inialized"); $UN.ptr0_get(the_null_ptr) ) end implement{vt} {a} exec$fwork (v) = ( (panic("Not overloaded")); $UN.ptr0_get(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