| 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, "code");
|
| 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 | } // declare namespace runtime
|
| 53 |
|
| 54 | namespace num { // declare
|
| 55 |
|
| 56 | value::Int* ToBig(int i);
|
| 57 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
|
| 58 | int Exponent2(int x, int y);
|
| 59 | mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y);
|
| 60 | int IntDivide2(int x, int y);
|
| 61 | mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y);
|
| 62 | int IntRemainder2(int x, int y);
|
| 63 |
|
| 64 | } // declare namespace num
|
| 65 |
|
| 66 | namespace runtime { // define
|
| 67 |
|
| 68 | using hnode_asdl::hnode;
|
| 69 | using hnode_asdl::color_t;
|
| 70 | using hnode_asdl::color_e;
|
| 71 | int NO_SPID = -1;
|
| 72 |
|
| 73 | hnode::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 |
|
| 79 | hnode::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 |
|
| 90 | TraversalState::TraversalState() {
|
| 91 | this->seen = Alloc<Dict<int, bool>>();
|
| 92 | this->ref_count = Alloc<Dict<int, int>>();
|
| 93 | }
|
| 94 | BigStr* TRUE_STR = str3;
|
| 95 | BigStr* FALSE_STR = str4;
|
| 96 |
|
| 97 | } // define namespace runtime
|
| 98 |
|
| 99 | namespace error { // define
|
| 100 |
|
| 101 | using syntax_asdl::loc_e;
|
| 102 | using syntax_asdl::loc_t;
|
| 103 | using syntax_asdl::loc;
|
| 104 | using value_asdl::value;
|
| 105 | using value_asdl::value_t;
|
| 106 | using value_asdl::value_str;
|
| 107 |
|
| 108 | BigStr* _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 |
|
| 124 | bool _ErrorWithLocation::HasLocation() {
|
| 125 | return this->location->tag() != loc_e::Missing;
|
| 126 | }
|
| 127 |
|
| 128 | BigStr* _ErrorWithLocation::UserErrorString() {
|
| 129 | return this->msg;
|
| 130 | }
|
| 131 |
|
| 132 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 133 | }
|
| 134 |
|
| 135 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 136 | }
|
| 137 |
|
| 138 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 139 | }
|
| 140 |
|
| 141 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 142 | }
|
| 143 |
|
| 144 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 145 | this->exit_status = exit_status;
|
| 146 | }
|
| 147 |
|
| 148 | int FatalRuntime::ExitStatus() {
|
| 149 | return this->exit_status;
|
| 150 | }
|
| 151 |
|
| 152 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
|
| 153 | }
|
| 154 |
|
| 155 | ErrExit::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 |
|
| 159 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(3, msg, location) {
|
| 160 | }
|
| 161 |
|
| 162 | Structured::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 |
|
| 166 | value::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 |
|
| 175 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
| 176 | }
|
| 177 |
|
| 178 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
| 179 | }
|
| 180 |
|
| 181 | TypeErr::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 |
|
| 184 | Runtime::Runtime(BigStr* msg) {
|
| 185 | this->msg = msg;
|
| 186 | }
|
| 187 |
|
| 188 | BigStr* Runtime::UserErrorString() {
|
| 189 | return this->msg;
|
| 190 | }
|
| 191 |
|
| 192 | Decode::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 |
|
| 200 | BigStr* 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 |
|
| 212 | BigStr* Decode::__str__() {
|
| 213 | return this->Message();
|
| 214 | }
|
| 215 |
|
| 216 | Encode::Encode(BigStr* msg) {
|
| 217 | this->msg = msg;
|
| 218 | }
|
| 219 |
|
| 220 | BigStr* 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 |
|
| 261 | namespace num { // define
|
| 262 |
|
| 263 | using value_asdl::value;
|
| 264 |
|
| 265 | value::Int* ToBig(int i) {
|
| 266 | return Alloc<value::Int>(mops::IntWiden(i));
|
| 267 | }
|
| 268 |
|
| 269 | mops::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 |
|
| 280 | int Exponent2(int x, int y) {
|
| 281 | return mops::BigTruncate(Exponent(mops::IntWiden(x), mops::IntWiden(y)));
|
| 282 | }
|
| 283 |
|
| 284 | mops::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 |
|
| 308 | int IntDivide2(int x, int y) {
|
| 309 | return mops::BigTruncate(IntDivide(mops::IntWiden(x), mops::IntWiden(y)));
|
| 310 | }
|
| 311 |
|
| 312 | mops::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 |
|
| 335 | int IntRemainder2(int x, int y) {
|
| 336 | return mops::BigTruncate(IntRemainder(mops::IntWiden(x), mops::IntWiden(y)));
|
| 337 | }
|
| 338 |
|
| 339 | } // define namespace num
|
| 340 |
|