aboutsummaryrefslogtreecommitdiff
path: root/lplvm.h
diff options
context:
space:
mode:
Diffstat (limited to 'lplvm.h')
-rw-r--r--lplvm.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/lplvm.h b/lplvm.h
new file mode 100644
index 0000000..19a1502
--- /dev/null
+++ b/lplvm.h
@@ -0,0 +1,66 @@
1/*
2** $Id: lplvm.h $
3*/
4
5#if !defined(lplvm_h)
6#define lplvm_h
7
8#include "lplcap.h"
9
10
11/* Virtual Machine's instructions */
12typedef enum Opcode {
13 IAny, /* if no char, fail */
14 IChar, /* if char != aux, fail */
15 ISet, /* if char not in buff, fail */
16 ITestAny, /* in no char, jump to 'offset' */
17 ITestChar, /* if char != aux, jump to 'offset' */
18 ITestSet, /* if char not in buff, jump to 'offset' */
19 ISpan, /* read a span of chars in buff */
20 IUTFR, /* if codepoint not in range [offset, utf_to], fail */
21 IBehind, /* walk back 'aux' characters (fail if not possible) */
22 IRet, /* return from a rule */
23 IEnd, /* end of pattern */
24 IChoice, /* stack a choice; next fail will jump to 'offset' */
25 IPredChoice, /* labeld failure: stack a choice; changes label env next fail will jump to 'offset' */ /*labeled failure */
26 IJmp, /* jump to 'offset' */
27 ICall, /* call rule at 'offset' */
28 IOpenCall, /* call rule number 'key' (must be closed to a ICall) */
29 ICommit, /* pop choice and jump to 'offset' */
30 IPartialCommit, /* update top choice to current position and jump */
31 IBackCommit, /* backtrack like "fail" but jump to its own 'offset' */
32 IFailTwice, /* pop one choice and then fail */
33 IFail, /* go back to saved state on choice and jump to saved offset */
34 IGiveup, /* internal use */
35 IFullCapture, /* complete capture of last 'off' chars */
36 IOpenCapture, /* start a capture */
37 ICloseCapture,
38 ICloseRunTime,
39 IThrow, /* fails with a given label */ /*labeled failure */
40 IThrowRec, /* fails with a given label and call rule at 'offset' */ /*labeled failure */
41 IEmpty /* to fill empty slots left by optimizations */
42} Opcode;
43
44
45
46typedef union Instruction {
47 struct Inst {
48 byte code;
49 byte aux;
50 short key;
51 } i;
52 int offset;
53 byte buff[1];
54} Instruction;
55
56
57/* extract 24-bit value from an instruction */
58#define utf_to(inst) (((inst)->i.key << 8) | (inst)->i.aux)
59
60
61LUAI_FUNC void printpatt (Instruction *p, int n);
62LUAI_FUNC const char *match (lua_State *L, const char *o, const char *s, const char *e,
63 Instruction *op, Capture *capture, int ptop, short *labelf, const char **sfail); /* labeled failure */
64
65#endif
66