OILS / prebuilt / core / error.mycpp.cc View on Github | oilshell.org

340 lines, 199 significant
1// prebuilt/core/error.mycpp.cc: GENERATED by mycpp
2
3#include "prebuilt/core/error.mycpp.h"
4// BEGIN mycpp output
5
6#include "mycpp/runtime.h"
7
8GLOBAL_STR(str0, "(");
9GLOBAL_STR(str1, ")");
10GLOBAL_STR(str2, "_");
11GLOBAL_STR(str3, "T");
12GLOBAL_STR(str4, "F");
13GLOBAL_STR(str5, "<%s %r>");
14GLOBAL_STR(str6, "code");
15GLOBAL_STR(str7, "message");
16GLOBAL_STR(str8, "%s, got %s");
17GLOBAL_STR(str9, " (line %d, offset %d-%d: %r)");
18
19namespace runtime { // forward declare
20
21 class TraversalState;
22
23} // forward declare namespace runtime
24
25namespace num { // forward declare
26
27
28} // forward declare namespace num
29
30namespace runtime { // declare
31
32using hnode_asdl::hnode;
33extern int NO_SPID;
34hnode::Record* NewRecord(BigStr* node_type);
35hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
36class TraversalState {
37 public:
38 TraversalState();
39 Dict<int, bool>* seen;
40 Dict<int, int>* ref_count;
41
42 static constexpr ObjHeader obj_header() {
43 return ObjHeader::ClassScanned(2, sizeof(TraversalState));
44 }
45
46 DISALLOW_COPY_AND_ASSIGN(TraversalState)
47};
48
49extern BigStr* TRUE_STR;
50extern BigStr* FALSE_STR;
51
52} // declare namespace runtime
53
54namespace num { // declare
55
56value::Int* ToBig(int i);
57mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
58int Exponent2(int x, int y);
59mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y);
60int IntDivide2(int x, int y);
61mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y);
62int IntRemainder2(int x, int y);
63
64} // declare namespace num
65
66namespace runtime { // define
67
68using hnode_asdl::hnode;
69using hnode_asdl::color_t;
70using hnode_asdl::color_e;
71int NO_SPID = -1;
72
73hnode::Record* NewRecord(BigStr* node_type) {
74 StackRoot _root0(&node_type);
75
76 return Alloc<hnode::Record>(node_type, Alloc<List<hnode_asdl::Field*>>(), false, str0, str1, Alloc<List<hnode_asdl::hnode_t*>>());
77}
78
79hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
80 StackRoot _root0(&s);
81
82 if (s == nullptr) {
83 return Alloc<hnode::Leaf>(str2, color_e::OtherConst);
84 }
85 else {
86 return Alloc<hnode::Leaf>(s, e_color);
87 }
88}
89
90TraversalState::TraversalState() {
91 this->seen = Alloc<Dict<int, bool>>();
92 this->ref_count = Alloc<Dict<int, int>>();
93}
94BigStr* TRUE_STR = str3;
95BigStr* FALSE_STR = str4;
96
97} // define namespace runtime
98
99namespace error { // define
100
101using syntax_asdl::loc_e;
102using syntax_asdl::loc_t;
103using syntax_asdl::loc;
104using value_asdl::value;
105using value_asdl::value_t;
106using value_asdl::value_str;
107
108BigStr* _ValType(value_asdl::value_t* val) {
109 StackRoot _root0(&val);
110
111 return value_str(val->tag(), false);
112}
113
114_ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
115 this->msg = msg;
116 if (location == nullptr) {
117 this->location = loc::Missing;
118 }
119 else {
120 this->location = location;
121 }
122}
123
124bool _ErrorWithLocation::HasLocation() {
125 return this->location->tag() != loc_e::Missing;
126}
127
128BigStr* _ErrorWithLocation::UserErrorString() {
129 return this->msg;
130}
131
132Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
133}
134
135Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
136}
137
138FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
139}
140
141RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
142}
143
144FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
145 this->exit_status = exit_status;
146}
147
148int FatalRuntime::ExitStatus() {
149 return this->exit_status;
150}
151
152Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
153}
154
155ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : ::error::FatalRuntime(exit_status, msg, location) {
156 this->show_code = show_code;
157}
158
159Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(3, msg, location) {
160}
161
162Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : ::error::FatalRuntime(status, msg, location) {
163 this->properties = properties;
164}
165
166value::Dict* Structured::ToDict() {
167 if (this->properties == nullptr) {
168 this->properties = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
169 }
170 this->properties->set(str6, num::ToBig(this->ExitStatus()));
171 this->properties->set(str7, Alloc<value::Str>(this->msg));
172 return Alloc<value::Dict>(this->properties);
173}
174
175AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
176}
177
178TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
179}
180
181TypeErr::TypeErr(value_asdl::value_t* actual_val, BigStr* msg, syntax_asdl::loc_t* location) : ::error::TypeErrVerbose(StrFormat("%s, got %s", msg, _ValType(actual_val)), location) {
182}
183
184Runtime::Runtime(BigStr* msg) {
185 this->msg = msg;
186}
187
188BigStr* Runtime::UserErrorString() {
189 return this->msg;
190}
191
192Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num) {
193 this->msg = msg;
194 this->s = s;
195 this->start_pos = start_pos;
196 this->end_pos = end_pos;
197 this->line_num = line_num;
198}
199
200BigStr* Decode::Message() {
201 int start;
202 int end;
203 BigStr* part = nullptr;
204 StackRoot _root0(&part);
205
206 start = max(0, (this->start_pos - 4));
207 end = min(len(this->s), (this->end_pos + 4));
208 part = this->s->slice(start, end);
209 return str_concat(this->msg, StrFormat(" (line %d, offset %d-%d: %r)", this->line_num, this->start_pos, this->end_pos, part));
210}
211
212BigStr* Decode::__str__() {
213 return this->Message();
214}
215
216Encode::Encode(BigStr* msg) {
217 this->msg = msg;
218}
219
220BigStr* Encode::Message() {
221 return this->msg;
222}
223
224[[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
225 StackRoot _root0(&msg);
226 StackRoot _root1(&location);
227
228 throw Alloc<Usage>(msg, location);
229}
230
231[[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
232 StackRoot _root0(&msg);
233 StackRoot _root1(&location);
234
235 throw Alloc<Strict>(msg, location);
236}
237
238[[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
239 StackRoot _root0(&msg);
240 StackRoot _root1(&location);
241
242 throw Alloc<Parse>(msg, location);
243}
244
245[[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
246 StackRoot _root0(&msg);
247 StackRoot _root1(&location);
248
249 throw Alloc<FatalRuntime>(1, msg, location);
250}
251
252[[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location) {
253 StackRoot _root0(&msg);
254 StackRoot _root1(&location);
255
256 throw Alloc<FatalRuntime>(status, msg, location);
257}
258
259} // define namespace error
260
261namespace num { // define
262
263using value_asdl::value;
264
265value::Int* ToBig(int i) {
266 return Alloc<value::Int>(mops::IntWiden(i));
267}
268
269mops::BigInt Exponent(mops::BigInt x, mops::BigInt y) {
270 int y_int;
271 mops::BigInt result;
272 y_int = mops::BigTruncate(y);
273 result = mops::BigInt(1);
274 for (int i = 0; i < y_int; ++i) {
275 result = mops::Mul(result, x);
276 }
277 return result;
278}
279
280int Exponent2(int x, int y) {
281 return mops::BigTruncate(Exponent(mops::IntWiden(x), mops::IntWiden(y)));
282}
283
284mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y) {
285 mops::BigInt ZERO;
286 int sign;
287 mops::BigInt ax;
288 mops::BigInt ay;
289 ZERO = mops::BigInt(0);
290 sign = 1;
291 if (mops::Greater(ZERO, x)) {
292 ax = mops::Negate(x);
293 sign = -1;
294 }
295 else {
296 ax = x;
297 }
298 if (mops::Greater(ZERO, y)) {
299 ay = mops::Negate(y);
300 sign = -sign;
301 }
302 else {
303 ay = y;
304 }
305 return mops::Mul(mops::IntWiden(sign), mops::Div(ax, ay));
306}
307
308int IntDivide2(int x, int y) {
309 return mops::BigTruncate(IntDivide(mops::IntWiden(x), mops::IntWiden(y)));
310}
311
312mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y) {
313 mops::BigInt ZERO;
314 mops::BigInt ax;
315 int sign;
316 mops::BigInt ay;
317 ZERO = mops::BigInt(0);
318 if (mops::Greater(ZERO, x)) {
319 ax = mops::Negate(x);
320 sign = -1;
321 }
322 else {
323 ax = x;
324 sign = 1;
325 }
326 if (mops::Greater(ZERO, y)) {
327 ay = mops::Negate(y);
328 }
329 else {
330 ay = y;
331 }
332 return mops::Mul(mops::IntWiden(sign), mops::Rem(ax, ay));
333}
334
335int IntRemainder2(int x, int y) {
336 return mops::BigTruncate(IntRemainder(mops::IntWiden(x), mops::IntWiden(y)));
337}
338
339} // define namespace num
340