Move a GC macro.
[luajit-2.0/celess22.git] / src / lj_lex.h
blob7a4fd74b41817109a252fbdbd9e61088aae9752f
1 /*
2 ** Lexical analyzer.
3 ** Major parts taken verbatim from the Lua interpreter.
4 ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
5 */
7 #ifndef _LJ_LEX_H
8 #define _LJ_LEX_H
10 #include <stdarg.h>
12 #include "lj_obj.h"
13 #include "lj_err.h"
15 /* Lua lexer tokens. */
16 #define TKDEF(_, __) \
17 _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \
18 _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \
19 _(repeat) _(return) _(then) _(true) _(until) _(while) \
20 __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \
21 __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \
22 __(eof, <eof>)
24 enum {
25 TK_OFS = 256,
26 #define TKENUM1(name) TK_##name,
27 #define TKENUM2(name, sym) TK_##name,
28 TKDEF(TKENUM1, TKENUM2)
29 #undef TKENUM1
30 #undef TKENUM2
31 TK_RESERVED = TK_while - TK_OFS
34 typedef int LexToken;
36 /* Combined bytecode ins/line. Only used during bytecode generation. */
37 typedef struct BCInsLine {
38 BCIns ins; /* Bytecode instruction. */
39 BCLine line; /* Line number for this bytecode. */
40 } BCInsLine;
42 /* Info for local variables. Only used during bytecode generation. */
43 typedef struct VarInfo {
44 GCRef name; /* Local variable name. */
45 BCPos startpc; /* First point where the local variable is active. */
46 BCPos endpc; /* First point where the local variable is dead. */
47 } VarInfo;
49 /* Lua lexer state. */
50 typedef struct LexState {
51 struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */
52 struct lua_State *L; /* Lua state. */
53 TValue tokenval; /* Current token value. */
54 TValue lookaheadval; /* Lookahead token value. */
55 int current; /* Current character (charint). */
56 LexToken token; /* Current token. */
57 LexToken lookahead; /* Lookahead token. */
58 MSize n; /* Bytes left in input buffer. */
59 const char *p; /* Current position in input buffer. */
60 SBuf sb; /* String buffer for tokens. */
61 lua_Reader rfunc; /* Reader callback. */
62 void *rdata; /* Reader callback data. */
63 BCLine linenumber; /* Input line counter. */
64 BCLine lastline; /* Line of last token. */
65 GCstr *chunkname; /* Current chunk name (interned string). */
66 const char *chunkarg; /* Chunk name argument. */
67 const char *mode; /* Allow loading bytecode (b) and/or source text (t). */
68 VarInfo *vstack; /* Stack for names and extents of local variables. */
69 MSize sizevstack; /* Size of variable stack. */
70 MSize vtop; /* Top of variable stack. */
71 BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */
72 MSize sizebcstack; /* Size of bytecode stack. */
73 uint32_t level; /* Syntactical nesting level. */
74 } LexState;
76 LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);
77 LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);
78 LJ_FUNC void lj_lex_next(LexState *ls);
79 LJ_FUNC LexToken lj_lex_lookahead(LexState *ls);
80 LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token);
81 LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...);
82 LJ_FUNC void lj_lex_init(lua_State *L);
84 #endif