diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/DATS/init.dats | 31 | ||||
-rw-r--r-- | lib/DATS/panic.dats | 2 | ||||
-rw-r--r-- | lib/DATS/writer.dats | 18 | ||||
-rw-r--r-- | lib/SATS/init.sats | 3 |
4 files changed, 31 insertions, 23 deletions
diff --git a/lib/DATS/init.dats b/lib/DATS/init.dats index c2ae39d..206dc6f 100644 --- a/lib/DATS/init.dats +++ b/lib/DATS/init.dats @@ -26,7 +26,25 @@ in panic("Not initialized") end -implement{vt} exec_void$fwork (v) = panic("Not overloaded") +//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<vt>(p->obj) + prval () = opt_some p->obj + in + end + else ( + $effmask_ref(initialize<vt>(r)); + if p->initialized then + $effmask_ref(exec_void<vt>(r)) + else + panic("Not inialized"); + ) +end implement{vt} {a} exec (r) = let val (vbox pf | p) = ref_get_viewptr{initializable vt}(r) @@ -45,10 +63,6 @@ in ) 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) @@ -59,10 +73,3 @@ in val () = p->initialized := initialize$fwork(p->obj) in end end - -implement{vt} initialize$fwork (v) = let - prval () = opt_none v -in - false -end - diff --git a/lib/DATS/panic.dats b/lib/DATS/panic.dats index 356eda5..fc3122b 100644 --- a/lib/DATS/panic.dats +++ b/lib/DATS/panic.dats @@ -15,7 +15,7 @@ staload UN = "prelude/SATS/unsafe.sats" extern fun halt():<!ntm> void = "mac#" -implement panic_loc(loc,msg) = ( +implement panic_loc(loc,msg) = $effmask_all( put_string "KERNEL PANIC:\n "; put_string loc; put_string "\n\n "; diff --git a/lib/DATS/writer.dats b/lib/DATS/writer.dats index b8625f4..6a183c1 100644 --- a/lib/DATS/writer.dats +++ b/lib/DATS/writer.dats @@ -96,6 +96,12 @@ in in + implement initialize$fwork<writer_t>(v) = + ( + v := @{position = 0, color_code = code_value(White,Black)}; + let prval() = opt_some v in true end + ) + implement put_string (str : string) : void = let implement exec_void$fwork<writer_t>(v) = let implement string_foreach$fwork<writer_t> (c,env) = put_char(c,env) @@ -103,21 +109,13 @@ in in end in - $effmask_ref(exec_void<writer_t>(writer_ref)) + $effmask_ref(exec_init<writer_t>(writer_ref)) end implement clear_screen() : void = let implement exec_void$fwork<writer_t>(v) = _clear_screen(v) - implement initialize$fwork<writer_t>(v) = - ( - v := @{position = 0, color_code = code_value(White,Black)}; - let prval() = opt_some v in true end - ) in - if not writer_ref->initialized then - initialize<writer_t>(writer_ref); - - exec_void<writer_t>(writer_ref) + exec_init<writer_t>(writer_ref) end end diff --git a/lib/SATS/init.sats b/lib/SATS/init.sats index 69c6c9a..9fe8581 100644 --- a/lib/SATS/init.sats +++ b/lib/SATS/init.sats @@ -6,6 +6,9 @@ fun {vt:viewt@ype} uninitialized (v : opt(vt,false)): initializable vt fun {vt:viewt@ype} exec_void (r: ref(initializable vt)):<!refwrt> void fun {vt:viewt@ype} exec_void$fwork (v : &vt):<!wrt> void +// function will also inialize if not yet initalized +fun {vt:viewt@ype} exec_init (r: ref(initializable vt)):<!refwrt> void + fun {vt:viewt@ype} {a: t@ype} exec (r: ref(initializable vt)):<!refwrt> a fun {vt:viewt@ype} {a: t@ype} exec$fwork (v : &vt):<!wrt> a |