This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
shared.dylan
61 lines (48 loc) · 1.88 KB
/
shared.dylan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Module: shared
// Whether to do verbose output. This is set based on the --verbose command
// line option.
define variable *verbose?* :: <bool> = #f;
// Whether to run in debug mode, which has two effects:
// * Errors aren't caught and printed, so they result in entering the debugger
// or printing a backtrace.
// * In combination with *verbose?* it results in trace-level output.
define variable *debug?* :: <bool> = #f;
//// Output
// Using these instead of calling format-out directly is intended to make it
// easier to make global changes in what the output looks like. For example, we
// don't have to call force-out after each output if we want line-buffered
// output (which we do).
define inline function note (fmt, #rest args) => ()
apply(format-out, fmt, args);
format-out("\n");
force-out();
end;
define inline function debug (fmt, #rest args) => ()
*debug?* & apply(note, fmt, args);
end;
define inline function verbose (fmt, #rest args) => ()
*verbose?* & apply(note, fmt, args);
end;
define inline function trace (fmt, #rest args) => ()
*debug?* & *verbose?* & apply(note, fmt, args);
end;
define inline function warn (fmt, #rest args) => ()
apply(note, concat("WARNING: ", fmt), args);
end;
// Find the full path to dylan-compiler or signal an error.
define function locate-dylan-compiler () => (dc :: <string>)
let output = with-output-to-string (stream)
local method outputter (output, #key end: epos)
write(stream, copy-sequence(output, end: epos));
end;
os/run-application("which dylan-compiler",
under-shell?: #t,
outputter: outputter);
end;
let lines = split-lines(output);
if (lines[0].size > 0)
lines[0]
else
error("dylan-compiler not found. Is it on your PATH?");
end
end function;