Cleanup architecture, ABI and OS definitions.

This commit is contained in:
Mike Pall 2010-11-16 14:06:59 +01:00
parent 1de05d1147
commit 24baf77955
19 changed files with 113 additions and 72 deletions

View File

@ -336,7 +336,7 @@ ifeq (Windows,$(TARGET_SYS))
LUAJIT_SO= $(TARGET_DLLNAME) LUAJIT_SO= $(TARGET_DLLNAME)
LUAJIT_T= luajit.exe LUAJIT_T= luajit.exe
ifneq ($(HOST_SYS),$(TARGET_SYS)) ifneq ($(HOST_SYS),$(TARGET_SYS))
HOST_XCFLAGS+= -malign-double HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
endif endif
# Mixed mode is not supported on Windows. And static mode doesn't work well. # Mixed mode is not supported on Windows. And static mode doesn't work well.
# C modules cannot be loaded, because they bind to lua51.dll. # C modules cannot be loaded, because they bind to lua51.dll.

View File

@ -23,7 +23,7 @@
#include "lj_dispatch.h" #include "lj_dispatch.h"
#include "luajit.h" #include "luajit.h"
#ifdef LUA_USE_WIN #if defined(_WIN32)
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#endif #endif
@ -64,11 +64,12 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);
#define DASM_ALIGNED_WRITES 1 #define DASM_ALIGNED_WRITES 1
/* Embed architecture-specific DynASM encoder and backend. */ /* Embed architecture-specific DynASM encoder and backend. */
#if LJ_TARGET_X86ORX64 #if LJ_TARGET_X86
#include "../dynasm/dasm_x86.h" #include "../dynasm/dasm_x86.h"
#if LJ_32
#include "buildvm_x86.h" #include "buildvm_x86.h"
#elif defined(_WIN64) #elif LJ_TARGET_X64
#include "../dynasm/dasm_x86.h"
#if LJ_ABI_WIN
#include "buildvm_x64win.h" #include "buildvm_x64win.h"
#else #else
#include "buildvm_x64.h" #include "buildvm_x64.h"
@ -449,7 +450,7 @@ int main(int argc, char **argv)
if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') {
ctx->fp = stdout; ctx->fp = stdout;
#ifdef LUA_USE_WIN #if defined(_WIN32)
if (binmode) if (binmode)
_setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */
#endif #endif

View File

