-
Notifications
You must be signed in to change notification settings - Fork 0
/
State.mag
93 lines (80 loc) · 3.24 KB
/
State.mag
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This file is part of ExactpAdics
// Copyright (C) 2018 Christopher Doris
//
// ExactpAdics is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ExactpAdics is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ExactpAdics. If not, see <http://www.gnu.org/licenses/>.
///# Internals
freeze;
declare type ExactpAdics_State;
declare attributes ExactpAdics_State: next_id, warnings;
STATE := New(ExactpAdics_State);
STATE`next_id := 1;
STATE`warnings := AssociativeArray();
///## Global ID
/// Each p-adic object (`AnyPadExact`) has a unique `id` attribute, which is ordered according to dependency.
intrinsic ExactpAdics_NextId() -> RngIntElt
{The next global id.}
s := STATE;
id := s`next_id;
s`next_id := id + 1;
return id;
end intrinsic;
///## Warnings
/// For controlling the extent to which errors and warning occur in the package.
valid_warn_actions := {"Ignore", "Warn", "WarnOnce", "Error"};
/// Sets how the warning `name` is displayed. `action` is one of:
/// - `"Ignore"`: ignores the warning and does nothing
/// - `"Warn"`: prints the warning to the screen
/// - `"WarnOnce"`: prints the warning to the screen the first time it occurs
/// - `"Error"`: raises an error
intrinsic ExactpAdics_SetWarningAction(name :: MonStgElt, action :: MonStgElt)
{Sets how the warning `name` is displayed, where `action` is one of `"Hide"`, `"Warn"`, `"WarnOnce"` and `"Error"`.}
require action in valid_warn_actions: "action is not valid";
s := STATE;
s`warnings[name] := action;
end intrinsic;
intrinsic ExactpAdics_WarningActionIsDefined(name :: MonStgElt) -> BoolElt, MonStgElt
{True if there is a warning action defined for warning `name`. If so, also returns the action.}
return IsDefined(STATE`warnings, name);
end intrinsic;
intrinsic ExactpAdics_GetWarningAction(name :: MonStgElt, dflt :: MonStgElt) -> MonStgElt
{The warning action set for warning `name`, if set, or else `dflt`.}
ok, ret := ExactpAdics_WarningActionIsDefined(name);
if ok then
return ret;
else
require dflt in valid_warn_actions: "invalid dflt";
return dflt;
end if;
end intrinsic;
intrinsic ExactpAdics_Warn(name :: MonStgElt, msg : DefaultAction:="Warn", Action:=ExactpAdics_GetWarningAction(name, DefaultAction))
{Raises the warning `name` with message `msg`.}
case Action:
when "Ignore":
;
when "Warn", "WarnOnce":
printf "Warning (%o): %o\n", name, msg;
case Action:
when "Warn":
printf "Note: you can suppress future warnings with ExactpAdics_SetWarningAction(%m, %m)\n", name, "Ignore";
when "WarnOnce":
ExactpAdics_SetWarningAction(name, "Ignore");
else
assert false;
end case;
when "Error":
error Error(<name, msg>);
else
assert false;
end case;
end intrinsic;