diff options
| -rw-r--r-- | fallback.c | 44 | ||||
| -rw-r--r-- | fallback.h | 13 | ||||
| -rw-r--r-- | opcode.c | 32 |
3 files changed, 49 insertions, 40 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 2.3 1997/04/06 14:08:08 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 2.4 1997/04/07 14:48:53 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -111,9 +111,7 @@ static int luaI_checkevent (char *name, char *list[]) | |||
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | static struct IM { | 114 | struct IM *luaI_IMtable = NULL; |
| 115 | TObject int_method[IM_N]; | ||
| 116 | } *luaI_IMtable = NULL; | ||
| 117 | 115 | ||
| 118 | static int IMtable_size = 0; | 116 | static int IMtable_size = 0; |
| 119 | static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ | 117 | static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ |
| @@ -141,7 +139,7 @@ static void init_entry (int tag) | |||
| 141 | { | 139 | { |
| 142 | int i; | 140 | int i; |
| 143 | for (i=0; i<IM_N; i++) | 141 | for (i=0; i<IM_N; i++) |
| 144 | luaI_IMtable[-tag].int_method[i].ttype = LUA_T_NIL; | 142 | ttype(luaI_getim(tag, i)) = LUA_T_NIL; |
| 145 | } | 143 | } |
| 146 | 144 | ||
| 147 | void luaI_initfallbacks (void) | 145 | void luaI_initfallbacks (void) |
| @@ -194,32 +192,26 @@ void luaI_settag (int tag, TObject *o) | |||
| 194 | } | 192 | } |
| 195 | 193 | ||
| 196 | 194 | ||
| 197 | int luaI_tag (TObject *o) | 195 | int luaI_efectivetag (TObject *o) |
| 198 | { | 196 | { |
| 199 | lua_Type t = ttype(o); | 197 | lua_Type t = ttype(o); |
| 200 | if (t == LUA_T_USERDATA) | 198 | if (t == LUA_T_USERDATA) { |
| 201 | return o->value.ts->tag; | 199 | int tag = o->value.ts->tag; |
| 200 | return (tag >= 0) ? LUA_T_USERDATA : tag; | ||
| 201 | } | ||
| 202 | else if (t == LUA_T_ARRAY) | 202 | else if (t == LUA_T_ARRAY) |
| 203 | return o->value.a->htag; | 203 | return o->value.a->htag; |
| 204 | else return t; | 204 | else return t; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | 207 | ||
| 208 | TObject *luaI_getim (int tag, IMS event) | ||
| 209 | { | ||
| 210 | if (tag > LUA_T_USERDATA) | ||
| 211 | tag = LUA_T_USERDATA; /* default for non-registered tags */ | ||
| 212 | return &luaI_IMtable[-tag].int_method[event]; | ||
| 213 | } | ||
| 214 | |||
| 215 | |||
| 216 | void luaI_gettagmethod (void) | 208 | void luaI_gettagmethod (void) |
| 217 | { | 209 | { |
| 218 | int t = (int)luaL_check_number(1); | 210 | int t = (int)luaL_check_number(1); |
| 219 | int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); | 211 | int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); |
| 220 | checktag(t); | 212 | checktag(t); |
| 221 | if (validevent(t, e)) | 213 | if (validevent(t, e)) |
| 222 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); | 214 | luaI_pushobject(luaI_getim(t,e)); |
| 223 | } | 215 | } |
| 224 | 216 | ||
| 225 | 217 | ||
| @@ -234,8 +226,8 @@ void luaI_settagmethod (void) | |||
| 234 | luaI_eventname[e], t); | 226 | luaI_eventname[e], t); |
| 235 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), | 227 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), |
| 236 | 3, "function expected"); | 228 | 3, "function expected"); |
| 237 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); | 229 | luaI_pushobject(luaI_getim(t,e)); |
| 238 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); | 230 | *luaI_getim(t, e) = *luaI_Address(func); |
| 239 | } | 231 | } |
| 240 | 232 | ||
| 241 | 233 | ||
| @@ -264,7 +256,7 @@ char *luaI_travfallbacks (int (*fn)(TObject *)) | |||
| 264 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ | 256 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ |
| 265 | int t; | 257 | int t; |
| 266 | for (t=0; t>=last_tag; t--) | 258 | for (t=0; t>=last_tag; t--) |
| 267 | if (fn(&luaI_IMtable[-t].int_method[e])) | 259 | if (fn(luaI_getim(t,e))) |
| 268 | return luaI_eventname[e]; | 260 | return luaI_eventname[e]; |
| 269 | } | 261 | } |
| 270 | return NULL; | 262 | return NULL; |
| @@ -301,7 +293,7 @@ static void fillvalids (IMS e, TObject *func) | |||
| 301 | int t; | 293 | int t; |
| 302 | for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) | 294 | for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) |
| 303 | if (validevent(t, e)) | 295 | if (validevent(t, e)) |
| 304 | luaI_IMtable[-t].int_method[e] = *func; | 296 | *luaI_getim(t, e) = *func; |
| 305 | } | 297 | } |
| 306 | 298 | ||
| 307 | void luaI_setfallback (void) | 299 | void luaI_setfallback (void) |
| @@ -320,13 +312,13 @@ void luaI_setfallback (void) | |||
| 320 | replace = errorFB; | 312 | replace = errorFB; |
| 321 | break; | 313 | break; |
| 322 | case 1: /* old getglobal fallback */ | 314 | case 1: /* old getglobal fallback */ |
| 323 | oldfunc = luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL]; | 315 | oldfunc = *luaI_getim(LUA_T_NIL, IM_GETGLOBAL); |
| 324 | luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL] = *luaI_Address(func); | 316 | *luaI_getim(LUA_T_NIL, IM_GETGLOBAL) = *luaI_Address(func); |
| 325 | replace = nilFB; | 317 | replace = nilFB; |
| 326 | break; | 318 | break; |
| 327 | case 2: { /* old arith fallback */ | 319 | case 2: { /* old arith fallback */ |
| 328 | int i; | 320 | int i; |
| 329 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_POW]; | 321 | oldfunc = *luaI_getim(LUA_T_USERDATA, IM_POW); |
| 330 | for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ | 322 | for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ |
| 331 | fillvalids(i, luaI_Address(func)); | 323 | fillvalids(i, luaI_Address(func)); |
| 332 | replace = typeFB; | 324 | replace = typeFB; |
| @@ -334,7 +326,7 @@ void luaI_setfallback (void) | |||
| 334 | } | 326 | } |
| 335 | case 3: { /* old order fallback */ | 327 | case 3: { /* old order fallback */ |
| 336 | int i; | 328 | int i; |
| 337 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_LT]; | 329 | oldfunc = *luaI_getim(LUA_T_USERDATA, IM_LT); |
| 338 | for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ | 330 | for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ |
| 339 | fillvalids(i, luaI_Address(func)); | 331 | fillvalids(i, luaI_Address(func)); |
| 340 | replace = typeFB; | 332 | replace = typeFB; |
| @@ -343,7 +335,7 @@ void luaI_setfallback (void) | |||
| 343 | default: { | 335 | default: { |
| 344 | int e; | 336 | int e; |
| 345 | if ((e = luaI_findstring(name, luaI_eventname)) >= 0) { | 337 | if ((e = luaI_findstring(name, luaI_eventname)) >= 0) { |
| 346 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[e]; | 338 | oldfunc = *luaI_getim(LUA_T_USERDATA, e); |
| 347 | fillvalids(e, luaI_Address(func)); | 339 | fillvalids(e, luaI_Address(func)); |
| 348 | replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; | 340 | replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; |
| 349 | } | 341 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: fallback.h,v 1.21 1997/04/02 23:04:12 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
| @@ -35,8 +35,15 @@ typedef enum { | |||
| 35 | 35 | ||
| 36 | #define IM_N 18 | 36 | #define IM_N 18 |
| 37 | 37 | ||
| 38 | |||
| 39 | extern struct IM { | ||
| 40 | TObject int_method[IM_N]; | ||
| 41 | } *luaI_IMtable; | ||
| 42 | |||
| 38 | extern char *luaI_eventname[]; | 43 | extern char *luaI_eventname[]; |
| 39 | 44 | ||
| 45 | #define luaI_getim(tag,event) (&luaI_IMtable[-(tag)].int_method[event]) | ||
| 46 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_efectivetag(o),(e))) | ||
| 40 | 47 | ||
| 41 | void luaI_setfallback (void); | 48 | void luaI_setfallback (void); |
| 42 | int luaI_ref (TObject *object, int lock); | 49 | int luaI_ref (TObject *object, int lock); |
| @@ -47,10 +54,8 @@ char *luaI_travfallbacks (int (*fn)(TObject *)); | |||
| 47 | 54 | ||
| 48 | void luaI_settag (int tag, TObject *o); | 55 | void luaI_settag (int tag, TObject *o); |
| 49 | void luaI_realtag (int tag); | 56 | void luaI_realtag (int tag); |
| 50 | TObject *luaI_getim (int tag, IMS event); | ||
| 51 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) | ||
| 52 | TObject *luaI_geterrorim (void); | 57 | TObject *luaI_geterrorim (void); |
| 53 | int luaI_tag (TObject *o); | 58 | int luaI_efectivetag (TObject *o); |
| 54 | void luaI_settagmethod (void); | 59 | void luaI_settagmethod (void); |
| 55 | void luaI_gettagmethod (void); | 60 | void luaI_gettagmethod (void); |
| 56 | void luaI_seterrormethod (void); | 61 | void luaI_seterrormethod (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 4.2 1997/04/04 22:24:51 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.3 1997/04/15 17:32:47 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -180,11 +180,14 @@ static int lua_tostring (TObject *obj) | |||
| 180 | */ | 180 | */ |
| 181 | static void adjust_top (StkId newtop) | 181 | static void adjust_top (StkId newtop) |
| 182 | { | 182 | { |
| 183 | TObject *nt; | 183 | if (newtop <= top-stack) /* int arith, since newtop may be out of stack */ |
| 184 | lua_checkstack(stack+newtop); | 184 | top = stack+newtop; |
| 185 | nt = stack+newtop; /* warning: previous call may change stack */ | 185 | else { |
| 186 | while (top < nt) ttype(top++) = LUA_T_NIL; | 186 | TObject *nt; |
| 187 | top = nt; /* top could be bigger than newtop */ | 187 | lua_checkstack(stack+newtop); |
| 188 | nt = stack+newtop; /* warning: previous call may change stack */ | ||
| 189 | while (top < nt) ttype(top++) = LUA_T_NIL; | ||
| 190 | } | ||
| 188 | } | 191 | } |
| 189 | 192 | ||
| 190 | #define adjustC(nParams) adjust_top(CLS_current.base+nParams) | 193 | #define adjustC(nParams) adjust_top(CLS_current.base+nParams) |
| @@ -300,7 +303,7 @@ static void do_call (StkId base, int nResults) | |||
| 300 | return; | 303 | return; |
| 301 | } | 304 | } |
| 302 | /* adjust the number of results */ | 305 | /* adjust the number of results */ |
| 303 | if (nResults != MULT_RET && top - (stack+firstResult) != nResults) | 306 | if (nResults != MULT_RET) |
| 304 | adjust_top(firstResult+nResults); | 307 | adjust_top(firstResult+nResults); |
| 305 | /* move results to base-1 (to erase parameters and function) */ | 308 | /* move results to base-1 (to erase parameters and function) */ |
| 306 | base--; | 309 | base--; |
| @@ -317,7 +320,7 @@ static void do_call (StkId base, int nResults) | |||
| 317 | */ | 320 | */ |
| 318 | static void pushsubscript (void) | 321 | static void pushsubscript (void) |
| 319 | { | 322 | { |
| 320 | int tg = luaI_tag(top-2); | 323 | int tg = luaI_efectivetag(top-2); |
| 321 | TObject *im = luaI_getim(tg, IM_GETTABLE); | 324 | TObject *im = luaI_getim(tg, IM_GETTABLE); |
| 322 | if (ttype(top-2) == LUA_T_ARRAY && ttype(im) == LUA_T_NIL) { | 325 | if (ttype(top-2) == LUA_T_ARRAY && ttype(im) == LUA_T_NIL) { |
| 323 | TObject *h = lua_hashget(avalue(top-2), top-1); | 326 | TObject *h = lua_hashget(avalue(top-2), top-1); |
| @@ -1033,9 +1036,18 @@ void lua_pushobject (lua_Object o) | |||
| 1033 | incr_top; | 1036 | incr_top; |
| 1034 | } | 1037 | } |
| 1035 | 1038 | ||
| 1036 | int lua_tag (lua_Object o) | 1039 | int lua_tag (lua_Object lo) |
| 1037 | { | 1040 | { |
| 1038 | return (o == LUA_NOOBJECT) ? LUA_T_NIL : luaI_tag(Address(o)); | 1041 | if (lo == LUA_NOOBJECT) return LUA_T_NIL; |
| 1042 | else { | ||
| 1043 | TObject *o = Address(lo); | ||
| 1044 | lua_Type t = ttype(o); | ||
| 1045 | if (t == LUA_T_USERDATA) | ||
| 1046 | return o->value.ts->tag; | ||
| 1047 | else if (t == LUA_T_ARRAY) | ||
| 1048 | return o->value.a->htag; | ||
| 1049 | else return t; | ||
| 1050 | } | ||
| 1039 | } | 1051 | } |
| 1040 | 1052 | ||
| 1041 | 1053 | ||
