Skip to content

Commit 693f4e8

Browse files
committed
Update Lua code for 16-bit compiler compatibility
Removed old patches and added a new patch file that modifieds Luas source code with conditional macros to address limitations and bugs in 16-bit compilers. If fixes the problem by bypassing several true mathematical checks in favor of the '_M_I86' definition. This ensures proper handling of integer size checks, UTF-8 decoding, and macro definitions for these environments while hopefully maintaining compatibility for building Lua on modern systems.
1 parent 81b2cc3 commit 693f4e8

File tree

4 files changed

+71
-55
lines changed

4 files changed

+71
-55
lines changed

lopcodes.pat

Lines changed: 0 additions & 14 deletions
This file was deleted.

lua.pat

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--- lua/lopcodes.h
2+
+++ lua/lopcodes.h
3+
@@ -65,10 +65,16 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
4+
*/
5+
6+
/* Check whether type 'int' has at least 'b' bits ('b' < 32) */
7+
+#if defined(_M_I86)
8+
+/* Hardcoded due to bugs in some 16-bit compilers */
9+
+#define L_INTHASBITS(b) ((0xFFFF >> ((b) - 1)) >= 1)
10+
+#else
11+
#define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1)
12+
+#endif
13+
14+
-
15+
-#if L_INTHASBITS(SIZE_Bx)
16+
+#if defined(_M_I86)
17+
+#define MAXARG_Bx 0xFFFF
18+
+#elif L_INTHASBITS(SIZE_Bx)
19+
#define MAXARG_Bx ((1<<SIZE_Bx)-1)
20+
#else
21+
#define MAXARG_Bx MAX_INT
22+
@@ -76,14 +82,17 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
23+
24+
#define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
25+
26+
-
27+
-#if L_INTHASBITS(SIZE_Ax)
28+
+#if defined(_M_I86)
29+
+#define MAXARG_Ax 0xFFFF
30+
+#elif L_INTHASBITS(SIZE_Ax)
31+
#define MAXARG_Ax ((1<<SIZE_Ax)-1)
32+
#else
33+
#define MAXARG_Ax MAX_INT
34+
#endif
35+
36+
-#if L_INTHASBITS(SIZE_sJ)
37+
+#if defined(_M_I86)
38+
+#define MAXARG_sJ 0xFFFF
39+
+#elif L_INTHASBITS(SIZE_sJ)
40+
#define MAXARG_sJ ((1 << SIZE_sJ) - 1)
41+
#else
42+
#define MAXARG_sJ MAX_INT
43+
--- lua/luaconf.h
44+
+++ lua/luaconf.h
45+
@@ -79,7 +79,12 @@
46+
/*
47+
@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
48+
*/
49+
+#if defined(_M_I86)
50+
+/* Hardcoded due to bugs in some 16-bit compilers */
51+
+#define LUAI_IS32INT 0
52+
+#else
53+
#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
54+
+#endif
55+
56+
/* }================================================================== */
57+
58+
59+
--- lua/lutf8lib.c
60+
+++ lua/lutf8lib.c
61+
@@ -31,7 +31,9 @@
62+
/*
63+
** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
64+
*/
65+
-#if (UINT_MAX >> 30) >= 1
66+
+#if defined(_M_I86)
67+
+typedef unsigned long utfint;
68+
+#elif (UINT_MAX >> 30) >= 1
69+
typedef unsigned int utfint;
70+
#else
71+
typedef unsigned long utfint;

luaconf.pat

Lines changed: 0 additions & 21 deletions
This file was deleted.

lutf8lib.pat

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)