diff options
author | Richard Quirk <richard.quirk@gmail.com> | 2014-03-19 19:31:31 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:31:54 +0200 |
commit | 36378988ad4059982742f05f5eb50580b456840a (patch) | |
tree | ee70be810d894566c5e351f21a1ebb79be742a85 /apps/plugins/lua/lparser.h | |
parent | 020f16a1c7d5bc9a302671cef03f56ac735e20c5 (diff) | |
download | rockbox-36378988ad4059982742f05f5eb50580b456840a.tar.gz rockbox-36378988ad4059982742f05f5eb50580b456840a.zip |
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'apps/plugins/lua/lparser.h')
-rw-r--r-- | apps/plugins/lua/lparser.h | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/apps/plugins/lua/lparser.h b/apps/plugins/lua/lparser.h index f9b8e24913..0346e3c41a 100644 --- a/apps/plugins/lua/lparser.h +++ b/apps/plugins/lua/lparser.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id$ | 2 | ** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,34 +23,72 @@ typedef enum { | |||
23 | VFALSE, | 23 | VFALSE, |
24 | VK, /* info = index of constant in `k' */ | 24 | VK, /* info = index of constant in `k' */ |
25 | VKNUM, /* nval = numerical value */ | 25 | VKNUM, /* nval = numerical value */ |
26 | VNONRELOC, /* info = result register */ | ||
26 | VLOCAL, /* info = local register */ | 27 | VLOCAL, /* info = local register */ |
27 | VUPVAL, /* info = index of upvalue in `upvalues' */ | 28 | VUPVAL, /* info = index of upvalue in 'upvalues' */ |
28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ | 29 | VINDEXED, /* t = table register/upvalue; idx = index R/K */ |
29 | VINDEXED, /* info = table register; aux = index register (or `k') */ | ||
30 | VJMP, /* info = instruction pc */ | 30 | VJMP, /* info = instruction pc */ |
31 | VRELOCABLE, /* info = instruction pc */ | 31 | VRELOCABLE, /* info = instruction pc */ |
32 | VNONRELOC, /* info = result register */ | ||
33 | VCALL, /* info = instruction pc */ | 32 | VCALL, /* info = instruction pc */ |
34 | VVARARG /* info = instruction pc */ | 33 | VVARARG /* info = instruction pc */ |
35 | } expkind; | 34 | } expkind; |
36 | 35 | ||
36 | |||
37 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) | ||
38 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) | ||
39 | |||
37 | typedef struct expdesc { | 40 | typedef struct expdesc { |
38 | expkind k; | 41 | expkind k; |
39 | union { | 42 | union { |
40 | struct { int info, aux; } s; | 43 | struct { /* for indexed variables (VINDEXED) */ |
41 | lua_Number nval; | 44 | short idx; /* index (R/K) */ |
45 | lu_byte t; /* table (register or upvalue) */ | ||
46 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ | ||
47 | } ind; | ||
48 | int info; /* for generic use */ | ||
49 | lua_Number nval; /* for VKNUM */ | ||
42 | } u; | 50 | } u; |
43 | int t; /* patch list of `exit when true' */ | 51 | int t; /* patch list of `exit when true' */ |
44 | int f; /* patch list of `exit when false' */ | 52 | int f; /* patch list of `exit when false' */ |
45 | } expdesc; | 53 | } expdesc; |
46 | 54 | ||
47 | 55 | ||
48 | typedef struct upvaldesc { | 56 | /* description of active local variable */ |
49 | lu_byte k; | 57 | typedef struct Vardesc { |
50 | lu_byte info; | 58 | short idx; /* variable index in stack */ |
51 | } upvaldesc; | 59 | } Vardesc; |
60 | |||
61 | |||
62 | /* description of pending goto statements and label statements */ | ||
63 | typedef struct Labeldesc { | ||
64 | TString *name; /* label identifier */ | ||
65 | int pc; /* position in code */ | ||
66 | int line; /* line where it appeared */ | ||
67 | lu_byte nactvar; /* local level where it appears in current block */ | ||
68 | } Labeldesc; | ||
69 | |||
70 | |||
71 | /* list of labels or gotos */ | ||
72 | typedef struct Labellist { | ||
73 | Labeldesc *arr; /* array */ | ||
74 | int n; /* number of entries in use */ | ||
75 | int size; /* array size */ | ||
76 | } Labellist; | ||
77 | |||
78 | |||
79 | /* dynamic structures used by the parser */ | ||
80 | typedef struct Dyndata { | ||
81 | struct { /* list of active local variables */ | ||
82 | Vardesc *arr; | ||
83 | int n; | ||
84 | int size; | ||
85 | } actvar; | ||
86 | Labellist gt; /* list of pending gotos */ | ||
87 | Labellist label; /* list of active labels */ | ||
88 | } Dyndata; | ||
52 | 89 | ||
53 | 90 | ||
91 | /* control of blocks */ | ||
54 | struct BlockCnt; /* defined in lparser.c */ | 92 | struct BlockCnt; /* defined in lparser.c */ |
55 | 93 | ||
56 | 94 | ||
@@ -60,23 +98,22 @@ typedef struct FuncState { | |||
60 | Table *h; /* table to find (and reuse) elements in `k' */ | 98 | Table *h; /* table to find (and reuse) elements in `k' */ |
61 | struct FuncState *prev; /* enclosing function */ | 99 | struct FuncState *prev; /* enclosing function */ |
62 | struct LexState *ls; /* lexical state */ | 100 | struct LexState *ls; /* lexical state */ |
63 | struct lua_State *L; /* copy of the Lua state */ | ||
64 | struct BlockCnt *bl; /* chain of current blocks */ | 101 | struct BlockCnt *bl; /* chain of current blocks */ |
65 | int pc; /* next position to code (equivalent to `ncode') */ | 102 | int pc; /* next position to code (equivalent to `ncode') */ |
66 | int lasttarget; /* `pc' of last `jump target' */ | 103 | int lasttarget; /* 'label' of last 'jump label' */ |
67 | int jpc; /* list of pending jumps to `pc' */ | 104 | int jpc; /* list of pending jumps to `pc' */ |
68 | int freereg; /* first free register */ | ||
69 | int nk; /* number of elements in `k' */ | 105 | int nk; /* number of elements in `k' */ |
70 | int np; /* number of elements in `p' */ | 106 | int np; /* number of elements in `p' */ |
71 | short nlocvars; /* number of elements in `locvars' */ | 107 | int firstlocal; /* index of first local var (in Dyndata array) */ |
108 | short nlocvars; /* number of elements in 'f->locvars' */ | ||
72 | lu_byte nactvar; /* number of active local variables */ | 109 | lu_byte nactvar; /* number of active local variables */ |
73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ | 110 | lu_byte nups; /* number of upvalues */ |
74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ | 111 | lu_byte freereg; /* first free register */ |
75 | } FuncState; | 112 | } FuncState; |
76 | 113 | ||
77 | 114 | ||
78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | 115 | LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, |
79 | const char *name); | 116 | Dyndata *dyd, const char *name, int firstchar); |
80 | 117 | ||
81 | 118 | ||
82 | #endif | 119 | #endif |