diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
commit | 72659a06050632da1a9b4c492302be46ac283f6b (patch) | |
tree | bac06b4ea523ba5443564d0869e392180d4b7b77 /lvm.c | |
parent | dfaf8c5291fa8aef5bedbfa375853475364ac76e (diff) | |
download | lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.gz lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.bz2 lua-72659a06050632da1a9b4c492302be46ac283f6b.zip |
no more explicit support for wide-chars; too much troble...
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.197 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lvm.c,v 1.198 2001/11/06 21:41:53 roberto Exp $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -10,7 +10,6 @@ | |||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <string.h> | 11 | #include <string.h> |
12 | 12 | ||
13 | #define LUA_PRIVATE | ||
14 | #include "lua.h" | 13 | #include "lua.h" |
15 | 14 | ||
16 | #include "lapi.h" | 15 | #include "lapi.h" |
@@ -54,7 +53,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { | |||
54 | if (ttype(obj) != LUA_TNUMBER) | 53 | if (ttype(obj) != LUA_TNUMBER) |
55 | return 1; | 54 | return 1; |
56 | else { | 55 | else { |
57 | l_char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 56 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
58 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 57 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
59 | setsvalue(obj, luaS_new(L, s)); | 58 | setsvalue(obj, luaS_new(L, s)); |
60 | return 0; | 59 | return 0; |
@@ -86,7 +85,7 @@ static void traceexec (lua_State *L, lua_Hook linehook) { | |||
86 | /* maximum stack used by a call to a tag method (func + args) */ | 85 | /* maximum stack used by a call to a tag method (func + args) */ |
87 | #define MAXSTACK_TM 4 | 86 | #define MAXSTACK_TM 4 |
88 | 87 | ||
89 | static StkId callTM (lua_State *L, Closure *f, const l_char *fmt, ...) { | 88 | static StkId callTM (lua_State *L, Closure *f, const char *fmt, ...) { |
90 | va_list argp; | 89 | va_list argp; |
91 | StkId base = L->top; | 90 | StkId base = L->top; |
92 | lua_assert(strlen(fmt)+1 <= MAXSTACK_TM); | 91 | lua_assert(strlen(fmt)+1 <= MAXSTACK_TM); |
@@ -95,11 +94,11 @@ static StkId callTM (lua_State *L, Closure *f, const l_char *fmt, ...) { | |||
95 | setclvalue(L->top, f); /* push function */ | 94 | setclvalue(L->top, f); /* push function */ |
96 | L->top++; | 95 | L->top++; |
97 | while (*fmt) { | 96 | while (*fmt) { |
98 | if (*fmt++ == l_c('o')) { | 97 | if (*fmt++ == 'o') { |
99 | setobj(L->top, va_arg(argp, TObject *)); | 98 | setobj(L->top, va_arg(argp, TObject *)); |
100 | } | 99 | } |
101 | else { | 100 | else { |
102 | lua_assert(*(fmt-1) == l_c('s')); | 101 | lua_assert(*(fmt-1) == 's'); |
103 | setsvalue(L->top, va_arg(argp, TString *)); | 102 | setsvalue(L->top, va_arg(argp, TString *)); |
104 | } | 103 | } |
105 | L->top++; | 104 | L->top++; |
@@ -146,9 +145,9 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) { | |||
146 | } else { /* not a table; try a `gettable' tag method */ | 145 | } else { /* not a table; try a `gettable' tag method */ |
147 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); | 146 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); |
148 | if (tm == NULL) /* no tag method? */ | 147 | if (tm == NULL) /* no tag method? */ |
149 | luaG_typeerror(L, t, l_s("index")); | 148 | luaG_typeerror(L, t, "index"); |
150 | } | 149 | } |
151 | setTMresult(L, res, callTM(L, tm, l_s("oo"), t, key)); | 150 | setTMresult(L, res, callTM(L, tm, "oo", t, key)); |
152 | } | 151 | } |
153 | 152 | ||
154 | 153 | ||
@@ -169,9 +168,9 @@ void luaV_settable (lua_State *L, StkId t, TObject *key, StkId val) { | |||
169 | } else { /* not a table; try a `settable' tag method */ | 168 | } else { /* not a table; try a `settable' tag method */ |
170 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); | 169 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
171 | if (tm == NULL) /* no tag method? */ | 170 | if (tm == NULL) /* no tag method? */ |
172 | luaG_typeerror(L, t, l_s("index")); | 171 | luaG_typeerror(L, t, "index"); |
173 | } | 172 | } |
174 | setTM(L, callTM(L, tm, l_s("ooo"), t, key, val)); | 173 | setTM(L, callTM(L, tm, "ooo", t, key, val)); |
175 | } | 174 | } |
176 | 175 | ||
177 | 176 | ||
@@ -183,7 +182,7 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) { | |||
183 | setobj(res, value); /* default behavior */ | 182 | setobj(res, value); /* default behavior */ |
184 | } | 183 | } |
185 | else | 184 | else |
186 | setTMresult(L, res, callTM(L, tm, l_s("so"), name, value)); | 185 | setTMresult(L, res, callTM(L, tm, "so", name, value)); |
187 | } | 186 | } |
188 | 187 | ||
189 | 188 | ||
@@ -198,7 +197,7 @@ void luaV_setglobal (lua_State *L, TString *name, StkId val) { | |||
198 | settableval(oldvalue, val); /* warning: tricky optimization! */ | 197 | settableval(oldvalue, val); /* warning: tricky optimization! */ |
199 | } | 198 | } |
200 | else | 199 | else |
201 | setTM(L, callTM(L, tm, l_s("soo"), name, oldvalue, val)); | 200 | setTM(L, callTM(L, tm, "soo", name, oldvalue, val)); |
202 | } | 201 | } |
203 | 202 | ||
204 | 203 | ||
@@ -213,7 +212,7 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | |||
213 | return 0; /* no tag method */ | 212 | return 0; /* no tag method */ |
214 | } | 213 | } |
215 | } | 214 | } |
216 | setTMresult(L, res, callTM(L, tm, l_s("oo"), p1, p2)); | 215 | setTMresult(L, res, callTM(L, tm, "oo", p1, p2)); |
217 | return 1; | 216 | return 1; |
218 | } | 217 | } |
219 | 218 | ||
@@ -226,9 +225,9 @@ static void call_arith (lua_State *L, StkId p1, TObject *p2, | |||
226 | 225 | ||
227 | 226 | ||
228 | static int luaV_strlessthan (const TString *ls, const TString *rs) { | 227 | static int luaV_strlessthan (const TString *ls, const TString *rs) { |
229 | const l_char *l = getstr(ls); | 228 | const char *l = getstr(ls); |
230 | size_t ll = ls->tsv.len; | 229 | size_t ll = ls->tsv.len; |
231 | const l_char *r = getstr(rs); | 230 | const char *r = getstr(rs); |
232 | size_t lr = rs->tsv.len; | 231 | size_t lr = rs->tsv.len; |
233 | for (;;) { | 232 | for (;;) { |
234 | int temp = strcoll(l, r); | 233 | int temp = strcoll(l, r); |
@@ -271,14 +270,14 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
271 | /* at least two string values; get as many as possible */ | 270 | /* at least two string values; get as many as possible */ |
272 | lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + | 271 | lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + |
273 | cast(lu_mem, tsvalue(top-2)->tsv.len); | 272 | cast(lu_mem, tsvalue(top-2)->tsv.len); |
274 | l_char *buffer; | 273 | char *buffer; |
275 | int i; | 274 | int i; |
276 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 275 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
277 | tl += tsvalue(top-n-1)->tsv.len; | 276 | tl += tsvalue(top-n-1)->tsv.len; |
278 | n++; | 277 | n++; |
279 | } | 278 | } |
280 | if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow")); | 279 | if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); |
281 | buffer = luaO_openspace(L, tl, l_char); | 280 | buffer = luaO_openspace(L, tl, char); |
282 | tl = 0; | 281 | tl = 0; |
283 | for (i=n; i>0; i--) { /* concat all strings */ | 282 | for (i=n; i>0; i--) { /* concat all strings */ |
284 | size_t l = tsvalue(top-i)->tsv.len; | 283 | size_t l = tsvalue(top-i)->tsv.len; |
@@ -301,7 +300,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) { | |||
301 | luaH_setnum(L, htab, i+1, firstelem+i); | 300 | luaH_setnum(L, htab, i+1, firstelem+i); |
302 | /* store counter in field `n' */ | 301 | /* store counter in field `n' */ |
303 | setnvalue(&n, i); | 302 | setnvalue(&n, i); |
304 | luaH_setstr(L, htab, luaS_newliteral(L, l_s("n")), &n); | 303 | luaH_setstr(L, htab, luaS_newliteral(L, "n"), &n); |
305 | L->top = firstelem; /* remove elements from the stack */ | 304 | L->top = firstelem; /* remove elements from the stack */ |
306 | sethvalue(L->top, htab); | 305 | sethvalue(L->top, htab); |
307 | incr_top; | 306 | incr_top; |
@@ -567,11 +566,11 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
567 | } | 566 | } |
568 | case OP_FORPREP: { | 567 | case OP_FORPREP: { |
569 | if (luaV_tonumber(ra, ra) == NULL) | 568 | if (luaV_tonumber(ra, ra) == NULL) |
570 | luaD_error(L, l_s("`for' initial value must be a number")); | 569 | luaD_error(L, "`for' initial value must be a number"); |
571 | if (luaV_tonumber(ra+1, ra+1) == NULL) | 570 | if (luaV_tonumber(ra+1, ra+1) == NULL) |
572 | luaD_error(L, l_s("`for' limit must be a number")); | 571 | luaD_error(L, "`for' limit must be a number"); |
573 | if (luaV_tonumber(ra+2, ra+2) == NULL) | 572 | if (luaV_tonumber(ra+2, ra+2) == NULL) |
574 | luaD_error(L, l_s("`for' step must be a number")); | 573 | luaD_error(L, "`for' step must be a number"); |
575 | /* decrement index (to be incremented) */ | 574 | /* decrement index (to be incremented) */ |
576 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); | 575 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); |
577 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ | 576 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ |
@@ -583,7 +582,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
583 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER && | 582 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER && |
584 | ttype(ra+2) == LUA_TNUMBER); | 583 | ttype(ra+2) == LUA_TNUMBER); |
585 | if (ttype(ra) != LUA_TNUMBER) | 584 | if (ttype(ra) != LUA_TNUMBER) |
586 | luaD_error(L, l_s("`for' index must be a number")); | 585 | luaD_error(L, "`for' index must be a number"); |
587 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ | 586 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ |
588 | if (nvalue(ra+1) >= 0) { | 587 | if (nvalue(ra+1) >= 0) { |
589 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ | 588 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ |
@@ -593,7 +592,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
593 | } | 592 | } |
594 | case OP_TFORPREP: { | 593 | case OP_TFORPREP: { |
595 | if (ttype(ra) != LUA_TTABLE) | 594 | if (ttype(ra) != LUA_TTABLE) |
596 | luaD_error(L, l_s("`for' table must be a table")); | 595 | luaD_error(L, "`for' table must be a table"); |
597 | setnvalue(ra+1, -1); /* initial index */ | 596 | setnvalue(ra+1, -1); /* initial index */ |
598 | setnilvalue(ra+2); | 597 | setnilvalue(ra+2); |
599 | setnilvalue(ra+3); | 598 | setnilvalue(ra+3); |