| 438 | #define condfailed(p) { int f = p->i.offset; if (f) p+=f; else goto fail; } |
| 439 | |
| 440 | static const char *match (lua_State *L, |
| 441 | const char *o, const char *s, const char *e, |
| 442 | Instruction *op, Capture *capture, int ptop) { |
| 443 | Stack stackbase[INITBACK]; |
| 444 | Stack *stacklimit = stackbase + INITBACK; |
| 445 | Stack *stack = stackbase; /* point to first empty slot in stack */ |
| 446 | int capsize = INITCAPSIZE; |
| 447 | int captop = 0; /* point to first empty slot in captures */ |
| 448 | const Instruction *p = op; |
| 449 | stack->p = &giveup; stack->s = s; stack->caplevel = 0; stack++; |
| 450 | lua_pushlightuserdata(L, stackbase); |
| 451 | for (;;) { |
| 452 | #if defined(DEBUG) |
| 453 | printf("s: |%s| stck: %d c: %d ", |
| 454 | s, (int)(stack - getstackbase(L, ptop)), captop); |
| 455 | printinst(op, p); |
| 456 | #endif |
| 457 | switch ((Opcode)p->i.code) { |
| 458 | case IEnd: { |
| 459 | assert(stack == getstackbase(L, ptop) + 1); |
| 460 | capture[captop].kind = Cclose; |
| 461 | capture[captop].s = NULL; |
| 462 | return s; |
| 463 | } |
| 464 | case IGiveup: { |
| 465 | assert(stack == getstackbase(L, ptop)); |
| 466 | return NULL; |
| 467 | } |
| 468 | case IRet: { |
| 469 | assert(stack > getstackbase(L, ptop) && (stack - 1)->s == NULL); |
| 470 | p = (--stack)->p; |
| 471 | continue; |
| 472 | } |
| 473 | case IAny: { |
| 474 | int n = p->i.aux; |
| 475 | if (n <= e - s) { p++; s += n; } |
| 476 | else condfailed(p); |
| 477 | continue; |
| 478 | } |
| 479 | case IChar: { |
| 480 | if ((byte)*s == p->i.aux && s < e) { p++; s++; } |
| 481 | else condfailed(p); |
| 482 | continue; |
| 483 | } |
| 484 | case ISet: { |
| 485 | int c = (byte)*s; |
| 486 | if (testchar((p+1)->buff, c) && s < e) |
| 487 | { p += CHARSETINSTSIZE; s++; } |
| 488 | else condfailed(p); |
| 489 | continue; |
| 490 | } |
| 491 | case IBack: { |
| 492 | int n = p->i.aux; |
| 493 | if (n > s - o) goto fail; |
| 494 | s -= n; p++; |
| 495 | continue; |
| 496 | } |
| 497 | case ISpan: { |
no test coverage detected