summaryrefslogtreecommitdiff
path: root/exn_handler.fun
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-05-17 14:45:50 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-05-17 14:45:50 +0200
commit5edd85474d6d8f3a0cc06cc0250ed3db8b26fcfa (patch)
treebd7ad914025858b4389b1801216ac7d41a0c1f45 /exn_handler.fun
parent1f31e550385cfa64a36167a5f3f9ec780baaad86 (diff)
Function-like macros
Diffstat (limited to 'exn_handler.fun')
-rw-r--r--exn_handler.fun26
1 files changed, 12 insertions, 14 deletions
diff --git a/exn_handler.fun b/exn_handler.fun
index 078225f..b4e7275 100644
--- a/exn_handler.fun
+++ b/exn_handler.fun
@@ -2,44 +2,42 @@ functor ExnHandler(structure T: TOKENIZER; structure P: PPC):
EXN_HANDLER =
struct
- fun eprint s = printf `"error: " `s %
+ val eprintf = fn z => printf `"error: " z
fun otherExn e =
let
val hist = MLton.Exn.history e
in
- eprint $ "exception " ^ exnMessage e ^ " was raised\n";
+ eprintf `"exception " `(exnMessage e) `" was raised\n";
if hist = [] then
- (output "No stack trace is avaliable\n";
- output "Recompile with -const \"Exn.keepHistory true\"\n")
+ printf
+ `"No stack trace is avaliable\n"
+ `"Recompile with -const \"Exn.keepHistory true\"\n" %
else
List.app (fn x => printf `"\t" `x `"\n" %) hist
end
- fun exit code = Posix.Process.exit $ Word8.fromInt code
-
fun ioExn (IO.Io { name, function = _, cause }) =
let
- val prefix = name ^ ": "
val reason =
case cause of
OS.SysErr (str, _) => str
| _ => exnMessage cause
in
- printf `prefix `reason `"\n" %
+ eprintf `name `": " `reason `"\n" %
end
- | ioExn _ = (output "ioExn: unreachable\n"; exit 254)
+ | ioExn _ = die 126 `"ioExn: unreachable\n" %
fun handler e = (
- printf `"\n" %;
+ printf `"\n";
case e of
T.FsmTableIsTooSmall =>
- eprint "fsm table is too small. Increate 'maxState' value"
+ eprintf `"fsm table is too small. Increate 'maxState' value\n" %
| IO.Io _ => ioExn e
- | T.TkErrorAug (pos, msg) => eprint $ T.S.pos2str pos ^ ": " ^ msg
+ | T.TkErrorAug (pos, msg) => eprintf T.S.Ppos pos `": " `msg `"\n" %
| P.TkError v => P.tkErrorPrint v
| P.TkClassError v => P.tkClassErrorPrint v
| _ => otherExn e;
- exit 255
- )
+ exit 1
+ ) handle _ => sysExit 127
end