mirror of
https://github.com/opentx/opentx.git
synced 2025-07-17 13:25:20 +03:00
RAM saving in the Lua interpreter
This commit is contained in:
parent
950f651af9
commit
f94b4c743d
4 changed files with 23 additions and 17 deletions
|
@ -29,7 +29,7 @@ static const luaL_Reg loadedlibs[] = {
|
||||||
{"_G", luaopen_base},
|
{"_G", luaopen_base},
|
||||||
// {LUA_LOADLIBNAME, luaopen_package},
|
// {LUA_LOADLIBNAME, luaopen_package},
|
||||||
// {LUA_COLIBNAME, luaopen_coroutine},
|
// {LUA_COLIBNAME, luaopen_coroutine},
|
||||||
{LUA_TABLIBNAME, luaopen_table},
|
// {LUA_TABLIBNAME, luaopen_table},
|
||||||
// {LUA_IOLIBNAME, luaopen_io},
|
// {LUA_IOLIBNAME, luaopen_io},
|
||||||
// {LUA_OSLIBNAME, luaopen_os},
|
// {LUA_OSLIBNAME, luaopen_os},
|
||||||
// {LUA_STRLIBNAME, luaopen_string},
|
// {LUA_STRLIBNAME, luaopen_string},
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MINSIZEARRAY 4
|
#define MINSIZEARRAY 2
|
||||||
|
|
||||||
void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
|
void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
|
||||||
int limit, const char *what) {
|
int limit, const char *what) {
|
||||||
|
@ -80,6 +80,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
|
||||||
if (nsize > realosize && g->gcrunning)
|
if (nsize > realosize && g->gcrunning)
|
||||||
luaC_fullgc(L, 1); /* force a GC whenever possible */
|
luaC_fullgc(L, 1); /* force a GC whenever possible */
|
||||||
#endif
|
#endif
|
||||||
|
// TRACE("ALLOC %d %d", (int)osize, (int)nsize);
|
||||||
newblock = (*g->frealloc)(g->ud, block, osize, nsize);
|
newblock = (*g->frealloc)(g->ud, block, osize, nsize);
|
||||||
if (newblock == NULL && nsize > 0) {
|
if (newblock == NULL && nsize > 0) {
|
||||||
api_check(L, nsize > realosize,
|
api_check(L, nsize > realosize,
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
#ifndef lobject_h
|
#ifndef lobject_h
|
||||||
#define lobject_h
|
#define lobject_h
|
||||||
|
|
||||||
|
#ifndef PACK
|
||||||
|
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
@ -101,9 +104,9 @@ typedef union Value Value;
|
||||||
** an actual value plus a tag with its type.
|
** an actual value plus a tag with its type.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define TValuefields Value value_; int tt_
|
#define TValuefields Value value_; int8_t tt_
|
||||||
|
|
||||||
typedef struct lua_TValue TValue;
|
#define TValue lua_TValue
|
||||||
|
|
||||||
|
|
||||||
/* macro defining a nil value */
|
/* macro defining a nil value */
|
||||||
|
@ -394,9 +397,9 @@ union Value {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct lua_TValue {
|
PACK(typedef struct {
|
||||||
TValuefields;
|
TValuefields;
|
||||||
};
|
}) lua_TValue;
|
||||||
|
|
||||||
|
|
||||||
typedef TValue *StkId; /* index to stack elements */
|
typedef TValue *StkId; /* index to stack elements */
|
||||||
|
@ -543,10 +546,10 @@ typedef union Closure {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef union TKey {
|
typedef union TKey {
|
||||||
struct {
|
PACK(struct {
|
||||||
TValuefields;
|
TValuefields;
|
||||||
struct Node *next; /* for chaining */
|
struct Node *next; /* for chaining */
|
||||||
} nk;
|
}) nk;
|
||||||
TValue tvk;
|
TValue tvk;
|
||||||
} TKey;
|
} TKey;
|
||||||
|
|
||||||
|
@ -560,7 +563,7 @@ typedef struct Node {
|
||||||
typedef struct Table {
|
typedef struct Table {
|
||||||
CommonHeader;
|
CommonHeader;
|
||||||
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
||||||
lu_byte lsizenode; /* log2 of size of `node' array */
|
lu_byte lsizenode; /* size of `node' array */
|
||||||
struct Table *metatable;
|
struct Table *metatable;
|
||||||
TValue *array; /* array part */
|
TValue *array; /* array part */
|
||||||
Node *node;
|
Node *node;
|
||||||
|
@ -579,7 +582,7 @@ typedef struct Table {
|
||||||
|
|
||||||
|
|
||||||
#define twoto(x) (1<<(x))
|
#define twoto(x) (1<<(x))
|
||||||
#define sizenode(t) (twoto((t)->lsizenode))
|
#define sizenode(t) ((t)->lsizenode)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -282,14 +282,16 @@ static void setnodevector (lua_State *L, Table *t, int size) {
|
||||||
int lsize;
|
int lsize;
|
||||||
if (size == 0) { /* no elements to hash part? */
|
if (size == 0) { /* no elements to hash part? */
|
||||||
t->node = cast(Node *, dummynode); /* use common `dummynode' */
|
t->node = cast(Node *, dummynode); /* use common `dummynode' */
|
||||||
lsize = 0;
|
lsize = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i;
|
int i;
|
||||||
lsize = luaO_ceillog2(size);
|
// lsize = luaO_ceillog2(size);
|
||||||
if (lsize > MAXBITS)
|
// if (lsize > MAXBITS)
|
||||||
luaG_runerror(L, "table overflow");
|
// luaG_runerror(L, "table overflow");
|
||||||
size = twoto(lsize);
|
// size = twoto(lsize);
|
||||||
|
// size += size/2;
|
||||||
|
lsize = size;
|
||||||
t->node = luaM_newvector(L, size, Node);
|
t->node = luaM_newvector(L, size, Node);
|
||||||
for (i=0; i<size; i++) {
|
for (i=0; i<size; i++) {
|
||||||
Node *n = gnode(t, i);
|
Node *n = gnode(t, i);
|
||||||
|
@ -322,7 +324,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
|
||||||
luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
|
luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
|
||||||
}
|
}
|
||||||
/* re-insert elements from hash part */
|
/* re-insert elements from hash part */
|
||||||
for (i = twoto(oldhsize) - 1; i >= 0; i--) {
|
for (i = oldhsize - 1; i >= 0; i--) {
|
||||||
Node *old = nold+i;
|
Node *old = nold+i;
|
||||||
if (!ttisnil(gval(old))) {
|
if (!ttisnil(gval(old))) {
|
||||||
/* doesn't need barrier/invalidate cache, as entry was
|
/* doesn't need barrier/invalidate cache, as entry was
|
||||||
|
@ -331,7 +333,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isdummy(nold))
|
if (!isdummy(nold))
|
||||||
luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
|
luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old array */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue