diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 54 |
1 files changed, 27 insertions, 27 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.170 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.171 2001/02/22 18:59:59 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -43,7 +43,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ | |||
43 | if (ttype(obj) != LUA_TNUMBER) | 43 | if (ttype(obj) != LUA_TNUMBER) |
44 | return 1; | 44 | return 1; |
45 | else { | 45 | else { |
46 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 46 | l_char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
47 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 47 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
48 | setsvalue(obj, luaS_new(L, s)); | 48 | setsvalue(obj, luaS_new(L, s)); |
49 | return 0; | 49 | return 0; |
@@ -96,23 +96,23 @@ void luaV_Lclosure (lua_State *L, Proto *l, int nelems) { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | static void callTM (lua_State *L, const char *fmt, ...) { | 99 | static void callTM (lua_State *L, const l_char *fmt, ...) { |
100 | va_list argp; | 100 | va_list argp; |
101 | StkId base = L->top; | 101 | StkId base = L->top; |
102 | int has_result = 0; | 102 | int has_result = 0; |
103 | va_start(argp, fmt); | 103 | va_start(argp, fmt); |
104 | while (*fmt) { | 104 | while (*fmt) { |
105 | switch (*fmt++) { | 105 | switch (*fmt++) { |
106 | case 'c': | 106 | case l_c('c'): |
107 | setclvalue(L->top, va_arg(argp, Closure *)); | 107 | setclvalue(L->top, va_arg(argp, Closure *)); |
108 | break; | 108 | break; |
109 | case 'o': | 109 | case l_c('o'): |
110 | setobj(L->top, va_arg(argp, TObject *)); | 110 | setobj(L->top, va_arg(argp, TObject *)); |
111 | break; | 111 | break; |
112 | case 's': | 112 | case l_c('s'): |
113 | setsvalue(L->top, va_arg(argp, TString *)); | 113 | setsvalue(L->top, va_arg(argp, TString *)); |
114 | break; | 114 | break; |
115 | case 'r': | 115 | case l_c('r'): |
116 | has_result = 1; | 116 | has_result = 1; |
117 | continue; | 117 | continue; |
118 | } | 118 | } |
@@ -151,9 +151,9 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) { | |||
151 | else { /* not a table; try a `gettable' tag method */ | 151 | else { /* not a table; try a `gettable' tag method */ |
152 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); | 152 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); |
153 | if (tm == NULL) /* no tag method? */ | 153 | if (tm == NULL) /* no tag method? */ |
154 | luaG_typeerror(L, t, "index"); | 154 | luaG_typeerror(L, t, l_s("index")); |
155 | } | 155 | } |
156 | callTM(L, "coor", tm, t, key, res); | 156 | callTM(L, l_s("coor"), tm, t, key, res); |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
@@ -175,9 +175,9 @@ void luaV_settable (lua_State *L, StkId t, StkId key, StkId val) { | |||
175 | else { /* not a table; try a `settable' tag method */ | 175 | else { /* not a table; try a `settable' tag method */ |
176 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); | 176 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
177 | if (tm == NULL) /* no tag method? */ | 177 | if (tm == NULL) /* no tag method? */ |
178 | luaG_typeerror(L, t, "index"); | 178 | luaG_typeerror(L, t, l_s("index")); |
179 | } | 179 | } |
180 | callTM(L, "cooo", tm, t, key, val); | 180 | callTM(L, l_s("cooo"), tm, t, key, val); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
@@ -189,7 +189,7 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) { | |||
189 | setobj(res, value); /* default behavior */ | 189 | setobj(res, value); /* default behavior */ |
190 | } | 190 | } |
191 | else | 191 | else |
192 | callTM(L, "csor", tm, name, value, res); | 192 | callTM(L, l_s("csor"), tm, name, value, res); |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
@@ -201,7 +201,7 @@ void luaV_setglobal (lua_State *L, TString *name, StkId val) { | |||
201 | setobj(oldvalue, val); /* raw set */ | 201 | setobj(oldvalue, val); /* raw set */ |
202 | } | 202 | } |
203 | else | 203 | else |
204 | callTM(L, "csoo", tm, name, oldvalue, val); | 204 | callTM(L, l_s("csoo"), tm, name, oldvalue, val); |
205 | } | 205 | } |
206 | 206 | ||
207 | 207 | ||
@@ -218,21 +218,21 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | |||
218 | } | 218 | } |
219 | } | 219 | } |
220 | opname = luaS_new(L, luaT_eventname[event]); | 220 | opname = luaS_new(L, luaT_eventname[event]); |
221 | callTM(L, "coosr", tm, p1, p2, opname, res); | 221 | callTM(L, l_s("coosr"), tm, p1, p2, opname, res); |
222 | return 1; | 222 | return 1; |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | static void call_arith (lua_State *L, StkId p1, TMS event) { | 226 | static void call_arith (lua_State *L, StkId p1, TMS event) { |
227 | if (!call_binTM(L, p1, p1+1, p1, event)) | 227 | if (!call_binTM(L, p1, p1+1, p1, event)) |
228 | luaG_binerror(L, p1, LUA_TNUMBER, "perform arithmetic on"); | 228 | luaG_binerror(L, p1, LUA_TNUMBER, l_s("perform arithmetic on")); |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | static int luaV_strlessthan (const TString *ls, const TString *rs) { | 232 | static int luaV_strlessthan (const TString *ls, const TString *rs) { |
233 | const char *l = getstr(ls); | 233 | const l_char *l = getstr(ls); |
234 | size_t ll = ls->len; | 234 | size_t ll = ls->len; |
235 | const char *r = getstr(rs); | 235 | const l_char *r = getstr(rs); |
236 | size_t lr = rs->len; | 236 | size_t lr = rs->len; |
237 | for (;;) { | 237 | for (;;) { |
238 | int temp = strcoll(l, r); | 238 | int temp = strcoll(l, r); |
@@ -269,18 +269,18 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
269 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 269 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
270 | if (tostring(L, top-2) || tostring(L, top-1)) { | 270 | if (tostring(L, top-2) || tostring(L, top-1)) { |
271 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) | 271 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) |
272 | luaG_binerror(L, top-2, LUA_TSTRING, "concat"); | 272 | luaG_binerror(L, top-2, LUA_TSTRING, l_s("concat")); |
273 | } | 273 | } |
274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | 274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
275 | /* at least two string values; get as many as possible */ | 275 | /* at least two string values; get as many as possible */ |
276 | lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; | 276 | lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; |
277 | char *buffer; | 277 | l_char *buffer; |
278 | int i; | 278 | int i; |
279 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 279 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
280 | tl += tsvalue(top-n-1)->len; | 280 | tl += tsvalue(top-n-1)->len; |
281 | n++; | 281 | n++; |
282 | } | 282 | } |
283 | if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); | 283 | if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow")); |
284 | buffer = luaO_openspace(L, tl); | 284 | buffer = luaO_openspace(L, tl); |
285 | tl = 0; | 285 | tl = 0; |
286 | for (i=n; i>0; i--) { /* concat all strings */ | 286 | for (i=n; i>0; i--) { /* concat all strings */ |
@@ -303,7 +303,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) { | |||
303 | for (i=0; firstelem+i<L->top; i++) | 303 | for (i=0; firstelem+i<L->top; i++) |
304 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); | 304 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); |
305 | /* store counter in field `n' */ | 305 | /* store counter in field `n' */ |
306 | n = luaH_setstr(L, htab, luaS_newliteral(L, "n")); | 306 | n = luaH_setstr(L, htab, luaS_newliteral(L, l_s("n"))); |
307 | setnvalue(n, i); | 307 | setnvalue(n, i); |
308 | L->top = firstelem; /* remove elements from the stack */ | 308 | L->top = firstelem; /* remove elements from the stack */ |
309 | sethvalue(L->top, htab); | 309 | sethvalue(L->top, htab); |
@@ -509,7 +509,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
509 | } | 509 | } |
510 | case OP_POW: { | 510 | case OP_POW: { |
511 | if (!call_binTM(L, top-2, top-1, top-2, TM_POW)) | 511 | if (!call_binTM(L, top-2, top-1, top-2, TM_POW)) |
512 | luaD_error(L, "undefined operation"); | 512 | luaD_error(L, l_s("undefined operation")); |
513 | top--; | 513 | top--; |
514 | break; | 514 | break; |
515 | } | 515 | } |
@@ -595,11 +595,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
595 | case OP_FORPREP: { | 595 | case OP_FORPREP: { |
596 | int jmp = GETARG_S(i); | 596 | int jmp = GETARG_S(i); |
597 | if (tonumber(top-1)) | 597 | if (tonumber(top-1)) |
598 | luaD_error(L, "`for' step must be a number"); | 598 | luaD_error(L, l_s("`for' step must be a number")); |
599 | if (tonumber(top-2)) | 599 | if (tonumber(top-2)) |
600 | luaD_error(L, "`for' limit must be a number"); | 600 | luaD_error(L, l_s("`for' limit must be a number")); |
601 | if (tonumber(top-3)) | 601 | if (tonumber(top-3)) |
602 | luaD_error(L, "`for' initial value must be a number"); | 602 | luaD_error(L, l_s("`for' initial value must be a number")); |
603 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ | 603 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ |
604 | goto forloop; /* do not increment index */ | 604 | goto forloop; /* do not increment index */ |
605 | } | 605 | } |
@@ -607,7 +607,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
607 | lua_assert(ttype(top-1) == LUA_TNUMBER); | 607 | lua_assert(ttype(top-1) == LUA_TNUMBER); |
608 | lua_assert(ttype(top-2) == LUA_TNUMBER); | 608 | lua_assert(ttype(top-2) == LUA_TNUMBER); |
609 | if (ttype(top-3) != LUA_TNUMBER) | 609 | if (ttype(top-3) != LUA_TNUMBER) |
610 | luaD_error(L, "`for' index must be a number"); | 610 | luaD_error(L, l_s("`for' index must be a number")); |
611 | nvalue(top-3) += nvalue(top-1); /* increment index */ | 611 | nvalue(top-3) += nvalue(top-1); /* increment index */ |
612 | forloop: | 612 | forloop: |
613 | if (nvalue(top-1) > 0 ? | 613 | if (nvalue(top-1) > 0 ? |
@@ -621,7 +621,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
621 | case OP_LFORPREP: { | 621 | case OP_LFORPREP: { |
622 | int jmp = GETARG_S(i); | 622 | int jmp = GETARG_S(i); |
623 | if (ttype(top-1) != LUA_TTABLE) | 623 | if (ttype(top-1) != LUA_TTABLE) |
624 | luaD_error(L, "`for' table must be a table"); | 624 | luaD_error(L, l_s("`for' table must be a table")); |
625 | top += 3; /* index,key,value */ | 625 | top += 3; /* index,key,value */ |
626 | setnvalue(top-3, -1); /* initial index */ | 626 | setnvalue(top-3, -1); /* initial index */ |
627 | setnilvalue(top-2); | 627 | setnilvalue(top-2); |