Path: blob/main/sys/contrib/openzfs/module/lua/lparser.h
48383 views
// SPDX-License-Identifier: MIT1/*2** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $3** Lua Parser4** See Copyright Notice in lua.h5*/67#ifndef lparser_h8#define lparser_h910#include "llimits.h"11#include "lobject.h"12#include "lzio.h"131415/*16** Expression descriptor17*/1819typedef enum {20VVOID, /* no value */21VNIL,22VTRUE,23VFALSE,24VK, /* info = index of constant in `k' */25VKNUM, /* nval = numerical value */26VNONRELOC, /* info = result register */27VLOCAL, /* info = local register */28VUPVAL, /* info = index of upvalue in 'upvalues' */29VINDEXED, /* t = table register/upvalue; idx = index R/K */30VJMP, /* info = instruction pc */31VRELOCABLE, /* info = instruction pc */32VCALL, /* info = instruction pc */33VVARARG /* info = instruction pc */34} expkind;353637#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)38#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)3940typedef struct expdesc {41expkind k;42union {43struct { /* for indexed variables (VINDEXED) */44short idx; /* index (R/K) */45lu_byte t; /* table (register or upvalue) */46lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */47} ind;48int info; /* for generic use */49lua_Number nval; /* for VKNUM */50} u;51int t; /* patch list of `exit when true' */52int f; /* patch list of `exit when false' */53} expdesc;545556/* description of active local variable */57typedef struct Vardesc {58short idx; /* variable index in stack */59} Vardesc;606162/* description of pending goto statements and label statements */63typedef struct Labeldesc {64TString *name; /* label identifier */65int pc; /* position in code */66int line; /* line where it appeared */67lu_byte nactvar; /* local level where it appears in current block */68} Labeldesc;697071/* list of labels or gotos */72typedef struct Labellist {73Labeldesc *arr; /* array */74int n; /* number of entries in use */75int size; /* array size */76} Labellist;777879/* dynamic structures used by the parser */80typedef struct Dyndata {81struct { /* list of active local variables */82Vardesc *arr;83int n;84int size;85} actvar;86Labellist gt; /* list of pending gotos */87Labellist label; /* list of active labels */88} Dyndata;899091/* control of blocks */92struct BlockCnt; /* defined in lparser.c */939495/* state needed to generate code for a given function */96typedef struct FuncState {97Proto *f; /* current function header */98Table *h; /* table to find (and reuse) elements in `k' */99struct FuncState *prev; /* enclosing function */100struct LexState *ls; /* lexical state */101struct BlockCnt *bl; /* chain of current blocks */102int pc; /* next position to code (equivalent to `ncode') */103int lasttarget; /* 'label' of last 'jump label' */104int jpc; /* list of pending jumps to `pc' */105int nk; /* number of elements in `k' */106int np; /* number of elements in `p' */107int firstlocal; /* index of first local var (in Dyndata array) */108short nlocvars; /* number of elements in 'f->locvars' */109lu_byte nactvar; /* number of active local variables */110lu_byte nups; /* number of upvalues */111lu_byte freereg; /* first free register */112} FuncState;113114115LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,116Dyndata *dyd, const char *name, int firstchar);117118119#endif120121122