#if !defined rplx_h
#define rplx_h
#include <limits.h>
#include <inttypes.h>
#include "config.h"
#include "ktable.h"
#define BITSPERCHAR 8
#define CHARSETSIZE ((UCHAR_MAX/BITSPERCHAR) + 1)
#define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1)
#define CHARSETINSTSIZE instsize(CHARSETSIZE)
typedef struct Charset {
byte cs[CHARSETSIZE];
} Charset;
#define opcode(pc) ((pc)->i.code)
#define setopcode(pc, op) ((pc)->i.code) = (op)
#define addr(pc) ((pc+1)->offset)
#define setaddr(pc, addr) (pc+1)->offset = (addr)
#define index(pc) ((pc)->i.aux)
#define setindex(pc, idx) (pc)->i.aux = ((idx) & 0xFFFFFF)
#define ichar(pc) ((pc)->i.aux & 0xFF)
#define setichar(pc, c) (pc)->i.aux = ((pc)->i.aux & 0xFFFF00) | (c & 0xFF)
typedef struct CodeAux {
uint8_t code;
unsigned int aux : 24;
} CodeAux;
typedef union Instruction {
CodeAux i;
int32_t offset;
uint8_t buff[1];
} Instruction;
typedef enum Opcode {
IGiveup = 0,
IAny,
IRet,
IEnd,
IHalt,
IFailTwice,
IFail,
ICloseCapture,
IBehind,
IBackref,
IChar,
ICloseConstCapture,
ISet,
ISpan,
IPartialCommit,
ITestAny,
IJmp,
ICall,
IOpenCall,
IChoice,
ICommit,
IBackCommit,
IOpenCapture,
ITestChar,
ITestSet,
} Opcode;
#define OPCODE_NAME(code) (OPCODE_NAMES[code])
static const char *const OPCODE_NAMES[] = {
"giveup",
"any",
"ret",
"end",
"halt",
"failtwice",
"fail",
"closecapture",
"behind",
"backref",
"char",
"closeconstcapture",
"set",
"span",
"partialcommit",
"testany",
"jmp",
"call",
"opencall",
"choice",
"commit",
"backcommit",
"opencapture",
"testchar",
"testset",
};
typedef struct Chunk {
size_t codesize;
Instruction *code;
Ktable *ktable;
unsigned short rpl_major;
unsigned short rpl_minor;
char *filename;
unsigned short file_version;
} Chunk;
void rplx_free(Chunk *c);
#endif