From 11539792ffcbdba74d6ca63dea2be937d62de7fc Mon Sep 17 00:00:00 2001 From: Xander Date: Fri, 28 Jul 2023 00:57:36 +0200 Subject: Added template init_exec function --- lib/DATS/init.dats | 14 ++++++++++++++ lib/DATS/writer.dats | 16 +++++++++------- lib/SATS/init.sats | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/DATS/init.dats b/lib/DATS/init.dats index 492d5dc..a4c84b3 100644 --- a/lib/DATS/init.dats +++ b/lib/DATS/init.dats @@ -7,3 +7,17 @@ let in @{initialized = false, obj = v}: initializable vt end + + +implement{vt} init_exec (x) = + if x.initialized then + let + prval () = opt_unsome x.obj + val () = init_exec$fwork (x.obj) + prval () = opt_some x.obj + in + end + +implement{vt} init_exec$fwork (v) = () + + diff --git a/lib/DATS/writer.dats b/lib/DATS/writer.dats index d5a327b..b7e9973 100644 --- a/lib/DATS/writer.dats +++ b/lib/DATS/writer.dats @@ -3,6 +3,9 @@ staload "lib/SATS/writer.sats" staload "lib/SATS/init.sats" +// when this .dats file not staloaded I get weird error from template function +staload "lib/DATS/init.dats" + #define ATS_DYNLOADFLAG 0 %{^ @@ -48,6 +51,7 @@ in implement _clear_screen(w) = let fun loop {n : nat | n < N - 1} .. (i : int n, w : &writer_t) : void = (put_char('\0', w); if (i < N - 2) then loop(i+1,w)) + val () = w := @{position = 0, color_code = code_value(White,Black)} in loop(0,w); w.position := 0; @@ -103,17 +107,15 @@ in in end end + + implement clear_screen() : void = let val (vbox pf | p) = ref_get_viewptr(writer_ref) + implement init_exec$fwork(v) = _clear_screen(v) in - if p->initialized then - let - prval () = opt_unsome p->obj - val () = _clear_screen(p->obj) - prval () = opt_some p->obj - in - end + if p->initialized then + init_exec (!p) else let prval () = opt_unnone p->obj diff --git a/lib/SATS/init.sats b/lib/SATS/init.sats index c9d9d89..676657b 100644 --- a/lib/SATS/init.sats +++ b/lib/SATS/init.sats @@ -2,3 +2,7 @@ viewtypedef initializable (vt:viewt@ype) = [initialized: bool] @{ initialized = bool initialized, obj = opt (vt, initialized) } fun {vt:viewt@ype} uninitialized (v : opt(vt,false)): initializable vt + +fun {vt:viewt@ype} init_exec (x : &(initializable vt)): void +fun {vt:viewt@ype} init_exec$fwork (v : &vt): void + -- cgit v1.2.3