@ -114,9 +114,9 @@ static int io_file_close(lua_State *L, IOFileUD *iof)
if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) { if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) {
ok = (fclose(iof->fp) == 0); ok = (fclose(iof->fp) == 0);
} else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) { } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {
#if defined(LUA_USE_POSIX) #if LJ_TARGET_POSIX
ok = (pclose(iof->fp) != -1); ok = (pclose(iof->fp) != -1);
#elif defined(LUA_USE_WIN) #elif LJ_TARGET_WINDOWS
ok = (_pclose(iof->fp) != -1); ok = (_pclose(iof->fp) != -1);
#else #else
ok = 0; ok = 0;
@ -289,7 +289,7 @@ LJLIB_CF(io_method_seek)
, ,
ofs = 0; ofs = 0;
) )
#if defined(LUA_USE_POSIX) #if LJ_TARGET_POSIX
res = fseeko(fp, (int64_t)ofs, opt); res = fseeko(fp, (int64_t)ofs, opt);
#elif _MSC_VER >= 1400 #elif _MSC_VER >= 1400
res = _fseeki64(fp, (int64_t)ofs, opt); res = _fseeki64(fp, (int64_t)ofs, opt);
@ -300,7 +300,7 @@ LJLIB_CF(io_method_seek)
#endif #endif
if (res) if (res)
return io_pushresult(L, 0, NULL); return io_pushresult(L, 0, NULL);
#if defined(LUA_USE_POSIX) #if LJ_TARGET_POSIX
ofs = cast_num(ftello(fp)); ofs = cast_num(ftello(fp));
#elif _MSC_VER >= 1400 #elif _MSC_VER >= 1400
ofs = cast_num(_ftelli64(fp)); ofs = cast_num(_ftelli64(fp));
@ -374,13 +374,13 @@ LJLIB_CF(io_open)
LJLIB_CF(io_popen) LJLIB_CF(io_popen)
{ {
#if defined(LUA_USE_POSIX) || defined(LUA_USE_WIN) #if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS
const char *fname = strdata(lj_lib_checkstr(L, 1)); const char *fname = strdata(lj_lib_checkstr(L, 1));
GCstr *s = lj_lib_optstr(L, 2); GCstr *s = lj_lib_optstr(L, 2);
const char *mode = s ? strdata(s) : "r"; const char *mode = s ? strdata(s) : "r";
IOFileUD *iof = io_file_new(L); IOFileUD *iof = io_file_new(L);
iof->type = IOFILE_TYPE_PIPE; iof->type = IOFILE_TYPE_PIPE;
#ifdef LUA_USE_POSIX #if LJ_TARGET_POSIX
fflush(NULL); fflush(NULL);
iof->fp = popen(fname, mode); iof->fp = popen(fname, mode);
#else #else

View File

@ -17,16 +17,16 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#ifdef LUA_USE_POSIX #include "lj_obj.h"
#include "lj_err.h"
#include "lj_lib.h"
#if LJ_TARGET_POSIX
#include <unistd.h> #include <unistd.h>
#else #else
#include <stdio.h> #include <stdio.h>
#endif #endif
#include "lj_obj.h"
#include "lj_err.h"
#include "lj_lib.h"
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
#define LJLIB_MODULE_os #define LJLIB_MODULE_os
@ -66,7 +66,7 @@ LJLIB_CF(os_rename)
LJLIB_CF(os_tmpname) LJLIB_CF(os_tmpname)
{ {
#ifdef LUA_USE_POSIX #if LJ_TARGET_POSIX
char buf[15+1]; char buf[15+1];
int fp; int fp;
strcpy(buf, "/tmp/lua_XXXXXX"); strcpy(buf, "/tmp/lua_XXXXXX");

View File

@ -27,7 +27,7 @@
#define PACKAGE_LIB_FAIL "open" #define PACKAGE_LIB_FAIL "open"
#define setprogdir(L) ((void)0) #define setprogdir(L) ((void)0)
#if defined(LUA_DL_DLOPEN) #if LJ_TARGET_DLOPEN
#include <dlfcn.h> #include <dlfcn.h>
@ -50,7 +50,7 @@ static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
return f; return f;
} }
#elif defined(LUA_DL_DLL) #elif LJ_TARGET_WINDOWS
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -107,7 +107,7 @@ static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
#undef PACKAGE_LIB_FAIL #undef PACKAGE_LIB_FAIL
#define PACKAGE_LIB_FAIL "absent" #define PACKAGE_LIB_FAIL "absent"
#define DLMSG "dynamic libraries not enabled; check your Lua installation" #define DLMSG "dynamic libraries not enabled; no support for target OS"
static void ll_unloadlib(void *lib) static void ll_unloadlib(void *lib)
{ {

View File

@ -72,7 +72,7 @@
#define IS_DIRECT_BIT (SIZE_T_ONE) #define IS_DIRECT_BIT (SIZE_T_ONE)
#ifdef LUA_USE_WIN #if LJ_TARGET_WINDOWS
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -166,13 +166,12 @@ static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
#if LJ_64 #if LJ_64
/* 64 bit mode needs special support for allocating memory in the lower 2GB. */ /* 64 bit mode needs special support for allocating memory in the lower 2GB. */
#if defined(__linux__) #if LJ_TARGET_LINUX
/* Actually this only gives us max. 1GB in current Linux kernels. */ /* Actually this only gives us max. 1GB in current Linux kernels. */
#define CALL_MMAP(s) mmap(NULL, (s), MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0) #define CALL_MMAP(s) mmap(NULL, (s), MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0)
#elif (defined(__MACH__) && defined(__APPLE__)) || \ #elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
/* OSX and FreeBSD mmap() use a naive first-fit linear search. /* OSX and FreeBSD mmap() use a naive first-fit linear search.
** That's perfect for us. Except that -pagezero_size must be set for OSX, ** That's perfect for us. Except that -pagezero_size must be set for OSX,
@ -233,7 +232,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t size)
#define DIRECT_MMAP(s) CALL_MMAP(s) #define DIRECT_MMAP(s) CALL_MMAP(s)
#define CALL_MUNMAP(a, s) munmap((a), (s)) #define CALL_MUNMAP(a, s) munmap((a), (s))
#ifdef __linux__ #if LJ_TARGET_LINUX
/* Need to define _GNU_SOURCE to get the mremap prototype. */ /* Need to define _GNU_SOURCE to get the mremap prototype. */
#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) #define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv))
#define CALL_MREMAP_NOMOVE 0 #define CALL_MREMAP_NOMOVE 0
@ -420,7 +419,7 @@ typedef struct malloc_state *mstate;
(((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\ (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\
& ~(DEFAULT_GRANULARITY - SIZE_T_ONE)) & ~(DEFAULT_GRANULARITY - SIZE_T_ONE))
#ifdef LUA_USE_WIN #if LJ_TARGET_WINDOWS
#define mmap_align(S) granularity_align(S) #define mmap_align(S) granularity_align(S)
#else #else
#define mmap_align(S) page_align(S) #define mmap_align(S) page_align(S)

View File

@ -8,7 +8,6 @@
#include "lua.h" #include "lua.h"
/* Target endianess. */ /* Target endianess. */
#define LUAJIT_LE 0 #define LUAJIT_LE 0
#define LUAJIT_BE 1 #define LUAJIT_BE 1
@ -23,6 +22,13 @@
#define LUAJIT_ARCH_PPCSPE 4 #define LUAJIT_ARCH_PPCSPE 4
#define LUAJIT_ARCH_ppcspe 4 #define LUAJIT_ARCH_ppcspe 4
/* Target OS. */
#define LUAJIT_OS_OTHER 0
#define LUAJIT_OS_WINDOWS 1
#define LUAJIT_OS_LINUX 2
#define LUAJIT_OS_OSX 3
#define LUAJIT_OS_BSD 4
#define LUAJIT_OS_POSIX 5
/* Select native target if no target defined. */ /* Select native target if no target defined. */
#ifndef LUAJIT_TARGET #ifndef LUAJIT_TARGET
@ -43,15 +49,58 @@
#endif #endif
/* Set target properties. */ /* Select native OS if no target OS defined. */
#ifndef LUAJIT_OS
#if defined(_WIN32)
#define LUAJIT_OS LUAJIT_OS_WINDOWS
#elif defined(__linux__)
#define LUAJIT_OS LUAJIT_OS_LINUX
#elif defined(__MACH__) && defined(__APPLE__)
#define LUAJIT_OS LUAJIT_OS_OSX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
defined(__NetBSD__) || defined(__OpenBSD__)
#define LUAJIT_OS LUAJIT_OS_BSD
#elif defined(__solaris__) || defined(__CYGWIN__)
#define LUAJIT_OS LUAJIT_OS_POSIX
#else
#define LUAJIT_OS LUAJIT_OS_OTHER
#endif
#endif
/* Set target OS properties. */
#if LUAJIT_OS == LUAJIT_OS_WINDOWS
#define LJ_OS_NAME "Windows"
#elif LUAJIT_OS == LUAJIT_OS_LINUX
#define LJ_OS_NAME "Linux"
#elif LUAJIT_OS == LUAJIT_OS_OSX
#define LJ_OS_NAME "OSX"
#elif LUAJIT_OS == LUAJIT_OS_BSD
#define LJ_OS_NAME "BSD"
#elif LUAJIT_OS == LUAJIT_OS_POSIX
#define LJ_OS_NAME "Posix"
#else
#define LJ_OS_NAME "Other"
#endif
#define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
#define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
/* Set target architecture properties. */
#if LUAJIT_TARGET == LUAJIT_ARCH_X86 #if LUAJIT_TARGET == LUAJIT_ARCH_X86
#define LJ_ARCH_NAME "x86" #define LJ_ARCH_NAME "x86"
#define LJ_ARCH_BITS 32 #define LJ_ARCH_BITS 32
#define LJ_ARCH_ENDIAN LUAJIT_LE #define LJ_ARCH_ENDIAN LUAJIT_LE
#define LJ_ARCH_BITENDIAN LUAJIT_LE
#define LJ_ARCH_HASFPU 1
#define LJ_ABI_WIN LJ_TARGET_WINDOWS
#define LJ_TARGET_X86 1 #define LJ_TARGET_X86 1
#define LJ_TARGET_X86ORX64 1 #define LJ_TARGET_X86ORX64 1
#define LJ_PAGESIZE 4096
#define LJ_TARGET_EHRETREG 0 #define LJ_TARGET_EHRETREG 0
#define LJ_TARGET_MASKSHIFT 1 #define LJ_TARGET_MASKSHIFT 1
#define LJ_TARGET_MASKROT 1 #define LJ_TARGET_MASKROT 1
@ -61,9 +110,11 @@
#define LJ_ARCH_NAME "x64" #define LJ_ARCH_NAME "x64"
#define LJ_ARCH_BITS 64 #define LJ_ARCH_BITS 64
#define LJ_ARCH_ENDIAN LUAJIT_LE #define LJ_ARCH_ENDIAN LUAJIT_LE
#define LJ_ARCH_BITENDIAN LUAJIT_LE
#define LJ_ARCH_HASFPU 1
#define LJ_ABI_WIN LJ_TARGET_WINDOWS
#define LJ_TARGET_X64 1 #define LJ_TARGET_X64 1
#define LJ_TARGET_X86ORX64 1 #define LJ_TARGET_X86ORX64 1
#define LJ_PAGESIZE 4096
#define LJ_TARGET_EHRETREG 0 #define LJ_TARGET_EHRETREG 0
#define LJ_TARGET_MASKSHIFT 1 #define LJ_TARGET_MASKSHIFT 1
#define LJ_TARGET_MASKROT 1 #define LJ_TARGET_MASKROT 1
@ -77,9 +128,12 @@
#define LJ_ARCH_NAME "ppcspe" #define LJ_ARCH_NAME "ppcspe"
#define LJ_ARCH_BITS 32 #define LJ_ARCH_BITS 32
#define LJ_ARCH_ENDIAN LUAJIT_BE #define LJ_ARCH_ENDIAN LUAJIT_BE
#define LJ_ARCH_BITENDIAN LUAJIT_BE
#define LJ_ARCH_HASFPU 1
#define LJ_ABI_SOFTFP 1
#define LJ_ABI_EABI 1
#define LJ_TARGET_PPC 1 #define LJ_TARGET_PPC 1
#define LJ_TARGET_PPCSPE 1 #define LJ_TARGET_PPCSPE 1
#define LJ_PAGESIZE 4096
#define LJ_TARGET_EHRETREG 3 #define LJ_TARGET_EHRETREG 3
#define LJ_TARGET_MASKSHIFT 0 #define LJ_TARGET_MASKSHIFT 0
#define LJ_TARGET_MASKROT 1 #define LJ_TARGET_MASKROT 1
@ -89,6 +143,10 @@
#error "No target architecture defined" #error "No target architecture defined"
#endif #endif
#ifndef LJ_PAGESIZE
#define LJ_PAGESIZE 4096
#endif
/* Check for minimum required compiler versions. */ /* Check for minimum required compiler versions. */
#if defined(__GNUC__) #if defined(__GNUC__)
#if LJ_TARGET_X64 #if LJ_TARGET_X64

View File

@ -1345,7 +1345,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
for (n = 0; n < nargs; n++) { /* Setup args. */ for (n = 0; n < nargs; n++) { /* Setup args. */
IRIns *ir = IR(args[n]); IRIns *ir = IR(args[n]);
Reg r; Reg r;
#if LJ_64 && defined(_WIN64) #if LJ_64 && LJ_ABI_WIN
/* Windows/x64 argument registers are strictly positional. */ /* Windows/x64 argument registers are strictly positional. */
r = irt_isnum(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31); r = irt_isnum(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);
fpr++; gprs >>= 5; fpr++; gprs >>= 5;
@ -3518,11 +3518,7 @@ static void asm_setup_regsp(ASMState *as, GCtrace *T)
const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
#if LJ_64 #if LJ_64
/* NYI: add stack slots for x64 calls with many args. */ /* NYI: add stack slots for x64 calls with many args. */
#ifdef _WIN64 lua_assert(CCI_NARGS(ci) <= (LJ_ABI_WIN ? 4 : 6));
lua_assert(CCI_NARGS(ci) <= 4);
#else
lua_assert(CCI_NARGS(ci) <= 6); /* Safe lower bound. */
#endif
ir->prev = REGSP_HINT(irt_isnum(ir->t) ? RID_FPRET : RID_RET); ir->prev = REGSP_HINT(irt_isnum(ir->t) ? RID_FPRET : RID_RET);
#else #else
/* NYI: not fastcall-aware, but doesn't matter (yet). */ /* NYI: not fastcall-aware, but doesn't matter (yet). */

View File

@ -63,15 +63,11 @@
** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. ** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13.
*/ */
#if defined(__GNUC__) #if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL))
#if LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)
#define LJ_UNWIND_EXT 1 #define LJ_UNWIND_EXT 1
#endif #elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS
#elif defined(LUA_USE_WIN)
#if LJ_TARGET_X64
#define LJ_UNWIND_EXT 1 #define LJ_UNWIND_EXT 1
#endif #endif
#endif
/* -- Error messages ------------------------------------------------------ */ /* -- Error messages ------------------------------------------------------ */
@ -604,7 +600,7 @@ static void err_raise_ext(int errcode)
} }
#endif #endif
#elif defined(_WIN64) #elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS
/* /*
** Someone in Redmond owes me several days of my life. A lot of this is ** Someone in Redmond owes me several days of my life. A lot of this is

View File

@ -57,7 +57,7 @@ ERRDEF(NOENV, "no calling environment")
ERRDEF(CYIELD, "attempt to yield across C-call boundary") ERRDEF(CYIELD, "attempt to yield across C-call boundary")
ERRDEF(BADLU, "bad light userdata pointer") ERRDEF(BADLU, "bad light userdata pointer")
ERRDEF(NOGCMM, "bad action while in __gc metamethod") ERRDEF(NOGCMM, "bad action while in __gc metamethod")
#ifdef LUA_USE_WIN #if LJ_TARGET_WINDOWS
ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)") ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)")
#endif #endif

View File

@ -69,7 +69,7 @@ enum {
#define CFRAME_SIZE_JIT CFRAME_SIZE #define CFRAME_SIZE_JIT CFRAME_SIZE
#define CFRAME_SHIFT_MULTRES 0 #define CFRAME_SHIFT_MULTRES 0
#elif LJ_TARGET_X64 #elif LJ_TARGET_X64
#if _WIN64 #if LJ_ABI_WIN
#define CFRAME_OFS_PREV (13*8) #define CFRAME_OFS_PREV (13*8)
#define CFRAME_OFS_PC (25*4) #define CFRAME_OFS_PC (25*4)
#define CFRAME_OFS_L (24*4) #define CFRAME_OFS_L (24*4)

View File

@ -335,7 +335,7 @@ static const ELFheader elfhdr_template = {
.eclass = LJ_64 ? 2 : 1, .eclass = LJ_64 ? 2 : 1,
.eendian = LJ_ENDIAN_SELECT(1, 2), .eendian = LJ_ENDIAN_SELECT(1, 2),
.eversion = 1, .eversion = 1,
#if defined(__linux__) #if LJ_TARGET_LINUX
.eosabi = 0, /* Nope, it's not 3. */ .eosabi = 0, /* Nope, it's not 3. */
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
.eosabi = 9, .eosabi = 9,

View File

@ -55,7 +55,7 @@
(JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_FUSE) (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_FUSE)
#define JIT_F_OPT_DEFAULT JIT_F_OPT_3 #define JIT_F_OPT_DEFAULT JIT_F_OPT_3
#if defined(LUA_USE_WIN) || LJ_64 #if LJ_TARGET_WINDOWS || LJ_64
/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ /* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
#define JIT_P_sizemcode_DEFAULT 64 #define JIT_P_sizemcode_DEFAULT 64
#else #else

View File

@ -49,7 +49,7 @@ LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);
#define lj_lib_upvalue(L, n) \ #define lj_lib_upvalue(L, n) \
(&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1]) (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])
#ifdef LUA_USE_WIN #if LJ_TARGET_WINDOWS
#define lj_lib_checkfpu(L) \ #define lj_lib_checkfpu(L) \
do { setnumV(L->top++, (lua_Number)1437217655); \ do { setnumV(L->top++, (lua_Number)1437217655); \
if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \ if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \

View File

@ -19,7 +19,7 @@
/* -- OS-specific functions ----------------------------------------------- */ /* -- OS-specific functions ----------------------------------------------- */
#if defined(LUA_USE_WIN) #if LJ_TARGET_WINDOWS
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -49,7 +49,7 @@ static void mcode_setprot(void *p, size_t sz, DWORD prot)
VirtualProtect(p, sz, prot, &oprot); VirtualProtect(p, sz, prot, &oprot);
} }
#elif defined(LUA_USE_POSIX) #elif LJ_TARGET_POSIX
#include <sys/mman.h> #include <sys/mman.h>
@ -82,7 +82,7 @@ static void mcode_setprot(void *p, size_t sz, int prot)
#elif LJ_64 #elif LJ_64
#error "Missing OS support for allocating executable memory" #error "Missing OS support for explicit placement of executable memory"
#else #else

View File

@ -719,7 +719,7 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
return (int32_t)o.u32.lo; return (int32_t)o.u32.lo;
} }
#if (defined(__i386__) || defined(_M_IX86)) && !defined(__SSE2__) #if LJ_TARGET_X86 && !defined(__SSE2__)
#define lj_num2int(n) lj_num2bit((n)) #define lj_num2int(n) lj_num2bit((n))
#else #else
#define lj_num2int(n) ((int32_t)(n)) #define lj_num2int(n) ((int32_t)(n))

View File

@ -40,7 +40,7 @@ enum {
/* These definitions must match with the *.dasc file(s): */ /* These definitions must match with the *.dasc file(s): */
RID_BASE = RID_EDX, /* Interpreter BASE. */ RID_BASE = RID_EDX, /* Interpreter BASE. */
#if LJ_64 && !defined(_WIN64) #if LJ_64 && !LJ_ABI_WIN
RID_PC = RID_EBX, /* Interpreter PC. */ RID_PC = RID_EBX, /* Interpreter PC. */
RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */ RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */
#else #else
@ -74,7 +74,7 @@ enum {
/* ABI-specific register sets. */ /* ABI-specific register sets. */
#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX)) #define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))
#if LJ_64 #if LJ_64
#ifdef _WIN64 #if LJ_ABI_WIN
/* Windows x64 ABI. */ /* Windows x64 ABI. */
#define RSET_SCRATCH \ #define RSET_SCRATCH \
(RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1)) (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))
@ -117,7 +117,7 @@ enum {
** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. ** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
*/ */
#if LJ_64 #if LJ_64
#ifdef _WIN64 #if LJ_ABI_WIN
#define SPS_FIXED (4*2) #define SPS_FIXED (4*2)
#define SPS_FIRST (4*2) /* Don't use callee register save area. */ #define SPS_FIRST (4*2) /* Don't use callee register save area. */
#else #else

View File

@ -9,19 +9,8 @@
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
/* Try to determine supported features for a couple of standard platforms. */
#if defined(_WIN32)
#define LUA_USE_WIN
#define LUA_DL_DLL
#elif defined(__linux__) || defined(__solaris__) || defined(__CYGWIN__) || \
defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__FreeBSD_kernel__) || (defined(__MACH__) && defined(__APPLE__))
#define LUA_USE_POSIX
#define LUA_DL_DLOPEN
#endif
/* Default path for loading Lua and C modules with require(). */ /* Default path for loading Lua and C modules with require(). */
#ifdef LUA_USE_WIN #if defined(_WIN32)
/* /*
** In Windows, any exclamation mark ('!') in the path is replaced by the ** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process. ** path of the directory of the executable file of the current process.
@ -58,7 +47,7 @@
#define LUA_INIT "LUA_INIT" #define LUA_INIT "LUA_INIT"
/* Special file system characters. */ /* Special file system characters. */
#ifdef LUA_USE_WIN #if defined(_WIN32)
#define LUA_DIRSEP "\\" #define LUA_DIRSEP "\\"
#else #else
#define LUA_DIRSEP "/" #define LUA_DIRSEP "/"

View File

@ -18,10 +18,12 @@
#include "lualib.h" #include "lualib.h"
#include "luajit.h" #include "luajit.h"
#if defined(LUA_USE_POSIX) #include "lj_arch.h"
#if LJ_TARGET_POSIX
#include <unistd.h> #include <unistd.h>
#define lua_stdin_is_tty() isatty(0) #define lua_stdin_is_tty() isatty(0)
#elif defined(LUA_USE_WIN) #elif LJ_TARGET_WINDOWS
#include <io.h> #include <io.h>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#define lua_stdin_is_tty() isatty(_fileno(stdin)) #define lua_stdin_is_tty() isatty(_fileno(stdin))