Commit 38efa482 authored by Robert Foss's avatar Robert Foss
Browse files

Merge remote-tracking branch 'upstream/dev' into dev

parents d2fc8782 340edbbe
...@@ -13,7 +13,19 @@ ...@@ -13,7 +13,19 @@
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) #ifdef LUA_OPTIMIZE_DEBUG
# include "lvm.h"
# define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0)
# define INFO_FILL_BYTE 0x7F
# define INFO_DELTA_MASK 0x80
# define INFO_SIGN_MASK 0x40
# define INFO_DELTA_6BITS 0x3F
# define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126
# define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset)
#else
# define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
#endif
#define resethookcount(L) (L->hookcount = L->basehookcount) #define resethookcount(L) (L->hookcount = L->basehookcount)
...@@ -29,5 +41,9 @@ LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); ...@@ -29,5 +41,9 @@ LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC void luaG_errormsg (lua_State *L); LUAI_FUNC void luaG_errormsg (lua_State *L);
LUAI_FUNC int luaG_checkcode (const Proto *pt); LUAI_FUNC int luaG_checkcode (const Proto *pt);
LUAI_FUNC int luaG_checkopenop (Instruction i); LUAI_FUNC int luaG_checkopenop (Instruction i);
#ifdef LUA_OPTIMIZE_DEBUG
LUAI_FUNC int luaG_getline (const Proto *f, int pc);
LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv);
#endif
#endif #endif
...@@ -4,15 +4,14 @@ ...@@ -4,15 +4,14 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include <setjmp.h> #include <setjmp.h>
#include "c_stdlib.h"
#include "c_string.h"
#define ldo_c #define ldo_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
......
...@@ -4,13 +4,12 @@ ...@@ -4,13 +4,12 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include "c_stddef.h"
#include "c_string.h"
#define ldump_c #define ldump_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "lobject.h" #include "lobject.h"
#include "lstate.h" #include "lstate.h"
...@@ -73,18 +72,18 @@ static void DumpIntWithSize(int x, int sizeof_int, DumpState* D) ...@@ -73,18 +72,18 @@ static void DumpIntWithSize(int x, int sizeof_int, DumpState* D)
/* dump signed integer */ /* dump signed integer */
switch(sizeof_int) { switch(sizeof_int) {
case 1: { case 1: {
if (x>0x7F || x<(-0x80)) D->status=LUA_ERR_CC_INTOVERFLOW; if (x>0x7F || x<(-0x80)) D->status=LUA_ERR_CC_INTOVERFLOW;
DumpChar(x,D); DumpChar(x,D);
} break; } break;
case 2: { case 2: {
if (x>0x7FFF || x<(-0x8000)) D->status=LUA_ERR_CC_INTOVERFLOW; if (x>0x7FFF || x<(-0x8000)) D->status=LUA_ERR_CC_INTOVERFLOW;
int16_t y=(int16_t)x; int16_t y=(int16_t)x;
MaybeByteSwap((char*)&y,2,D); MaybeByteSwap((char*)&y,2,D);
DumpVar(y,D); DumpVar(y,D);
} break; } break;
case 4: { case 4: {
/* Need to reduce bounds by 1 to avoid messing 32-bit compilers up */ /* Need to reduce bounds by 1 to avoid messing 32-bit compilers up */
if (x>0x7FFFFFFE || x<(-0x7FFFFFFF)) D->status=LUA_ERR_CC_INTOVERFLOW; if (x>0x7FFFFFFE || x<(-0x7FFFFFFF)) D->status=LUA_ERR_CC_INTOVERFLOW;
int32_t y=(int32_t)x; int32_t y=(int32_t)x;
MaybeByteSwap((char*)&y,4,D); MaybeByteSwap((char*)&y,4,D);
DumpVar(y,D); DumpVar(y,D);
...@@ -103,7 +102,7 @@ static void DumpSize(uint32_t x, DumpState* D) ...@@ -103,7 +102,7 @@ static void DumpSize(uint32_t x, DumpState* D)
/* dump unsigned integer */ /* dump unsigned integer */
switch(D->target.sizeof_strsize_t) { switch(D->target.sizeof_strsize_t) {
case 1: { case 1: {
if (x>0xFF) D->status=LUA_ERR_CC_INTOVERFLOW; if (x>0xFF) D->status=LUA_ERR_CC_INTOVERFLOW;
DumpChar(x,D); DumpChar(x,D);
} break; } break;
case 2: { case 2: {
...@@ -145,8 +144,8 @@ static void DumpNumber(lua_Number x, DumpState* D) ...@@ -145,8 +144,8 @@ static void DumpNumber(lua_Number x, DumpState* D)
} break; } break;
case 8: { case 8: {
double y=x; double y=x;
// ARM FPA mode: keep endianness, but swap high and low parts of the // ARM FPA mode: keep endianness, but swap high and low parts of the
// memory representation. This is the default compilation mode for ARM // memory representation. This is the default compilation mode for ARM
// targets with non-EABI gcc // targets with non-EABI gcc
if(D->target.is_arm_fpa) if(D->target.is_arm_fpa)
{ {
...@@ -154,7 +153,7 @@ static void DumpNumber(lua_Number x, DumpState* D) ...@@ -154,7 +153,7 @@ static void DumpNumber(lua_Number x, DumpState* D)
c_memcpy(temp,pnum,4); c_memcpy(temp,pnum,4);
c_memcpy(pnum,pnum+4,4); c_memcpy(pnum,pnum+4,4);
c_memcpy(pnum+4,temp,4); c_memcpy(pnum+4,temp,4);
} }
MaybeByteSwap((char*)&y,8,D); MaybeByteSwap((char*)&y,8,D);
DumpVar(y,D); DumpVar(y,D);
} break; } break;
...@@ -229,6 +228,16 @@ static void DumpConstants(const Proto* f, DumpState* D) ...@@ -229,6 +228,16 @@ static void DumpConstants(const Proto* f, DumpState* D)
static void DumpDebug(const Proto* f, DumpState* D) static void DumpDebug(const Proto* f, DumpState* D)
{ {
int i,n; int i,n;
#ifdef LUA_OPTIMIZE_DEBUG
n = (D->strip || f->packedlineinfo == NULL) ? 0: c_strlen(cast(char *,f->packedlineinfo))+1;
DumpInt(n,D);
Align4(D);
if (n)
{
DumpBlock(f->packedlineinfo, n, D);
}
#else
n= (D->strip) ? 0 : f->sizelineinfo; n= (D->strip) ? 0 : f->sizelineinfo;
DumpInt(n,D); DumpInt(n,D);
Align4(D); Align4(D);
...@@ -236,7 +245,8 @@ static void DumpDebug(const Proto* f, DumpState* D) ...@@ -236,7 +245,8 @@ static void DumpDebug(const Proto* f, DumpState* D)
{ {
DumpInt(f->lineinfo[i],D); DumpInt(f->lineinfo[i],D);
} }
#endif
n= (D->strip) ? 0 : f->sizelocvars; n= (D->strip) ? 0 : f->sizelocvars;
DumpInt(n,D); DumpInt(n,D);
for (i=0; i<n; i++) for (i=0; i<n; i++)
...@@ -269,7 +279,7 @@ static void DumpHeader(DumpState* D) ...@@ -269,7 +279,7 @@ static void DumpHeader(DumpState* D)
{ {
char buf[LUAC_HEADERSIZE]; char buf[LUAC_HEADERSIZE];
char *h=buf; char *h=buf;
/* This code must be kept in sync wiht luaU_header */ /* This code must be kept in sync wiht luaU_header */
c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
h+=sizeof(LUA_SIGNATURE)-1; h+=sizeof(LUA_SIGNATURE)-1;
...@@ -281,7 +291,7 @@ static void DumpHeader(DumpState* D) ...@@ -281,7 +291,7 @@ static void DumpHeader(DumpState* D)
*h++=(char)sizeof(Instruction); *h++=(char)sizeof(Instruction);
*h++=(char)D->target.sizeof_lua_Number; *h++=(char)D->target.sizeof_lua_Number;
*h++=(char)D->target.lua_Number_integral; *h++=(char)D->target.lua_Number_integral;
DumpBlock(buf,LUAC_HEADERSIZE,D); DumpBlock(buf,LUAC_HEADERSIZE,D);
} }
......
...@@ -4,13 +4,12 @@ ...@@ -4,13 +4,12 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include "c_stddef.h"
#define lfunc_c #define lfunc_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "lfunc.h" #include "lfunc.h"
#include "lgc.h" #include "lgc.h"
...@@ -121,14 +120,18 @@ Proto *luaF_newproto (lua_State *L) { ...@@ -121,14 +120,18 @@ Proto *luaF_newproto (lua_State *L) {
f->sizep = 0; f->sizep = 0;
f->code = NULL; f->code = NULL;
f->sizecode = 0; f->sizecode = 0;
f->sizelineinfo = 0;
f->sizeupvalues = 0; f->sizeupvalues = 0;
f->nups = 0; f->nups = 0;
f->upvalues = NULL; f->upvalues = NULL;
f->numparams = 0; f->numparams = 0;
f->is_vararg = 0; f->is_vararg = 0;
f->maxstacksize = 0; f->maxstacksize = 0;
#ifdef LUA_OPTIMIZE_DEBUG
f->packedlineinfo = NULL;
#else
f->sizelineinfo = 0;
f->lineinfo = NULL; f->lineinfo = NULL;
#endif
f->sizelocvars = 0; f->sizelocvars = 0;
f->locvars = NULL; f->locvars = NULL;
f->linedefined = 0; f->linedefined = 0;
...@@ -145,7 +148,13 @@ void luaF_freeproto (lua_State *L, Proto *f) { ...@@ -145,7 +148,13 @@ void luaF_freeproto (lua_State *L, Proto *f) {
luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
if (!proto_is_readonly(f)) { if (!proto_is_readonly(f)) {
luaM_freearray(L, f->code, f->sizecode, Instruction); luaM_freearray(L, f->code, f->sizecode, Instruction);
#ifdef LUA_OPTIMIZE_DEBUG
if (f->packedlineinfo) {
luaM_freearray(L, f->packedlineinfo, c_strlen(cast(char *, f->packedlineinfo))+1, unsigned char);
}
#else
luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
#endif
} }
luaM_free(L, f); luaM_free(L, f);
} }
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include "c_string.h"
#define lgc_c #define lgc_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
...@@ -312,12 +312,19 @@ static l_mem propagatemark (global_State *g) { ...@@ -312,12 +312,19 @@ static l_mem propagatemark (global_State *g) {
Proto *p = gco2p(o); Proto *p = gco2p(o);
g->gray = p->gclist; g->gray = p->gclist;
traverseproto(g, p); traverseproto(g, p);
return sizeof(Proto) + sizeof(Proto *) * p->sizep + return sizeof(Proto) + sizeof(Proto *) * p->sizep +
sizeof(TValue) * p->sizek + sizeof(TValue) * p->sizek +
sizeof(LocVar) * p->sizelocvars + sizeof(LocVar) * p->sizelocvars +
sizeof(TString *) * p->sizeupvalues + sizeof(TString *) * p->sizeupvalues +
(proto_is_readonly(p) ? 0 : sizeof(Instruction) * p->sizecode + (proto_is_readonly(p) ? 0 : sizeof(Instruction) * p->sizecode +
#ifdef LUA_OPTIMIZE_DEBUG
(p->packedlineinfo ?
c_strlen(cast(char *, p->packedlineinfo))+1 :
0));
#else
sizeof(int) * p->sizelineinfo); sizeof(int) * p->sizelineinfo);
#endif
} }
default: lua_assert(0); return 0; default: lua_assert(0); return 0;
} }
...@@ -729,7 +736,7 @@ void luaC_linkupval (lua_State *L, UpVal *uv) { ...@@ -729,7 +736,7 @@ void luaC_linkupval (lua_State *L, UpVal *uv) {
GCObject *o = obj2gco(uv); GCObject *o = obj2gco(uv);
o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */
g->rootgc = o; g->rootgc = o;
if (isgray(o)) { if (isgray(o)) {
if (g->gcstate == GCSpropagate) { if (g->gcstate == GCSpropagate) {
gray2black(o); /* closed upvalues need barrier */ gray2black(o); /* closed upvalues need barrier */
luaC_barrier(L, uv, uv->v); luaC_barrier(L, uv, uv->v);
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
*/ */
#include "c_ctype.h"
#include "c_locale.h"
#include "c_string.h"
#define llex_c #define llex_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_CTYPE
#include C_HEADER_LOCALE
#include C_HEADER_STRING
#include "ldo.h" #include "ldo.h"
#include "llex.h" #include "llex.h"
......
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
//#include "c_limits.h" //#include "c_limits.h"
//#include "c_stddef.h"
#include "lua.h" #include "lua.h"
typedef LUAI_UINT32 lu_int32; typedef LUAI_UINT32 lu_int32;
typedef LUAI_UMEM lu_mem; typedef LUAI_UMEM lu_mem;
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
*/ */
#include "c_stdlib.h"
#include "c_math.h"
#define lmathlib_c #define lmathlib_c
#define LUA_LIB #define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDLIB
#include C_HEADER_MATH
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
...@@ -35,7 +35,7 @@ static int math_abs (lua_State *L) { ...@@ -35,7 +35,7 @@ static int math_abs (lua_State *L) {
} }
#ifndef LUA_NUMBER_INTEGRAL #ifndef LUA_NUMBER_INTEGRAL
#if 0
static int math_sin (lua_State *L) { static int math_sin (lua_State *L) {
lua_pushnumber(L, sin(luaL_checknumber(L, 1))); lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
return 1; return 1;
...@@ -85,6 +85,7 @@ static int math_atan2 (lua_State *L) { ...@@ -85,6 +85,7 @@ static int math_atan2 (lua_State *L) {
lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1; return 1;
} }
#endif
static int math_ceil (lua_State *L) { static int math_ceil (lua_State *L) {
lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
...@@ -95,7 +96,7 @@ static int math_floor (lua_State *L) { ...@@ -95,7 +96,7 @@ static int math_floor (lua_State *L) {
lua_pushnumber(L, floor(luaL_checknumber(L, 1))); lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
return 1; return 1;
} }
#if 0
static int math_fmod (lua_State *L) { static int math_fmod (lua_State *L) {
lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1; return 1;
...@@ -108,6 +109,7 @@ static int math_modf (lua_State *L) { ...@@ -108,6 +109,7 @@ static int math_modf (lua_State *L) {
lua_pushnumber(L, fp); lua_pushnumber(L, fp);
return 2; return 2;
} }
#endif
#else // #ifndef LUA_NUMBER_INTEGRAL #else // #ifndef LUA_NUMBER_INTEGRAL
...@@ -173,7 +175,7 @@ static int math_pow (lua_State *L) { ...@@ -173,7 +175,7 @@ static int math_pow (lua_State *L) {
#ifndef LUA_NUMBER_INTEGRAL #ifndef LUA_NUMBER_INTEGRAL
#if 0
static int math_log (lua_State *L) { static int math_log (lua_State *L) {
lua_pushnumber(L, log(luaL_checknumber(L, 1))); lua_pushnumber(L, log(luaL_checknumber(L, 1)));
return 1; return 1;
...@@ -210,6 +212,7 @@ static int math_ldexp (lua_State *L) { ...@@ -210,6 +212,7 @@ static int math_ldexp (lua_State *L) {
lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
return 1; return 1;
} }
#endif
#endif // #ifdef LUA_NUMBER_INTEGRAL #endif // #ifdef LUA_NUMBER_INTEGRAL
...@@ -306,6 +309,8 @@ static int math_randomseed (lua_State *L) { ...@@ -306,6 +309,8 @@ static int math_randomseed (lua_State *L) {
return 0; return 0;
} }
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE math_map[] = { const LUA_REG_TYPE math_map[] = {
......
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
*/ */
#include "c_stddef.h"
#define lmem_c #define lmem_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#define lmem_h #define lmem_h
//#ifdef LUA_CROSS_COMPILER
//#include <stddef.h>
//#else
//#include "c_stddef.h" //#include "c_stddef.h"
//#endif
#include "llimits.h" #include "llimits.h"
#include "lua.h" #include "lua.h"
......
...@@ -9,15 +9,18 @@ ...@@ -9,15 +9,18 @@
*/ */
#include "c_stdlib.h"
#include "c_string.h"
#include "c_fcntl.h"
#include "flash_fs.h"
#define loadlib_c #define loadlib_c
#define LUA_LIB #define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#include C_HEADER_FCNTL
#ifndef LUA_CROSS_COMPILER
#include "flash_fs.h"
#endif
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
...@@ -328,7 +331,7 @@ static int ll_loadlib (lua_State *L) { ...@@ -328,7 +331,7 @@ static int ll_loadlib (lua_State *L) {
** 'require' function ** 'require' function
** ======================================================= ** =======================================================
*/ */
#if 0 #ifdef LUA_CROSS_COMPILER
static int readable (const char *filename) { static int readable (const char *filename) {
FILE *f = c_fopen(filename, "r"); /* try to open file */ FILE *f = c_fopen(filename, "r"); /* try to open file */
if (f == NULL) return 0; /* open failed */ if (f == NULL) return 0; /* open failed */
...@@ -389,7 +392,7 @@ static int loader_Lua (lua_State *L) { ...@@ -389,7 +392,7 @@ static int loader_Lua (lua_State *L) {
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
filename = findfile(L, name, "path"); filename = findfile(L, name, "path");
if (filename == NULL) return 1; /* library not found in this path */ if (filename == NULL) return 1; /* library not found in this path */
#if 0 #ifdef LUA_CROSS_COMPILER
if (luaL_loadfile(L, filename) != 0) if (luaL_loadfile(L, filename) != 0)
#else #else
if (luaL_loadfsfile(L, filename) != 0) if (luaL_loadfsfile(L, filename) != 0)
......
...@@ -4,16 +4,15 @@ ...@@ -4,16 +4,15 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include "c_ctype.h"
#include "c_stdarg.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#define lobject_c #define lobject_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STRING
#include C_HEADER_STDLIB
#include "ldo.h" #include "ldo.h"
#include "lmem.h" #include "lmem.h"
...@@ -21,9 +20,11 @@ ...@@ -21,9 +20,11 @@
#include "lstate.h" #include "lstate.h"
#include "lstring.h" #include "lstring.h"
#include "lvm.h" #include "lvm.h"
#ifndef LUA_CROSS_COMPILER
#include "flash_api.h" #include "flash_api.h"
#else
#include <limits.h>
#endif
const TValue luaO_nilobject_ = {LUA_TVALUE_NIL}; const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
...@@ -64,9 +65,11 @@ int luaO_log2 (unsigned int x) { ...@@ -64,9 +65,11 @@ int luaO_log2 (unsigned int x) {
}; };
int l = -1; int l = -1;
while (x >= 256) { l += 8; x >>= 8; } while (x >= 256) { l += 8; x >>= 8; }
// return l + log_2[x]; #ifdef LUA_CROSS_COMPILER
return l + log_2[x];
#else
return l + byte_of_aligned_array(log_2,x); return l + byte_of_aligned_array(log_2,x);
#endif
} }
...@@ -95,7 +98,21 @@ int luaO_str2d (const char *s, lua_Number *result) { ...@@ -95,7 +98,21 @@ int luaO_str2d (const char *s, lua_Number *result) {
*result = lua_str2number(s, &endptr); *result = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* conversion failed */ if (endptr == s) return 0; /* conversion failed */
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
#if defined(LUA_CROSS_COMPILER)
{
long lres = strtoul(s, &endptr, 16);
#if LONG_MAX != 2147483647L
if (lres & ~0xffffffffL)
*result = cast_num(-1);
else if (lres & 0x80000000L)
*result = cast_num(lres | ~0x7fffffffL);
else
#endif
*result = cast_num(lres);
}
#else
*result = cast_num(c_strtoul(s, &endptr, 16)); *result = cast_num(c_strtoul(s, &endptr, 16));
#endif
if (*endptr == '\0') return 1; /* most common case */ if (*endptr == '\0') return 1; /* most common case */
while (isspace(cast(unsigned char, *endptr))) endptr++; while (isspace(cast(unsigned char, *endptr))) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */ if (*endptr != '\0') return 0; /* invalid trailing characters? */
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#ifndef lobject_h #ifndef lobject_h
#define lobject_h #define lobject_h
#ifdef LUA_CROSS_COMPILER
#include <stdarg.h>
#else
#include "c_stdarg.h" #include "c_stdarg.h"
#endif
#include "llimits.h" #include "llimits.h"
#include "lua.h" #include "lua.h"
...@@ -209,10 +211,10 @@ typedef TValuefields TValue; ...@@ -209,10 +211,10 @@ typedef TValuefields TValue;
#define setpvalue(obj,x) \ #define setpvalue(obj,x) \
{ void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTUSERDATA; } { void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTUSERDATA; }
#define setrvalue(obj,x) \ #define setrvalue(obj,x) \
{ void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TROTABLE; } { void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TROTABLE; }
#define setfvalue(obj,x) \ #define setfvalue(obj,x) \
{ void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTFUNCTION; } { void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTFUNCTION; }
...@@ -392,14 +394,20 @@ typedef struct Proto { ...@@ -392,14 +394,20 @@ typedef struct Proto {
TValue *k; /* constants used by the function */ TValue *k; /* constants used by the function */
Instruction *code; Instruction *code;
struct Proto **p; /* functions defined inside the function */ struct Proto **p; /* functions defined inside the function */
#ifdef LUA_OPTIMIZE_DEBUG
unsigned char *packedlineinfo;
#else
int *lineinfo; /* map from opcodes to source lines */ int *lineinfo; /* map from opcodes to source lines */
#endif
struct LocVar *locvars; /* information about local variables */ struct LocVar *locvars; /* information about local variables */
TString **upvalues; /* upvalue names */ TString **upvalues; /* upvalue names */
TString *source; TString *source;
int sizeupvalues; int sizeupvalues;
int sizek; /* size of `k' */ int sizek; /* size of `k' */
int sizecode; int sizecode;
#ifndef LUA_OPTIMIZE_DEBUG
int sizelineinfo; int sizelineinfo;
#endif
int sizep; /* size of `p' */ int sizep; /* size of `p' */
int sizelocvars; int sizelocvars;
int linedefined; int linedefined;
...@@ -508,7 +516,7 @@ typedef struct Node { ...@@ -508,7 +516,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; /* log2 of size of `node' array */
struct Table *metatable; struct Table *metatable;
TValue *array; /* array part */ TValue *array; /* array part */
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#define lopcodes_c #define lopcodes_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "luac_cross.h"
#include "lopcodes.h" #include "lopcodes.h"
/* ORDER OP */ /* ORDER OP */
const char *const luaP_opnames[NUM_OPCODES+1] = { const char *const luaP_opnames[NUM_OPCODES+1] = {
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
*/ */
#include "c_string.h"
#define lparser_c #define lparser_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "lcode.h" #include "lcode.h"
#include "ldebug.h" #include "ldebug.h"
...@@ -344,6 +344,12 @@ static void open_func (LexState *ls, FuncState *fs) { ...@@ -344,6 +344,12 @@ static void open_func (LexState *ls, FuncState *fs) {
fs->bl = NULL; fs->bl = NULL;
f->source = ls->source; f->source = ls->source;
f->maxstacksize = 2; /* registers 0/1 are always valid */ f->maxstacksize = 2; /* registers 0/1 are always valid */
#ifdef LUA_OPTIMIZE_DEBUG
fs->packedlineinfoSize = 0;
fs->lastline = 0;
fs->lastlineOffset = 0;
fs->lineinfoLastPC = -1;
#endif
fs->h = luaH_new(L, 0, 0); fs->h = luaH_new(L, 0, 0);
/* anchor table of constants and prototype (to avoid being collected) */ /* anchor table of constants and prototype (to avoid being collected) */
sethvalue2s(L, L->top, fs->h); sethvalue2s(L, L->top, fs->h);
...@@ -361,8 +367,15 @@ static void close_func (LexState *ls) { ...@@ -361,8 +367,15 @@ static void close_func (LexState *ls) {
luaK_ret(fs, 0, 0); /* final return */ luaK_ret(fs, 0, 0); /* final return */
luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
f->sizecode = fs->pc; f->sizecode = fs->pc;
#ifdef LUA_OPTIMIZE_DEBUG
f->packedlineinfo[fs->lastlineOffset+1]=0;
luaM_reallocvector(L, f->packedlineinfo, fs->packedlineinfoSize,
fs->lastlineOffset+2, unsigned char);
#else
luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
f->sizelineinfo = fs->pc; f->sizelineinfo = fs->pc;
#endif
luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
f->sizek = fs->nk; f->sizek = fs->nk;
luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
...@@ -379,6 +392,21 @@ static void close_func (LexState *ls) { ...@@ -379,6 +392,21 @@ static void close_func (LexState *ls) {
L->top -= 2; /* remove table and prototype from the stack */ L->top -= 2; /* remove table and prototype from the stack */
} }
#ifdef LUA_OPTIMIZE_DEBUG
static void compile_stripdebug(lua_State *L, Proto *f) {
int level;
lua_pushlightuserdata(L, &luaG_stripdebug );
lua_gettable(L, LUA_REGISTRYINDEX);
level = lua_isnil(L, -1) ? LUA_OPTIMIZE_DEBUG : lua_tointeger(L, -1);
lua_pop(L, 1);
if (level > 1) {
int len = luaG_stripdebug(L, f, level, 1);
UNUSED(len);
}
}
#endif
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
struct LexState lexstate; struct LexState lexstate;
...@@ -394,6 +422,9 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { ...@@ -394,6 +422,9 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
chunk(&lexstate); chunk(&lexstate);
check(&lexstate, TK_EOS); check(&lexstate, TK_EOS);
close_func(&lexstate); close_func(&lexstate);
#ifdef LUA_OPTIMIZE_DEBUG
compile_stripdebug(L, funcstate.f);
#endif
L->top--; /* remove 'name' from stack */ L->top--; /* remove 'name' from stack */
lua_assert(funcstate.prev == NULL); lua_assert(funcstate.prev == NULL);
lua_assert(funcstate.f->nups == 0); lua_assert(funcstate.f->nups == 0);
......
...@@ -72,6 +72,12 @@ typedef struct FuncState { ...@@ -72,6 +72,12 @@ typedef struct FuncState {
lu_byte nactvar; /* number of active local variables */ lu_byte nactvar; /* number of active local variables */
upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
#ifdef LUA_OPTIMIZE_DEBUG
int packedlineinfoSize; /* only used during compilation for line info */
int lastline; /* ditto */
int lastlineOffset; /* ditto */
int lineinfoLastPC; /* ditto */
#endif
} FuncState; } FuncState;
......
/* Read-only tables for Lua */ /* Read-only tables for Lua */
#define LUAC_CROSS_FILE
#include "c_string.h"
#include "lrotable.h"
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "lrotable.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lstring.h" #include "lstring.h"
#include "lobject.h" #include "lobject.h"
......
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
*/ */
#include "c_stddef.h"
#define lstate_c #define lstate_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
*/ */
#include "c_string.h"
#define lstring_c #define lstring_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING
#include "lmem.h" #include "lmem.h"
#include "lobject.h" #include "lobject.h"
......
...@@ -5,16 +5,13 @@ ...@@ -5,16 +5,13 @@
*/ */
#include "c_ctype.h"
#include "c_stddef.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#define lstrlib_c #define lstrlib_c
#define LUA_LIB #define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STRING
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment