summaryrefslogtreecommitdiff
path: root/common.sml
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-08-09 01:17:24 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-08-09 01:17:24 +0200
commit9bc877d781b988768c79d40a0f6a7055e9ad14e7 (patch)
tree72ea857d9df1a9dc179e82e1809220013a995606 /common.sml
parentffee5da4dab26c8500add63da540ee252545370f (diff)
Register map
Diffstat (limited to 'common.sml')
-rw-r--r--common.sml37
1 files changed, 37 insertions, 0 deletions
diff --git a/common.sml b/common.sml
index f8adede..7ed59c3 100644
--- a/common.sml
+++ b/common.sml
@@ -124,6 +124,25 @@ in
Fold.fold ((false, makePrintfBase output), finish)
end g
+fun printfp n g =
+let
+ val buf = ref []
+ fun output s = buf := s :: !buf
+ fun finish _ =
+ let
+ val s = String.concat $ rev $ !buf
+ val s =
+ if size s < n then
+ implode (List.tabulate (n - size s, fn _ => #" ")) ^ s
+ else
+ s
+ in
+ TextIO.output (TextIO.stdOut, s)
+ end
+in
+ Fold.fold ((false, makePrintfBase output), finish)
+end g
+
fun Printf out g = Fold.fold ((false, out), fn _ => ()) g
local
@@ -152,6 +171,24 @@ fun F z = bind A0 (fn (_, mf) => mf ()) z
val I = fn z => bindWith2str Int.toString z
fun i v out = Printf out I v %
+val Ip = fn z =>
+let
+ fun f w i out =
+ let
+ val s = Int.toString i
+ val len = size s
+ val s =
+ if len < w then
+ implode (List.tabulate (w - len, fn _ => #" ")) ^ s
+ else
+ s
+ in
+ Printf out `s %
+ end
+in
+ bind A2 f
+end z
+
val C = fn z => bindWith2str str z
val B = fn z => bindWith2str Bool.toString z
val W = fn z => bindWith2str (Word.fmt StringCvt.DEC) z