The goal of stage 06 is to try parse zig synax in lua. I pulled in lpeglable 1.2.0 and parser-gen off github to get started. All of this needs to be cleaned up rather soon. Lua boostraps using tcc and musl from the previous stage. Since musl 0.6.0 doesn't support dynamic linking this build of lua doesn't support shared libraries. I couldn't easily patch musl with dlopen and friends so instead I link statically and call deps with c api.
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
/*
|
|
** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $
|
|
*/
|
|
|
|
#if !defined(lpvm_h)
|
|
#define lpvm_h
|
|
|
|
#include "lpcap.h"
|
|
|
|
|
|
/* Virtual Machine's instructions */
|
|
typedef enum Opcode {
|
|
IAny, /* if no char, fail */
|
|
IChar, /* if char != aux, fail */
|
|
ISet, /* if char not in buff, fail */
|
|
ITestAny, /* in no char, jump to 'offset' */
|
|
ITestChar, /* if char != aux, jump to 'offset' */
|
|
ITestSet, /* if char not in buff, jump to 'offset' */
|
|
ISpan, /* read a span of chars in buff */
|
|
IBehind, /* walk back 'aux' characters (fail if not possible) */
|
|
IRet, /* return from a rule */
|
|
IEnd, /* end of pattern */
|
|
IChoice, /* stack a choice; next fail will jump to 'offset' */
|
|
IJmp, /* jump to 'offset' */
|
|
ICall, /* call rule at 'offset' */
|
|
IOpenCall, /* call rule number 'key' (must be closed to a ICall) */
|
|
ICommit, /* pop choice and jump to 'offset' */
|
|
IPartialCommit, /* update top choice to current position and jump */
|
|
IBackCommit, /* "fails" but jump to its own 'offset' */
|
|
IFailTwice, /* pop one choice and then fail */
|
|
IFail, /* go back to saved state on choice and jump to saved offset */
|
|
IGiveup, /* internal use */
|
|
IFullCapture, /* complete capture of last 'off' chars */
|
|
IOpenCapture, /* start a capture */
|
|
ICloseCapture,
|
|
ICloseRunTime,
|
|
IThrow, /* "fails" with a specific label labeled failure */
|
|
IRecov /* stack a recovery; next fail with label 'f' will jump to 'offset' */
|
|
} Opcode;
|
|
|
|
|
|
|
|
typedef union Instruction {
|
|
struct Inst {
|
|
byte code;
|
|
byte aux;
|
|
short key;
|
|
} i;
|
|
int offset;
|
|
byte buff[1];
|
|
} Instruction;
|
|
|
|
|
|
void printpatt (Instruction *p, int n);
|
|
const char *match (lua_State *L, const char *o, const char *s, const char *e,
|
|
Instruction *op, Capture *capture, int ptop, byte *labelf, const char **sfail); /* labeled failure */
|
|
|
|
|
|
#endif
|
|
|