aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-28 14:03:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-28 14:03:32 -0300
commit906434011f09a5afe60fbb644db6995a5ca21f0d (patch)
treefff81c98cb05e9e7e20ff70f3ea2d46abab11185
parentc07cebbbf622a949747349a219b2ba5973c4359c (diff)
downloadlua-906434011f09a5afe60fbb644db6995a5ca21f0d.tar.gz
lua-906434011f09a5afe60fbb644db6995a5ca21f0d.tar.bz2
lua-906434011f09a5afe60fbb644db6995a5ca21f0d.zip
better (?) treatment for 16-bit machines
-rw-r--r--llimits.h62
1 files changed, 43 insertions, 19 deletions
diff --git a/llimits.h b/llimits.h
index 146ae73d..f1ac6acf 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.9 2000/06/06 16:27:11 roberto Exp roberto $ 2** $Id: llimits.h,v 1.10 2000/06/16 17:16:34 roberto Exp roberto $
3** Limits, basic types, and some other "instalation-dependent" definitions 3** Limits, basic types, and some other "instalation-dependent" definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,25 @@
12#include <stddef.h> 12#include <stddef.h>
13 13
14 14
15
16/*
17** try to find number of bits in an integer
18*/
19#ifndef BITS_INT
20/* avoid overflows in comparison */
21#if INT_MAX-20 < 32760
22#define BITS_INT 16
23#else
24#if INT_MAX > 2147483640L
25/* machine has at least 32 bits */
26#define BITS_INT 32
27#else
28#error "you must define BITS_INT with number of bits in an integer"
29#endif
30#endif
31#endif
32
33
15/* 34/*
16** Define the type `number' of Lua 35** Define the type `number' of Lua
17** GREP LUA_NUMBER to change that 36** GREP LUA_NUMBER to change that
@@ -66,51 +85,56 @@ typedef unsigned long Instruction;
66 85
67 86
68/* 87/*
69** limits for opcode arguments. 88** size and position of opcode arguments.
70** For an instruction with 2 bytes, size is 16, and size_b can be 5 89** For an instruction with 2 bytes, size is 16, and size_b can be 5
90** (accordingly, size_u will be 10, and size_a will be 5)
71*/ 91*/
72#define SIZE_INSTRUCTION 32 92#define SIZE_INSTRUCTION 32
73#define SIZE_OP 6
74#define SIZE_B 9 93#define SIZE_B 9
75 94
95#define SIZE_OP 6
76#define SIZE_U (SIZE_INSTRUCTION-SIZE_OP) 96#define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
77#define POS_U SIZE_OP 97#define POS_U SIZE_OP
78#define POS_B SIZE_OP 98#define POS_B SIZE_OP
79#define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B)) 99#define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
80#define POS_A (SIZE_OP+SIZE_B) 100#define POS_A (SIZE_OP+SIZE_B)
81 101
82#define MAXARG_U ((1<<SIZE_U)-1)
83#define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
84#define MAXARG_A ((1<<SIZE_A)-1)
85#define MAXARG_B ((1<<SIZE_B)-1)
86
87 102
88/* 103/*
89** we use int to manipulate most arguments, so they must fit 104** limits for opcode arguments.
105** we use (signed) int to manipulate most arguments,
106** so they must fit in BITS_INT-1 bits (-1 for signal)
90*/ 107*/
91#if MAXARG_U > MAX_INT 108#if SIZE_U < BITS_INT-1
92#undef MAXARG_U 109#define MAXARG_U ((1<<SIZE_U)-1)
110#define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
111#else
93#define MAXARG_U MAX_INT 112#define MAXARG_U MAX_INT
94#endif
95
96#if MAXARG_S > MAX_INT
97#undef MAXARG_S
98#define MAXARG_S MAX_INT 113#define MAXARG_S MAX_INT
99#endif 114#endif
100 115
101#if MAXARG_A > MAX_INT 116#if SIZE_A < BITS_INT-1
102#undef MAXARG_A 117#define MAXARG_A ((1<<SIZE_A)-1)
118#else
103#define MAXARG_A MAX_INT 119#define MAXARG_A MAX_INT
104#endif 120#endif
105 121
106#if MAXARG_B > MAX_INT 122#if SIZE_B < BITS_INT-1
107#undef MAXARG_B 123#define MAXARG_B ((1<<SIZE_B)-1)
124#else
108#define MAXARG_B MAX_INT 125#define MAXARG_B MAX_INT
109#endif 126#endif
110 127
111 128
112/* maximum stack size in a function */ 129/* maximum stack size in a function */
130#ifndef MAXSTACK
131#define MAXSTACK 250
132#endif
133
134#if MAXSTACK > MAXARG_B
135#undef MAXSTACK
113#define MAXSTACK MAXARG_B 136#define MAXSTACK MAXARG_B
137#endif
114 138
115 139
116/* maximum number of local variables */ 140/* maximum number of local variables */