| 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 | 
 | 
| 8 | GLOBAL_STR(str0, "(");
 | 
| 9 | GLOBAL_STR(str1, ")");
 | 
| 10 | GLOBAL_STR(str2, "_");
 | 
| 11 | GLOBAL_STR(str3, "T");
 | 
| 12 | GLOBAL_STR(str4, "F");
 | 
| 13 | GLOBAL_STR(str5, "<%s %r>");
 | 
| 14 | GLOBAL_STR(str6, "status");
 | 
| 15 | GLOBAL_STR(str7, "message");
 | 
| 16 | GLOBAL_STR(str8, "%s, got %s");
 | 
| 17 | GLOBAL_STR(str9, " (line %d, offset %d-%d: %r)");
 | 
| 18 | 
 | 
| 19 | namespace runtime {  // forward declare
 | 
| 20 | 
 | 
| 21 |   class TraversalState;
 | 
| 22 | 
 | 
| 23 | }  // forward declare namespace runtime
 | 
| 24 | 
 | 
| 25 | namespace num {  // forward declare
 | 
| 26 | 
 | 
| 27 | 
 | 
| 28 | }  // forward declare namespace num
 | 
| 29 | 
 | 
| 30 | namespace runtime {  // declare
 | 
| 31 | 
 | 
| 32 | using hnode_asdl::hnode;
 | 
| 33 | extern int NO_SPID;
 | 
| 34 | hnode::Record* NewRecord(BigStr* node_type);
 | 
| 35 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
 | 
| 36 | class 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 | 
 | 
| 49 | extern BigStr* TRUE_STR;
 | 
| 50 | extern BigStr* FALSE_STR;
 | 
| 51 | 
 | 
| 52 | 
 | 
| 53 | }  // declare namespace runtime
 | 
| 54 | 
 | 
| 55 | namespace num {  // declare
 | 
| 56 | 
 | 
| 57 | value::Int* ToBig(int i);
 | 
| 58 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
 | 
| 59 | int Exponent2(int x, int y);
 | 
| 60 | mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y);
 | 
| 61 | int IntDivide2(int x, int y);
 | 
| 62 | mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y);
 | 
| 63 | int IntRemainder2(int x, int y);
 | 
| 64 | 
 | 
| 65 | 
 | 
| 66 | }  // declare namespace num
 | 
| 67 | 
 | 
| 68 | namespace runtime {  // define
 | 
| 69 | 
 | 
| 70 | using hnode_asdl::hnode;
 | 
| 71 | using hnode_asdl::color_t;
 | 
| 72 | using hnode_asdl::color_e;
 | 
| 73 | int NO_SPID = -1;
 | 
| 74 | 
 | 
| 75 | hnode::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 | 
 | 
| 81 | hnode::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 | 
 | 
| 92 | TraversalState::TraversalState() {
 | 
| 93 |   this->seen = Alloc<Dict<int, bool>>();
 | 
| 94 |   this->ref_count = Alloc<Dict<int, int>>();
 | 
| 95 | }
 | 
| 96 | BigStr* TRUE_STR = str3;
 | 
| 97 | BigStr* FALSE_STR = str4;
 | 
| 98 | 
 | 
| 99 | }  // define namespace runtime
 | 
| 100 | 
 | 
| 101 | namespace error {  // define
 | 
| 102 | 
 | 
| 103 | using syntax_asdl::loc_e;
 | 
| 104 | using syntax_asdl::loc_t;
 | 
| 105 | using syntax_asdl::loc;
 | 
| 106 | using value_asdl::value;
 | 
| 107 | using value_asdl::value_t;
 | 
| 108 | using value_asdl::value_str;
 | 
| 109 | 
 | 
| 110 | BigStr* _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 | 
 | 
| 126 | bool _ErrorWithLocation::HasLocation() {
 | 
| 127 |   return this->location->tag() != loc_e::Missing;
 | 
| 128 | }
 | 
| 129 | 
 | 
| 130 | BigStr* _ErrorWithLocation::UserErrorString() {
 | 
| 131 |   return this->msg;
 | 
| 132 | }
 | 
| 133 | 
 | 
| 134 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
 | 
| 135 | }
 | 
| 136 | 
 | 
| 137 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
 | 
| 138 | }
 | 
| 139 | 
 | 
| 140 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
 | 
| 141 | }
 | 
| 142 | 
 | 
| 143 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
 | 
| 144 | }
 | 
| 145 | 
 | 
| 146 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
 | 
| 147 |   this->exit_status = exit_status;
 | 
| 148 | }
 | 
| 149 | 
 | 
| 150 | int FatalRuntime::ExitStatus() {
 | 
| 151 |   return this->exit_status;
 | 
| 152 | }
 | 
| 153 | 
 | 
| 154 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(1, msg, location) {
 | 
| 155 | }
 | 
| 156 | 
 | 
| 157 | ErrExit::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 | 
 | 
| 161 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(3, msg, location) {
 | 
| 162 | }
 | 
| 163 | 
 | 
| 164 | Structured::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 | 
 | 
| 168 | value::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 | 
 | 
| 177 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
 | 
| 178 | }
 | 
| 179 | 
 | 
| 180 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
 | 
| 181 | }
 | 
| 182 | 
 | 
| 183 | TypeErr::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 | 
 | 
| 186 | Runtime::Runtime(BigStr* msg) {
 | 
| 187 |   this->msg = msg;
 | 
| 188 | }
 | 
| 189 | 
 | 
| 190 | BigStr* Runtime::UserErrorString() {
 | 
| 191 |   return this->msg;
 | 
| 192 | }
 | 
| 193 | 
 | 
| 194 | Decode::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 | 
 | 
| 202 | BigStr* 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 | 
 | 
| 214 | BigStr* Decode::__str__() {
 | 
| 215 |   return this->Message();
 | 
| 216 | }
 | 
| 217 | 
 | 
| 218 | Encode::Encode(BigStr* msg) {
 | 
| 219 |   this->msg = msg;
 | 
| 220 | }
 | 
| 221 | 
 | 
| 222 | BigStr* 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 | 
 | 
| 263 | namespace num {  // define
 | 
| 264 | 
 | 
| 265 | using value_asdl::value;
 | 
| 266 | 
 | 
| 267 | value::Int* ToBig(int i) {
 | 
| 268 |   return Alloc<value::Int>(mops::IntWiden(i));
 | 
| 269 | }
 | 
| 270 | 
 | 
| 271 | mops::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 | 
 | 
| 282 | int Exponent2(int x, int y) {
 | 
| 283 |   return mops::BigTruncate(Exponent(mops::IntWiden(x), mops::IntWiden(y)));
 | 
| 284 | }
 | 
| 285 | 
 | 
| 286 | mops::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 | 
 | 
| 310 | int IntDivide2(int x, int y) {
 | 
| 311 |   return mops::BigTruncate(IntDivide(mops::IntWiden(x), mops::IntWiden(y)));
 | 
| 312 | }
 | 
| 313 | 
 | 
| 314 | mops::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 | 
 | 
| 337 | int IntRemainder2(int x, int y) {
 | 
| 338 |   return mops::BigTruncate(IntRemainder(mops::IntWiden(x), mops::IntWiden(y)));
 | 
| 339 | }
 | 
| 340 | 
 | 
| 341 | }  // define namespace num
 | 
| 342 | 
 |