aboutsummaryrefslogtreecommitdiff
path: root/lpvm.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-29 09:39:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-29 09:39:03 -0300
commit44fab2a44d06a956c3121ceba2b39ca7b00dc428 (patch)
tree9f492ba2ebaa4fb3cf6554fcb63f3fe026d43a5d /lpvm.h
parent460a35cbcb33fbc56f5a658b96a793b9bb8963e9 (diff)
downloadlpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.tar.gz
lpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.tar.bz2
lpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.zip
Code size stored in code itself
Most patterns do not have code, as they are not directly used for a match; they are created only to compose larger patterns. So, we shouldn't waste space to store the size of their code, as a NULL pointer already indicates that the size is zero.
Diffstat (limited to 'lpvm.h')
-rw-r--r--lpvm.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/lpvm.h b/lpvm.h
index a64d577..684f0c9 100644
--- a/lpvm.h
+++ b/lpvm.h
@@ -43,7 +43,11 @@ typedef enum Opcode {
43} Opcode; 43} Opcode;
44 44
45 45
46 46/*
47** All array of instructions has a 'codesize' as its first element
48** and is referred by a pointer to its second element, which is the
49** first actual opcode.
50*/
47typedef union Instruction { 51typedef union Instruction {
48 struct Inst { 52 struct Inst {
49 byte code; 53 byte code;
@@ -57,6 +61,7 @@ typedef union Instruction {
57 } aux2; 61 } aux2;
58 } i; 62 } i;
59 int offset; 63 int offset;
64 uint codesize;
60 byte buff[1]; 65 byte buff[1];
61} Instruction; 66} Instruction;
62 67
@@ -66,7 +71,6 @@ typedef union Instruction {
66 71
67 72
68int charinset (const Instruction *i, const byte *buff, uint c); 73int charinset (const Instruction *i, const byte *buff, uint c);
69void printpatt (Instruction *p, int n);
70const char *match (lua_State *L, const char *o, const char *s, const char *e, 74const char *match (lua_State *L, const char *o, const char *s, const char *e,
71 Instruction *op, Capture *capture, int ptop); 75 Instruction *op, Capture *capture, int ptop);
72 76