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

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