diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-20 16:20:43 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-20 16:20:43 -0300 |
commit | 5d60470508aad81eac145ab4e004fbf150130267 (patch) | |
tree | e019d25234bccc195614a7303520db0b86aca2ed | |
parent | 88d7ffb0d0c7303ef1b766b1100e4220e775ab57 (diff) | |
download | lua-5d60470508aad81eac145ab4e004fbf150130267.tar.gz lua-5d60470508aad81eac145ab4e004fbf150130267.tar.bz2 lua-5d60470508aad81eac145ab4e004fbf150130267.zip |
i.m. "arith" and "order" splited for different operations
-rw-r--r-- | fallback.c | 167 | ||||
-rw-r--r-- | fallback.h | 60 | ||||
-rw-r--r-- | opcode.c | 40 | ||||
-rw-r--r-- | opcode.h | 6 |
4 files changed, 151 insertions, 122 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.28 1997/03/19 19:41:10 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.29 1997/03/19 21:12:34 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -18,6 +18,19 @@ char *rcs_fallback="$Id: fallback.c,v 1.28 1997/03/19 19:41:10 roberto Exp rober | |||
18 | #include "hash.h" | 18 | #include "hash.h" |
19 | 19 | ||
20 | 20 | ||
21 | static char *typenames[] = { /* ORDER LUA_T */ | ||
22 | "userdata", "line", "cmark", "mark", "function", | ||
23 | "function", "table", "string", "number", "nil", | ||
24 | NULL | ||
25 | }; | ||
26 | |||
27 | |||
28 | void luaI_type (void) | ||
29 | { | ||
30 | lua_Object o = lua_getparam(1); | ||
31 | lua_pushstring(typenames[-ttype(luaI_Address(o))]); | ||
32 | lua_pushnumber(lua_tag(o)); | ||
33 | } | ||
21 | 34 | ||
22 | 35 | ||
23 | /* ------------------------------------------- | 36 | /* ------------------------------------------- |
@@ -94,27 +107,19 @@ void luaI_invalidaterefs (void) | |||
94 | * Internal Methods | 107 | * Internal Methods |
95 | */ | 108 | */ |
96 | 109 | ||
97 | char *eventname[] = { | 110 | char *luaI_eventname[] = { /* ORDER IM */ |
98 | "gettable", /* IM_GETTABLE */ | 111 | "gettable", "settable", "index", "add", "sub", "mul", "div", |
99 | "arith", /* IM_ARITH */ | 112 | "pow", "unm", "lt", "le", "gt", "ge", "concat", "gc", "function", |
100 | "order", /* IM_ORDER */ | ||
101 | "concat", /* IM_CONCAT */ | ||
102 | "settable", /* IM_SETTABLE */ | ||
103 | "gc", /* IM_GC */ | ||
104 | "function", /* IM_FUNCTION */ | ||
105 | "index", /* IM_INDEX */ | ||
106 | NULL | 113 | NULL |
107 | }; | 114 | }; |
108 | 115 | ||
109 | 116 | ||
110 | char *geventname[] = { | 117 | static char *geventname[] = { /* ORDER GIM */ |
111 | "error", /* GIM_ERROR */ | 118 | "error", "getglobal", "setglobal", |
112 | "getglobal", /* GIM_GETGLOBAL */ | ||
113 | "setglobal", /* GIM_SETGLOBAL */ | ||
114 | NULL | 119 | NULL |
115 | }; | 120 | }; |
116 | 121 | ||
117 | static int luaI_findevent (char *name, char *list[]) | 122 | static int findstring (char *name, char *list[]) |
118 | { | 123 | { |
119 | int i; | 124 | int i; |
120 | for (i=0; list[i]; i++) | 125 | for (i=0; list[i]; i++) |
@@ -126,7 +131,7 @@ static int luaI_findevent (char *name, char *list[]) | |||
126 | 131 | ||
127 | static int luaI_checkevent (char *name, char *list[]) | 132 | static int luaI_checkevent (char *name, char *list[]) |
128 | { | 133 | { |
129 | int e = luaI_findevent(name, list); | 134 | int e = findstring(name, list); |
130 | if (e < 0) | 135 | if (e < 0) |
131 | lua_error("invalid event name"); | 136 | lua_error("invalid event name"); |
132 | return e; | 137 | return e; |
@@ -141,38 +146,25 @@ static struct IM { | |||
141 | static int IMtable_size = 0; | 146 | static int IMtable_size = 0; |
142 | static int last_tag = LUA_T_NIL; | 147 | static int last_tag = LUA_T_NIL; |
143 | 148 | ||
144 | static struct { | 149 | static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */ |
145 | lua_Type t; | 150 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_USERDATA */ |
146 | int event; | 151 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_LINE */ |
147 | } exceptions[] = { /* list of events that cannot be modified */ | 152 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_CMARK */ |
148 | {LUA_T_NUMBER, IM_ARITH}, | 153 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_MARK */ |
149 | {LUA_T_NUMBER, IM_ORDER}, | 154 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CFUNCTION */ |
150 | {LUA_T_NUMBER, IM_GC}, | 155 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_FUNCTION */ |
151 | {LUA_T_STRING, IM_ARITH}, | 156 | {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_ARRAY */ |
152 | {LUA_T_STRING, IM_ORDER}, | 157 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ |
153 | {LUA_T_STRING, IM_CONCAT}, | 158 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, /* LUA_T_NUMBER */ |
154 | {LUA_T_STRING, IM_GC}, | 159 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0} /* LUA_T_NIL */ |
155 | {LUA_T_ARRAY, IM_GETTABLE}, | ||
156 | {LUA_T_ARRAY, IM_SETTABLE}, | ||
157 | {LUA_T_FUNCTION, IM_FUNCTION}, | ||
158 | {LUA_T_FUNCTION, IM_GC}, | ||
159 | {LUA_T_CFUNCTION, IM_FUNCTION}, | ||
160 | {LUA_T_CFUNCTION, IM_GC}, | ||
161 | {LUA_T_NIL, 0} /* flag end of list */ | ||
162 | }; | 160 | }; |
163 | 161 | ||
164 | 162 | static int validevent (lua_Type t, int e) | |
165 | static int validevent (int t, int event) | ||
166 | { | 163 | { |
167 | int i; | 164 | return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; |
168 | if (t == LUA_T_NIL) /* cannot modify any event for nil */ | ||
169 | return 0; | ||
170 | for (i=0; exceptions[i].t != LUA_T_NIL; i++) | ||
171 | if (exceptions[i].t == t && exceptions[i].event == event) | ||
172 | return 0; | ||
173 | return 1; | ||
174 | } | 165 | } |
175 | 166 | ||
167 | |||
176 | static void init_entry (int tag) | 168 | static void init_entry (int tag) |
177 | { | 169 | { |
178 | int i; | 170 | int i; |
@@ -193,14 +185,14 @@ void luaI_initfallbacks (void) | |||
193 | 185 | ||
194 | int lua_newtag (char *t) | 186 | int lua_newtag (char *t) |
195 | { | 187 | { |
188 | int tp; | ||
196 | --last_tag; | 189 | --last_tag; |
197 | if ((-last_tag) >= IMtable_size) | 190 | if ((-last_tag) >= IMtable_size) |
198 | IMtable_size = growvector(&luaI_IMtable, IMtable_size, | 191 | IMtable_size = growvector(&luaI_IMtable, IMtable_size, |
199 | struct IM, memEM, MAX_INT); | 192 | struct IM, memEM, MAX_INT); |
200 | if (strcmp(t, "table") == 0) | 193 | tp = -findstring(t, typenames); |
201 | luaI_IMtable[-last_tag].tp = LUA_T_ARRAY; | 194 | if (tp == LUA_T_ARRAY || tp == LUA_T_USERDATA) |
202 | else if (strcmp(t, "userdata") == 0) | 195 | luaI_IMtable[-last_tag].tp = tp; |
203 | luaI_IMtable[-last_tag].tp = LUA_T_USERDATA; | ||
204 | else | 196 | else |
205 | lua_error("invalid type for new tag"); | 197 | lua_error("invalid type for new tag"); |
206 | init_entry(last_tag); | 198 | init_entry(last_tag); |
@@ -246,14 +238,14 @@ int luaI_tag (Object *o) | |||
246 | else return t; | 238 | else return t; |
247 | } | 239 | } |
248 | 240 | ||
249 | Object *luaI_getim (int tag, int event) | 241 | Object *luaI_getim (int tag, IMS event) |
250 | { | 242 | { |
251 | if (tag > LUA_T_USERDATA) | 243 | if (tag > LUA_T_USERDATA) |
252 | tag = LUA_T_USERDATA; /* default for non-registered tags */ | 244 | tag = LUA_T_USERDATA; /* default for non-registered tags */ |
253 | return &luaI_IMtable[-tag].int_method[event]; | 245 | return &luaI_IMtable[-tag].int_method[event]; |
254 | } | 246 | } |
255 | 247 | ||
256 | Object *luaI_getimbyObj (Object *o, int event) | 248 | Object *luaI_getimbyObj (Object *o, IMS event) |
257 | { | 249 | { |
258 | return luaI_getim(luaI_tag(o), event); | 250 | return luaI_getim(luaI_tag(o), event); |
259 | } | 251 | } |
@@ -261,13 +253,13 @@ Object *luaI_getimbyObj (Object *o, int event) | |||
261 | void luaI_setintmethod (void) | 253 | void luaI_setintmethod (void) |
262 | { | 254 | { |
263 | int t = (int)luaL_check_number(1, "setintmethod"); | 255 | int t = (int)luaL_check_number(1, "setintmethod"); |
264 | int e = luaI_checkevent(luaL_check_string(2, "setintmethod"), eventname); | 256 | int e = luaI_checkevent(luaL_check_string(2, "setintmethod"), luaI_eventname); |
265 | lua_Object func = lua_getparam(3); | 257 | lua_Object func = lua_getparam(3); |
258 | checktag(t); | ||
266 | if (!validevent(t, e)) | 259 | if (!validevent(t, e)) |
267 | lua_error("cannot change this internal method"); | 260 | lua_error("cannot change this internal method"); |
268 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod", | 261 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod", |
269 | 3, "function expected"); | 262 | 3, "function expected"); |
270 | checktag(t); | ||
271 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); | 263 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); |
272 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); | 264 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); |
273 | } | 265 | } |
@@ -276,7 +268,7 @@ static Object gmethod[GIM_N] = { | |||
276 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}} | 268 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}} |
277 | }; | 269 | }; |
278 | 270 | ||
279 | Object *luaI_getgim (int event) | 271 | Object *luaI_getgim (IMGS event) |
280 | { | 272 | { |
281 | return &gmethod[event]; | 273 | return &gmethod[event]; |
282 | } | 274 | } |
@@ -326,47 +318,54 @@ static void typeFB (void) | |||
326 | } | 318 | } |
327 | 319 | ||
328 | 320 | ||
321 | static void fillvalids (IMS e, Object *func) | ||
322 | { | ||
323 | int t; | ||
324 | for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) | ||
325 | if (validevent(t, e)) | ||
326 | luaI_IMtable[-t].int_method[e] = *func; | ||
327 | } | ||
328 | |||
329 | void luaI_setfallback (void) | 329 | void luaI_setfallback (void) |
330 | { | 330 | { |
331 | int e; | 331 | int e; |
332 | Object oldfunc; | ||
333 | lua_CFunction replace; | ||
332 | char *name = luaL_check_string(1, "setfallback"); | 334 | char *name = luaL_check_string(1, "setfallback"); |
333 | lua_Object func = lua_getparam(2); | 335 | lua_Object func = lua_getparam(2); |
334 | luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected"); | 336 | luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected"); |
335 | e = luaI_findevent(name, geventname); | 337 | e = findstring(name, geventname); |
336 | if (e >= 0) { /* global event */ | 338 | if (e >= 0) { /* global event */ |
337 | switch (e) { | 339 | oldfunc = gmethod[e]; |
338 | case GIM_ERROR: | 340 | gmethod[e] = *luaI_Address(func); |
339 | gmethod[e] = *luaI_Address(func); | 341 | replace = (e == GIM_ERROR) ? errorFB : nilFB; |
340 | lua_pushcfunction(errorFB); | ||
341 | break; | ||
342 | case GIM_GETGLOBAL: /* goes through */ | ||
343 | case GIM_SETGLOBAL: | ||
344 | gmethod[e] = *luaI_Address(func); | ||
345 | lua_pushcfunction(nilFB); | ||
346 | break; | ||
347 | default: lua_error("internal error"); | ||
348 | } | ||
349 | } | 342 | } |
350 | else { /* tagged name? */ | 343 | else if ((e = findstring(name, luaI_eventname)) >= 0) { |
351 | int t; | ||
352 | Object oldfunc; | ||
353 | e = luaI_checkevent(name, eventname); | ||
354 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[e]; | 344 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[e]; |
355 | for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) | 345 | fillvalids(e, luaI_Address(func)); |
356 | if (validevent(t, e)) | 346 | replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; |
357 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); | ||
358 | if (oldfunc.ttype != LUA_T_NIL) | ||
359 | luaI_pushobject(&oldfunc); | ||
360 | else { | ||
361 | switch (e) { | ||
362 | case IM_GC: case IM_INDEX: | ||
363 | lua_pushcfunction(nilFB); | ||
364 | break; | ||
365 | default: | ||
366 | lua_pushcfunction(typeFB); | ||
367 | break; | ||
368 | } | ||
369 | } | ||
370 | } | 347 | } |
348 | else if (strcmp(name, "arith") == 0) { /* old arith fallback */ | ||
349 | int i; | ||
350 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_ADD]; | ||
351 | for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ | ||
352 | fillvalids(i, luaI_Address(func)); | ||
353 | replace = typeFB; | ||
354 | } | ||
355 | else if (strcmp(name, "order") == 0) { /* old order fallback */ | ||
356 | int i; | ||
357 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_LT]; | ||
358 | for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ | ||
359 | fillvalids(i, luaI_Address(func)); | ||
360 | replace = typeFB; | ||
361 | } | ||
362 | else { | ||
363 | lua_error("invalid fallback name"); | ||
364 | replace = NULL; /* to avoid warnings */ | ||
365 | } | ||
366 | if (oldfunc.ttype != LUA_T_NIL) | ||
367 | luaI_pushobject(&oldfunc); | ||
368 | else | ||
369 | lua_pushcfunction(replace); | ||
371 | } | 370 | } |
372 | 371 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.14 1997/02/26 17:38:41 roberto Unstable roberto $ | 2 | ** $Id: fallback.h,v 1.15 1997/03/19 19:41:10 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -8,19 +8,44 @@ | |||
8 | #include "lua.h" | 8 | #include "lua.h" |
9 | #include "opcode.h" | 9 | #include "opcode.h" |
10 | 10 | ||
11 | #define IM_GETTABLE 0 | 11 | /* |
12 | #define IM_ARITH 1 | 12 | * WARNING: if you change the order of this enumeration, |
13 | #define IM_ORDER 2 | 13 | * grep "ORDER IM" |
14 | #define IM_CONCAT 3 | 14 | */ |
15 | #define IM_SETTABLE 4 | 15 | typedef enum { |
16 | #define IM_GC 5 | 16 | IM_GETTABLE = 0, |
17 | #define IM_FUNCTION 6 | 17 | IM_SETTABLE, |
18 | #define IM_INDEX 7 | 18 | IM_INDEX, |
19 | #define IM_N 8 | 19 | IM_ADD, |
20 | 20 | IM_SUB, | |
21 | #define GIM_ERROR 0 | 21 | IM_MUL, |
22 | #define GIM_GETGLOBAL 1 | 22 | IM_DIV, |
23 | #define GIM_SETGLOBAL 2 | 23 | IM_POW, |
24 | IM_UNM, | ||
25 | IM_LT, | ||
26 | IM_LE, | ||
27 | IM_GT, | ||
28 | IM_GE, | ||
29 | IM_CONCAT, | ||
30 | IM_GC, | ||
31 | IM_FUNCTION | ||
32 | } IMS; | ||
33 | |||
34 | #define IM_N 16 | ||
35 | |||
36 | extern char *luaI_eventname[]; | ||
37 | |||
38 | |||
39 | /* | ||
40 | * WARNING: if you change the order of this enumeration, | ||
41 | * grep "ORDER GIM" | ||
42 | */ | ||
43 | typedef enum { | ||
44 | GIM_ERROR = 0, | ||
45 | GIM_GETGLOBAL, | ||
46 | GIM_SETGLOBAL | ||
47 | } IMGS; | ||
48 | |||
24 | #define GIM_N 3 | 49 | #define GIM_N 3 |
25 | 50 | ||
26 | void luaI_setfallback (void); | 51 | void luaI_setfallback (void); |
@@ -30,11 +55,12 @@ void luaI_travlock (int (*fn)(Object *)); | |||
30 | void luaI_invalidaterefs (void); | 55 | void luaI_invalidaterefs (void); |
31 | char *luaI_travfallbacks (int (*fn)(Object *)); | 56 | char *luaI_travfallbacks (int (*fn)(Object *)); |
32 | 57 | ||
58 | void luaI_type (void); | ||
33 | void luaI_settag (int tag, Object *o); | 59 | void luaI_settag (int tag, Object *o); |
34 | lua_Type luaI_typetag (int tag); | 60 | lua_Type luaI_typetag (int tag); |
35 | Object *luaI_getim (int tag, int event); | 61 | Object *luaI_getim (int tag, IMS event); |
36 | Object *luaI_getgim (int event); | 62 | Object *luaI_getgim (IMGS event); |
37 | Object *luaI_getimbyObj (Object *o, int event); | 63 | Object *luaI_getimbyObj (Object *o, IMS event); |
38 | int luaI_tag (Object *o); | 64 | int luaI_tag (Object *o); |
39 | void luaI_setintmethod (void); | 65 | void luaI_setintmethod (void); |
40 | void luaI_setglobalmethod (void); | 66 | void luaI_setglobalmethod (void); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.84 1997/03/11 18:44:28 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.85 1997/03/19 19:41:10 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -1006,18 +1006,18 @@ void luaI_gcIM (Object *o) | |||
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | 1008 | ||
1009 | static void call_arith (char *op) | 1009 | static void call_arith (IMS event) |
1010 | { | 1010 | { |
1011 | Object *im = luaI_getimbyObj(top-2, IM_ARITH); /* try first operand */ | 1011 | Object *im = luaI_getimbyObj(top-2, event); /* try first operand */ |
1012 | if (ttype(im) == LUA_T_NIL) { | 1012 | if (ttype(im) == LUA_T_NIL) { |
1013 | im = luaI_getimbyObj(top-1, IM_ARITH); /* try second operand */ | 1013 | im = luaI_getimbyObj(top-1, event); /* try second operand */ |
1014 | if (ttype(im) == LUA_T_NIL) { | 1014 | if (ttype(im) == LUA_T_NIL) { |
1015 | im = luaI_getim(0, IM_ARITH); /* try a 'global' i.m. */ | 1015 | im = luaI_getim(0, event); /* try a 'global' i.m. */ |
1016 | if (ttype(im) == LUA_T_NIL) | 1016 | if (ttype(im) == LUA_T_NIL) |
1017 | lua_error("unexpected type at conversion to number"); | 1017 | lua_error("unexpected type at conversion to number"); |
1018 | } | 1018 | } |
1019 | } | 1019 | } |
1020 | lua_pushstring(op); | 1020 | lua_pushstring(luaI_eventname[event]); |
1021 | callIM(im, 3, 1); | 1021 | callIM(im, 3, 1); |
1022 | } | 1022 | } |
1023 | 1023 | ||
@@ -1029,17 +1029,17 @@ static void concim (Object *o) | |||
1029 | callIM(im, 2, 1); | 1029 | callIM(im, 2, 1); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | static void ordim (Object *o, char *op) | 1032 | static void ordim (Object *o, IMS event) |
1033 | { | 1033 | { |
1034 | Object *im = luaI_getimbyObj(o, IM_ORDER); | 1034 | Object *im = luaI_getimbyObj(o, event); |
1035 | if (ttype(im) == LUA_T_NIL) | 1035 | if (ttype(im) == LUA_T_NIL) |
1036 | lua_error("unexpected type at comparison"); | 1036 | lua_error("unexpected type at comparison"); |
1037 | lua_pushstring(op); | 1037 | lua_pushstring(luaI_eventname[event]); |
1038 | callIM(im, 3, 1); | 1038 | callIM(im, 3, 1); |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | 1041 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, |
1042 | lua_Type ttype_great, char *op) | 1042 | lua_Type ttype_great, IMS op) |
1043 | { | 1043 | { |
1044 | Object *l = top-2; | 1044 | Object *l = top-2; |
1045 | Object *r = top-1; | 1045 | Object *r = top-1; |
@@ -1292,19 +1292,19 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1292 | break; | 1292 | break; |
1293 | 1293 | ||
1294 | case LTOP: | 1294 | case LTOP: |
1295 | comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, "lt"); | 1295 | comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); |
1296 | break; | 1296 | break; |
1297 | 1297 | ||
1298 | case LEOP: | 1298 | case LEOP: |
1299 | comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, "le"); | 1299 | comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); |
1300 | break; | 1300 | break; |
1301 | 1301 | ||
1302 | case GTOP: | 1302 | case GTOP: |
1303 | comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, "gt"); | 1303 | comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); |
1304 | break; | 1304 | break; |
1305 | 1305 | ||
1306 | case GEOP: | 1306 | case GEOP: |
1307 | comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, "ge"); | 1307 | comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); |
1308 | break; | 1308 | break; |
1309 | 1309 | ||
1310 | case ADDOP: | 1310 | case ADDOP: |
@@ -1312,7 +1312,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1312 | Object *l = top-2; | 1312 | Object *l = top-2; |
1313 | Object *r = top-1; | 1313 | Object *r = top-1; |
1314 | if (tonumber(r) || tonumber(l)) | 1314 | if (tonumber(r) || tonumber(l)) |
1315 | call_arith("add"); | 1315 | call_arith(IM_ADD); |
1316 | else | 1316 | else |
1317 | { | 1317 | { |
1318 | nvalue(l) += nvalue(r); | 1318 | nvalue(l) += nvalue(r); |
@@ -1326,7 +1326,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1326 | Object *l = top-2; | 1326 | Object *l = top-2; |
1327 | Object *r = top-1; | 1327 | Object *r = top-1; |
1328 | if (tonumber(r) || tonumber(l)) | 1328 | if (tonumber(r) || tonumber(l)) |
1329 | call_arith("sub"); | 1329 | call_arith(IM_SUB); |
1330 | else | 1330 | else |
1331 | { | 1331 | { |
1332 | nvalue(l) -= nvalue(r); | 1332 | nvalue(l) -= nvalue(r); |
@@ -1340,7 +1340,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1340 | Object *l = top-2; | 1340 | Object *l = top-2; |
1341 | Object *r = top-1; | 1341 | Object *r = top-1; |
1342 | if (tonumber(r) || tonumber(l)) | 1342 | if (tonumber(r) || tonumber(l)) |
1343 | call_arith("mul"); | 1343 | call_arith(IM_MUL); |
1344 | else | 1344 | else |
1345 | { | 1345 | { |
1346 | nvalue(l) *= nvalue(r); | 1346 | nvalue(l) *= nvalue(r); |
@@ -1354,7 +1354,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1354 | Object *l = top-2; | 1354 | Object *l = top-2; |
1355 | Object *r = top-1; | 1355 | Object *r = top-1; |
1356 | if (tonumber(r) || tonumber(l)) | 1356 | if (tonumber(r) || tonumber(l)) |
1357 | call_arith("div"); | 1357 | call_arith(IM_DIV); |
1358 | else | 1358 | else |
1359 | { | 1359 | { |
1360 | nvalue(l) /= nvalue(r); | 1360 | nvalue(l) /= nvalue(r); |
@@ -1364,7 +1364,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1364 | break; | 1364 | break; |
1365 | 1365 | ||
1366 | case POWOP: | 1366 | case POWOP: |
1367 | call_arith("pow"); | 1367 | call_arith(IM_POW); |
1368 | break; | 1368 | break; |
1369 | 1369 | ||
1370 | case CONCOP: { | 1370 | case CONCOP: { |
@@ -1386,7 +1386,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1386 | { | 1386 | { |
1387 | ttype(top) = LUA_T_NIL; | 1387 | ttype(top) = LUA_T_NIL; |
1388 | incr_top; | 1388 | incr_top; |
1389 | call_arith("unm"); | 1389 | call_arith(IM_UNM); |
1390 | } | 1390 | } |
1391 | else | 1391 | else |
1392 | nvalue(top-1) = - nvalue(top-1); | 1392 | nvalue(top-1) = - nvalue(top-1); |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.28 1997/03/11 18:44:28 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.29 1997/03/19 19:41:10 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -14,6 +14,10 @@ | |||
14 | 14 | ||
15 | #define FIELDS_PER_FLUSH 40 | 15 | #define FIELDS_PER_FLUSH 40 |
16 | 16 | ||
17 | /* | ||
18 | * WARNING: if you change the order of this enumeration, | ||
19 | * grep "ORDER LUA_T" | ||
20 | */ | ||
17 | typedef enum | 21 | typedef enum |
18 | { | 22 | { |
19 | LUA_T_NIL = -9, | 23 | LUA_T_NIL = -9, |