diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:11:52 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:11:52 -0200 |
commit | 9deac27704eee47f858f6b41a386c3198bc49587 (patch) | |
tree | 27f28b2953f4cd9e2ee60a2ae7067fadb21b8a00 /opcode.c | |
parent | d531ccd082a73aa2fda585dfe5edf2749c7e7d13 (diff) | |
download | lua-9deac27704eee47f858f6b41a386c3198bc49587.tar.gz lua-9deac27704eee47f858f6b41a386c3198bc49587.tar.bz2 lua-9deac27704eee47f858f6b41a386c3198bc49587.zip |
fallback list moved from opcode.c to fallback.c
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 74 |
1 files changed, 11 insertions, 63 deletions
@@ -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.6 1994/11/08 19:56:39 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -50,6 +50,7 @@ static int lua_execute (Byte *pc, int base); | |||
50 | static void do_call (Object *func, int base, int nResults, int whereRes); | 50 | static void do_call (Object *func, int base, int nResults, int whereRes); |
51 | 51 | ||
52 | 52 | ||
53 | |||
53 | Object *luaI_Address (lua_Object o) | 54 | Object *luaI_Address (lua_Object o) |
54 | { | 55 | { |
55 | return Address(o); | 56 | return Address(o); |
@@ -57,66 +58,13 @@ Object *luaI_Address (lua_Object o) | |||
57 | 58 | ||
58 | 59 | ||
59 | /* | 60 | /* |
60 | ** Fallbacks | ||
61 | */ | ||
62 | |||
63 | static struct FB { | ||
64 | char *kind; | ||
65 | Object function; | ||
66 | } fallBacks[] = { | ||
67 | #define FB_ERROR 0 | ||
68 | {"error", {LUA_T_CFUNCTION, luaI_errorFB}}, | ||
69 | #define FB_INDEX 1 | ||
70 | {"index", {LUA_T_CFUNCTION, luaI_indexFB}}, | ||
71 | #define FB_GETTABLE 2 | ||
72 | {"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, | ||
73 | #define FB_ARITH 3 | ||
74 | {"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, | ||
75 | #define FB_ORDER 4 | ||
76 | {"order", {LUA_T_CFUNCTION, luaI_orderFB}}, | ||
77 | #define FB_CONCAT 5 | ||
78 | {"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, | ||
79 | #define FB_UNMINUS 6 | ||
80 | {"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, | ||
81 | #define FB_SETTABLE 7 | ||
82 | {"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} | ||
83 | }; | ||
84 | |||
85 | #define N_FB (sizeof(fallBacks)/sizeof(struct FB)) | ||
86 | |||
87 | |||
88 | void luaI_setfallback (void) | ||
89 | { | ||
90 | int i; | ||
91 | char *name = lua_getstring(lua_getparam(1)); | ||
92 | lua_Object func = lua_getparam(2); | ||
93 | if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func))) | ||
94 | { | ||
95 | lua_pushnil(); | ||
96 | return; | ||
97 | } | ||
98 | for (i=0; i<N_FB; i++) | ||
99 | { | ||
100 | if (strcmp(fallBacks[i].kind, name) == 0) | ||
101 | { | ||
102 | luaI_pushobject(&fallBacks[i].function); | ||
103 | fallBacks[i].function = *Address(func); | ||
104 | return; | ||
105 | } | ||
106 | } | ||
107 | /* name not found */ | ||
108 | lua_pushnil(); | ||
109 | } | ||
110 | |||
111 | |||
112 | /* | ||
113 | ** Error messages | 61 | ** Error messages |
114 | */ | 62 | */ |
115 | 63 | ||
116 | static void lua_message (char *s) | 64 | static void lua_message (char *s) |
117 | { | 65 | { |
118 | lua_pushstring(s); | 66 | lua_pushstring(s); |
119 | do_call(&fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1); | 67 | do_call(&luaI_fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1); |
120 | } | 68 | } |
121 | 69 | ||
122 | /* | 70 | /* |
@@ -311,12 +259,12 @@ static void do_call (Object *func, int base, int nResults, int whereRes) | |||
311 | static void pushsubscript (void) | 259 | static void pushsubscript (void) |
312 | { | 260 | { |
313 | if (tag(top-2) != LUA_T_ARRAY) | 261 | if (tag(top-2) != LUA_T_ARRAY) |
314 | do_call(&fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2); | 262 | do_call(&luaI_fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2); |
315 | else | 263 | else |
316 | { | 264 | { |
317 | Object *h = lua_hashget(avalue(top-2), top-1); | 265 | Object *h = lua_hashget(avalue(top-2), top-1); |
318 | if (h == NULL) | 266 | if (h == NULL) |
319 | do_call(&fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2); | 267 | do_call(&luaI_fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2); |
320 | else | 268 | else |
321 | { | 269 | { |
322 | --top; | 270 | --top; |
@@ -332,7 +280,7 @@ static void pushsubscript (void) | |||
332 | static void storesubscript (void) | 280 | static void storesubscript (void) |
333 | { | 281 | { |
334 | if (tag(top-3) != LUA_T_ARRAY) | 282 | if (tag(top-3) != LUA_T_ARRAY) |
335 | do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); | 283 | do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); |
336 | else | 284 | else |
337 | { | 285 | { |
338 | Object *h = lua_hashdefine (avalue(top-3), top-2); | 286 | Object *h = lua_hashdefine (avalue(top-3), top-2); |
@@ -688,7 +636,7 @@ int lua_type (lua_Object o) | |||
688 | static void call_arith (char *op) | 636 | static void call_arith (char *op) |
689 | { | 637 | { |
690 | lua_pushstring(op); | 638 | lua_pushstring(op); |
691 | do_call(&fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3); | 639 | do_call(&luaI_fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3); |
692 | } | 640 | } |
693 | 641 | ||
694 | static void comparison (lua_Type tag_less, lua_Type tag_equal, | 642 | static void comparison (lua_Type tag_less, lua_Type tag_equal, |
@@ -702,7 +650,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, | |||
702 | else if (tostring(l) || tostring(r)) | 650 | else if (tostring(l) || tostring(r)) |
703 | { | 651 | { |
704 | lua_pushstring(op); | 652 | lua_pushstring(op); |
705 | do_call(&fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3); | 653 | do_call(&luaI_fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3); |
706 | return; | 654 | return; |
707 | } | 655 | } |
708 | else | 656 | else |
@@ -824,7 +772,7 @@ static int lua_execute (Byte *pc, int base) | |||
824 | *(top) = *(top-2-n); | 772 | *(top) = *(top-2-n); |
825 | *(top-1) = *(top-3-n); | 773 | *(top-1) = *(top-3-n); |
826 | top += 2; | 774 | top += 2; |
827 | do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); | 775 | do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); |
828 | } | 776 | } |
829 | else | 777 | else |
830 | { | 778 | { |
@@ -1016,7 +964,7 @@ static int lua_execute (Byte *pc, int base) | |||
1016 | Object *l = top-2; | 964 | Object *l = top-2; |
1017 | Object *r = top-1; | 965 | Object *r = top-1; |
1018 | if (tostring(r) || tostring(l)) | 966 | if (tostring(r) || tostring(l)) |
1019 | do_call(&fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2); | 967 | do_call(&luaI_fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2); |
1020 | else | 968 | else |
1021 | { | 969 | { |
1022 | svalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r))); | 970 | svalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r))); |
@@ -1027,7 +975,7 @@ static int lua_execute (Byte *pc, int base) | |||
1027 | 975 | ||
1028 | case MINUSOP: | 976 | case MINUSOP: |
1029 | if (tonumber(top-1)) | 977 | if (tonumber(top-1)) |
1030 | do_call(&fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1); | 978 | do_call(&luaI_fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1); |
1031 | else | 979 | else |
1032 | nvalue(top-1) = - nvalue(top-1); | 980 | nvalue(top-1) = - nvalue(top-1); |
1033 | break; | 981 | break; |