summaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 12:02:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 12:02:26 -0300
commita580480b07cdf7201306b246deeb2fe84f2c25a9 (patch)
tree30e9d4798228156eea5be2589834f1ff2db4355e /lvm.c
parent0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532 (diff)
downloadlua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.gz
lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.bz2
lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.zip
new implementation for globals: Global value is stored in TaggedString
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/lvm.c b/lvm.c
index 5b7971c6..6051067e 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.4 1997/09/22 20:53:20 roberto Exp roberto $ 2** $Id: lvm.c,v 1.5 1997/09/24 19:43:11 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*/
@@ -12,7 +12,6 @@
12#include "ldo.h" 12#include "ldo.h"
13#include "lfunc.h" 13#include "lfunc.h"
14#include "lgc.h" 14#include "lgc.h"
15#include "lglobal.h"
16#include "lmem.h" 15#include "lmem.h"
17#include "lopcodes.h" 16#include "lopcodes.h"
18#include "lstring.h" 17#include "lstring.h"
@@ -155,17 +154,17 @@ void luaV_settable (TObject *t, int mode)
155} 154}
156 155
157 156
158void luaV_getglobal (Word n) 157void luaV_getglobal (TaggedString *ts)
159{ 158{
160 /* WARNING: caller must assure stack space */ 159 /* WARNING: caller must assure stack space */
161 TObject *value = &luaG_global[n].object; 160 TObject *value = &ts->u.globalval;
162 TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); 161 TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
163 if (ttype(im) == LUA_T_NIL) { /* default behavior */ 162 if (ttype(im) == LUA_T_NIL) { /* default behavior */
164 *luaD_stack.top++ = *value; 163 *luaD_stack.top++ = *value;
165 } 164 }
166 else { 165 else {
167 ttype(luaD_stack.top) = LUA_T_STRING; 166 ttype(luaD_stack.top) = LUA_T_STRING;
168 tsvalue(luaD_stack.top) = luaG_global[n].varname; 167 tsvalue(luaD_stack.top) = ts;
169 luaD_stack.top++; 168 luaD_stack.top++;
170 *luaD_stack.top++ = *value; 169 *luaD_stack.top++ = *value;
171 luaD_callTM(im, 2, 1); 170 luaD_callTM(im, 2, 1);
@@ -173,17 +172,17 @@ void luaV_getglobal (Word n)
173} 172}
174 173
175 174
176void luaV_setglobal (Word n) 175void luaV_setglobal (TaggedString *ts)
177{ 176{
178 TObject *oldvalue = &luaG_global[n].object; 177 TObject *oldvalue = &ts->u.globalval;
179 TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); 178 TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
180 if (ttype(im) == LUA_T_NIL) /* default behavior */ 179 if (ttype(im) == LUA_T_NIL) /* default behavior */
181 s_object(n) = *(--luaD_stack.top); 180 luaS_rawsetglobal(ts, --luaD_stack.top);
182 else { 181 else {
183 /* WARNING: caller must assure stack space */ 182 /* WARNING: caller must assure stack space */
184 TObject newvalue = *(luaD_stack.top-1); 183 TObject newvalue = *(luaD_stack.top-1);
185 ttype(luaD_stack.top-1) = LUA_T_STRING; 184 ttype(luaD_stack.top-1) = LUA_T_STRING;
186 tsvalue(luaD_stack.top-1) = luaG_global[n].varname; 185 tsvalue(luaD_stack.top-1) = ts;
187 *luaD_stack.top++ = *oldvalue; 186 *luaD_stack.top++ = *oldvalue;
188 *luaD_stack.top++ = newvalue; 187 *luaD_stack.top++ = newvalue;
189 luaD_callTM(im, 3, 0); 188 luaD_callTM(im, 3, 0);
@@ -334,7 +333,7 @@ StkId luaV_execute (Closure *cl, StkId base)
334 case GETGLOBAL9: 333 case GETGLOBAL9:
335 aux -= GETGLOBAL0; 334 aux -= GETGLOBAL0;
336 getglobal: 335 getglobal:
337 luaV_getglobal(luaG_findsymbol(tsvalue(&consts[aux]))); 336 luaV_getglobal(tsvalue(&consts[aux]));
338 break; 337 break;
339 338
340 case GETTABLE: 339 case GETTABLE:
@@ -396,7 +395,7 @@ StkId luaV_execute (Closure *cl, StkId base)
396 case SETGLOBALB: 395 case SETGLOBALB:
397 aux = *pc++; 396 aux = *pc++;
398 setglobal: 397 setglobal:
399 luaV_setglobal(luaG_findsymbol(tsvalue(&consts[aux]))); 398 luaV_setglobal(tsvalue(&consts[aux]));
400 break; 399 break;
401 400
402 case SETTABLE0: 401 case SETTABLE0: