lpvm.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #if !defined(lpvm_h)
  2. #define lpvm_h
  3. #include "lpcap.h"
  4. /*
  5. ** About Character sets in instructions: a set is a bit map with an
  6. ** initial offset, in bits, and a size, in number of instructions.
  7. ** aux1 has the default value for the bits outsize that range.
  8. */
  9. /* Virtual Machine's instructions */
  10. typedef enum Opcode {
  11. IAny, /* if no char, fail */
  12. IChar, /* if char != aux1, fail */
  13. ISet, /* if char not in set, fail */
  14. ITestAny, /* in no char, jump to 'offset' */
  15. ITestChar, /* if char != aux1, jump to 'offset' */
  16. ITestSet, /* if char not in set, jump to 'offset' */
  17. ISpan, /* read a span of chars in set */
  18. IUTFR, /* if codepoint not in range [offset, utf_to], fail */
  19. IBehind, /* walk back 'aux1' characters (fail if not possible) */
  20. IRet, /* return from a rule */
  21. IEnd, /* end of pattern */
  22. IChoice, /* stack a choice; next fail will jump to 'offset' */
  23. IJmp, /* jump to 'offset' */
  24. ICall, /* call rule at 'offset' */
  25. IOpenCall, /* call rule number 'key' (must be closed to a ICall) */
  26. ICommit, /* pop choice and jump to 'offset' */
  27. IPartialCommit, /* update top choice to current position and jump */
  28. IBackCommit, /* backtrack like "fail" but jump to its own 'offset' */
  29. IFailTwice, /* pop one choice and then fail */
  30. IFail, /* go back to saved state on choice and jump to saved offset */
  31. IGiveup, /* internal use */
  32. IFullCapture, /* complete capture of last 'off' chars */
  33. IOpenCapture, /* start a capture */
  34. ICloseCapture,
  35. ICloseRunTime,
  36. IEmpty /* to fill empty slots left by optimizations */
  37. } Opcode;
  38. /*
  39. ** All array of instructions has a 'codesize' as its first element
  40. ** and is referred by a pointer to its second element, which is the
  41. ** first actual opcode.
  42. */
  43. typedef union Instruction {
  44. struct Inst {
  45. byte code;
  46. byte aux1;
  47. union {
  48. short key;
  49. struct {
  50. byte offset;
  51. byte size;
  52. } set;
  53. } aux2;
  54. } i;
  55. int offset;
  56. uint codesize;
  57. byte buff[1];
  58. } Instruction;
  59. /* extract 24-bit value from an instruction */
  60. #define utf_to(inst) (((inst)->i.aux2.key << 8) | (inst)->i.aux1)
  61. int charinset (const Instruction *i, const byte *buff, uint c);
  62. const char *match (lua_State *L, const char *o, const char *s, const char *e,
  63. Instruction *op, Capture *capture, int ptop);
  64. #endif