aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-11-16 14:06:59 +0100
committerMike Pall <mike>2010-11-16 15:03:40 +0100
commit24baf7795574ca40be2c2be8da8cd483551a546a (patch)
treee3e2629947dc8c8bd2d25d7a6c9ab7db54f814a1 /src
parent1de05d1147a6fe69b55111d605eccdedc8c6c993 (diff)
downloadluajit-24baf7795574ca40be2c2be8da8cd483551a546a.tar.gz
luajit-24baf7795574ca40be2c2be8da8cd483551a546a.tar.bz2
luajit-24baf7795574ca40be2c2be8da8cd483551a546a.zip
Cleanup architecture, ABI and OS definitions.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/buildvm.c11
-rw-r--r--src/lib_io.c12
-rw-r--r--src/lib_os.c12
-rw-r--r--src/lib_package.c6
-rw-r--r--src/lj_alloc.c11
-rw-r--r--src/lj_arch.h68
-rw-r--r--src/lj_asm.c8
-rw-r--r--src/lj_err.c10
-rw-r--r--src/lj_errmsg.h2
-rw-r--r--src/lj_frame.h2
-rw-r--r--src/lj_gdbjit.c2
-rw-r--r--src/lj_jit.h2
-rw-r--r--src/lj_lib.h2
-rw-r--r--src/lj_mcode.c6
-rw-r--r--src/lj_obj.h2
-rw-r--r--src/lj_target_x86.h6
-rw-r--r--src/luaconf.h15
-rw-r--r--src/luajit.c6
19 files changed, 113 insertions, 72 deletions
diff --git a/src/Makefile b/src/Makefile
index bae6691e..da9f67b2 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -336,7 +336,7 @@ ifeq (Windows,$(TARGET_SYS))
336 LUAJIT_SO= $(TARGET_DLLNAME) 336 LUAJIT_SO= $(TARGET_DLLNAME)
337 LUAJIT_T= luajit.exe 337 LUAJIT_T= luajit.exe
338 ifneq ($(HOST_SYS),$(TARGET_SYS)) 338 ifneq ($(HOST_SYS),$(TARGET_SYS))
339 HOST_XCFLAGS+= -malign-double 339 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
340 endif 340 endif
341 # Mixed mode is not supported on Windows. And static mode doesn't work well. 341 # Mixed mode is not supported on Windows. And static mode doesn't work well.
342 # C modules cannot be loaded, because they bind to lua51.dll. 342 # C modules cannot be loaded, because they bind to lua51.dll.
diff --git a/src/buildvm.c b/src/buildvm.c
index 382550b8..72e612c1 100644
--- a/src/buildvm.c
+++ b/src/buildvm.c
@@ -23,7 +23,7 @@
23#include "lj_dispatch.h" 23#include "lj_dispatch.h"
24#include "luajit.h" 24#include "luajit.h"
25 25
26#ifdef LUA_USE_WIN 26#if defined(_WIN32)
27#include <fcntl.h> 27#include <fcntl.h>
28#include <io.h> 28#include <io.h>
29#endif 29#endif
@@ -64,11 +64,12 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);
64#define DASM_ALIGNED_WRITES 1 64#define DASM_ALIGNED_WRITES 1
65 65
66/* Embed architecture-specific DynASM encoder and backend. */ 66/* Embed architecture-specific DynASM encoder and backend. */
67#if LJ_TARGET_X86ORX64 67#if LJ_TARGET_X86
68#include "../dynasm/dasm_x86.h" 68#include "../dynasm/dasm_x86.h"
69#if LJ_32
70#include "buildvm_x86.h" 69#include "buildvm_x86.h"
71#elif defined(_WIN64) 70#elif LJ_TARGET_X64
71#include "../dynasm/dasm_x86.h"
72#if LJ_ABI_WIN
72#include "buildvm_x64win.h" 73#include "buildvm_x64win.h"
73#else 74#else
74#include "buildvm_x64.h" 75#include "buildvm_x64.h"
@@ -449,7 +450,7 @@ int main(int argc, char **argv)
449 450
450 if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { 451 if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') {
451 ctx->fp = stdout; 452 ctx->fp = stdout;
452#ifdef LUA_USE_WIN 453#if defined(_WIN32)
453 if (binmode) 454 if (binmode)
454 _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ 455 _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */
455#endif 456#endif
diff --git a/src/lib_io.c b/src/lib_io.c
index 787fdc6b..878b98af 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -114,9 +114,9 @@ static int io_file_close(lua_State *L, IOFileUD *iof)
114 if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) { 114 if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) {
115 ok = (fclose(iof->fp) == 0); 115 ok = (fclose(iof->fp) == 0);
116 } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) { 116 } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {
117#if defined(LUA_USE_POSIX) 117#if LJ_TARGET_POSIX
118 ok = (pclose(iof->fp) != -1); 118 ok = (pclose(iof->fp) != -1);
119#elif defined(LUA_USE_WIN) 119#elif LJ_TARGET_WINDOWS
120 ok = (_pclose(iof->fp) != -1); 120 ok = (_pclose(iof->fp) != -1);
121#else 121#else
122 ok = 0; 122 ok = 0;
@@ -289,7 +289,7 @@ LJLIB_CF(io_method_seek)
289 , 289 ,
290 ofs = 0; 290 ofs = 0;
291 ) 291 )
292#if defined(LUA_USE_POSIX) 292#if LJ_TARGET_POSIX
293 res = fseeko(fp, (int64_t)ofs, opt); 293 res = fseeko(fp, (int64_t)ofs, opt);
294#elif _MSC_VER >= 1400 294#elif _MSC_VER >= 1400
295 res = _fseeki64(fp, (int64_t)ofs, opt); 295 res = _fseeki64(fp, (int64_t)ofs, opt);
@@ -300,7 +300,7 @@ LJLIB_CF(io_method_seek)
300#endif 300#endif
301 if (res) 301 if (res)
302 return io_pushresult(L, 0, NULL); 302 return io_pushresult(L, 0, NULL);
303#if defined(LUA_USE_POSIX) 303#if LJ_TARGET_POSIX
304 ofs = cast_num(ftello(fp)); 304 ofs = cast_num(ftello(fp));
305#elif _MSC_VER >= 1400 305#elif _MSC_VER >= 1400
306 ofs = cast_num(_ftelli64(fp)); 306 ofs = cast_num(_ftelli64(fp));
@@ -374,13 +374,13 @@ LJLIB_CF(io_open)
374 374
375LJLIB_CF(io_popen) 375LJLIB_CF(io_popen)
376{ 376{
377#if defined(LUA_USE_POSIX) || defined(LUA_USE_WIN) 377#if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS
378 const char *fname = strdata(lj_lib_checkstr(L, 1)); 378 const char *fname = strdata(lj_lib_checkstr(L, 1));
379 GCstr *s = lj_lib_optstr(L, 2); 379 GCstr *s = lj_lib_optstr(L, 2);
380 const char *mode = s ? strdata(s) : "r"; 380 const char *mode = s ? strdata(s) : "r";
381 IOFileUD *iof = io_file_new(L); 381 IOFileUD *iof = io_file_new(L);
382 iof->type = IOFILE_TYPE_PIPE; 382 iof->type = IOFILE_TYPE_PIPE;
383#ifdef LUA_USE_POSIX 383#if LJ_TARGET_POSIX
384 fflush(NULL); 384 fflush(NULL);
385 iof->fp = popen(fname, mode); 385 iof->fp = popen(fname, mode);
386#else 386#else
diff --git a/src/lib_os.c b/src/lib_os.c
index 8f08616f..690bffe8 100644
--- a/src/lib_os.c
+++ b/src/lib_os.c
@@ -17,16 +17,16 @@
17#include "lauxlib.h" 17#include "lauxlib.h"
18#include "lualib.h" 18#include "lualib.h"
19 19
20#ifdef LUA_USE_POSIX 20#include "lj_obj.h"
21#include "lj_err.h"
22#include "lj_lib.h"
23
24#if LJ_TARGET_POSIX
21#include <unistd.h> 25#include <unistd.h>
22#else 26#else
23#include <stdio.h> 27#include <stdio.h>
24#endif 28#endif
25 29
26#include "lj_obj.h"
27#include "lj_err.h"
28#include "lj_lib.h"
29
30/* ------------------------------------------------------------------------ */ 30/* ------------------------------------------------------------------------ */
31 31
32#define LJLIB_MODULE_os 32#define LJLIB_MODULE_os
@@ -66,7 +66,7 @@ LJLIB_CF(os_rename)
66 66
67LJLIB_CF(os_tmpname) 67LJLIB_CF(os_tmpname)
68{ 68{
69#ifdef LUA_USE_POSIX 69#if LJ_TARGET_POSIX
70 char buf[15+1]; 70 char buf[15+1];
71 int fp; 71 int fp;
72 strcpy(buf, "/tmp/lua_XXXXXX"); 72 strcpy(buf, "/tmp/lua_XXXXXX");
diff --git a/src/lib_package.c b/src/lib_package.c
index 5678ca4a..1757a944 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -27,7 +27,7 @@
27#define PACKAGE_LIB_FAIL "open" 27#define PACKAGE_LIB_FAIL "open"
28#define setprogdir(L) ((void)0) 28#define setprogdir(L) ((void)0)
29 29
30#if defined(LUA_DL_DLOPEN) 30#if LJ_TARGET_DLOPEN
31 31
32#include <dlfcn.h> 32#include <dlfcn.h>
33 33
@@ -50,7 +50,7 @@ static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
50 return f; 50 return f;
51} 51}
52 52
53#elif defined(LUA_DL_DLL) 53#elif LJ_TARGET_WINDOWS
54 54
55#define WIN32_LEAN_AND_MEAN 55#define WIN32_LEAN_AND_MEAN
56#include <windows.h> 56#include <windows.h>
@@ -107,7 +107,7 @@ static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
107#undef PACKAGE_LIB_FAIL 107#undef PACKAGE_LIB_FAIL
108#define PACKAGE_LIB_FAIL "absent" 108#define PACKAGE_LIB_FAIL "absent"
109 109
110#define DLMSG "dynamic libraries not enabled; check your Lua installation" 110#define DLMSG "dynamic libraries not enabled; no support for target OS"
111 111
112static void ll_unloadlib(void *lib) 112static void ll_unloadlib(void *lib)
113{ 113{
diff --git a/src/lj_alloc.c b/src/lj_alloc.c
index 2c686597..2f3fb473 100644
--- a/src/lj_alloc.c
+++ b/src/lj_alloc.c
@@ -72,7 +72,7 @@
72 72
73#define IS_DIRECT_BIT (SIZE_T_ONE) 73#define IS_DIRECT_BIT (SIZE_T_ONE)
74 74
75#ifdef LUA_USE_WIN 75#if LJ_TARGET_WINDOWS
76 76
77#define WIN32_LEAN_AND_MEAN 77#define WIN32_LEAN_AND_MEAN
78#include <windows.h> 78#include <windows.h>
@@ -166,13 +166,12 @@ static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
166#if LJ_64 166#if LJ_64
167/* 64 bit mode needs special support for allocating memory in the lower 2GB. */ 167/* 64 bit mode needs special support for allocating memory in the lower 2GB. */
168 168
169#if defined(__linux__) 169#if LJ_TARGET_LINUX
170 170
171/* Actually this only gives us max. 1GB in current Linux kernels. */ 171/* Actually this only gives us max. 1GB in current Linux kernels. */
172#define CALL_MMAP(s) mmap(NULL, (s), MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0) 172#define CALL_MMAP(s) mmap(NULL, (s), MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0)
173 173
174#elif (defined(__MACH__) && defined(__APPLE__)) || \ 174#elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
175 defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
176 175
177/* OSX and FreeBSD mmap() use a naive first-fit linear search. 176/* OSX and FreeBSD mmap() use a naive first-fit linear search.
178** That's perfect for us. Except that -pagezero_size must be set for OSX, 177** 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)
233#define DIRECT_MMAP(s) CALL_MMAP(s) 232#define DIRECT_MMAP(s) CALL_MMAP(s)
234#define CALL_MUNMAP(a, s) munmap((a), (s)) 233#define CALL_MUNMAP(a, s) munmap((a), (s))
235 234
236#ifdef __linux__ 235#if LJ_TARGET_LINUX
237/* Need to define _GNU_SOURCE to get the mremap prototype. */ 236/* Need to define _GNU_SOURCE to get the mremap prototype. */
238#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) 237#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv))
239#define CALL_MREMAP_NOMOVE 0 238#define CALL_MREMAP_NOMOVE 0
@@ -420,7 +419,7 @@ typedef struct malloc_state *mstate;
420 (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\ 419 (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\
421 & ~(DEFAULT_GRANULARITY - SIZE_T_ONE)) 420 & ~(DEFAULT_GRANULARITY - SIZE_T_ONE))
422 421
423#ifdef LUA_USE_WIN 422#if LJ_TARGET_WINDOWS
424#define mmap_align(S) granularity_align(S) 423#define mmap_align(S) granularity_align(S)
425#else 424#else
426#define mmap_align(S) page_align(S) 425#define mmap_align(S) page_align(S)
diff --git a/src/lj_arch.h b/src/lj_arch.h
index 7f1fe93c..f9cb12e7 100644
--- a/src/lj_arch.h
+++ b/src/lj_arch.h
@@ -8,7 +8,6 @@
8 8
9#include "lua.h" 9#include "lua.h"
10 10
11
12/* Target endianess. */ 11/* Target endianess. */
13#define LUAJIT_LE 0 12#define LUAJIT_LE 0
14#define LUAJIT_BE 1 13#define LUAJIT_BE 1
@@ -23,6 +22,13 @@
23#define LUAJIT_ARCH_PPCSPE 4 22#define LUAJIT_ARCH_PPCSPE 4
24#define LUAJIT_ARCH_ppcspe 4 23#define LUAJIT_ARCH_ppcspe 4
25 24
25/* Target OS. */
26#define LUAJIT_OS_OTHER 0
27#define LUAJIT_OS_WINDOWS 1
28#define LUAJIT_OS_LINUX 2
29#define LUAJIT_OS_OSX 3
30#define LUAJIT_OS_BSD 4
31#define LUAJIT_OS_POSIX 5
26 32
27/* Select native target if no target defined. */ 33/* Select native target if no target defined. */
28#ifndef LUAJIT_TARGET 34#ifndef LUAJIT_TARGET
@@ -43,15 +49,58 @@
43 49
44#endif 50#endif
45 51
46/* Set target properties. */ 52/* Select native OS if no target OS defined. */
53#ifndef LUAJIT_OS
54
55#if defined(_WIN32)
56#define LUAJIT_OS LUAJIT_OS_WINDOWS
57#elif defined(__linux__)
58#define LUAJIT_OS LUAJIT_OS_LINUX
59#elif defined(__MACH__) && defined(__APPLE__)
60#define LUAJIT_OS LUAJIT_OS_OSX
61#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
62 defined(__NetBSD__) || defined(__OpenBSD__)
63#define LUAJIT_OS LUAJIT_OS_BSD
64#elif defined(__solaris__) || defined(__CYGWIN__)
65#define LUAJIT_OS LUAJIT_OS_POSIX
66#else
67#define LUAJIT_OS LUAJIT_OS_OTHER
68#endif
69
70#endif
71
72/* Set target OS properties. */
73#if LUAJIT_OS == LUAJIT_OS_WINDOWS
74#define LJ_OS_NAME "Windows"
75#elif LUAJIT_OS == LUAJIT_OS_LINUX
76#define LJ_OS_NAME "Linux"
77#elif LUAJIT_OS == LUAJIT_OS_OSX
78#define LJ_OS_NAME "OSX"
79#elif LUAJIT_OS == LUAJIT_OS_BSD
80#define LJ_OS_NAME "BSD"
81#elif LUAJIT_OS == LUAJIT_OS_POSIX
82#define LJ_OS_NAME "Posix"
83#else
84#define LJ_OS_NAME "Other"
85#endif
86
87#define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
88#define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
89#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
90#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
91#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
92
93/* Set target architecture properties. */
47#if LUAJIT_TARGET == LUAJIT_ARCH_X86 94#if LUAJIT_TARGET == LUAJIT_ARCH_X86
48 95
49#define LJ_ARCH_NAME "x86" 96#define LJ_ARCH_NAME "x86"
50#define LJ_ARCH_BITS 32 97#define LJ_ARCH_BITS 32
51#define LJ_ARCH_ENDIAN LUAJIT_LE 98#define LJ_ARCH_ENDIAN LUAJIT_LE
99#define LJ_ARCH_BITENDIAN LUAJIT_LE
100#define LJ_ARCH_HASFPU 1
101#define LJ_ABI_WIN LJ_TARGET_WINDOWS
52#define LJ_TARGET_X86 1 102#define LJ_TARGET_X86 1
53#define LJ_TARGET_X86ORX64 1 103#define LJ_TARGET_X86ORX64 1
54#define LJ_PAGESIZE 4096
55#define LJ_TARGET_EHRETREG 0 104#define LJ_TARGET_EHRETREG 0
56#define LJ_TARGET_MASKSHIFT 1 105#define LJ_TARGET_MASKSHIFT 1
57#define LJ_TARGET_MASKROT 1 106#define LJ_TARGET_MASKROT 1
@@ -61,9 +110,11 @@
61#define LJ_ARCH_NAME "x64" 110#define LJ_ARCH_NAME "x64"
62#define LJ_ARCH_BITS 64 111#define LJ_ARCH_BITS 64
63#define LJ_ARCH_ENDIAN LUAJIT_LE 112#define LJ_ARCH_ENDIAN LUAJIT_LE
113#define LJ_ARCH_BITENDIAN LUAJIT_LE
114#define LJ_ARCH_HASFPU 1
115#define LJ_ABI_WIN LJ_TARGET_WINDOWS
64#define LJ_TARGET_X64 1 116#define LJ_TARGET_X64 1
65#define LJ_TARGET_X86ORX64 1 117#define LJ_TARGET_X86ORX64 1
66#define LJ_PAGESIZE 4096
67#define LJ_TARGET_EHRETREG 0 118#define LJ_TARGET_EHRETREG 0
68#define LJ_TARGET_MASKSHIFT 1 119#define LJ_TARGET_MASKSHIFT 1
69#define LJ_TARGET_MASKROT 1 120#define LJ_TARGET_MASKROT 1
@@ -77,9 +128,12 @@
77#define LJ_ARCH_NAME "ppcspe" 128#define LJ_ARCH_NAME "ppcspe"
78#define LJ_ARCH_BITS 32 129#define LJ_ARCH_BITS 32
79#define LJ_ARCH_ENDIAN LUAJIT_BE 130#define LJ_ARCH_ENDIAN LUAJIT_BE
131#define LJ_ARCH_BITENDIAN LUAJIT_BE
132#define LJ_ARCH_HASFPU 1
133#define LJ_ABI_SOFTFP 1
134#define LJ_ABI_EABI 1
80#define LJ_TARGET_PPC 1 135#define LJ_TARGET_PPC 1
81#define LJ_TARGET_PPCSPE 1 136#define LJ_TARGET_PPCSPE 1
82#define LJ_PAGESIZE 4096
83#define LJ_TARGET_EHRETREG 3 137#define LJ_TARGET_EHRETREG 3
84#define LJ_TARGET_MASKSHIFT 0 138#define LJ_TARGET_MASKSHIFT 0
85#define LJ_TARGET_MASKROT 1 139#define LJ_TARGET_MASKROT 1
@@ -89,6 +143,10 @@
89#error "No target architecture defined" 143#error "No target architecture defined"
90#endif 144#endif
91 145
146#ifndef LJ_PAGESIZE
147#define LJ_PAGESIZE 4096
148#endif
149
92/* Check for minimum required compiler versions. */ 150/* Check for minimum required compiler versions. */
93#if defined(__GNUC__) 151#if defined(__GNUC__)
94#if LJ_TARGET_X64 152#if LJ_TARGET_X64
diff --git a/src/lj_asm.c b/src/lj_asm.c
index 322799e6..80dda36a 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1345,7 +1345,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
1345 for (n = 0; n < nargs; n++) { /* Setup args. */ 1345 for (n = 0; n < nargs; n++) { /* Setup args. */
1346 IRIns *ir = IR(args[n]); 1346 IRIns *ir = IR(args[n]);
1347 Reg r; 1347 Reg r;
1348#if LJ_64 && defined(_WIN64) 1348#if LJ_64 && LJ_ABI_WIN
1349 /* Windows/x64 argument registers are strictly positional. */ 1349 /* Windows/x64 argument registers are strictly positional. */
1350 r = irt_isnum(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31); 1350 r = irt_isnum(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);
1351 fpr++; gprs >>= 5; 1351 fpr++; gprs >>= 5;
@@ -3518,11 +3518,7 @@ static void asm_setup_regsp(ASMState *as, GCtrace *T)
3518 const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; 3518 const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
3519#if LJ_64 3519#if LJ_64
3520 /* NYI: add stack slots for x64 calls with many args. */ 3520 /* NYI: add stack slots for x64 calls with many args. */
3521#ifdef _WIN64 3521 lua_assert(CCI_NARGS(ci) <= (LJ_ABI_WIN ? 4 : 6));
3522 lua_assert(CCI_NARGS(ci) <= 4);
3523#else
3524 lua_assert(CCI_NARGS(ci) <= 6); /* Safe lower bound. */
3525#endif
3526 ir->prev = REGSP_HINT(irt_isnum(ir->t) ? RID_FPRET : RID_RET); 3522 ir->prev = REGSP_HINT(irt_isnum(ir->t) ? RID_FPRET : RID_RET);
3527#else 3523#else
3528 /* NYI: not fastcall-aware, but doesn't matter (yet). */ 3524 /* NYI: not fastcall-aware, but doesn't matter (yet). */
diff --git a/src/lj_err.c b/src/lj_err.c
index 5a6aac83..8a80c9c8 100644
--- a/src/lj_err.c
+++ b/src/lj_err.c
@@ -63,15 +63,11 @@
63** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. 63** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13.
64*/ 64*/
65 65
66#if defined(__GNUC__) 66#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL))
67#if LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)
68#define LJ_UNWIND_EXT 1 67#define LJ_UNWIND_EXT 1
69#endif 68#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS
70#elif defined(LUA_USE_WIN)
71#if LJ_TARGET_X64
72#define LJ_UNWIND_EXT 1 69#define LJ_UNWIND_EXT 1
73#endif 70#endif
74#endif
75 71
76/* -- Error messages ------------------------------------------------------ */ 72/* -- Error messages ------------------------------------------------------ */
77 73
@@ -604,7 +600,7 @@ static void err_raise_ext(int errcode)
604} 600}
605#endif 601#endif
606 602
607#elif defined(_WIN64) 603#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS
608 604
609/* 605/*
610** Someone in Redmond owes me several days of my life. A lot of this is 606** Someone in Redmond owes me several days of my life. A lot of this is
diff --git a/src/lj_errmsg.h b/src/lj_errmsg.h
index 4891b74e..4fe8e1b1 100644
--- a/src/lj_errmsg.h
+++ b/src/lj_errmsg.h
@@ -57,7 +57,7 @@ ERRDEF(NOENV, "no calling environment")
57ERRDEF(CYIELD, "attempt to yield across C-call boundary") 57ERRDEF(CYIELD, "attempt to yield across C-call boundary")
58ERRDEF(BADLU, "bad light userdata pointer") 58ERRDEF(BADLU, "bad light userdata pointer")
59ERRDEF(NOGCMM, "bad action while in __gc metamethod") 59ERRDEF(NOGCMM, "bad action while in __gc metamethod")
60#ifdef LUA_USE_WIN 60#if LJ_TARGET_WINDOWS
61ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)") 61ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)")
62#endif 62#endif
63 63
diff --git a/src/lj_frame.h b/src/lj_frame.h
index c4931072..143a6812 100644
--- a/src/lj_frame.h
+++ b/src/lj_frame.h
@@ -69,7 +69,7 @@ enum {
69#define CFRAME_SIZE_JIT CFRAME_SIZE 69#define CFRAME_SIZE_JIT CFRAME_SIZE
70#define CFRAME_SHIFT_MULTRES 0 70#define CFRAME_SHIFT_MULTRES 0
71#elif LJ_TARGET_X64 71#elif LJ_TARGET_X64
72#if _WIN64 72#if LJ_ABI_WIN
73#define CFRAME_OFS_PREV (13*8) 73#define CFRAME_OFS_PREV (13*8)
74#define CFRAME_OFS_PC (25*4) 74#define CFRAME_OFS_PC (25*4)
75#define CFRAME_OFS_L (24*4) 75#define CFRAME_OFS_L (24*4)
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c
index 30aab774..d106bb5d 100644
--- a/src/lj_gdbjit.c
+++ b/src/lj_gdbjit.c
@@ -335,7 +335,7 @@ static const ELFheader elfhdr_template = {
335 .eclass = LJ_64 ? 2 : 1, 335 .eclass = LJ_64 ? 2 : 1,
336 .eendian = LJ_ENDIAN_SELECT(1, 2), 336 .eendian = LJ_ENDIAN_SELECT(1, 2),
337 .eversion = 1, 337 .eversion = 1,
338#if defined(__linux__) 338#if LJ_TARGET_LINUX
339 .eosabi = 0, /* Nope, it's not 3. */ 339 .eosabi = 0, /* Nope, it's not 3. */
340#elif defined(__FreeBSD__) 340#elif defined(__FreeBSD__)
341 .eosabi = 9, 341 .eosabi = 9,
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 77377931..d309f828 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -55,7 +55,7 @@
55 (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_FUSE) 55 (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_FUSE)
56#define JIT_F_OPT_DEFAULT JIT_F_OPT_3 56#define JIT_F_OPT_DEFAULT JIT_F_OPT_3
57 57
58#if defined(LUA_USE_WIN) || LJ_64 58#if LJ_TARGET_WINDOWS || LJ_64
59/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ 59/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
60#define JIT_P_sizemcode_DEFAULT 64 60#define JIT_P_sizemcode_DEFAULT 64
61#else 61#else
diff --git a/src/lj_lib.h b/src/lj_lib.h
index 814c9739..6782e725 100644
--- a/src/lj_lib.h
+++ b/src/lj_lib.h
@@ -49,7 +49,7 @@ LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);
49#define lj_lib_upvalue(L, n) \ 49#define lj_lib_upvalue(L, n) \
50 (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1]) 50 (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])
51 51
52#ifdef LUA_USE_WIN 52#if LJ_TARGET_WINDOWS
53#define lj_lib_checkfpu(L) \ 53#define lj_lib_checkfpu(L) \
54 do { setnumV(L->top++, (lua_Number)1437217655); \ 54 do { setnumV(L->top++, (lua_Number)1437217655); \
55 if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \ 55 if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \
diff --git a/src/lj_mcode.c b/src/lj_mcode.c
index 9b1cae00..72002175 100644
--- a/src/lj_mcode.c
+++ b/src/lj_mcode.c
@@ -19,7 +19,7 @@
19 19
20/* -- OS-specific functions ----------------------------------------------- */ 20/* -- OS-specific functions ----------------------------------------------- */
21 21
22#if defined(LUA_USE_WIN) 22#if LJ_TARGET_WINDOWS
23 23
24#define WIN32_LEAN_AND_MEAN 24#define WIN32_LEAN_AND_MEAN
25#include <windows.h> 25#include <windows.h>
@@ -49,7 +49,7 @@ static void mcode_setprot(void *p, size_t sz, DWORD prot)
49 VirtualProtect(p, sz, prot, &oprot); 49 VirtualProtect(p, sz, prot, &oprot);
50} 50}
51 51
52#elif defined(LUA_USE_POSIX) 52#elif LJ_TARGET_POSIX
53 53
54#include <sys/mman.h> 54#include <sys/mman.h>
55 55
@@ -82,7 +82,7 @@ static void mcode_setprot(void *p, size_t sz, int prot)
82 82
83#elif LJ_64 83#elif LJ_64
84 84
85#error "Missing OS support for allocating executable memory" 85#error "Missing OS support for explicit placement of executable memory"
86 86
87#else 87#else
88 88
diff --git a/src/lj_obj.h b/src/lj_obj.h
index 4baa62d8..c7b653f3 100644
--- a/src/lj_obj.h
+++ b/src/lj_obj.h
@@ -719,7 +719,7 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
719 return (int32_t)o.u32.lo; 719 return (int32_t)o.u32.lo;
720} 720}
721 721
722#if (defined(__i386__) || defined(_M_IX86)) && !defined(__SSE2__) 722#if LJ_TARGET_X86 && !defined(__SSE2__)
723#define lj_num2int(n) lj_num2bit((n)) 723#define lj_num2int(n) lj_num2bit((n))
724#else 724#else
725#define lj_num2int(n) ((int32_t)(n)) 725#define lj_num2int(n) ((int32_t)(n))
diff --git a/src/lj_target_x86.h b/src/lj_target_x86.h
index ad4e3d1a..03c52770 100644
--- a/src/lj_target_x86.h
+++ b/src/lj_target_x86.h
@@ -40,7 +40,7 @@ enum {
40 40
41 /* These definitions must match with the *.dasc file(s): */ 41 /* These definitions must match with the *.dasc file(s): */
42 RID_BASE = RID_EDX, /* Interpreter BASE. */ 42 RID_BASE = RID_EDX, /* Interpreter BASE. */
43#if LJ_64 && !defined(_WIN64) 43#if LJ_64 && !LJ_ABI_WIN
44 RID_PC = RID_EBX, /* Interpreter PC. */ 44 RID_PC = RID_EBX, /* Interpreter PC. */
45 RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */ 45 RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */
46#else 46#else
@@ -74,7 +74,7 @@ enum {
74/* ABI-specific register sets. */ 74/* ABI-specific register sets. */
75#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX)) 75#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))
76#if LJ_64 76#if LJ_64
77#ifdef _WIN64 77#if LJ_ABI_WIN
78/* Windows x64 ABI. */ 78/* Windows x64 ABI. */
79#define RSET_SCRATCH \ 79#define RSET_SCRATCH \
80 (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1)) 80 (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))
@@ -117,7 +117,7 @@ enum {
117** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. 117** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
118*/ 118*/
119#if LJ_64 119#if LJ_64
120#ifdef _WIN64 120#if LJ_ABI_WIN
121#define SPS_FIXED (4*2) 121#define SPS_FIXED (4*2)
122#define SPS_FIRST (4*2) /* Don't use callee register save area. */ 122#define SPS_FIRST (4*2) /* Don't use callee register save area. */
123#else 123#else
diff --git a/src/luaconf.h b/src/luaconf.h
index 4506b5fb..7278b3ef 100644
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -9,19 +9,8 @@
9#include <limits.h> 9#include <limits.h>
10#include <stddef.h> 10#include <stddef.h>
11 11
12/* Try to determine supported features for a couple of standard platforms. */
13#if defined(_WIN32)
14#define LUA_USE_WIN
15#define LUA_DL_DLL
16#elif defined(__linux__) || defined(__solaris__) || defined(__CYGWIN__) || \
17 defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
18 defined(__FreeBSD_kernel__) || (defined(__MACH__) && defined(__APPLE__))
19#define LUA_USE_POSIX
20#define LUA_DL_DLOPEN
21#endif
22
23/* Default path for loading Lua and C modules with require(). */ 12/* Default path for loading Lua and C modules with require(). */
24#ifdef LUA_USE_WIN 13#if defined(_WIN32)
25/* 14/*
26** In Windows, any exclamation mark ('!') in the path is replaced by the 15** In Windows, any exclamation mark ('!') in the path is replaced by the
27** path of the directory of the executable file of the current process. 16** path of the directory of the executable file of the current process.
@@ -58,7 +47,7 @@
58#define LUA_INIT "LUA_INIT" 47#define LUA_INIT "LUA_INIT"
59 48
60/* Special file system characters. */ 49/* Special file system characters. */
61#ifdef LUA_USE_WIN 50#if defined(_WIN32)
62#define LUA_DIRSEP "\\" 51#define LUA_DIRSEP "\\"
63#else 52#else
64#define LUA_DIRSEP "/" 53#define LUA_DIRSEP "/"
diff --git a/src/luajit.c b/src/luajit.c
index e8024479..2e85f01d 100644
--- a/src/luajit.c
+++ b/src/luajit.c
@@ -18,10 +18,12 @@
18#include "lualib.h" 18#include "lualib.h"
19#include "luajit.h" 19#include "luajit.h"
20 20
21#if defined(LUA_USE_POSIX) 21#include "lj_arch.h"
22
23#if LJ_TARGET_POSIX
22#include <unistd.h> 24#include <unistd.h>
23#define lua_stdin_is_tty() isatty(0) 25#define lua_stdin_is_tty() isatty(0)
24#elif defined(LUA_USE_WIN) 26#elif LJ_TARGET_WINDOWS
25#include <io.h> 27#include <io.h>
26#ifdef __BORLANDC__ 28#ifdef __BORLANDC__
27#define lua_stdin_is_tty() isatty(_fileno(stdin)) 29#define lua_stdin_is_tty() isatty(_fileno(stdin))