Showing the changes to src (32 of 62 files). Show all
Unified · Split
| @@ -1,40 +1,66 @@ | ||
| 1 | −# makefile for lua distribution | |
| 1 | +# makefile for lua distribution (main library) | |
| 2 | 2 | |
| 3 | −INC= $(LUA)/include | |
| 4 | −LIB= $(LUA)/lib | |
| 3 | +LUA= .. | |
| 5 | 4 | |
| 6 | −# in SunOs /usr/5include contains prototypes for standard lib | |
| 7 | −INCS= -I/usr/5include -I$(INC) | |
| 8 | −WARN= -Wall -Wmissing-prototypes -Wshadow -ansi | |
| 5 | +include $(LUA)/config | |
| 9 | 6 | |
| 10 | −CC= gcc | |
| 11 | −CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 | |
| 7 | +OBJS= fallback.o\ | |
| 8 | + func.o\ | |
| 9 | + hash.o\ | |
| 10 | + inout.o\ | |
| 11 | + lex.o\ | |
| 12 | + mem.o\ | |
| 13 | + opcode.o\ | |
| 14 | + parser.o\ | |
| 15 | + table.o\ | |
| 16 | + tree.o\ | |
| 17 | + undump.o | |
| 12 | 18 | |
| 13 | −OBJS= fallback.o func.o hash.o inout.o lex.o mem.o opcode.o parser.o table.o tree.o | |
| 14 | −SRCS= fallback.c func.c hash.c inout.c lex.c mem.c opcode.c table.c tree.c fallback.h func.h hash.h inout.h mem.h opcode.h table.h tree.h types.h ugly.h lua.stx | |
| 19 | +SRCS= fallback.c\ | |
| 20 | + fallback.h\ | |
| 21 | + func.c\ | |
| 22 | + func.h\ | |
| 23 | + hash.c\ | |
| 24 | + hash.h\ | |
| 25 | + inout.c\ | |
| 26 | + inout.h\ | |
| 27 | + lex.c\ | |
| 28 | + lex.h\ | |
| 29 | + mem.c\ | |
| 30 | + mem.h\ | |
| 31 | + opcode.c\ | |
| 32 | + opcode.h\ | |
| 33 | + parser.c\ | |
| 34 | + parser.h\ | |
| 35 | + table.c\ | |
| 36 | + table.h\ | |
| 37 | + tree.c\ | |
| 38 | + tree.h\ | |
| 39 | + types.h\ | |
| 40 | + undump.c\ | |
| 41 | + undump.h\ | |
| 42 | + lua.stx | |
| 15 | 43 | |
| 16 | 44 | SLIB= $(LIB)/liblua.a |
| 17 | 45 | |
| 18 | −# dynamic libraries only work for SunOs | |
| 19 | −DLIB= $(LIB)/liblua.so.$(VERSION) | |
| 20 | − | |
| 21 | 46 | all: $(SLIB) |
| 22 | 47 | |
| 23 | −dynamic: $(DLIB) | |
| 24 | − | |
| 25 | 48 | $(SLIB): $(OBJS) |
| 26 | 49 | ar rcuv $@ $(OBJS) |
| 27 | 50 | ranlib $@ |
| 28 | 51 | |
| 29 | −$(DLIB): $(OBJS) | |
| 30 | − ld -o $@ $(OBJS) | |
| 31 | − | |
| 32 | 52 | clean: |
| 33 | − rm -f $(OBJS) $(SLIB) $(DLIB) | |
| 53 | + rm -f $(OBJS) $(SLIB) | |
| 34 | 54 | |
| 35 | 55 | co: |
| 36 | 56 | co -f -M $(SRCS) |
| 37 | − yacc -d lua.stx ; mv -f y.tab.c parser.c ; mv -f y.tab.h parser.h | |
| 57 | + | |
| 58 | +parser: | |
| 59 | + yacc -d lua.stx | |
| 60 | + rm -f parser.c parser.h | |
| 61 | + sed -e 's/yy/luaY_/g' y.tab.c > parser.c | |
| 62 | + sed -e 's/yy/luaY_/g' y.tab.h > parser.h | |
| 63 | + rm y.tab.c y.tab.h | |
| 38 | 64 | |
| 39 | 65 | klean: clean |
| 40 | − rm -f $(SRCS) parser.c parser.h | |
| 66 | + rm -f $(SRCS) | |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_fallback="$Id: fallback.c,v 1.17 1995/10/17 14:30:05 roberto Exp $"; | |
| 6 | +char *rcs_fallback="$Id: fallback.c,v 1.25 1996/04/25 14:10:00 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <string.h> |
| @@ -12,6 +12,7 @@ char *rcs_fallback="$Id: fallback.c,v 1.17 1995/10/17 14:30:05 roberto Exp $"; · 2 unmodified lines | ||
| 12 | 12 | #include "fallback.h" |
| 13 | 13 | #include "opcode.h" |
| 14 | 14 | #include "lua.h" |
| 15 | +#include "table.h" | |
| 15 | 16 | |
| 16 | 17 | |
| 17 | 18 | static void errorFB (void); |
| @@ -36,8 +37,10 @@ struct FB luaI_fallBacks[] = { · 18 unmodified lines | ||
| 36 | 37 | {"concat", {LUA_T_CFUNCTION, {concatFB}}, 2, 1}, |
| 37 | 38 | {"settable", {LUA_T_CFUNCTION, {gettableFB}}, 3, 0}, |
| 38 | 39 | {"gc", {LUA_T_CFUNCTION, {GDFB}}, 1, 0}, |
| 39 | −{"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1} | |
| 40 | +{"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1}, | |
| 40 | 41 | /* no fixed number of params or results */ |
| 42 | +{"getglobal", {LUA_T_CFUNCTION, {indexFB}}, 1, 1} | |
| 43 | + /* same default behavior of index FB */ | |
| 41 | 44 | }; |
| 42 | 45 | |
| 43 | 46 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) |
| @@ -47,7 +50,7 @@ void luaI_setfallback (void) · 3 unmodified lines | ||
| 47 | 50 | int i; |
| 48 | 51 | char *name = lua_getstring(lua_getparam(1)); |
| 49 | 52 | lua_Object func = lua_getparam(2); |
| 50 | − if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func))) | |
| 53 | + if (name == NULL || !lua_isfunction(func)) | |
| 51 | 54 | lua_error("incorrect argument to function `setfallback'"); |
| 52 | 55 | for (i=0; i<N_FB; i++) |
| 53 | 56 | { |
| @@ -110,66 +113,77 @@ static void funcFB (void) · 56 unmodified lines | ||
| 110 | 113 | |
| 111 | 114 | |
| 112 | 115 | /* |
| 113 | −** Lock routines | |
| 116 | +** Reference routines | |
| 114 | 117 | */ |
| 115 | 118 | |
| 116 | −static Object *lockArray = NULL; | |
| 117 | −static Word lockSize = 0; | |
| 119 | +static struct ref { | |
| 120 | + Object o; | |
| 121 | + enum {LOCK, HOLD, FREE, COLLECTED} status; | |
| 122 | +} *refArray = NULL; | |
| 123 | +static int refSize = 0; | |
| 118 | 124 | |
| 119 | −int luaI_lock (Object *object) | |
| 125 | +int luaI_ref (Object *object, int lock) | |
| 120 | 126 | { |
| 121 | − Word i; | |
| 122 | − Word oldSize; | |
| 127 | + int i; | |
| 128 | + int oldSize; | |
| 123 | 129 | if (tag(object) == LUA_T_NIL) |
| 124 | − return -1; | |
| 125 | − for (i=0; i<lockSize; i++) | |
| 126 | − if (tag(&lockArray[i]) == LUA_T_NIL) | |
| 127 | − { | |
| 128 | − lockArray[i] = *object; | |
| 129 | − return i; | |
| 130 | − } | |
| 130 | + return -1; /* special ref for nil */ | |
| 131 | + for (i=0; i<refSize; i++) | |
| 132 | + if (refArray[i].status == FREE) | |
| 133 | + goto found; | |
| 131 | 134 | /* no more empty spaces */ |
| 132 | − oldSize = lockSize; | |
| 133 | − if (lockArray == NULL) | |
| 134 | − { | |
| 135 | − lockSize = 10; | |
| 136 | − lockArray = newvector(lockSize, Object); | |
| 137 | − } | |
| 138 | − else | |
| 139 | − { | |
| 140 | − lockSize = 3*oldSize/2 + 5; | |
| 141 | − lockArray = growvector(lockArray, lockSize, Object); | |
| 142 | − } | |
| 143 | − for (i=oldSize; i<lockSize; i++) | |
| 144 | − tag(&lockArray[i]) = LUA_T_NIL; | |
| 145 | − lockArray[oldSize] = *object; | |
| 146 | − return oldSize; | |
| 135 | + oldSize = refSize; | |
| 136 | + refSize = growvector(&refArray, refSize, struct ref, refEM, MAX_WORD); | |
| 137 | + for (i=oldSize; i<refSize; i++) | |
| 138 | + refArray[i].status = FREE; | |
| 139 | + i = oldSize; | |
| 140 | + found: | |
| 141 | + refArray[i].o = *object; | |
| 142 | + refArray[i].status = lock ? LOCK : HOLD; | |
| 143 | + return i; | |
| 147 | 144 | } |
| 148 | 145 | |
| 149 | 146 | |
| 150 | −void lua_unlock (int ref) | |
| 147 | +void lua_unref (int ref) | |
| 151 | 148 | { |
| 152 | − tag(&lockArray[ref]) = LUA_T_NIL; | |
| 149 | + if (ref >= 0 && ref < refSize) | |
| 150 | + refArray[ref].status = FREE; | |
| 153 | 151 | } |
| 154 | 152 | |
| 155 | 153 | |
| 156 | −Object *luaI_getlocked (int ref) | |
| 154 | +Object *luaI_getref (int ref) | |
| 157 | 155 | { |
| 158 | − return &lockArray[ref]; | |
| 156 | + static Object nul = {LUA_T_NIL, {0}}; | |
| 157 | + if (ref == -1) | |
| 158 | + return &nul; | |
| 159 | + if (ref >= 0 && ref < refSize && | |
| 160 | + (refArray[ref].status == LOCK || refArray[ref].status == HOLD)) | |
| 161 | + return &refArray[ref].o; | |
| 162 | + else | |
| 163 | + return NULL; | |
| 159 | 164 | } |
| 160 | 165 | |
| 161 | 166 | |
| 162 | 167 | void luaI_travlock (int (*fn)(Object *)) |
| 163 | 168 | { |
| 164 | − Word i; | |
| 165 | − for (i=0; i<lockSize; i++) | |
| 166 | − fn(&lockArray[i]); | |
| 169 | + int i; | |
| 170 | + for (i=0; i<refSize; i++) | |
| 171 | + if (refArray[i].status == LOCK) | |
| 172 | + fn(&refArray[i].o); | |
| 167 | 173 | } |
| 168 | 174 | |
| 169 | 175 | |
| 176 | +void luaI_invalidaterefs (void) | |
| 177 | +{ | |
| 178 | + int i; | |
| 179 | + for (i=0; i<refSize; i++) | |
| 180 | + if (refArray[i].status == HOLD && !luaI_ismarked(&refArray[i].o)) | |
| 181 | + refArray[i].status = COLLECTED; | |
| 182 | +} | |
| 183 | + | |
| 170 | 184 | char *luaI_travfallbacks (int (*fn)(Object *)) |
| 171 | 185 | { |
| 172 | − Word i; | |
| 186 | + int i; | |
| 173 | 187 | for (i=0; i<N_FB; i++) |
| 174 | 188 | if (fn(&luaI_fallBacks[i].function)) |
| 175 | 189 | return luaI_fallBacks[i].kind; |
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: fallback.h,v 1.10 1995/10/17 11:52:38 roberto Exp $ | |
| 2 | +** $Id: fallback.h,v 1.13 1996/04/25 14:10:00 roberto Exp $ | |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | #ifndef fallback_h |
| 6 | 6 | #define fallback_h |
| 7 | 7 | |
| 8 | +#include "lua.h" | |
| 8 | 9 | #include "opcode.h" |
| 9 | 10 | |
| 10 | 11 | extern struct FB { |
| @@ -23,11 +24,13 @@ extern struct FB { · 12 unmodified lines | ||
| 23 | 24 | #define FB_SETTABLE 6 |
| 24 | 25 | #define FB_GC 7 |
| 25 | 26 | #define FB_FUNCTION 8 |
| 27 | +#define FB_GETGLOBAL 9 | |
| 26 | 28 | |
| 27 | 29 | void luaI_setfallback (void); |
| 28 | −int luaI_lock (Object *object); | |
| 29 | −Object *luaI_getlocked (int ref); | |
| 30 | +int luaI_ref (Object *object, int lock); | |
| 31 | +Object *luaI_getref (int ref); | |
| 30 | 32 | void luaI_travlock (int (*fn)(Object *)); |
| 33 | +void luaI_invalidaterefs (void); | |
| 31 | 34 | char *luaI_travfallbacks (int (*fn)(Object *)); |
| 32 | 35 | |
| 33 | 36 | #endif |
| @@ -1,4 +1,4 @@ | ||
| 1 | −#include <stdio.h> | |
| 1 | +#include <stdlib.h> | |
| 2 | 2 | |
| 3 | 3 | #include "luadebug.h" |
| 4 | 4 | #include "table.h" |
| @@ -6,8 +6,26 @@ · 1 unmodified line | ||
| 6 | 6 | #include "func.h" |
| 7 | 7 | #include "opcode.h" |
| 8 | 8 | |
| 9 | + | |
| 9 | 10 | static TFunc *function_root = NULL; |
| 11 | +static LocVar *currvars = NULL; | |
| 12 | +static int numcurrvars = 0; | |
| 13 | +static int maxcurrvars = 0; | |
| 14 | + | |
| 10 | 15 | |
| 16 | +/* | |
| 17 | +** Initialize TFunc struct | |
| 18 | +*/ | |
| 19 | +void luaI_initTFunc (TFunc *f) | |
| 20 | +{ | |
| 21 | + f->next = NULL; | |
| 22 | + f->marked = 0; | |
| 23 | + f->size = 0; | |
| 24 | + f->code = NULL; | |
| 25 | + f->lineDefined = 0; | |
| 26 | + f->fileName = NULL; | |
| 27 | + f->locvars = NULL; | |
| 28 | +} | |
| 11 | 29 | |
| 12 | 30 | /* |
| 13 | 31 | ** Insert function in list for GC |
| @@ -24,9 +42,10 @@ void luaI_insertfunction (TFunc *f) · 10 unmodified lines | ||
| 24 | 42 | /* |
| 25 | 43 | ** Free function |
| 26 | 44 | */ |
| 27 | −static void freefunc (TFunc *f) | |
| 45 | +void luaI_freefunc (TFunc *f) | |
| 28 | 46 | { |
| 29 | 47 | luaI_free (f->code); |
| 48 | + luaI_free (f->locvars); | |
| 30 | 49 | luaI_free (f); |
| 31 | 50 | } |
| 32 | 51 | |
| @@ -48,7 +67,7 @@ Long luaI_funccollector (void) · 15 unmodified lines | ||
| 48 | 67 | function_root = next; |
| 49 | 68 | else |
| 50 | 69 | prev->next = next; |
| 51 | − freefunc (curr); | |
| 70 | + luaI_freefunc (curr); | |
| 52 | 71 | ++counter; |
| 53 | 72 | } |
| 54 | 73 | else |
| @@ -77,3 +96,61 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined) · 22 unmodified lines | ||
| 77 | 96 | } |
| 78 | 97 | } |
| 79 | 98 | |
| 99 | +/* | |
| 100 | +** Stores information to know that variable has been declared in given line | |
| 101 | +*/ | |
| 102 | +void luaI_registerlocalvar (TaggedString *varname, int line) | |
| 103 | +{ | |
| 104 | + if (numcurrvars >= maxcurrvars) | |
| 105 | + maxcurrvars = growvector(&currvars, maxcurrvars, LocVar, "", MAX_WORD); | |
| 106 | + currvars[numcurrvars].varname = varname; | |
| 107 | + currvars[numcurrvars].line = line; | |
| 108 | + numcurrvars++; | |
| 109 | +} | |
| 110 | + | |
| 111 | +/* | |
| 112 | +** Stores information to know that variable has been out of scope in given line | |
| 113 | +*/ | |
| 114 | +void luaI_unregisterlocalvar (int line) | |
| 115 | +{ | |
| 116 | + luaI_registerlocalvar(NULL, line); | |
| 117 | +} | |
| 118 | + | |
| 119 | +/* | |
| 120 | +** Copies "currvars" into a new area and store it in function header. | |
| 121 | +** The values (varname = NULL, line = -1) signal the end of vector. | |
| 122 | +*/ | |
| 123 | +void luaI_closelocalvars (TFunc *func) | |
| 124 | +{ | |
| 125 | + func->locvars = newvector (numcurrvars+1, LocVar); | |
| 126 | + memcpy (func->locvars, currvars, numcurrvars*sizeof(LocVar)); | |
| 127 | + func->locvars[numcurrvars].varname = NULL; | |
| 128 | + func->locvars[numcurrvars].line = -1; | |
| 129 | + numcurrvars = 0; /* prepares for next function */ | |
| 130 | +} | |
| 131 | + | |
| 132 | +/* | |
| 133 | +** Look for n-esim local variable at line "line" in function "func". | |
| 134 | +** Returns NULL if not found. | |
| 135 | +*/ | |
| 136 | +char *luaI_getlocalname (TFunc *func, int local_number, int line) | |
| 137 | +{ | |
| 138 | + int count = 0; | |
| 139 | + char *varname = NULL; | |
| 140 | + LocVar *lv = func->locvars; | |
| 141 | + if (lv == NULL) | |
| 142 | + return NULL; | |
| 143 | + for (; lv->line != -1 && lv->line < line; lv++) | |
| 144 | + { | |
| 145 | + if (lv->varname) /* register */ | |
| 146 | + { | |
| 147 | + if (++count == local_number) | |
| 148 | + varname = lv->varname->str; | |
| 149 | + } | |
| 150 | + else /* unregister */ | |
| 151 | + if (--count < local_number) | |
| 152 | + varname = NULL; | |
| 153 | + } | |
| 154 | + return varname; | |
| 155 | +} | |
| 156 | + | |
| @@ -1,24 +1,44 @@ | ||
| 1 | +/* | |
| 2 | +** $Id: func.h,v 1.8 1996/03/14 15:54:20 roberto Exp $ | |
| 3 | +*/ | |
| 4 | + | |
| 1 | 5 | #ifndef func_h |
| 2 | 6 | #define func_h |
| 3 | 7 | |
| 4 | 8 | #include "types.h" |
| 5 | 9 | #include "lua.h" |
| 10 | +#include "tree.h" | |
| 11 | + | |
| 12 | +typedef struct LocVar | |
| 13 | +{ | |
| 14 | + TaggedString *varname; /* NULL signals end of scope */ | |
| 15 | + int line; | |
| 16 | +} LocVar; | |
| 17 | + | |
| 6 | 18 | |
| 7 | 19 | /* |
| 8 | −** Header para funcoes. | |
| 20 | +** Function Headers | |
| 9 | 21 | */ |
| 10 | 22 | typedef struct TFunc |
| 11 | 23 | { |
| 12 | 24 | struct TFunc *next; |
| 13 | − char marked; | |
| 25 | + int marked; | |
| 14 | 26 | int size; |
| 15 | 27 | Byte *code; |
| 16 | 28 | int lineDefined; |
| 17 | 29 | char *fileName; |
| 30 | + LocVar *locvars; | |
| 18 | 31 | } TFunc; |
| 19 | 32 | |
| 20 | 33 | Long luaI_funccollector (void); |
| 21 | 34 | void luaI_insertfunction (TFunc *f); |
| 22 | 35 | |
| 36 | +void luaI_initTFunc (TFunc *f); | |
| 37 | +void luaI_freefunc (TFunc *f); | |
| 38 | + | |
| 39 | +void luaI_registerlocalvar (TaggedString *varname, int line); | |
| 40 | +void luaI_unregisterlocalvar (int line); | |
| 41 | +void luaI_closelocalvars (TFunc *func); | |
| 42 | +char *luaI_getlocalname (TFunc *func, int local_number, int line); | |
| 23 | 43 | |
| 24 | 44 | #endif |
| @@ -3,9 +3,8 @@ · 2 unmodified lines | ||
| 3 | 3 | ** hash manager for lua |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_hash="$Id: hash.c,v 2.26 1995/10/04 14:20:26 roberto Exp $"; | |
| 6 | +char *rcs_hash="$Id: hash.c,v 2.30 1996/05/06 14:30:27 roberto Exp $"; | |
| 7 | 7 | |
| 8 | −#include <string.h> | |
| 9 | 8 | |
| 10 | 9 | #include "mem.h" |
| 11 | 10 | #include "opcode.h" |
| @@ -13,7 +12,6 @@ char *rcs_hash="$Id: hash.c,v 2.26 1995/10/04 14:20:26 roberto Exp $"; · 1 unmodified line | ||
| 13 | 12 | #include "table.h" |
| 14 | 13 | #include "lua.h" |
| 15 | 14 | |
| 16 | −#define streq(s1,s2) (s1 == s2 || (*(s1) == *(s2) && strcmp(s1,s2)==0)) | |
| 17 | 15 | |
| 18 | 16 | #define nhash(t) ((t)->nhash) |
| 19 | 17 | #define nuse(t) ((t)->nuse) |
| @@ -24,22 +22,22 @@ char *rcs_hash="$Id: hash.c,v 2.26 1995/10/04 14:20:26 roberto Exp $"; · 4 unmodified lines | ||
| 24 | 22 | #define val(n) (&(n)->val) |
| 25 | 23 | |
| 26 | 24 | |
| 27 | −#define REHASH_LIMIT 0.70 /* avoid more than this % full */ | |
| 25 | +#define REHASH_LIMIT 0.70 /* avoid more than this % full */ | |
| 28 | 26 | |
| 29 | 27 | |
| 30 | 28 | static Hash *listhead = NULL; |
| 31 | 29 | |
| 32 | 30 | |
| 33 | − | |
| 34 | 31 | /* hash dimensions values */ |
| 35 | −static Word dimensions[] = | |
| 36 | − {3, 5, 7, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, | |
| 37 | − 12853, 25717, 51437, 65521, 0}; /* 65521 == last prime < MAX_WORD */ | |
| 32 | +static Long dimensions[] = | |
| 33 | + {3L, 5L, 7L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, | |
| 34 | + 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L, | |
| 35 | + 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT}; | |
| 38 | 36 | |
| 39 | −static Word redimension (Word nhash) | |
| 37 | +int luaI_redimension (int nhash) | |
| 40 | 38 | { |
| 41 | − Word i; | |
| 42 | − for (i=0; dimensions[i]!=0; i++) | |
| 39 | + int i; | |
| 40 | + for (i=0; dimensions[i]<MAX_INT; i++) | |
| 43 | 41 | { |
| 44 | 42 | if (dimensions[i] > nhash) |
| 45 | 43 | return dimensions[i]; |
| @@ -48,7 +46,7 @@ static Word redimension (Word nhash) · 2 unmodified lines | ||
| 48 | 46 | return 0; /* to avoid warnings */ |
| 49 | 47 | } |
| 50 | 48 | |
| 51 | −static Word hashindex (Hash *t, Object *ref) /* hash function */ | |
| 49 | +static int hashindex (Hash *t, Object *ref) /* hash function */ | |
| 52 | 50 | { |
| 53 | 51 | switch (tag(ref)) |
| 54 | 52 | { |
| @@ -56,19 +54,9 @@ static Word hashindex (Hash *t, Object *ref) /* hash function */ · 1 unmodified line | ||
| 56 | 54 | lua_error ("unexpected type to index table"); |
| 57 | 55 | return -1; /* UNREACHEABLE */ |
| 58 | 56 | case LUA_T_NUMBER: |
| 59 | − return (((Word)nvalue(ref))%nhash(t)); | |
| 57 | + return (((int)nvalue(ref))%nhash(t)); | |
| 60 | 58 | case LUA_T_STRING: |
| 61 | − { | |
| 62 | − unsigned long h = tsvalue(ref)->hash; | |
| 63 | − if (h == 0) | |
| 64 | − { | |
| 65 | − char *name = svalue(ref); | |
| 66 | − while (*name) | |
| 67 | − h = ((h<<5)-h)^(unsigned char)*(name++); | |
| 68 | − tsvalue(ref)->hash = h; | |
| 69 | − } | |
| 70 | − return (Word)h%nhash(t); /* make it a valid index */ | |
| 71 | − } | |
| 59 | + return (int)((tsvalue(ref)->hash)%nhash(t)); /* make it a valid index */ | |
| 72 | 60 | case LUA_T_FUNCTION: |
| 73 | 61 | return (((IntPoint)ref->value.tf)%nhash(t)); |
| 74 | 62 | case LUA_T_CFUNCTION: |
| @@ -80,14 +68,14 @@ static Word hashindex (Hash *t, Object *ref) /* hash function */ · 5 unmodified lines | ||
| 80 | 68 | } |
| 81 | 69 | } |
| 82 | 70 | |
| 83 | −Bool lua_equalObj (Object *t1, Object *t2) | |
| 71 | +int lua_equalObj (Object *t1, Object *t2) | |
| 84 | 72 | { |
| 85 | 73 | if (tag(t1) != tag(t2)) return 0; |
| 86 | 74 | switch (tag(t1)) |
| 87 | 75 | { |
| 88 | 76 | case LUA_T_NIL: return 1; |
| 89 | 77 | case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); |
| 90 | − case LUA_T_STRING: return streq(svalue(t1), svalue(t2)); | |
| 78 | + case LUA_T_STRING: return svalue(t1) == svalue(t2); | |
| 91 | 79 | case LUA_T_ARRAY: return avalue(t1) == avalue(t2); |
| 92 | 80 | case LUA_T_FUNCTION: return t1->value.tf == t2->value.tf; |
| 93 | 81 | case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); |
| @@ -95,9 +83,9 @@ Bool lua_equalObj (Object *t1, Object *t2) · 1 unmodified line | ||
| 95 | 83 | } |
| 96 | 84 | } |
| 97 | 85 | |
| 98 | −static Word present (Hash *t, Object *ref) | |
| 86 | +static int present (Hash *t, Object *ref) | |
| 99 | 87 | { |
| 100 | − Word h = hashindex(t, ref); | |
| 88 | + int h = hashindex(t, ref); | |
| 101 | 89 | while (tag(ref(node(t, h))) != LUA_T_NIL) |
| 102 | 90 | { |
| 103 | 91 | if (lua_equalObj(ref, ref(node(t, h)))) |
| @@ -111,9 +99,9 @@ static Word present (Hash *t, Object *ref) · 7 unmodified lines | ||
| 111 | 99 | /* |
| 112 | 100 | ** Alloc a vector node |
| 113 | 101 | */ |
| 114 | −static Node *hashnodecreate (Word nhash) | |
| 102 | +static Node *hashnodecreate (int nhash) | |
| 115 | 103 | { |
| 116 | − Word i; | |
| 104 | + int i; | |
| 117 | 105 | Node *v = newvector (nhash, Node); |
| 118 | 106 | for (i=0; i<nhash; i++) |
| 119 | 107 | tag(ref(&v[i])) = LUA_T_NIL; |
| @@ -123,10 +111,10 @@ static Node *hashnodecreate (Word nhash) · 3 unmodified lines | ||
| 123 | 111 | /* |
| 124 | 112 | ** Create a new hash. Return the hash pointer or NULL on error. |
| 125 | 113 | */ |
| 126 | −static Hash *hashcreate (Word nhash) | |
| 114 | +static Hash *hashcreate (int nhash) | |
| 127 | 115 | { |
| 128 | 116 | Hash *t = new(Hash); |
| 129 | − nhash = redimension((Word)((float)nhash/REHASH_LIMIT)); | |
| 117 | + nhash = luaI_redimension((int)((float)nhash/REHASH_LIMIT)); | |
| 130 | 118 | nodevector(t) = hashnodecreate(nhash); |
| 131 | 119 | nhash(t) = nhash; |
| 132 | 120 | nuse(t) = 0; |
| @@ -151,7 +139,7 @@ void lua_hashmark (Hash *h) · 18 unmodified lines | ||
| 151 | 139 | { |
| 152 | 140 | if (markarray(h) == 0) |
| 153 | 141 | { |
| 154 | − Word i; | |
| 142 | + int i; | |
| 155 | 143 | markarray(h) = 1; |
| 156 | 144 | for (i=0; i<nhash(h); i++) |
| 157 | 145 | { |
| @@ -218,7 +206,7 @@ Long lua_hashcollector (void) · 60 unmodified lines | ||
| 218 | 206 | ** executes garbage collection if the number of arrays created |
| 219 | 207 | ** exceed a pre-defined range. |
| 220 | 208 | */ |
| 221 | −Hash *lua_createarray (Word nhash) | |
| 209 | +Hash *lua_createarray (int nhash) | |
| 222 | 210 | { |
| 223 | 211 | Hash *array; |
| 224 | 212 | lua_pack(); |
| @@ -234,10 +222,10 @@ Hash *lua_createarray (Word nhash) · 9 unmodified lines | ||
| 234 | 222 | */ |
| 235 | 223 | static void rehash (Hash *t) |
| 236 | 224 | { |
| 237 | − Word i; | |
| 238 | − Word nold = nhash(t); | |
| 225 | + int i; | |
| 226 | + int nold = nhash(t); | |
| 239 | 227 | Node *vold = nodevector(t); |
| 240 | − nhash(t) = redimension(nhash(t)); | |
| 228 | + nhash(t) = luaI_redimension(nhash(t)); | |
| 241 | 229 | nodevector(t) = hashnodecreate(nhash(t)); |
| 242 | 230 | for (i=0; i<nold; i++) |
| 243 | 231 | { |
| @@ -254,7 +242,7 @@ static void rehash (Hash *t) · 10 unmodified lines | ||
| 254 | 242 | */ |
| 255 | 243 | Object *lua_hashget (Hash *t, Object *ref) |
| 256 | 244 | { |
| 257 | − Word h = present(t, ref); | |
| 245 | + int h = present(t, ref); | |
| 258 | 246 | if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); |
| 259 | 247 | else return NULL; |
| 260 | 248 | } |
| @@ -266,7 +254,7 @@ Object *lua_hashget (Hash *t, Object *ref) · 5 unmodified lines | ||
| 266 | 254 | */ |
| 267 | 255 | Object *lua_hashdefine (Hash *t, Object *ref) |
| 268 | 256 | { |
| 269 | − Word h; | |
| 257 | + int h; | |
| 270 | 258 | Node *n; |
| 271 | 259 | h = present(t, ref); |
| 272 | 260 | n = node(t, h); |
| @@ -292,7 +280,7 @@ Object *lua_hashdefine (Hash *t, Object *ref) · 19 unmodified lines | ||
| 292 | 280 | ** in the hash. |
| 293 | 281 | ** This function pushs the element value and its reference to the stack. |
| 294 | 282 | */ |
| 295 | −static void hashnext (Hash *t, Word i) | |
| 283 | +static void hashnext (Hash *t, int i) | |
| 296 | 284 | { |
| 297 | 285 | if (i >= nhash(t)) |
| 298 | 286 | { |
| @@ -329,7 +317,7 @@ void lua_next (void) · 30 unmodified lines | ||
| 329 | 317 | } |
| 330 | 318 | else |
| 331 | 319 | { |
| 332 | − Word h = present (t, luaI_Address(r)); | |
| 320 | + int h = present (t, luaI_Address(r)); | |
| 333 | 321 | hashnext(t, h+1); |
| 334 | 322 | } |
| 335 | 323 | } |
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** hash.h |
| 3 | 3 | ** hash manager for lua |
| 4 | −** Luiz Henrique de Figueiredo - 17 Aug 90 | |
| 5 | −** $Id: hash.h,v 2.8 1995/01/12 14:19:04 roberto Exp $ | |
| 4 | +** $Id: hash.h,v 2.12 1996/05/06 14:30:27 roberto Exp $ | |
| 6 | 5 | */ |
| 7 | 6 | |
| 8 | 7 | #ifndef hash_h |
| 9 | 8 | #define hash_h |
| 10 | 9 | |
| 11 | 10 | #include "types.h" |
| 11 | +#include "opcode.h" | |
| 12 | 12 | |
| 13 | 13 | typedef struct node |
| 14 | 14 | { |
| @@ -19,15 +19,16 @@ typedef struct node · 4 unmodified lines | ||
| 19 | 19 | typedef struct Hash |
| 20 | 20 | { |
| 21 | 21 | struct Hash *next; |
| 22 | − char mark; | |
| 23 | − Word nhash; | |
| 24 | − Word nuse; | |
| 25 | 22 | Node *node; |
| 23 | + int nhash; | |
| 24 | + int nuse; | |
| 25 | + char mark; | |
| 26 | 26 | } Hash; |
| 27 | 27 | |
| 28 | 28 | |
| 29 | −Bool lua_equalObj (Object *t1, Object *t2); | |
| 30 | −Hash *lua_createarray (Word nhash); | |
| 29 | +int lua_equalObj (Object *t1, Object *t2); | |
| 30 | +int luaI_redimension (int nhash); | |
| 31 | +Hash *lua_createarray (int nhash); | |
| 31 | 32 | void lua_hashmark (Hash *h); |
| 32 | 33 | Long lua_hashcollector (void); |
| 33 | 34 | Object *lua_hashget (Hash *t, Object *ref); |
| @@ -5,31 +5,21 @@ · 4 unmodified lines | ||
| 5 | 5 | ** Also provides some predefined lua functions. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | −char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp $"; | |
| 8 | +char *rcs_inout="$Id: inout.c,v 2.36 1996/03/19 22:28:37 roberto Exp $"; | |
| 9 | 9 | |
| 10 | 10 | #include <stdio.h> |
| 11 | −#include <stdlib.h> | |
| 12 | −#include <string.h> | |
| 13 | 11 | |
| 14 | −#include "mem.h" | |
| 12 | +#include "lex.h" | |
| 15 | 13 | #include "opcode.h" |
| 16 | −#include "hash.h" | |
| 17 | 14 | #include "inout.h" |
| 18 | 15 | #include "table.h" |
| 19 | 16 | #include "tree.h" |
| 20 | 17 | #include "lua.h" |
| 21 | − | |
| 22 | − | |
| 23 | −#ifndef MAXFUNCSTACK | |
| 24 | −#define MAXFUNCSTACK 100 | |
| 25 | −#endif | |
| 26 | − | |
| 27 | −#define MAXMESSAGE MAXFUNCSTACK*80 | |
| 18 | +#include "mem.h" | |
| 28 | 19 | |
| 29 | 20 | |
| 30 | 21 | /* Exported variables */ |
| 31 | 22 | Word lua_linenumber; |
| 32 | −Bool lua_debug = 0; | |
| 33 | 23 | char *lua_parsedfile; |
| 34 | 24 | |
| 35 | 25 | |
| @@ -54,9 +44,9 @@ static int stringinput (void) · 18 unmodified lines | ||
| 54 | 44 | |
| 55 | 45 | /* |
| 56 | 46 | ** Function to open a file to be input unit. |
| 57 | −** Return 0 on success or error message on error. | |
| 47 | +** Return the file. | |
| 58 | 48 | */ |
| 59 | −char *lua_openfile (char *fn) | |
| 49 | +FILE *lua_openfile (char *fn) | |
| 60 | 50 | { |
| 61 | 51 | lua_setinput (fileinput); |
| 62 | 52 | if (fn == NULL) |
| @@ -67,14 +57,10 @@ char *lua_openfile (char *fn) · 4 unmodified lines | ||
| 67 | 57 | else |
| 68 | 58 | fp = fopen (fn, "r"); |
| 69 | 59 | if (fp == NULL) |
| 70 | − { | |
| 71 | − static char buff[255]; | |
| 72 | − sprintf(buff, "unable to open file `%.200s'", fn); | |
| 73 | − return buff; | |
| 74 | − } | |
| 60 | + return NULL; | |
| 75 | 61 | lua_linenumber = 1; |
| 76 | − lua_parsedfile = lua_constcreate(fn)->ts.str; | |
| 77 | − return NULL; | |
| 62 | + lua_parsedfile = luaI_createfixedstring(fn)->str; | |
| 63 | + return fp; | |
| 78 | 64 | } |
| 79 | 65 | |
| 80 | 66 | /* |
| @@ -97,7 +83,7 @@ void lua_openstring (char *s) · 16 unmodified lines | ||
| 97 | 83 | lua_setinput (stringinput); |
| 98 | 84 | st = s; |
| 99 | 85 | lua_linenumber = 1; |
| 100 | − lua_parsedfile = lua_constcreate("(string)")->ts.str; | |
| 86 | + lua_parsedfile = luaI_createfixedstring("(string)")->str; | |
| 101 | 87 | } |
| 102 | 88 | |
| 103 | 89 | /* |
| @@ -126,33 +112,57 @@ void lua_internaldostring (void) · 22 unmodified lines | ||
| 126 | 112 | void lua_internaldofile (void) |
| 127 | 113 | { |
| 128 | 114 | lua_Object obj = lua_getparam (1); |
| 129 | − if (lua_isstring(obj) && !lua_dofile(lua_getstring(obj))) | |
| 115 | + char *fname = NULL; | |
| 116 | + if (lua_isstring(obj)) | |
| 117 | + fname = lua_getstring(obj); | |
| 118 | + else if (obj != LUA_NOOBJECT) | |
| 119 | + lua_error("invalid argument to function `dofile'"); | |
| 120 | + /* else fname = NULL */ | |
| 121 | + if (!lua_dofile(fname)) | |
| 130 | 122 | lua_pushnumber(1); |
| 131 | 123 | else |
| 132 | 124 | lua_pushnil(); |
| 133 | 125 | } |
| 134 | 126 | |
| 135 | −/* | |
| 136 | −** Internal function: print object values | |
| 137 | −*/ | |
| 138 | −void lua_print (void) | |
| 127 | + | |
| 128 | +static char *tostring (lua_Object obj) | |
| 139 | 129 | { |
| 140 | − int i=1; | |
| 141 | − lua_Object obj; | |
| 142 | − while ((obj=lua_getparam (i++)) != LUA_NOOBJECT) | |
| 143 | − { | |
| 144 | − if (lua_isnumber(obj)) printf("%g\n",lua_getnumber(obj)); | |
| 145 | − else if (lua_isstring(obj)) printf("%s\n",lua_getstring(obj)); | |
| 146 | − else if (lua_isfunction(obj)) printf("function: %p\n",(luaI_Address(obj))->value.tf); | |
| 147 | − else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction(obj) | |
| 148 | −); | |
| 149 | − else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata(obj)); | |
| 150 | − else if (lua_istable(obj)) printf("table: %p\n",avalue(luaI_Address(obj))); | |
| 151 | − else if (lua_isnil(obj)) printf("nil\n"); | |
| 152 | − else printf("invalid value to print\n"); | |
| 153 | − } | |
| 130 | + char *buff = luaI_buffer(20); | |
| 131 | + if (lua_isstring(obj)) /* get strings and numbers */ | |
| 132 | + return lua_getstring(obj); | |
| 133 | + else switch(lua_type(obj)) | |
| 134 | + { | |
| 135 | + case LUA_T_FUNCTION: | |
| 136 | + sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf); | |
| 137 | + break; | |
| 138 | + case LUA_T_CFUNCTION: | |
| 139 | + sprintf(buff, "cfunction: %p", lua_getcfunction(obj)); | |
| 140 | + break; | |
| 141 | + case LUA_T_ARRAY: | |
| 142 | + sprintf(buff, "table: %p", avalue(luaI_Address(obj))); | |
| 143 | + break; | |
| 144 | + case LUA_T_NIL: | |
| 145 | + sprintf(buff, "nil"); | |
| 146 | + break; | |
| 147 | + default: | |
| 148 | + sprintf(buff, "userdata: %p", lua_getuserdata(obj)); | |
| 149 | + break; | |
| 150 | + } | |
| 151 | + return buff; | |
| 154 | 152 | } |
| 155 | 153 | |
| 154 | +void luaI_tostring (void) | |
| 155 | +{ | |
| 156 | + lua_pushstring(tostring(lua_getparam(1))); | |
| 157 | +} | |
| 158 | + | |
| 159 | +void luaI_print (void) | |
| 160 | +{ | |
| 161 | + int i = 1; | |
| 162 | + lua_Object obj; | |
| 163 | + while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) | |
| 164 | + printf("%s\n", tostring(obj)); | |
| 165 | +} | |
| 156 | 166 | |
| 157 | 167 | /* |
| 158 | 168 | ** Internal function: return an object type. |
| @@ -196,16 +206,7 @@ void lua_obj2number (void) · 37 unmodified lines | ||
| 196 | 206 | { |
| 197 | 207 | lua_Object o = lua_getparam(1); |
| 198 | 208 | if (lua_isnumber(o)) |
| 199 | − lua_pushobject(o); | |
| 200 | − else if (lua_isstring(o)) | |
| 201 | − { | |
| 202 | − char c; | |
| 203 | − float f; | |
| 204 | − if (sscanf(lua_getstring(o),"%f %c",&f,&c) == 1) | |
| 205 | − lua_pushnumber(f); | |
| 206 | − else | |
| 207 | − lua_pushnil(); | |
| 208 | − } | |
| 209 | + lua_pushnumber(lua_getnumber(o)); | |
| 209 | 210 | else |
| 210 | 211 | lua_pushnil(); |
| 211 | 212 | } |
| @@ -218,3 +219,28 @@ void luaI_error (void) · 6 unmodified lines | ||
| 218 | 219 | lua_error(s); |
| 219 | 220 | } |
| 220 | 221 | |
| 222 | +void luaI_assert (void) | |
| 223 | +{ | |
| 224 | + lua_Object p = lua_getparam(1); | |
| 225 | + if (p == LUA_NOOBJECT || lua_isnil(p)) | |
| 226 | + lua_error("assertion failed!"); | |
| 227 | +} | |
| 228 | + | |
| 229 | +void luaI_setglobal (void) | |
| 230 | +{ | |
| 231 | + lua_Object name = lua_getparam(1); | |
| 232 | + lua_Object value = lua_getparam(2); | |
| 233 | + if (!lua_isstring(name)) | |
| 234 | + lua_error("incorrect argument to function `setglobal'"); | |
| 235 | + lua_pushobject(value); | |
| 236 | + lua_storeglobal(lua_getstring(name)); | |
| 237 | + lua_pushobject(value); /* return given value */ | |
| 238 | +} | |
| 239 | + | |
| 240 | +void luaI_getglobal (void) | |
| 241 | +{ | |
| 242 | + lua_Object name = lua_getparam(1); | |
| 243 | + if (!lua_isstring(name)) | |
| 244 | + lua_error("incorrect argument to function `getglobal'"); | |
| 245 | + lua_pushobject(lua_getglobal(lua_getstring(name))); | |
| 246 | +} | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: inout.h,v 1.10 1995/10/17 11:58:41 roberto Exp $ | |
| 2 | +** $Id: inout.h,v 1.15 1996/03/15 18:21:58 roberto Exp $ | |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | |
| @@ -7,23 +7,27 @@ · 1 unmodified line | ||
| 7 | 7 | #define inout_h |
| 8 | 8 | |
| 9 | 9 | #include "types.h" |
| 10 | +#include <stdio.h> | |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | extern Word lua_linenumber; |
| 13 | −extern Bool lua_debug; | |
| 14 | 14 | extern Word lua_debugline; |
| 15 | 15 | extern char *lua_parsedfile; |
| 16 | 16 | |
| 17 | −char *lua_openfile (char *fn); | |
| 17 | +FILE *lua_openfile (char *fn); | |
| 18 | 18 | void lua_closefile (void); |
| 19 | 19 | void lua_openstring (char *s); |
| 20 | 20 | void lua_closestring (void); |
| 21 | 21 | |
| 22 | 22 | void lua_internaldofile (void); |
| 23 | 23 | void lua_internaldostring (void); |
| 24 | −void lua_print (void); | |
| 24 | +void luaI_tostring (void); | |
| 25 | +void luaI_print (void); | |
| 25 | 26 | void luaI_type (void); |
| 26 | 27 | void lua_obj2number (void); |
| 27 | 28 | void luaI_error (void); |
| 29 | +void luaI_assert (void); | |
| 30 | +void luaI_setglobal (void); | |
| 31 | +void luaI_getglobal (void); | |
| 28 | 32 | |
| 29 | 33 | #endif |
| @@ -1,23 +1,19 @@ | ||
| 1 | −char *rcs_lex = "$Id: lex.c,v 2.21 1995/11/16 20:46:24 roberto Exp $"; | |
| 1 | +char *rcs_lex = "$Id: lex.c,v 2.32 1996/03/21 16:33:47 roberto Exp $"; | |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | #include <ctype.h> |
| 5 | −#include <stdio.h> | |
| 6 | −#include <stdlib.h> | |
| 7 | 5 | #include <string.h> |
| 8 | 6 | |
| 9 | 7 | #include "mem.h" |
| 10 | 8 | #include "tree.h" |
| 11 | 9 | #include "table.h" |
| 12 | −#include "opcode.h" | |
| 10 | +#include "lex.h" | |
| 13 | 11 | #include "inout.h" |
| 12 | +#include "luadebug.h" | |
| 14 | 13 | #include "parser.h" |
| 15 | −#include "ugly.h" | |
| 16 | 14 | |
| 17 | 15 | #define MINBUFF 260 |
| 18 | 16 | |
| 19 | −#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) | |
| 20 | − | |
| 21 | 17 | #define next() { current = input(); } |
| 22 | 18 | #define save(x) { *yytextLast++ = (x); } |
| 23 | 19 | #define save_and_next() { save(current); next(); } |
| @@ -47,7 +43,6 @@ char *lua_lasttext (void) · 23 unmodified lines | ||
| 47 | 43 | } |
| 48 | 44 | |
| 49 | 45 | |
| 50 | −/* The reserved words must be listed in lexicographic order */ | |
| 51 | 46 | static struct |
| 52 | 47 | { |
| 53 | 48 | char *name; |
| @@ -74,30 +69,21 @@ static struct · 20 unmodified lines | ||
| 74 | 69 | #define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) |
| 75 | 70 | |
| 76 | 71 | |
| 77 | −static int findReserved (char *name) | |
| 72 | +void luaI_addReserved (void) | |
| 78 | 73 | { |
| 79 | − int l = 0; | |
| 80 | − int h = RESERVEDSIZE - 1; | |
| 81 | − while (l <= h) | |
| 74 | + int i; | |
| 75 | + for (i=0; i<RESERVEDSIZE; i++) | |
| 82 | 76 | { |
| 83 | − int m = (l+h)/2; | |
| 84 | − int comp = lua_strcmp(name, reserved[m].name); | |
| 85 | − if (comp < 0) | |
| 86 | − h = m-1; | |
| 87 | − else if (comp == 0) | |
| 88 | − return reserved[m].token; | |
| 89 | − else | |
| 90 | − l = m+1; | |
| 77 | + TaggedString *ts = lua_createstring(reserved[i].name); | |
| 78 | + ts->marked = reserved[i].token; /* reserved word (always > 255) */ | |
| 91 | 79 | } |
| 92 | − return 0; | |
| 93 | 80 | } |
| 94 | 81 | |
| 95 | 82 | |
| 96 | 83 | static void growtext (void) |
| 97 | 84 | { |
| 98 | 85 | int size = yytextLast - yytext; |
| 99 | − textsize *= 2; | |
| 100 | − yytext = growvector(yytext, textsize, char); | |
| 86 | + textsize = growvector(&yytext, textsize, char, lexEM, MAX_WORD); | |
| 101 | 87 | yytextLast = yytext + size; |
| 102 | 88 | } |
| 103 | 89 | |
| @@ -144,9 +130,9 @@ static int read_long_string (void) · 40 unmodified lines | ||
| 144 | 130 | } |
| 145 | 131 | |
| 146 | 132 | |
| 147 | −int yylex (void) | |
| 133 | +int luaY_lex (void) | |
| 148 | 134 | { |
| 149 | − float a; | |
| 135 | + double a; | |
| 150 | 136 | static int linelasttoken = 0; |
| 151 | 137 | if (lua_debug) |
| 152 | 138 | luaI_codedebugline(linelasttoken); |
| @@ -154,9 +140,6 @@ int yylex (void) · 1 unmodified line | ||
| 154 | 140 | while (1) |
| 155 | 141 | { |
| 156 | 142 | yytextLast = yytext; |
| 157 | −#if 0 | |
| 158 | − fprintf(stderr,"'%c' %d\n",current,current); | |
| 159 | −#endif | |
| 160 | 143 | switch (current) |
| 161 | 144 | { |
| 162 | 145 | case EOF: |
| @@ -174,22 +157,21 @@ int yylex (void) · 11 unmodified lines | ||
| 174 | 157 | while (isalnum(current) || current == '_') |
| 175 | 158 | save_and_next(); |
| 176 | 159 | *yytextLast = 0; |
| 177 | − if (lua_strcmp(yytext, "debug") == 0) | |
| 160 | + if (strcmp(yytext, "debug") == 0) | |
| 178 | 161 | { |
| 179 | − yylval.vInt = 1; | |
| 162 | + luaY_lval.vInt = 1; | |
| 180 | 163 | return DEBUG; |
| 181 | 164 | } |
| 182 | − else if (lua_strcmp(yytext, "nodebug") == 0) | |
| 165 | + else if (strcmp(yytext, "nodebug") == 0) | |
| 183 | 166 | { |
| 184 | − yylval.vInt = 0; | |
| 167 | + luaY_lval.vInt = 0; | |
| 185 | 168 | return DEBUG; |
| 186 | 169 | } |
| 187 | 170 | return WRONGTOKEN; |
| 188 | 171 | |
| 189 | 172 | case '-': |
| 190 | 173 | save_and_next(); |
| 191 | − if (current != '-') return '-'; /* else goes through */ | |
| 192 | − case '#': | |
| 174 | + if (current != '-') return '-'; | |
| 193 | 175 | do { next(); } while (current != '\n' && current != 0); |
| 194 | 176 | continue; |
| 195 | 177 | |
| @@ -203,7 +185,7 @@ int yylex (void) · 7 unmodified lines | ||
| 203 | 185 | return WRONGTOKEN; |
| 204 | 186 | save_and_next(); /* pass the second ']' */ |
| 205 | 187 | *(yytextLast-2) = 0; /* erases ']]' */ |
| 206 | − yylval.vWord = luaI_findconstantbyname(yytext+2); | |
| 188 | + luaY_lval.vWord = luaI_findconstantbyname(yytext+2); | |
| 207 | 189 | return STRING; |
| 208 | 190 | } |
| 209 | 191 | |
| @@ -254,6 +236,7 @@ int yylex (void) · 44 unmodified lines | ||
| 254 | 236 | case 'n': save('\n'); next(); break; |
| 255 | 237 | case 't': save('\t'); next(); break; |
| 256 | 238 | case 'r': save('\r'); next(); break; |
| 239 | + case '\n': lua_linenumber++; /* goes through */ | |
| 257 | 240 | default : save(current); next(); break; |
| 258 | 241 | } |
| 259 | 242 | break; |
| @@ -263,7 +246,7 @@ int yylex (void) · 3 unmodified lines | ||
| 263 | 246 | } |
| 264 | 247 | next(); /* skip the delimiter */ |
| 265 | 248 | *yytextLast = 0; |
| 266 | − yylval.vWord = luaI_findconstantbyname(yytext); | |
| 249 | + luaY_lval.vWord = luaI_findconstantbyname(yytext); | |
| 267 | 250 | return STRING; |
| 268 | 251 | } |
| 269 | 252 | |
| @@ -281,12 +264,14 @@ int yylex (void) · 11 unmodified lines | ||
| 281 | 264 | case 'Z': |
| 282 | 265 | case '_': |
| 283 | 266 | { |
| 284 | − Word res; | |
| 267 | + TaggedString *ts; | |
| 285 | 268 | do { save_and_next(); } while (isalnum(current) || current == '_'); |
| 286 | 269 | *yytextLast = 0; |
| 287 | − res = findReserved(yytext); | |
| 288 | − if (res) return res; | |
| 289 | − yylval.pNode = lua_constcreate(yytext); | |
| 270 | + ts = lua_createstring(yytext); | |
| 271 | + if (ts->marked > 2) | |
| 272 | + return ts->marked; /* reserved word */ | |
| 273 | + luaY_lval.pTStr = ts; | |
| 274 | + ts->marked = 2; /* avoid GC */ | |
| 290 | 275 | return NAME; |
| 291 | 276 | } |
| 292 | 277 | |
| @@ -305,48 +290,32 @@ int yylex (void) · 12 unmodified lines | ||
| 305 | 290 | case '0': case '1': case '2': case '3': case '4': |
| 306 | 291 | case '5': case '6': case '7': case '8': case '9': |
| 307 | 292 | a=0.0; |
| 308 | − do { a=10*a+current-'0'; save_and_next(); } while (isdigit(current)); | |
| 293 | + do { a=10.0*a+(current-'0'); save_and_next(); } while (isdigit(current)); | |
| 309 | 294 | if (current == '.') save_and_next(); |
| 310 | 295 | fraction: |
| 311 | − { float da=0.1; | |
| 296 | + { double da=0.1; | |
| 312 | 297 | while (isdigit(current)) |
| 313 | 298 | {a+=(current-'0')*da; da/=10.0; save_and_next()}; |
| 314 | 299 | if (current == 'e' || current == 'E') |
| 315 | 300 | { |
| 316 | 301 | int e=0; |
| 317 | 302 | int neg; |
| 318 | − float ea; | |
| 303 | + double ea; | |
| 319 | 304 | save_and_next(); |
| 320 | 305 | neg=(current=='-'); |
| 321 | 306 | if (current == '+' || current == '-') save_and_next(); |
| 322 | 307 | if (!isdigit(current)) return WRONGTOKEN; |
| 323 | − do { e=10*e+current-'0'; save_and_next(); } while (isdigit(current)); | |
| 308 | + do { e=10.0*e+(current-'0'); save_and_next(); } while (isdigit(current)); | |
| 324 | 309 | for (ea=neg?0.1:10.0; e>0; e>>=1) |
| 325 | 310 | { |
| 326 | 311 | if (e & 1) a*=ea; |
| 327 | 312 | ea*=ea; |
| 328 | 313 | } |
| 329 | 314 | } |
| 330 | − yylval.vFloat = a; | |
| 315 | + luaY_lval.vFloat = a; | |
| 331 | 316 | return NUMBER; |
| 332 | 317 | } |
| 333 | 318 | |
| 334 | − case U_and: case U_do: case U_else: case U_elseif: case U_end: | |
| 335 | − case U_function: case U_if: case U_local: case U_nil: case U_not: | |
| 336 | − case U_or: case U_repeat: case U_return: case U_then: | |
| 337 | − case U_until: case U_while: | |
| 338 | − { | |
| 339 | − int old = current; | |
| 340 | − next(); | |
| 341 | − return reserved[old-U_and].token; | |
| 342 | − } | |
| 343 | − | |
| 344 | − case U_eq: next(); return EQ; | |
| 345 | − case U_le: next(); return LE; | |
| 346 | − case U_ge: next(); return GE; | |
| 347 | − case U_ne: next(); return NE; | |
| 348 | − case U_sc: next(); return CONC; | |
| 349 | − | |
| 350 | 319 | default: /* also end of file */ |
| 351 | 320 | { |
| 352 | 321 | save_and_next(); |
| @@ -0,0 +1,19 @@ | ||
| 1 | +/* | |
| 2 | +** lex.h | |
| 3 | +** TecCGraf - PUC-Rio | |
| 4 | +** $Id: lex.h,v 1.2 1996/02/14 13:35:51 roberto Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#ifndef lex_h | |
| 8 | +#define lex_h | |
| 9 | + | |
| 10 | + | |
| 11 | +typedef int (*Input) (void); | |
| 12 | + | |
| 13 | +void lua_setinput (Input fn); | |
| 14 | +char *lua_lasttext (void); | |
| 15 | +int luaY_lex (void); | |
| 16 | +void luaI_addReserved (void); | |
| 17 | + | |
| 18 | + | |
| 19 | +#endif | |
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | %{ |
| 2 | 2 | |
| 3 | −char *rcs_luastx = "$Id: lua.stx,v 3.25 1995/10/26 17:02:50 roberto Exp $"; | |
| 3 | +char *rcs_luastx = "$Id: lua.stx,v 3.36 1996/03/21 16:31:32 roberto Exp $"; | |
| 4 | 4 | |
| 5 | 5 | #include <stdio.h> |
| 6 | 6 | #include <stdlib.h> |
| 7 | −#include <string.h> | |
| 8 | 7 | |
| 8 | +#include "luadebug.h" | |
| 9 | 9 | #include "mem.h" |
| 10 | +#include "lex.h" | |
| 10 | 11 | #include "opcode.h" |
| 11 | 12 | #include "hash.h" |
| 12 | 13 | #include "inout.h" |
| @@ -30,7 +31,7 @@ int yyparse (void); · 17 unmodified lines | ||
| 30 | 31 | #endif |
| 31 | 32 | static int maxcode; |
| 32 | 33 | static int maxmain; |
| 33 | −static Long maxcurr; /* to allow maxcurr *= 2 without overflow */ | |
| 34 | +static int maxcurr; | |
| 34 | 35 | static Byte *funcCode = NULL; |
| 35 | 36 | static Byte **initcode; |
| 36 | 37 | static Byte *basepc; |
| @@ -44,35 +45,32 @@ static Long varbuffer[MAXVAR]; /* variables in an assignment list; · 7 unmodified lines | ||
| 44 | 45 | static int nvarbuffer=0; /* number of variables at a list */ |
| 45 | 46 | |
| 46 | 47 | #define MAXLOCALS 32 |
| 47 | −static Word localvar[MAXLOCALS]; /* store local variable names */ | |
| 48 | +static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ | |
| 48 | 49 | static int nlocalvar=0; /* number of local variables */ |
| 49 | 50 | |
| 50 | 51 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
| 51 | 52 | static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ |
| 52 | 53 | static int nfields=0; |
| 53 | 54 | |
| 55 | +int lua_debug = 0; | |
| 54 | 56 | |
| 55 | 57 | /* Internal functions */ |
| 56 | 58 | |
| 57 | 59 | static void yyerror (char *s) |
| 58 | 60 | { |
| 59 | − static char msg[256]; | |
| 60 | − sprintf (msg,"%s near \"%s\" at line %d in file `%s'", | |
| 61 | − s, lua_lasttext (), lua_linenumber, lua_parsedfile); | |
| 61 | + char msg[256]; | |
| 62 | + char *token = lua_lasttext(); | |
| 63 | + if (token[0] == 0) | |
| 64 | + token = "<eof>"; | |
| 65 | + sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'", | |
| 66 | + s, token, lua_linenumber, lua_parsedfile); | |
| 62 | 67 | lua_error (msg); |
| 63 | 68 | } |
| 64 | 69 | |
| 65 | 70 | static void code_byte (Byte c) |
| 66 | 71 | { |
| 67 | 72 | if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ |
| 68 | − { | |
| 69 | − if (maxcurr >= MAX_INT) | |
| 70 | − lua_error("code size overflow"); | |
| 71 | − maxcurr *= 2; | |
| 72 | − if (maxcurr >= MAX_INT) | |
| 73 | − maxcurr = MAX_INT; | |
| 74 | − basepc = growvector(basepc, maxcurr, Byte); | |
| 75 | − } | |
| 73 | + maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT); | |
| 76 | 74 | basepc[pc++] = c; |
| 77 | 75 | } |
| 78 | 76 | |
| @@ -104,10 +102,12 @@ static void code_code (TFunc *tf) · 25 unmodified lines | ||
| 104 | 102 | code_byte(code.m.c4); |
| 105 | 103 | } |
| 106 | 104 | |
| 107 | −static void code_word_at (Byte *p, Word n) | |
| 105 | +static void code_word_at (Byte *p, int n) | |
| 108 | 106 | { |
| 109 | 107 | CodeWord code; |
| 110 | − code.w = n; | |
| 108 | + if ((Word)n != n) | |
| 109 | + yyerror("block too big"); | |
| 110 | + code.w = (Word)n; | |
| 111 | 111 | *p++ = code.m.c1; |
| 112 | 112 | *p++ = code.m.c2; |
| 113 | 113 | } |
| @@ -117,7 +117,7 @@ static void push_field (Word name) · 3 unmodified lines | ||
| 117 | 117 | if (nfields < MAXFIELDS) |
| 118 | 118 | fields[nfields++] = name; |
| 119 | 119 | else |
| 120 | − lua_error ("too many fields in nested constructors"); | |
| 120 | + yyerror ("too many fields in nested constructors"); | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | static void flush_record (int n) |
| @@ -142,24 +142,24 @@ static void flush_list (int m, int n) · 18 unmodified lines | ||
| 142 | 142 | code_byte(m); |
| 143 | 143 | } |
| 144 | 144 | else |
| 145 | − lua_error ("list constructor too long"); | |
| 145 | + yyerror ("list constructor too long"); | |
| 146 | 146 | code_byte(n); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | −static void add_localvar (Word name) | |
| 149 | +static void store_localvar (TaggedString *name, int n) | |
| 150 | 150 | { |
| 151 | − if (nlocalvar < MAXLOCALS) | |
| 152 | − localvar[nlocalvar++] = name; | |
| 151 | + if (nlocalvar+n < MAXLOCALS) | |
| 152 | + localvar[nlocalvar+n] = name; | |
| 153 | 153 | else |
| 154 | − lua_error ("too many local variables"); | |
| 154 | + yyerror ("too many local variables"); | |
| 155 | + if (lua_debug) | |
| 156 | + luaI_registerlocalvar(name, lua_linenumber); | |
| 155 | 157 | } |
| 156 | 158 | |
| 157 | −static void store_localvar (Word name, int n) | |
| 159 | +static void add_localvar (TaggedString *name) | |
| 158 | 160 | { |
| 159 | − if (nlocalvar+n < MAXLOCALS) | |
| 160 | − localvar[nlocalvar+n] = name; | |
| 161 | − else | |
| 162 | − lua_error ("too many local variables"); | |
| 161 | + store_localvar(name, 0); | |
| 162 | + nlocalvar++; | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | static void add_varbuffer (Long var) |
| @@ -167,7 +167,7 @@ static void add_varbuffer (Long var) · 1 unmodified line | ||
| 167 | 167 | if (nvarbuffer < MAXVAR) |
| 168 | 168 | varbuffer[nvarbuffer++] = var; |
| 169 | 169 | else |
| 170 | − lua_error ("variable buffer overflow"); | |
| 170 | + yyerror ("variable buffer overflow"); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | static void code_number (float f) |
| @@ -197,7 +197,7 @@ static void code_number (float f) · 23 unmodified lines | ||
| 197 | 197 | /* |
| 198 | 198 | ** Search a local name and if find return its index. If do not find return -1 |
| 199 | 199 | */ |
| 200 | −static int lua_localname (Word n) | |
| 200 | +static int lua_localname (TaggedString *n) | |
| 201 | 201 | { |
| 202 | 202 | int i; |
| 203 | 203 | for (i=nlocalvar-1; i >= 0; i--) |
| @@ -388,7 +388,6 @@ static void codeIf (Long thenAdd, Long elseAdd) · 184 unmodified lines | ||
| 388 | 388 | */ |
| 389 | 389 | void lua_parse (TFunc *tf) |
| 390 | 390 | { |
| 391 | − lua_debug = 0; | |
| 392 | 391 | initcode = &(tf->code); |
| 393 | 392 | *initcode = newvector(CODE_BLOCK, Byte); |
| 394 | 393 | maincode = 0; |
| @@ -416,7 +415,7 @@ void lua_parse (TFunc *tf) · 21 unmodified lines | ||
| 416 | 415 | Word vWord; |
| 417 | 416 | Long vLong; |
| 418 | 417 | TFunc *pFunc; |
| 419 | − TreeNode *pNode; | |
| 418 | + TaggedString *pTStr; | |
| 420 | 419 | } |
| 421 | 420 | |
| 422 | 421 | %start functionlist |
| @@ -429,7 +428,7 @@ void lua_parse (TFunc *tf) · 6 unmodified lines | ||
| 429 | 428 | %token FUNCTION |
| 430 | 429 | %token <vFloat> NUMBER |
| 431 | 430 | %token <vWord> STRING |
| 432 | −%token <pNode> NAME | |
| 431 | +%token <pTStr> NAME | |
| 433 | 432 | %token <vInt> DEBUG |
| 434 | 433 | |
| 435 | 434 | %type <vLong> PrepJump |
| @@ -481,7 +480,7 @@ funcname : var { $$ =$1; init_func(); } · 45 unmodified lines | ||
| 481 | 480 | code_word(luaI_findconstant($3)); |
| 482 | 481 | $$ = 0; /* indexed variable */ |
| 483 | 482 | init_func(); |
| 484 | − add_localvar(luaI_findsymbolbyname("self")); | |
| 483 | + add_localvar(luaI_createfixedstring("self")); | |
| 485 | 484 | } |
| 486 | 485 | ; |
| 487 | 486 | |
| @@ -489,11 +488,14 @@ body : '(' parlist ')' block END · 1 unmodified line | ||
| 489 | 488 | { |
| 490 | 489 | codereturn(); |
| 491 | 490 | $$ = new(TFunc); |
| 491 | + luaI_initTFunc($$); | |
| 492 | 492 | $$->size = pc; |
| 493 | 493 | $$->code = newvector(pc, Byte); |
| 494 | 494 | $$->fileName = lua_parsedfile; |
| 495 | 495 | $$->lineDefined = $2; |
| 496 | 496 | memcpy($$->code, basepc, pc*sizeof(Byte)); |
| 497 | + if (lua_debug) | |
| 498 | + luaI_closelocalvars($$); | |
| 497 | 499 | /* save func values */ |
| 498 | 500 | funcCode = basepc; maxcode=maxcurr; |
| 499 | 501 | #if LISTING |
| @@ -554,7 +556,11 @@ block : {$<vInt>$ = nlocalvar;} statlist ret · 54 unmodified lines | ||
| 554 | 556 | { |
| 555 | 557 | if (nlocalvar != $<vInt>1) |
| 556 | 558 | { |
| 557 | − nlocalvar = $<vInt>1; | |
| 559 | + if (lua_debug) | |
| 560 | + for (; nlocalvar > $<vInt>1; nlocalvar--) | |
| 561 | + luaI_unregisterlocalvar(lua_linenumber); | |
| 562 | + else | |
| 563 | + nlocalvar = $<vInt>1; | |
| 558 | 564 | lua_codeadjust (0); |
| 559 | 565 | } |
| 560 | 566 | } |
| @@ -672,14 +678,8 @@ parlist : /* empty */ { lua_codeadjust(0); $$ = lua_linenumber; } · 111 unmodified lines | ||
| 672 | 678 | | parlist1 { lua_codeadjust(0); $$ = lua_linenumber; } |
| 673 | 679 | ; |
| 674 | 680 | |
| 675 | −parlist1 : NAME | |
| 676 | − { | |
| 677 | − add_localvar(luaI_findsymbol($1)); | |
| 678 | − } | |
| 679 | − | parlist1 ',' NAME | |
| 680 | − { | |
| 681 | − add_localvar(luaI_findsymbol($3)); | |
| 682 | − } | |
| 681 | +parlist1 : NAME { add_localvar($1); } | |
| 682 | + | parlist1 ',' NAME { add_localvar($3); } | |
| 683 | 683 | ; |
| 684 | 684 | |
| 685 | 685 | fieldlist : lfieldlist |
| @@ -759,10 +759,9 @@ var : singlevar { $$ = $1; } · 73 unmodified lines | ||
| 759 | 759 | |
| 760 | 760 | singlevar : NAME |
| 761 | 761 | { |
| 762 | − Word s = luaI_findsymbol($1); | |
| 763 | − int local = lua_localname (s); | |
| 762 | + int local = lua_localname($1); | |
| 764 | 763 | if (local == -1) /* global var */ |
| 765 | − $$ = s + 1; /* return positive value */ | |
| 764 | + $$ = luaI_findsymbol($1)+1; /* return positive value */ | |
| 766 | 765 | else |
| 767 | 766 | $$ = -(local+1); /* return negative value */ |
| 768 | 767 | } |
| @@ -771,10 +770,10 @@ singlevar : NAME · 2 unmodified lines | ||
| 771 | 770 | varexp : var { lua_pushvar($1); } |
| 772 | 771 | ; |
| 773 | 772 | |
| 774 | −localdeclist : NAME {store_localvar(luaI_findsymbol($1), 0); $$ = 1;} | |
| 773 | +localdeclist : NAME {store_localvar($1, 0); $$ = 1;} | |
| 775 | 774 | | localdeclist ',' NAME |
| 776 | 775 | { |
| 777 | − store_localvar(luaI_findsymbol($3), $1); | |
| 776 | + store_localvar($3, $1); | |
| 778 | 777 | $$ = $1+1; |
| 779 | 778 | } |
| 780 | 779 | ; |
| @@ -787,228 +786,3 @@ setdebug : DEBUG { lua_debug = $1; } · 6 unmodified lines | ||
| 787 | 786 | ; |
| 788 | 787 | |
| 789 | 788 | %% |
| 790 | − | |
| 791 | −#if LISTING | |
| 792 | − | |
| 793 | −static void PrintCode (Byte *code, Byte *end) | |
| 794 | −{ | |
| 795 | − Byte *p = code; | |
| 796 | − printf ("\n\nCODE\n"); | |
| 797 | − while (p != end) | |
| 798 | − { | |
| 799 | − switch ((OpCode)*p) | |
| 800 | − { | |
| 801 | − case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break; | |
| 802 | − case PUSH0: case PUSH1: case PUSH2: | |
| 803 | − printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0'); | |
| 804 | − p++; | |
| 805 | − break; | |
| 806 | − case PUSHBYTE: | |
| 807 | − printf ("%d PUSHBYTE %d\n", p-code, *(++p)); | |
| 808 | − p++; | |
| 809 | − break; | |
| 810 | − case PUSHWORD: | |
| 811 | − { | |
| 812 | − CodeWord c; | |
| 813 | − int n = p-code; | |
| 814 | − p++; | |
| 815 | − get_word(c,p); | |
| 816 | − printf ("%d PUSHWORD %d\n", n, c.w); | |
| 817 | − } | |
| 818 | − break; | |
| 819 | − case PUSHFLOAT: | |
| 820 | − { | |
| 821 | − CodeFloat c; | |
| 822 | − int n = p-code; | |
| 823 | − p++; | |
| 824 | − get_float(c,p); | |
| 825 | − printf ("%d PUSHFLOAT %f\n", n, c.f); | |
| 826 | − } | |
| 827 | − break; | |
| 828 | − case PUSHSTRING: | |
| 829 | − { | |
| 830 | − CodeWord c; | |
| 831 | − int n = p-code; | |
| 832 | − p++; | |
| 833 | − get_word(c,p); | |
| 834 | − printf ("%d PUSHSTRING %d\n", n, c.w); | |
| 835 | − } | |
| 836 | − break; | |
| 837 | − case PUSHFUNCTION: | |
| 838 | − { | |
| 839 | − CodeCode c; | |
| 840 | − int n = p-code; | |
| 841 | − p++; | |
| 842 | − get_code(c,p); | |
| 843 | − printf ("%d PUSHFUNCTION %p\n", n, c.tf); | |
| 844 | − } | |
| 845 | − break; | |
| 846 | − | |
| 847 | − case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: | |
| 848 | − case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: | |
| 849 | − case PUSHLOCAL8: case PUSHLOCAL9: | |
| 850 | − printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0'); | |
| 851 | − p++; | |
| 852 | − break; | |
| 853 | − case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p)); | |
| 854 | − p++; | |
| 855 | − break; | |
| 856 | − case PUSHGLOBAL: | |
| 857 | − { | |
| 858 | − CodeWord c; | |
| 859 | − int n = p-code; | |
| 860 | − p++; | |
| 861 | − get_word(c,p); | |
| 862 | − printf ("%d PUSHGLOBAL %d\n", n, c.w); | |
| 863 | − } | |
| 864 | − break; | |
| 865 | − case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break; | |
| 866 | − case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: | |
| 867 | − case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: | |
| 868 | − case STORELOCAL8: case STORELOCAL9: | |
| 869 | − printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0'); | |
| 870 | − p++; | |
| 871 | − break; | |
| 872 | − case STORELOCAL: | |
| 873 | − printf ("%d STORELOCAL %d\n", p-code, *(++p)); | |
| 874 | − p++; | |
| 875 | − break; | |
| 876 | − case STOREGLOBAL: | |
| 877 | − { | |
| 878 | − CodeWord c; | |
| 879 | − int n = p-code; | |
| 880 | − p++; | |
| 881 | − get_word(c,p); | |
| 882 | − printf ("%d STOREGLOBAL %d\n", n, c.w); | |
| 883 | − } | |
| 884 | − break; | |
| 885 | − case PUSHSELF: | |
| 886 | − { | |
| 887 | − CodeWord c; | |
| 888 | − int n = p-code; | |
| 889 | − p++; | |
| 890 | − get_word(c,p); | |
| 891 | − printf ("%d PUSHSELF %d\n", n, c.w); | |
| 892 | − } | |
| 893 | − break; | |
| 894 | − case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break; | |
| 895 | − case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p)); | |
| 896 | − p++; | |
| 897 | − break; | |
| 898 | − case STORELIST0: | |
| 899 | − printf("%d STORELIST0 %d\n", p-code, *(++p)); | |
| 900 | − p++; | |
| 901 | − break; | |
| 902 | − case STORELIST: | |
| 903 | − printf("%d STORELIST %d %d\n", p-code, *(p+1), *(p+2)); | |
| 904 | − p+=3; | |
| 905 | − break; | |
| 906 | − case STORERECORD: | |
| 907 | − printf("%d STORERECORD %d\n", p-code, *(++p)); | |
| 908 | − p += *p*sizeof(Word) + 1; | |
| 909 | − break; | |
| 910 | − case ADJUST0: printf ("%d ADJUST0\n", (p++)-code); break; | |
| 911 | − case ADJUST: | |
| 912 | − printf ("%d ADJUST %d\n", p-code, *(++p)); | |
| 913 | − p++; | |
| 914 | − break; | |
| 915 | − case CREATEARRAY: | |
| 916 | − { | |
| 917 | − CodeWord c; | |
| 918 | − int n = p-code; | |
| 919 | − p++; | |
| 920 | − get_word(c,p); | |
| 921 | − printf ("%d CREATEARRAY %d\n", n, c.w); | |
| 922 | − break; | |
| 923 | − } | |
| 924 | − case EQOP: printf ("%d EQOP\n", (p++)-code); break; | |
| 925 | − case LTOP: printf ("%d LTOP\n", (p++)-code); break; | |
| 926 | − case LEOP: printf ("%d LEOP\n", (p++)-code); break; | |
| 927 | − case ADDOP: printf ("%d ADDOP\n", (p++)-code); break; | |
| 928 | − case SUBOP: printf ("%d SUBOP\n", (p++)-code); break; | |
| 929 | − case MULTOP: printf ("%d MULTOP\n", (p++)-code); break; | |
| 930 | − case DIVOP: printf ("%d DIVOP\n", (p++)-code); break; | |
| 931 | − case POWOP: printf ("%d POWOP\n", (p++)-code); break; | |
| 932 | − case CONCOP: printf ("%d CONCOP\n", (p++)-code); break; | |
| 933 | − case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break; | |
| 934 | − case NOTOP: printf ("%d NOTOP\n", (p++)-code); break; | |
| 935 | − case ONTJMP: | |
| 936 | − { | |
| 937 | − CodeWord c; | |
| 938 | − int n = p-code; | |
| 939 | − p++; | |
| 940 | − get_word(c,p); | |
| 941 | − printf ("%d ONTJMP %d\n", n, c.w); | |
| 942 | − } | |
| 943 | − break; | |
| 944 | − case ONFJMP: | |
| 945 | − { | |
| 946 | − CodeWord c; | |
| 947 | − int n = p-code; | |
| 948 | − p++; | |
| 949 | − get_word(c,p); | |
| 950 | − printf ("%d ONFJMP %d\n", n, c.w); | |
| 951 | − } | |
| 952 | − break; | |
| 953 | − case JMP: | |
| 954 | − { | |
| 955 | − CodeWord c; | |
| 956 | − int n = p-code; | |
| 957 | − p++; | |
| 958 | − get_word(c,p); | |
| 959 | − printf ("%d JMP %d\n", n, c.w); | |
| 960 | − } | |
| 961 | − break; | |
| 962 | − case UPJMP: | |
| 963 | − { | |
| 964 | − CodeWord c; | |
| 965 | − int n = p-code; | |
| 966 | − p++; | |
| 967 | − get_word(c,p); | |
| 968 | − printf ("%d UPJMP %d\n", n, c.w); | |
| 969 | − } | |
| 970 | − break; | |
| 971 | − case IFFJMP: | |
| 972 | − { | |
| 973 | − CodeWord c; | |
| 974 | − int n = p-code; | |
| 975 | − p++; | |
| 976 | − get_word(c,p); | |
| 977 | − printf ("%d IFFJMP %d\n", n, c.w); | |
| 978 | − } | |
| 979 | − break; | |
| 980 | − case IFFUPJMP: | |
| 981 | − { | |
| 982 | − CodeWord c; | |
| 983 | − int n = p-code; | |
| 984 | − p++; | |
| 985 | − get_word(c,p); | |
| 986 | − printf ("%d IFFUPJMP %d\n", n, c.w); | |
| 987 | − } | |
| 988 | − break; | |
| 989 | − case POP: printf ("%d POP\n", (p++)-code); break; | |
| 990 | − case CALLFUNC: | |
| 991 | − printf ("%d CALLFUNC %d %d\n", p-code, *(p+1), *(p+2)); | |
| 992 | − p+=3; | |
| 993 | − break; | |
| 994 | − case RETCODE0: printf ("%d RETCODE0\n", (p++)-code); break; | |
| 995 | − case RETCODE: | |
| 996 | − printf ("%d RETCODE %d\n", p-code, *(++p)); | |
| 997 | − p++; | |
| 998 | − break; | |
| 999 | − case SETLINE: | |
| 1000 | − { | |
| 1001 | − CodeWord c; | |
| 1002 | − int n = p-code; | |
| 1003 | − p++; | |
| 1004 | − get_word(c,p); | |
| 1005 | − printf ("%d SETLINE %d\n", n, c.w); | |
| 1006 | − } | |
| 1007 | − break; | |
| 1008 | − | |
| 1009 | − default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break; | |
| 1010 | − } | |
| 1011 | − } | |
| 1012 | −} | |
| 1013 | −#endif | |
| 1014 | − | |
| @@ -0,0 +1,24 @@ | ||
| 1 | +# makefile for lua distribution (compiler) | |
| 2 | + | |
| 3 | +LUA= ../.. | |
| 4 | + | |
| 5 | +include $(LUA)/config | |
| 6 | + | |
| 7 | +INCS= -I$(INC) $(EXTRA_INCS) -I.. | |
| 8 | +OBJS= dump.o luac.o print.o | |
| 9 | +SRCS= dump.c luac.c print.c luac.h print.h | |
| 10 | +T=$(BIN)/luac | |
| 11 | + | |
| 12 | +all: $T | |
| 13 | + | |
| 14 | +$T: $(OBJS) | |
| 15 | + $(CC) -o $@ $(OBJS) -L$(LIB) -llua | |
| 16 | + | |
| 17 | +clean: | |
| 18 | + rm -f $(OBJS) $T | |
| 19 | + | |
| 20 | +co: | |
| 21 | + co -f -M $(SRCS) | |
| 22 | + | |
| 23 | +klean: clean | |
| 24 | + rm -f $(SRCS) | |
| @@ -0,0 +1,247 @@ | ||
| 1 | +/* | |
| 2 | +** dump.c | |
| 3 | +** thread and save bytecodes to file | |
| 4 | +*/ | |
| 5 | + | |
| 6 | +char* rcs_dump="$Id: dump.c,v 1.12 1996/03/12 20:00:03 lhf Exp $"; | |
| 7 | + | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <string.h> | |
| 10 | +#include "luac.h" | |
| 11 | + | |
| 12 | +static TFunc* lastF=NULL; /* list of functions seen in code */ | |
| 13 | + | |
| 14 | +static int SawVar(int i, int at) | |
| 15 | +{ | |
| 16 | + int old=VarLoc(i); | |
| 17 | + VarLoc(i)=at; | |
| 18 | + return old; | |
| 19 | +} | |
| 20 | + | |
| 21 | +static int SawStr(int i, int at) | |
| 22 | +{ | |
| 23 | + int old=StrLoc(i); | |
| 24 | + StrLoc(i)=at; | |
| 25 | + return old; | |
| 26 | +} | |
| 27 | + | |
| 28 | +static void ThreadCode(Byte* code, Byte* end) | |
| 29 | +{ | |
| 30 | + Byte* p; | |
| 31 | + int i; | |
| 32 | + for (i=0; i<lua_ntable; i++) VarLoc(i)=0; | |
| 33 | + for (i=0; i<lua_nconstant; i++) StrLoc(i)=0; | |
| 34 | + for (p=code; p!=end;) | |
| 35 | + { | |
| 36 | + OpCode op=(OpCode)*p; | |
| 37 | + int at=p-code+1; | |
| 38 | + switch (op) | |
| 39 | + { | |
| 40 | + case PUSHNIL: | |
| 41 | + case PUSH0: | |
| 42 | + case PUSH1: | |
| 43 | + case PUSH2: | |
| 44 | + case PUSHLOCAL0: | |
| 45 | + case PUSHLOCAL1: | |
| 46 | + case PUSHLOCAL2: | |
| 47 | + case PUSHLOCAL3: | |
| 48 | + case PUSHLOCAL4: | |
| 49 | + case PUSHLOCAL5: | |
| 50 | + case PUSHLOCAL6: | |
| 51 | + case PUSHLOCAL7: | |
| 52 | + case PUSHLOCAL8: | |
| 53 | + case PUSHLOCAL9: | |
| 54 | + case PUSHINDEXED: | |
| 55 | + case STORELOCAL0: | |
| 56 | + case STORELOCAL1: | |
| 57 | + case STORELOCAL2: | |
| 58 | + case STORELOCAL3: | |
| 59 | + case STORELOCAL4: | |
| 60 | + case STORELOCAL5: | |
| 61 | + case STORELOCAL6: | |
| 62 | + case STORELOCAL7: | |
| 63 | + case STORELOCAL8: | |
| 64 | + case STORELOCAL9: | |
| 65 | + case STOREINDEXED0: | |
| 66 | + case ADJUST0: | |
| 67 | + case EQOP: | |
| 68 | + case LTOP: | |
| 69 | + case LEOP: | |
| 70 | + case GTOP: | |
| 71 | + case GEOP: | |
| 72 | + case ADDOP: | |
| 73 | + case SUBOP: | |
| 74 | + case MULTOP: | |
| 75 | + case DIVOP: | |
| 76 | + case POWOP: | |
| 77 | + case CONCOP: | |
| 78 | + case MINUSOP: | |
| 79 | + case NOTOP: | |
| 80 | + case POP: | |
| 81 | + case RETCODE0: | |
| 82 | + p++; | |
| 83 | + break; | |
| 84 | + case PUSHBYTE: | |
| 85 | + case PUSHLOCAL: | |
| 86 | + case STORELOCAL: | |
| 87 | + case STOREINDEXED: | |
| 88 | + case STORELIST0: | |
| 89 | + case ADJUST: | |
| 90 | + case RETCODE: | |
| 91 | + p+=2; | |
| 92 | + break; | |
| 93 | + case PUSHWORD: | |
| 94 | + case CREATEARRAY: | |
| 95 | + case ONTJMP: | |
| 96 | + case ONFJMP: | |
| 97 | + case JMP: | |
| 98 | + case UPJMP: | |
| 99 | + case IFFJMP: | |
| 100 | + case IFFUPJMP: | |
| 101 | + case SETLINE: | |
| 102 | + case STORELIST: | |
| 103 | + case CALLFUNC: | |
| 104 | + p+=3; | |
| 105 | + break; | |
| 106 | + case PUSHFLOAT: | |
| 107 | + p+=5; | |
| 108 | + break; | |
| 109 | + case PUSHSELF: | |
| 110 | + case PUSHSTRING: | |
| 111 | + { | |
| 112 | + CodeWord c; | |
| 113 | + p++; | |
| 114 | + get_word(c,p); | |
| 115 | + c.w=SawStr(c.w,at); | |
| 116 | + p[-2]=c.m.c1; | |
| 117 | + p[-1]=c.m.c2; | |
| 118 | + break; | |
| 119 | + } | |
| 120 | + case PUSHFUNCTION: | |
| 121 | + { | |
| 122 | + CodeCode c; | |
| 123 | + p++; | |
| 124 | + get_code(c,p); | |
| 125 | + c.tf->marked=at; | |
| 126 | + c.tf->next=NULL; /* TODO: remove? */ | |
| 127 | + lastF=lastF->next=c.tf; | |
| 128 | + break; | |
| 129 | + } | |
| 130 | + case PUSHGLOBAL: | |
| 131 | + case STOREGLOBAL: | |
| 132 | + { | |
| 133 | + CodeWord c; | |
| 134 | + p++; | |
| 135 | + get_word(c,p); | |
| 136 | + c.w=SawVar(c.w,at); | |
| 137 | + p[-2]=c.m.c1; | |
| 138 | + p[-1]=c.m.c2; | |
| 139 | + break; | |
| 140 | + } | |
| 141 | + case STORERECORD: | |
| 142 | + { | |
| 143 | + int n=*++p; | |
| 144 | + p++; | |
| 145 | + while (n--) | |
| 146 | + { | |
| 147 | + CodeWord c; | |
| 148 | + at=p-code; | |
| 149 | + get_word(c,p); | |
| 150 | + c.w=SawStr(c.w,at); | |
| 151 | + p[-2]=c.m.c1; | |
| 152 | + p[-1]=c.m.c2; | |
| 153 | + } | |
| 154 | + break; | |
| 155 | + } | |
| 156 | + default: | |
| 157 | + fprintf(stderr,"luac: cannot happen: opcode=%d",*p); | |
| 158 | + exit(1); | |
| 159 | + break; | |
| 160 | + } | |
| 161 | + } | |
| 162 | +} | |
| 163 | + | |
| 164 | +static void DumpWord(int i, FILE* D) | |
| 165 | +{ | |
| 166 | + Word w=i; | |
| 167 | + fwrite(&w,sizeof(w),1,D); | |
| 168 | +} | |
| 169 | + | |
| 170 | +static void DumpBlock(char* b, int size, FILE* D) | |
| 171 | +{ | |
| 172 | + fwrite(b,size,1,D); | |
| 173 | +} | |
| 174 | + | |
| 175 | +static void DumpSize(int i, FILE* D) | |
| 176 | +{ | |
| 177 | + Word lo=i&0x0FFFF; | |
| 178 | + Word hi=(i>>16)&0x0FFFF; | |
| 179 | + fwrite(&hi,sizeof(hi),1,D); | |
| 180 | + fwrite(&lo,sizeof(lo),1,D); | |
| 181 | + if (hi!=0) | |
| 182 | + fprintf(stderr, | |
| 183 | + "luac: warning: code too long for 16-bit machines (%d bytes)\n",i); | |
| 184 | +} | |
| 185 | + | |
| 186 | +static void DumpString(char* s, FILE* D) | |
| 187 | +{ | |
| 188 | + int n=strlen(s)+1; | |
| 189 | + if ((Word)n != n) | |
| 190 | + { | |
| 191 | + fprintf(stderr,"luac: string too long: \"%.32s...\"\n",s); | |
| 192 | + exit(1); | |
| 193 | + } | |
| 194 | + DumpWord(n,D); | |
| 195 | + DumpBlock(s,n,D); | |
| 196 | +} | |
| 197 | + | |
| 198 | +static void DumpStrings(FILE* D) | |
| 199 | +{ | |
| 200 | + int i; | |
| 201 | + for (i=0; i<lua_ntable; i++) | |
| 202 | + { | |
| 203 | + if (VarLoc(i)!=0) | |
| 204 | + { | |
| 205 | + fputc(ID_VAR,D); | |
| 206 | + DumpWord(VarLoc(i),D); | |
| 207 | + DumpString(VarStr(i),D); | |
| 208 | + } | |
| 209 | + VarLoc(i)=i; | |
| 210 | + } | |
| 211 | + for (i=0; i<lua_nconstant; i++) | |
| 212 | + { | |
| 213 | + if (StrLoc(i)!=0) | |
| 214 | + { | |
| 215 | + fputc(ID_STR,D); | |
| 216 | + DumpWord(StrLoc(i),D); | |
| 217 | + DumpString(StrStr(i),D); | |
| 218 | + } | |
| 219 | + StrLoc(i)=i; | |
| 220 | + } | |
| 221 | +} | |
| 222 | + | |
| 223 | +void DumpFunction(TFunc* tf, FILE* D) | |
| 224 | +{ | |
| 225 | + lastF=tf; | |
| 226 | + ThreadCode(tf->code,tf->code+tf->size); | |
| 227 | + fputc(ID_FUN,D); | |
| 228 | + DumpSize(tf->size,D); | |
| 229 | + DumpWord(tf->lineDefined,D); | |
| 230 | + if (IsMain(tf)) | |
| 231 | + DumpString(tf->fileName,D); | |
| 232 | + else | |
| 233 | + DumpWord(tf->marked,D); | |
| 234 | + DumpBlock(tf->code,tf->size,D); | |
| 235 | + DumpStrings(D); | |
| 236 | +} | |
| 237 | + | |
| 238 | +void DumpHeader(FILE* D) | |
| 239 | +{ | |
| 240 | + Word w=TEST_WORD; | |
| 241 | + float f=TEST_FLOAT; | |
| 242 | + fputc(ID_CHUNK,D); | |
| 243 | + fputs(SIGNATURE,D); | |
| 244 | + fputc(VERSION,D); | |
| 245 | + fwrite(&w,sizeof(w),1,D); | |
| 246 | + fwrite(&f,sizeof(f),1,D); | |
| 247 | +} | |
| @@ -0,0 +1,104 @@ | ||
| 1 | +/* | |
| 2 | +** luac.c | |
| 3 | +** lua compiler (saves bytecodes to files) | |
| 4 | +*/ | |
| 5 | + | |
| 6 | +char* rcs_luac="$Id: luac.c,v 1.16 1996/03/13 17:33:03 lhf Exp $"; | |
| 7 | + | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <string.h> | |
| 10 | +#include "luac.h" | |
| 11 | + | |
| 12 | +static void compile(char* filename); | |
| 13 | + | |
| 14 | +static int listing=0; /* list bytecodes? */ | |
| 15 | +static int dumping=1; /* dump bytecodes? */ | |
| 16 | +static FILE* D; /* output file */ | |
| 17 | + | |
| 18 | +static void usage(void) | |
| 19 | +{ | |
| 20 | + fprintf(stderr,"usage: luac [-dlpv] [-o output] file ...\n"); | |
| 21 | + exit(0); | |
| 22 | +} | |
| 23 | + | |
| 24 | +#define IS(s) (strcmp(argv[i],s)==0) | |
| 25 | + | |
| 26 | +int main(int argc, char* argv[]) | |
| 27 | +{ | |
| 28 | + char* d="luac.out"; /* default output file */ | |
| 29 | + int i; | |
| 30 | + for (i=1; i<argc; i++) | |
| 31 | + { | |
| 32 | + if (argv[i][0]!='-') /* end of options */ | |
| 33 | + break; | |
| 34 | + else if (IS("-")) /* use stdin */ | |
| 35 | + break; | |
| 36 | + else if (IS("-d")) /* debug */ | |
| 37 | + lua_debug=1; | |
| 38 | + else if (IS("-l")) /* list */ | |
| 39 | + listing=1; | |
| 40 | + else if (IS("-o")) /* output file */ | |
| 41 | + d=argv[++i]; | |
| 42 | + else if (IS("-p")) /* parse only (for timing purposes) */ | |
| 43 | + dumping=0; | |
| 44 | + else if (IS("-v")) /* show version */ | |
| 45 | + printf("%s %s\n(written by %s)\n\n",LUA_VERSION,LUA_COPYRIGHT,LUA_AUTHORS); | |
| 46 | + else /* unknown option */ | |
| 47 | + usage(); | |
| 48 | + } | |
| 49 | + --i; /* fake new argv[0] */ | |
| 50 | + argc-=i; | |
| 51 | + argv+=i; | |
| 52 | + if (argc<2) usage(); | |
| 53 | + for (i=1; i<argc; i++) | |
| 54 | + if (IS(d)) | |
| 55 | + { | |
| 56 | + fprintf(stderr,"luac: will not overwrite input file \"%s\"\n",d); | |
| 57 | + exit(1); | |
| 58 | + } | |
| 59 | + D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */ | |
| 60 | + if (D==NULL) | |
| 61 | + { | |
| 62 | + fprintf(stderr,"luac: cannot open "); | |
| 63 | + perror(d); | |
| 64 | + exit(1); | |
| 65 | + } | |
| 66 | + for (i=1; i<argc; i++) compile(IS("-")? NULL : argv[i]); | |
| 67 | + fclose(D); | |
| 68 | + return 0; | |
| 69 | +} | |
| 70 | + | |
| 71 | +static void do_dump(TFunc* tf) /* only for tf==main */ | |
| 72 | +{ | |
| 73 | + if (dumping) DumpHeader(D); | |
| 74 | + while (tf!=NULL) | |
| 75 | + { | |
| 76 | + TFunc* nf; | |
| 77 | + if (listing) PrintFunction(tf); | |
| 78 | + if (dumping) DumpFunction(tf,D); | |
| 79 | + nf=tf->next; /* list only built after first main */ | |
| 80 | + luaI_freefunc(tf); | |
| 81 | + tf=nf; | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +static void do_compile(void) | |
| 86 | +{ | |
| 87 | + TFunc* tf=new(TFunc); | |
| 88 | + luaI_initTFunc(tf); | |
| 89 | + tf->fileName = lua_parsedfile; | |
| 90 | + lua_parse(tf); | |
| 91 | + do_dump(tf); | |
| 92 | +} | |
| 93 | + | |
| 94 | +static void compile(char* filename) | |
| 95 | +{ | |
| 96 | + if (lua_openfile(filename)==NULL) | |
| 97 | + { | |
| 98 | + fprintf(stderr,"luac: cannot open "); | |
| 99 | + perror(filename); | |
| 100 | + exit(1); | |
| 101 | + } | |
| 102 | + do_compile(); | |
| 103 | + lua_closefile(); | |
| 104 | +} | |
| @@ -0,0 +1,24 @@ | ||
| 1 | +/* | |
| 2 | +** luac.h | |
| 3 | +** definitions for luac compiler | |
| 4 | +** $Id: luac.h,v 1.5 1996/03/08 21:41:47 lhf Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#include "inout.h" | |
| 8 | +#include "mem.h" | |
| 9 | +#include "opcode.h" | |
| 10 | +#include "table.h" | |
| 11 | +#include "undump.h" | |
| 12 | + | |
| 13 | +#define VarStr(i) (lua_table[i].varname->str) | |
| 14 | +#define VarLoc(i) (lua_table[i].varname->varindex) | |
| 15 | +#define StrStr(i) (lua_constant[i]->str) | |
| 16 | +#define StrLoc(i) (lua_constant[i]->constindex) | |
| 17 | + | |
| 18 | +extern Word lua_ntable; | |
| 19 | +extern Word lua_nconstant; | |
| 20 | +extern int lua_debug; | |
| 21 | + | |
| 22 | +void DumpHeader(FILE* D); | |
| 23 | +void DumpFunction(TFunc* tf, FILE* D); | |
| 24 | +void PrintFunction(TFunc* tf); | |
| @@ -0,0 +1,189 @@ | ||
| 1 | +/* | |
| 2 | +** print.c | |
| 3 | +** print bytecodes | |
| 4 | +*/ | |
| 5 | + | |
| 6 | +char* rcs_print="$Id: print.c,v 1.6 1996/03/12 20:00:24 lhf Exp $"; | |
| 7 | + | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <string.h> | |
| 10 | +#include "luac.h" | |
| 11 | +#include "print.h" | |
| 12 | + | |
| 13 | +static LocVar* V=NULL; | |
| 14 | + | |
| 15 | +static char* LocStr(int i) | |
| 16 | +{ | |
| 17 | + if (V==NULL) return ""; else return V[i].varname->str; | |
| 18 | +} | |
| 19 | + | |
| 20 | +static void PrintCode(Byte* code, Byte* end) | |
| 21 | +{ | |
| 22 | + Byte* p; | |
| 23 | + for (p=code; p!=end;) | |
| 24 | + { | |
| 25 | + OpCode op=(OpCode)*p; | |
| 26 | + if (op>SETLINE) op=SETLINE+1; | |
| 27 | + printf("%6d\t%s",p-code,OpCodeName[op]); | |
| 28 | + switch (op) | |
| 29 | + { | |
| 30 | + case PUSHNIL: | |
| 31 | + case PUSH0: | |
| 32 | + case PUSH1: | |
| 33 | + case PUSH2: | |
| 34 | + case PUSHINDEXED: | |
| 35 | + case STOREINDEXED0: | |
| 36 | + case ADJUST0: | |
| 37 | + case EQOP: | |
| 38 | + case LTOP: | |
| 39 | + case LEOP: | |
| 40 | + case GTOP: | |
| 41 | + case GEOP: | |
| 42 | + case ADDOP: | |
| 43 | + case SUBOP: | |
| 44 | + case MULTOP: | |
| 45 | + case DIVOP: | |
| 46 | + case POWOP: | |
| 47 | + case CONCOP: | |
| 48 | + case MINUSOP: | |
| 49 | + case NOTOP: | |
| 50 | + case POP: | |
| 51 | + case RETCODE0: | |
| 52 | + p++; | |
| 53 | + break; | |
| 54 | + case PUSHLOCAL0: | |
| 55 | + case PUSHLOCAL1: | |
| 56 | + case PUSHLOCAL2: | |
| 57 | + case PUSHLOCAL3: | |
| 58 | + case PUSHLOCAL4: | |
| 59 | + case PUSHLOCAL5: | |
| 60 | + case PUSHLOCAL6: | |
| 61 | + case PUSHLOCAL7: | |
| 62 | + case PUSHLOCAL8: | |
| 63 | + case PUSHLOCAL9: | |
| 64 | + { | |
| 65 | + int i=op-PUSHLOCAL0; | |
| 66 | + printf("\t%d\t; %s",i,LocStr(i)); | |
| 67 | + p++; | |
| 68 | + break; | |
| 69 | + } | |
| 70 | + case STORELOCAL0: | |
| 71 | + case STORELOCAL1: | |
| 72 | + case STORELOCAL2: | |
| 73 | + case STORELOCAL3: | |
| 74 | + case STORELOCAL4: | |
| 75 | + case STORELOCAL5: | |
| 76 | + case STORELOCAL6: | |
| 77 | + case STORELOCAL7: | |
| 78 | + case STORELOCAL8: | |
| 79 | + case STORELOCAL9: | |
| 80 | + { | |
| 81 | + int i=op-STORELOCAL0; | |
| 82 | + printf("\t%d\t; %s",i,LocStr(i)); | |
| 83 | + p++; | |
| 84 | + break; | |
| 85 | + } | |
| 86 | + case PUSHLOCAL: | |
| 87 | + case STORELOCAL: | |
| 88 | + { | |
| 89 | + int i=*(p+1); | |
| 90 | + printf("\t%d\t; %s",i,LocStr(i)); | |
| 91 | + p+=2; | |
| 92 | + break; | |
| 93 | + } | |
| 94 | + case PUSHBYTE: | |
| 95 | + case STOREINDEXED: | |
| 96 | + case STORELIST0: | |
| 97 | + case ADJUST: | |
| 98 | + case RETCODE: | |
| 99 | + printf("\t%d",*(p+1)); | |
| 100 | + p+=2; | |
| 101 | + break; | |
| 102 | + case PUSHWORD: | |
| 103 | + case CREATEARRAY: | |
| 104 | + case ONTJMP: | |
| 105 | + case ONFJMP: | |
| 106 | + case JMP: | |
| 107 | + case UPJMP: | |
| 108 | + case IFFJMP: | |
| 109 | + case IFFUPJMP: | |
| 110 | + case SETLINE: | |
| 111 | + { | |
| 112 | + CodeWord c; | |
| 113 | + p++; | |
| 114 | + get_word(c,p); | |
| 115 | + printf("\t%d",c.w); | |
| 116 | + break; | |
| 117 | + } | |
| 118 | + case PUSHFLOAT: | |
| 119 | + { | |
| 120 | + CodeFloat c; | |
| 121 | + p++; | |
| 122 | + get_float(c,p); | |
| 123 | + printf("\t%g",c.f); | |
| 124 | + break; | |
| 125 | + } | |
| 126 | + case PUSHSELF: | |
| 127 | + case PUSHSTRING: | |
| 128 | + { | |
| 129 | + CodeWord c; | |
| 130 | + p++; | |
| 131 | + get_word(c,p); | |
| 132 | + printf("\t%d\t; \"%s\"",c.w,StrStr(c.w)); | |
| 133 | + break; | |
| 134 | + } | |
| 135 | + case PUSHFUNCTION: | |
| 136 | + { | |
| 137 | + CodeCode c; | |
| 138 | + p++; | |
| 139 | + get_code(c,p); | |
| 140 | + printf("\t%p\t; \"%s\":%d",c.tf,c.tf->fileName,c.tf->lineDefined); | |
| 141 | + break; | |
| 142 | + } | |
| 143 | + case PUSHGLOBAL: | |
| 144 | + case STOREGLOBAL: | |
| 145 | + { | |
| 146 | + CodeWord c; | |
| 147 | + p++; | |
| 148 | + get_word(c,p); | |
| 149 | + printf("\t%d\t; %s",c.w,VarStr(c.w)); | |
| 150 | + break; | |
| 151 | + } | |
| 152 | + case STORELIST: | |
| 153 | + case CALLFUNC: | |
| 154 | + printf("\t%d %d",*(p+1),*(p+2)); | |
| 155 | + p+=3; | |
| 156 | + break; | |
| 157 | + case STORERECORD: | |
| 158 | + { | |
| 159 | + int n=*++p; | |
| 160 | + printf("\t%d",n); | |
| 161 | + p++; | |
| 162 | + while (n--) | |
| 163 | + { | |
| 164 | + CodeWord c; | |
| 165 | + printf("\n%6d\t FIELD",p-code); | |
| 166 | + get_word(c,p); | |
| 167 | + printf("\t%d\t; \"%s\"",c.w,StrStr(c.w)); | |
| 168 | + } | |
| 169 | + break; | |
| 170 | + } | |
| 171 | + default: | |
| 172 | + printf("\tcannot happen: opcode=%d",*p); | |
| 173 | + exit(1); | |
| 174 | + break; | |
| 175 | + } | |
| 176 | + printf("\n"); | |
| 177 | + } | |
| 178 | +} | |
| 179 | + | |
| 180 | +void PrintFunction(TFunc* tf) | |
| 181 | +{ | |
| 182 | + if (IsMain(tf)) | |
| 183 | + printf("\nmain of \"%s\" (%d bytes at %p)\n",tf->fileName,tf->size,tf); | |
| 184 | + else | |
| 185 | + printf("\nfunction \"%s\":%d (%d bytes at %p); used at main+%d\n", | |
| 186 | + tf->fileName,tf->lineDefined,tf->size,tf,tf->marked); | |
| 187 | + V=tf->locvars; | |
| 188 | + PrintCode(tf->code,tf->code+tf->size); | |
| 189 | +} | |
| @@ -0,0 +1,76 @@ | ||
| 1 | +/* | |
| 2 | +** print.h | |
| 3 | +** opcode names | |
| 4 | +** $Id: print.h,v 1.1 1996/02/23 19:04:13 lhf Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +static char* OpCodeName[]={ /* attention: same order as enum in opcode.h */ | |
| 8 | + "PUSHNIL", | |
| 9 | + "PUSH0", | |
| 10 | + "PUSH1", | |
| 11 | + "PUSH2", | |
| 12 | + "PUSHBYTE", | |
| 13 | + "PUSHWORD", | |
| 14 | + "PUSHFLOAT", | |
| 15 | + "PUSHSTRING", | |
| 16 | + "PUSHFUNCTION", | |
| 17 | + "PUSHLOCAL0", | |
| 18 | + "PUSHLOCAL1", | |
| 19 | + "PUSHLOCAL2", | |
| 20 | + "PUSHLOCAL3", | |
| 21 | + "PUSHLOCAL4", | |
| 22 | + "PUSHLOCAL5", | |
| 23 | + "PUSHLOCAL6", | |
| 24 | + "PUSHLOCAL7", | |
| 25 | + "PUSHLOCAL8", | |
| 26 | + "PUSHLOCAL9", | |
| 27 | + "PUSHLOCAL", | |
| 28 | + "PUSHGLOBAL", | |
| 29 | + "PUSHINDEXED", | |
| 30 | + "PUSHSELF", | |
| 31 | + "STORELOCAL0", | |
| 32 | + "STORELOCAL1", | |
| 33 | + "STORELOCAL2", | |
| 34 | + "STORELOCAL3", | |
| 35 | + "STORELOCAL4", | |
| 36 | + "STORELOCAL5", | |
| 37 | + "STORELOCAL6", | |
| 38 | + "STORELOCAL7", | |
| 39 | + "STORELOCAL8", | |
| 40 | + "STORELOCAL9", | |
| 41 | + "STORELOCAL", | |
| 42 | + "STOREGLOBAL", | |
| 43 | + "STOREINDEXED0", | |
| 44 | + "STOREINDEXED", | |
| 45 | + "STORELIST0", | |
| 46 | + "STORELIST", | |
| 47 | + "STORERECORD", | |
| 48 | + "ADJUST0", | |
| 49 | + "ADJUST", | |
| 50 | + "CREATEARRAY", | |
| 51 | + "EQOP", | |
| 52 | + "LTOP", | |
| 53 | + "LEOP", | |
| 54 | + "GTOP", | |
| 55 | + "GEOP", | |
| 56 | + "ADDOP", | |
| 57 | + "SUBOP", | |
| 58 | + "MULTOP", | |
| 59 | + "DIVOP", | |
| 60 | + "POWOP", | |
| 61 | + "CONCOP", | |
| 62 | + "MINUSOP", | |
| 63 | + "NOTOP", | |
| 64 | + "ONTJMP", | |
| 65 | + "ONFJMP", | |
| 66 | + "JMP", | |
| 67 | + "UPJMP", | |
| 68 | + "IFFJMP", | |
| 69 | + "IFFUPJMP", | |
| 70 | + "POP", | |
| 71 | + "CALLFUNC", | |
| 72 | + "RETCODE0", | |
| 73 | + "RETCODE", | |
| 74 | + "SETLINE", | |
| 75 | + "" | |
| 76 | +}; | |
| @@ -3,18 +3,24 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_mem = "$Id: mem.c,v 1.5 1995/02/06 19:34:03 roberto Exp $"; | |
| 6 | +char *rcs_mem = "$Id: mem.c,v 1.12 1996/05/06 16:59:00 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdlib.h> |
| 9 | −#include <string.h> | |
| 10 | 9 | |
| 11 | 10 | #include "mem.h" |
| 12 | 11 | #include "lua.h" |
| 13 | 12 | |
| 13 | + | |
| 14 | +#define mem_error() lua_error(memEM) | |
| 15 | + | |
| 16 | + | |
| 14 | 17 | void luaI_free (void *block) |
| 15 | 18 | { |
| 16 | − *((int *)block) = -1; /* to catch errors */ | |
| 17 | − free(block); | |
| 19 | + if (block) | |
| 20 | + { | |
| 21 | + *((int *)block) = -1; /* to catch errors */ | |
| 22 | + free(block); | |
| 23 | + } | |
| 18 | 24 | } |
| 19 | 25 | |
| 20 | 26 | |
| @@ -22,23 +28,40 @@ void *luaI_malloc (unsigned long size) · 1 unmodified line | ||
| 22 | 28 | { |
| 23 | 29 | void *block = malloc((size_t)size); |
| 24 | 30 | if (block == NULL) |
| 25 | − lua_error("not enough memory"); | |
| 31 | + mem_error(); | |
| 26 | 32 | return block; |
| 27 | 33 | } |
| 28 | 34 | |
| 29 | 35 | |
| 30 | 36 | void *luaI_realloc (void *oldblock, unsigned long size) |
| 31 | 37 | { |
| 32 | − void *block = realloc(oldblock, (size_t)size); | |
| 38 | + void *block = oldblock ? realloc(oldblock, (size_t)size) : | |
| 39 | + malloc((size_t)size); | |
| 33 | 40 | if (block == NULL) |
| 34 | − lua_error("not enough memory"); | |
| 41 | + mem_error(); | |
| 35 | 42 | return block; |
| 36 | 43 | } |
| 37 | 44 | |
| 38 | 45 | |
| 39 | −char *luaI_strdup (char *str) | |
| 46 | +int luaI_growvector (void **block, unsigned long nelems, int size, | |
| 47 | + char *errormsg, unsigned long limit) | |
| 40 | 48 | { |
| 41 | − char *newstr = luaI_malloc(strlen(str)+1); | |
| 42 | − strcpy(newstr, str); | |
| 43 | − return newstr; | |
| 49 | + if (nelems >= limit) | |
| 50 | + lua_error(errormsg); | |
| 51 | + nelems = (nelems == 0) ? 20 : nelems*2; | |
| 52 | + if (nelems > limit) | |
| 53 | + nelems = limit; | |
| 54 | + *block = luaI_realloc(*block, nelems*size); | |
| 55 | + return (int) nelems; | |
| 44 | 56 | } |
| 57 | + | |
| 58 | + | |
| 59 | +void* luaI_buffer (unsigned long size) | |
| 60 | +{ | |
| 61 | + static unsigned long buffsize = 0; | |
| 62 | + static char* buffer = NULL; | |
| 63 | + if (size > buffsize) | |
| 64 | + buffer = luaI_realloc(buffer, buffsize=size); | |
| 65 | + return buffer; | |
| 66 | +} | |
| 67 | + | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** mem.c |
| 3 | 3 | ** memory manager for lua |
| 4 | −** $Id: mem.h,v 1.2 1995/01/13 22:11:12 roberto Exp $ | |
| 4 | +** $Id: mem.h,v 1.7 1996/04/22 18:00:37 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef mem_h |
| @@ -11,15 +11,29 @@ · 3 unmodified lines | ||
| 11 | 11 | #define NULL 0 |
| 12 | 12 | #endif |
| 13 | 13 | |
| 14 | + | |
| 15 | +/* memory error messages */ | |
| 16 | +#define codeEM "code size overflow" | |
| 17 | +#define symbolEM "symbol table overflow" | |
| 18 | +#define constantEM "constant table overflow" | |
| 19 | +#define stackEM "stack size overflow" | |
| 20 | +#define lexEM "lex buffer overflow" | |
| 21 | +#define refEM "reference table overflow" | |
| 22 | +#define tableEM "table overflow" | |
| 23 | +#define memEM "not enough memory" | |
| 24 | + | |
| 25 | + | |
| 14 | 26 | void luaI_free (void *block); |
| 15 | 27 | void *luaI_malloc (unsigned long size); |
| 16 | 28 | void *luaI_realloc (void *oldblock, unsigned long size); |
| 17 | − | |
| 18 | −char *luaI_strdup (char *str); | |
| 29 | +void *luaI_buffer (unsigned long size); | |
| 30 | +int luaI_growvector (void **block, unsigned long nelems, int size, | |
| 31 | + char *errormsg, unsigned long limit); | |
| 19 | 32 | |
| 20 | 33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) |
| 21 | 34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) |
| 22 | −#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s))) | |
| 35 | +#define growvector(old,n,s,e,l) \ | |
| 36 | + (luaI_growvector((void**)old,n,sizeof(s),e,l)) | |
| 23 | 37 | |
| 24 | 38 | #endif |
| 25 | 39 | |
| @@ -3,10 +3,9 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_opcode="$Id: opcode.c,v 3.50 1995/11/16 20:46:24 roberto Exp $"; | |
| 6 | +char *rcs_opcode="$Id: opcode.c,v 3.68 1996/04/25 14:10:00 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <setjmp.h> |
| 9 | −#include <stdlib.h> | |
| 10 | 9 | #include <stdio.h> |
| 11 | 10 | #include <string.h> |
| 12 | 11 | |
| @@ -18,6 +17,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.50 1995/11/16 20:46:24 roberto Exp $"; · 5 unmodified lines | ||
| 18 | 17 | #include "table.h" |
| 19 | 18 | #include "lua.h" |
| 20 | 19 | #include "fallback.h" |
| 20 | +#include "undump.h" | |
| 21 | 21 | |
| 22 | 22 | #define tonumber(o) ((tag(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) |
| 23 | 23 | #define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) |
| @@ -25,6 +25,10 @@ char *rcs_opcode="$Id: opcode.c,v 3.50 1995/11/16 20:46:24 roberto Exp $"; · 1 unmodified line | ||
| 25 | 25 | |
| 26 | 26 | #define STACK_SIZE 128 |
| 27 | 27 | |
| 28 | +#ifndef STACK_LIMIT | |
| 29 | +#define STACK_LIMIT 6000 | |
| 30 | +#endif | |
| 31 | + | |
| 28 | 32 | typedef int StkId; /* index to stack elements */ |
| 29 | 33 | |
| 30 | 34 | static Object initial_stack; |
| @@ -53,6 +57,11 @@ static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ · 22 unmodified lines | ||
| 53 | 57 | static jmp_buf *errorJmp = NULL; /* current error recover point */ |
| 54 | 58 | |
| 55 | 59 | |
| 60 | +/* Hooks */ | |
| 61 | +lua_LHFunction lua_linehook = NULL; | |
| 62 | +lua_CHFunction lua_callhook = NULL; | |
| 63 | + | |
| 64 | + | |
| 56 | 65 | static StkId lua_execute (Byte *pc, StkId base); |
| 57 | 66 | static void do_call (StkId base, int nResults); |
| 58 | 67 | |
| @@ -64,7 +73,6 @@ Object *luaI_Address (lua_Object o) · 5 unmodified lines | ||
| 64 | 73 | } |
| 65 | 74 | |
| 66 | 75 | |
| 67 | − | |
| 68 | 76 | /* |
| 69 | 77 | ** Init stack |
| 70 | 78 | */ |
| @@ -89,14 +97,17 @@ static void growstack (void) · 18 unmodified lines | ||
| 89 | 97 | lua_initstack(); |
| 90 | 98 | else |
| 91 | 99 | { |
| 100 | + static int limit = STACK_LIMIT; | |
| 92 | 101 | StkId t = top-stack; |
| 93 | − Long maxstack = stackLimit - stack; | |
| 94 | − maxstack *= 2; | |
| 95 | − stack = growvector(stack, maxstack, Object); | |
| 96 | − stackLimit = stack+maxstack; | |
| 102 | + Long stacksize = stackLimit - stack; | |
| 103 | + stacksize = growvector(&stack, stacksize, Object, stackEM, limit+100); | |
| 104 | + stackLimit = stack+stacksize; | |
| 97 | 105 | top = stack + t; |
| 98 | − if (maxstack >= MAX_WORD/2) | |
| 99 | − lua_error("stack size overflow"); | |
| 106 | + if (stacksize >= limit) | |
| 107 | + { | |
| 108 | + limit = stacksize; | |
| 109 | + lua_error(stackEM); | |
| 110 | + } | |
| 100 | 111 | } |
| 101 | 112 | } |
| 102 | 113 | |
| @@ -106,18 +117,9 @@ static void growstack (void) · 3 unmodified lines | ||
| 106 | 117 | */ |
| 107 | 118 | static char *lua_strconc (char *l, char *r) |
| 108 | 119 | { |
| 109 | − static char *buffer = NULL; | |
| 110 | − static int buffer_size = 0; | |
| 111 | − int nl = strlen(l); | |
| 112 | − int n = nl+strlen(r)+1; | |
| 113 | − if (n > buffer_size) | |
| 114 | − { | |
| 115 | − buffer_size = n; | |
| 116 | − if (buffer != NULL) | |
| 117 | − luaI_free(buffer); | |
| 118 | − buffer = newvector(buffer_size, char); | |
| 119 | − } | |
| 120 | − strcpy(buffer,l); | |
| 120 | + int nl = strlen(l); | |
| 121 | + char *buffer = luaI_buffer(nl+strlen(r)+1); | |
| 122 | + strcpy(buffer, l); | |
| 121 | 123 | strcpy(buffer+nl, r); |
| 122 | 124 | return buffer; |
| 123 | 125 | } |
| @@ -150,7 +152,7 @@ static int lua_tonumber (Object *obj) · 26 unmodified lines | ||
| 150 | 152 | */ |
| 151 | 153 | static int lua_tostring (Object *obj) |
| 152 | 154 | { |
| 153 | − static char s[256]; | |
| 155 | + char s[256]; | |
| 154 | 156 | if (tag(obj) != LUA_T_NUMBER) |
| 155 | 157 | return 1; |
| 156 | 158 | if ((int) nvalue(obj) == nvalue(obj)) |
| @@ -158,8 +160,6 @@ static int lua_tostring (Object *obj) · 1 unmodified line | ||
| 158 | 160 | else |
| 159 | 161 | sprintf (s, "%g", nvalue(obj)); |
| 160 | 162 | tsvalue(obj) = lua_createstring(s); |
| 161 | − if (tsvalue(obj) == NULL) | |
| 162 | − return 1; | |
| 163 | 163 | tag(obj) = LUA_T_STRING; |
| 164 | 164 | return 0; |
| 165 | 165 | } |
| @@ -192,6 +192,48 @@ static void open_stack (int nelems) · 26 unmodified lines | ||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | +/* | |
| 196 | +** call Line hook | |
| 197 | +*/ | |
| 198 | +static void lineHook (int line) | |
| 199 | +{ | |
| 200 | + StkId oldBase = CBase; | |
| 201 | + int oldCnResults = CnResults; | |
| 202 | + StkId old_top = CBase = top-stack; | |
| 203 | + CnResults = 0; | |
| 204 | + (*lua_linehook)(line); | |
| 205 | + top = stack+old_top; | |
| 206 | + CnResults = oldCnResults; | |
| 207 | + CBase = oldBase; | |
| 208 | +} | |
| 209 | + | |
| 210 | + | |
| 211 | +/* | |
| 212 | +** Call hook | |
| 213 | +** The function being called is in [stack+base-1] | |
| 214 | +*/ | |
| 215 | +static void callHook (StkId base, lua_Type type, int isreturn) | |
| 216 | +{ | |
| 217 | + StkId oldBase = CBase; | |
| 218 | + int oldCnResults = CnResults; | |
| 219 | + StkId old_top = CBase = top-stack; | |
| 220 | + CnResults = 0; | |
| 221 | + if (isreturn) | |
| 222 | + (*lua_callhook)(LUA_NOOBJECT, "(return)", 0); | |
| 223 | + else | |
| 224 | + { | |
| 225 | + Object *f = stack+base-1; | |
| 226 | + if (type == LUA_T_MARK) | |
| 227 | + (*lua_callhook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined); | |
| 228 | + else | |
| 229 | + (*lua_callhook)(Ref(f), "(C)", -1); | |
| 230 | + } | |
| 231 | + top = stack+old_top; | |
| 232 | + CnResults = oldCnResults; | |
| 233 | + CBase = oldBase; | |
| 234 | +} | |
| 235 | + | |
| 236 | + | |
| 195 | 237 | /* |
| 196 | 238 | ** Call a C function. CBase will point to the top of the stack, |
| 197 | 239 | ** and CnResults is the number of parameters. Returns an index |
| @@ -204,8 +246,12 @@ static StkId callC (lua_CFunction func, StkId base) · 6 unmodified lines | ||
| 204 | 246 | StkId firstResult; |
| 205 | 247 | CnResults = (top-stack) - base; |
| 206 | 248 | /* incorporate parameters on the stack */ |
| 207 | − CBase = base+CnResults; | |
| 249 | + CBase = base+CnResults; /* == top-stack */ | |
| 250 | + if (lua_callhook) | |
| 251 | + callHook(base, LUA_T_CMARK, 0); | |
| 208 | 252 | (*func)(); |
| 253 | + if (lua_callhook) /* func may have changed lua_callhook */ | |
| 254 | + callHook(base, LUA_T_CMARK, 1); | |
| 209 | 255 | firstResult = CBase; |
| 210 | 256 | CBase = oldBase; |
| 211 | 257 | CnResults = oldCnResults; |
| @@ -303,6 +349,18 @@ static void storesubscript (void) · 91 unmodified lines | ||
| 303 | 349 | } |
| 304 | 350 | |
| 305 | 351 | |
| 352 | +static void getglobal (Word n) | |
| 353 | +{ | |
| 354 | + *top = lua_table[n].object; | |
| 355 | + incr_top; | |
| 356 | + if (tag(top-1) == LUA_T_NIL) | |
| 357 | + { /* must call getglobal fallback */ | |
| 358 | + tag(top-1) = LUA_T_STRING; | |
| 359 | + tsvalue(top-1) = lua_table[n].varname; | |
| 360 | + callFB(FB_GETGLOBAL); | |
| 361 | + } | |
| 362 | +} | |
| 363 | + | |
| 306 | 364 | /* |
| 307 | 365 | ** Traverse all objects on stack |
| 308 | 366 | */ |
| @@ -340,7 +398,7 @@ void lua_error (char *s) · 31 unmodified lines | ||
| 340 | 398 | } |
| 341 | 399 | |
| 342 | 400 | |
| 343 | −lua_Object lua_stackedfunction (int level) | |
| 401 | +lua_Function lua_stackedfunction (int level) | |
| 344 | 402 | { |
| 345 | 403 | Object *p = top; |
| 346 | 404 | while (--p >= stack) |
| @@ -351,13 +409,45 @@ lua_Object lua_stackedfunction (int level) · 4 unmodified lines | ||
| 351 | 409 | } |
| 352 | 410 | |
| 353 | 411 | |
| 354 | −int lua_currentline (lua_Object func) | |
| 412 | +int lua_currentline (lua_Function func) | |
| 355 | 413 | { |
| 356 | 414 | Object *f = Address(func); |
| 357 | 415 | return (f+1 < top && (f+1)->tag == LUA_T_LINE) ? (f+1)->value.i : -1; |
| 358 | 416 | } |
| 359 | 417 | |
| 360 | 418 | |
| 419 | +lua_Object lua_getlocal (lua_Function func, int local_number, char **name) | |
| 420 | +{ | |
| 421 | + Object *f = luaI_Address(func); | |
| 422 | + *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); | |
| 423 | + if (*name) | |
| 424 | + { | |
| 425 | + /* if "*name", there must be a LUA_T_LINE */ | |
| 426 | + /* therefore, f+2 points to function base */ | |
| 427 | + return Ref((f+2)+(local_number-1)); | |
| 428 | + } | |
| 429 | + else | |
| 430 | + return LUA_NOOBJECT; | |
| 431 | +} | |
| 432 | + | |
| 433 | +int lua_setlocal (lua_Function func, int local_number) | |
| 434 | +{ | |
| 435 | + Object *f = Address(func); | |
| 436 | + char *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); | |
| 437 | + adjustC(1); | |
| 438 | + --top; | |
| 439 | + if (name) | |
| 440 | + { | |
| 441 | + /* if "name", there must be a LUA_T_LINE */ | |
| 442 | + /* therefore, f+2 points to function base */ | |
| 443 | + *((f+2)+(local_number-1)) = *top; | |
| 444 | + return 1; | |
| 445 | + } | |
| 446 | + else | |
| 447 | + return 0; | |
| 448 | +} | |
| 449 | + | |
| 450 | + | |
| 361 | 451 | /* |
| 362 | 452 | ** Execute a protected call. Assumes that function is at CBase and |
| 363 | 453 | ** parameters are on top of it. Leave nResults on the stack. |
| @@ -386,6 +476,16 @@ static int do_protectedrun (int nResults) · 22 unmodified lines | ||
| 386 | 476 | return status; |
| 387 | 477 | } |
| 388 | 478 | |
| 479 | +int luaI_dorun (TFunc *tf) | |
| 480 | +{ | |
| 481 | + int status; | |
| 482 | + adjustC(1); /* one slot for the pseudo-function */ | |
| 483 | + stack[CBase].tag = LUA_T_FUNCTION; | |
| 484 | + stack[CBase].value.tf = tf; | |
| 485 | + status = do_protectedrun(0); | |
| 486 | + adjustC(0); | |
| 487 | + return status; | |
| 488 | +} | |
| 389 | 489 | |
| 390 | 490 | static int do_protectedmain (void) |
| 391 | 491 | { |
| @@ -394,16 +494,12 @@ static int do_protectedmain (void) · 2 unmodified lines | ||
| 394 | 494 | jmp_buf myErrorJmp; |
| 395 | 495 | jmp_buf *oldErr = errorJmp; |
| 396 | 496 | errorJmp = &myErrorJmp; |
| 397 | − adjustC(1); /* one slot for the pseudo-function */ | |
| 398 | − stack[CBase].tag = LUA_T_FUNCTION; | |
| 399 | − stack[CBase].value.tf = &tf; | |
| 400 | − tf.lineDefined = 0; | |
| 497 | + luaI_initTFunc(&tf); | |
| 401 | 498 | tf.fileName = lua_parsedfile; |
| 402 | − tf.code = NULL; | |
| 403 | 499 | if (setjmp(myErrorJmp) == 0) |
| 404 | 500 | { |
| 405 | 501 | lua_parse(&tf); |
| 406 | − status = do_protectedrun(0); | |
| 502 | + status = luaI_dorun(&tf); | |
| 407 | 503 | } |
| 408 | 504 | else |
| 409 | 505 | { |
| @@ -411,8 +507,7 @@ static int do_protectedmain (void) · 1 unmodified line | ||
| 411 | 507 | adjustC(0); /* erase extra slot */ |
| 412 | 508 | } |
| 413 | 509 | errorJmp = oldErr; |
| 414 | − if (tf.code) | |
| 415 | − luaI_free(tf.code); | |
| 510 | + luaI_free(tf.code); | |
| 416 | 511 | return status; |
| 417 | 512 | } |
| 418 | 513 | |
| @@ -449,13 +544,13 @@ int lua_call (char *funcname) · 30 unmodified lines | ||
| 449 | 544 | int lua_dofile (char *filename) |
| 450 | 545 | { |
| 451 | 546 | int status; |
| 452 | − char *message = lua_openfile (filename); | |
| 453 | − if (message) | |
| 454 | − { | |
| 455 | − lua_message(message); | |
| 547 | + int c; | |
| 548 | + FILE *f = lua_openfile(filename); | |
| 549 | + if (f == NULL) | |
| 456 | 550 | return 1; |
| 457 | − } | |
| 458 | − status = do_protectedmain(); | |
| 551 | + c = fgetc(f); | |
| 552 | + ungetc(c, f); | |
| 553 | + status = (c == ID_CHUNK) ? luaI_undump(f) : do_protectedmain(); | |
| 459 | 554 | lua_closefile(); |
| 460 | 555 | return status; |
| 461 | 556 | } |
| @@ -514,8 +609,9 @@ static StkId Cblocks[MAX_C_BLOCKS]; · 52 unmodified lines | ||
| 514 | 609 | */ |
| 515 | 610 | void lua_beginblock (void) |
| 516 | 611 | { |
| 517 | − if (numCblocks < MAX_C_BLOCKS) | |
| 518 | − Cblocks[numCblocks] = CBase; | |
| 612 | + if (numCblocks >= MAX_C_BLOCKS) | |
| 613 | + lua_error("`lua_beginblock': too many nested blocks"); | |
| 614 | + Cblocks[numCblocks] = CBase; | |
| 519 | 615 | numCblocks++; |
| 520 | 616 | } |
| 521 | 617 | |
| @@ -525,11 +621,8 @@ void lua_beginblock (void) · 3 unmodified lines | ||
| 525 | 621 | void lua_endblock (void) |
| 526 | 622 | { |
| 527 | 623 | --numCblocks; |
| 528 | − if (numCblocks < MAX_C_BLOCKS) | |
| 529 | − { | |
| 530 | − CBase = Cblocks[numCblocks]; | |
| 531 | − adjustC(0); | |
| 532 | − } | |
| 624 | + CBase = Cblocks[numCblocks]; | |
| 625 | + adjustC(0); | |
| 533 | 626 | } |
| 534 | 627 | |
| 535 | 628 | /* |
| @@ -566,6 +659,23 @@ lua_Object lua_getparam (int number) · 30 unmodified lines | ||
| 566 | 659 | return CBase-CnResults+number; |
| 567 | 660 | } |
| 568 | 661 | |
| 662 | +int lua_isnumber (lua_Object object) | |
| 663 | +{ | |
| 664 | + return (object != LUA_NOOBJECT) && (tonumber(Address(object)) == 0); | |
| 665 | +} | |
| 666 | + | |
| 667 | +int lua_isstring (lua_Object object) | |
| 668 | +{ | |
| 669 | + int t = lua_type(object); | |
| 670 | + return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); | |
| 671 | +} | |
| 672 | + | |
| 673 | +int lua_isfunction (lua_Object object) | |
| 674 | +{ | |
| 675 | + int t = lua_type(object); | |
| 676 | + return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION); | |
| 677 | +} | |
| 678 | + | |
| 569 | 679 | /* |
| 570 | 680 | ** Given an object handle, return its number value. On error, return 0.0. |
| 571 | 681 | */ |
| @@ -607,27 +717,31 @@ void *lua_getuserdata (lua_Object object) · 35 unmodified lines | ||
| 607 | 717 | } |
| 608 | 718 | |
| 609 | 719 | |
| 610 | −lua_Object lua_getlocked (int ref) | |
| 720 | +lua_Object lua_getref (int ref) | |
| 611 | 721 | { |
| 612 | − adjustC(0); | |
| 613 | − *top = *luaI_getlocked(ref); | |
| 614 | − incr_top; | |
| 615 | − CBase++; /* incorporate object in the stack */ | |
| 616 | − return Ref(top-1); | |
| 722 | + Object *o = luaI_getref(ref); | |
| 723 | + if (o == NULL) | |
| 724 | + return LUA_NOOBJECT; | |
| 725 | + adjustC(0); | |
| 726 | + luaI_pushobject(o); | |
| 727 | + CBase++; /* incorporate object in the stack */ | |
| 728 | + return Ref(top-1); | |
| 617 | 729 | } |
| 618 | 730 | |
| 619 | 731 | |
| 620 | −void lua_pushlocked (int ref) | |
| 732 | +void lua_pushref (int ref) | |
| 621 | 733 | { |
| 622 | − *top = *luaI_getlocked(ref); | |
| 623 | − incr_top; | |
| 734 | + Object *o = luaI_getref(ref); | |
| 735 | + if (o == NULL) | |
| 736 | + lua_error("access to invalid (possibly garbage collected) reference"); | |
| 737 | + luaI_pushobject(o); | |
| 624 | 738 | } |
| 625 | 739 | |
| 626 | 740 | |
| 627 | −int lua_lock (void) | |
| 741 | +int lua_ref (int lock) | |
| 628 | 742 | { |
| 629 | 743 | adjustC(1); |
| 630 | − return luaI_lock(--top); | |
| 744 | + return luaI_ref(--top, lock); | |
| 631 | 745 | } |
| 632 | 746 | |
| 633 | 747 | |
| @@ -637,10 +751,8 @@ int lua_lock (void) · 3 unmodified lines | ||
| 637 | 751 | */ |
| 638 | 752 | lua_Object lua_getglobal (char *name) |
| 639 | 753 | { |
| 640 | − Word n = luaI_findsymbolbyname(name); | |
| 641 | 754 | adjustC(0); |
| 642 | − *top = s_object(n); | |
| 643 | − incr_top; | |
| 755 | + getglobal(luaI_findsymbolbyname(name)); | |
| 644 | 756 | CBase++; /* incorporate object in the stack */ |
| 645 | 757 | return Ref(top-1); |
| 646 | 758 | } |
| @@ -678,20 +790,17 @@ void lua_pushnumber (real n) · 31 unmodified lines | ||
| 678 | 790 | */ |
| 679 | 791 | void lua_pushstring (char *s) |
| 680 | 792 | { |
| 681 | − tsvalue(top) = lua_createstring(s); | |
| 682 | − tag(top) = LUA_T_STRING; | |
| 683 | − incr_top; | |
| 684 | −} | |
| 685 | − | |
| 686 | −/* | |
| 687 | −** Push an object (tag=string) on stack and register it on the constant table. | |
| 688 | −*/ | |
| 689 | −void lua_pushliteral (char *s) | |
| 690 | −{ | |
| 691 | − tsvalue(top) = lua_constant[luaI_findconstantbyname(s)]; | |
| 692 | − tag(top) = LUA_T_STRING; | |
| 693 | − incr_top; | |
| 793 | + if (s == NULL) | |
| 794 | + tag(top) = LUA_T_NIL; | |
| 795 | + else | |
| 796 | + { | |
| 797 | + tsvalue(top) = lua_createstring(s); | |
| 798 | + tag(top) = LUA_T_STRING; | |
| 799 | + } | |
| 800 | + incr_top; | |
| 694 | 801 | } |
| 802 | +/*>>>>>>>>>#undef lua_pushliteral | |
| 803 | +void lua_pushliteral(char *s) { lua_pushstring(s); }*/ | |
| 695 | 804 | |
| 696 | 805 | /* |
| 697 | 806 | ** Push an object (tag=cfunction) to stack. |
| @@ -707,27 +816,29 @@ void lua_pushcfunction (lua_CFunction fn) · 9 unmodified lines | ||
| 707 | 816 | */ |
| 708 | 817 | void lua_pushusertag (void *u, int tag) |
| 709 | 818 | { |
| 710 | − if (tag < LUA_T_USERDATA) return; | |
| 819 | + if (tag < LUA_T_USERDATA) | |
| 820 | + lua_error("invalid tag in `lua_pushusertag'"); | |
| 711 | 821 | tag(top) = tag; uvalue(top) = u; |
| 712 | 822 | incr_top; |
| 713 | 823 | } |
| 714 | 824 | |
| 715 | 825 | /* |
| 716 | −** Push a lua_Object to stack. | |
| 826 | +** Push an object on the stack. | |
| 717 | 827 | */ |
| 718 | −void lua_pushobject (lua_Object o) | |
| 828 | +void luaI_pushobject (Object *o) | |
| 719 | 829 | { |
| 720 | − *top = *Address(o); | |
| 830 | + *top = *o; | |
| 721 | 831 | incr_top; |
| 722 | 832 | } |
| 723 | 833 | |
| 724 | 834 | /* |
| 725 | −** Push an object on the stack. | |
| 835 | +** Push a lua_Object on stack. | |
| 726 | 836 | */ |
| 727 | −void luaI_pushobject (Object *o) | |
| 837 | +void lua_pushobject (lua_Object o) | |
| 728 | 838 | { |
| 729 | − *top = *o; | |
| 730 | − incr_top; | |
| 839 | + if (o == LUA_NOOBJECT) | |
| 840 | + lua_error("attempt to push a NOOBJECT"); | |
| 841 | + luaI_pushobject(Address(o)); | |
| 731 | 842 | } |
| 732 | 843 | |
| 733 | 844 | int lua_type (lua_Object o) |
| @@ -783,6 +894,8 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, · 49 unmodified lines | ||
| 783 | 894 | */ |
| 784 | 895 | static StkId lua_execute (Byte *pc, StkId base) |
| 785 | 896 | { |
| 897 | + if (lua_callhook) | |
| 898 | + callHook (base, LUA_T_MARK, 0); | |
| 786 | 899 | while (1) |
| 787 | 900 | { |
| 788 | 901 | OpCode opcode; |
| @@ -849,8 +962,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 60 unmodified lines | ||
| 849 | 962 | { |
| 850 | 963 | CodeWord code; |
| 851 | 964 | get_word(code,pc); |
| 852 | − *top = s_object(code.w); | |
| 853 | − incr_top; | |
| 965 | + getglobal(code.w); | |
| 854 | 966 | } |
| 855 | 967 | break; |
| 856 | 968 | |
| @@ -1143,10 +1255,10 @@ static StkId lua_execute (Byte *pc, StkId base) · 286 unmodified lines | ||
| 1143 | 1255 | break; |
| 1144 | 1256 | |
| 1145 | 1257 | case RETCODE0: |
| 1146 | − return base; | |
| 1147 | − | |
| 1148 | 1258 | case RETCODE: |
| 1149 | − return base+*pc; | |
| 1259 | + if (lua_callhook) | |
| 1260 | + callHook (base, LUA_T_MARK, 1); | |
| 1261 | + return (base + ((opcode==RETCODE0) ? 0 : *pc)); | |
| 1150 | 1262 | |
| 1151 | 1263 | case SETLINE: |
| 1152 | 1264 | { |
| @@ -1160,6 +1272,8 @@ static StkId lua_execute (Byte *pc, StkId base) · 7 unmodified lines | ||
| 1160 | 1272 | (stack+base-1)->tag = LUA_T_LINE; |
| 1161 | 1273 | } |
| 1162 | 1274 | (stack+base-1)->value.i = code.w; |
| 1275 | + if (lua_linehook) | |
| 1276 | + lineHook (code.w); | |
| 1163 | 1277 | break; |
| 1164 | 1278 | } |
| 1165 | 1279 | |
| @@ -1169,4 +1283,3 @@ static StkId lua_execute (Byte *pc, StkId base) · 3 unmodified lines | ||
| 1169 | 1283 | } |
| 1170 | 1284 | } |
| 1171 | 1285 | |
| 1172 | − | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** TeCGraf - PUC-Rio |
| 3 | −** $Id: opcode.h,v 3.14 1995/10/25 13:05:51 roberto Exp $ | |
| 3 | +** $Id: opcode.h,v 3.20 1996/03/15 13:13:13 roberto Exp $ | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | #ifndef opcode_h |
| @@ -11,9 +11,6 @@ · 4 unmodified lines | ||
| 11 | 11 | #include "tree.h" |
| 12 | 12 | #include "func.h" |
| 13 | 13 | |
| 14 | −#ifndef real | |
| 15 | −#define real float | |
| 16 | −#endif | |
| 17 | 14 | |
| 18 | 15 | #define FIELDS_PER_FLUSH 40 |
| 19 | 16 | |
| @@ -74,12 +71,9 @@ typedef enum · 54 unmodified lines | ||
| 74 | 71 | #define MULT_RET 255 |
| 75 | 72 | |
| 76 | 73 | |
| 77 | −typedef void (*Cfunction) (void); | |
| 78 | −typedef int (*Input) (void); | |
| 79 | − | |
| 80 | 74 | typedef union |
| 81 | 75 | { |
| 82 | − Cfunction f; | |
| 76 | + lua_CFunction f; | |
| 83 | 77 | real n; |
| 84 | 78 | TaggedString *ts; |
| 85 | 79 | TFunc *tf; |
| @@ -94,10 +88,6 @@ typedef struct Object · 8 unmodified lines | ||
| 94 | 88 | Value value; |
| 95 | 89 | } Object; |
| 96 | 90 | |
| 97 | −typedef struct | |
| 98 | −{ | |
| 99 | − Object object; | |
| 100 | −} Symbol; | |
| 101 | 91 | |
| 102 | 92 | /* Macros to access structure members */ |
| 103 | 93 | #define tag(o) ((o)->tag) |
| @@ -119,14 +109,14 @@ typedef struct · 15 unmodified lines | ||
| 119 | 109 | |
| 120 | 110 | typedef union |
| 121 | 111 | { |
| 122 | − struct {char c1; char c2;} m; | |
| 112 | + struct {Byte c1; Byte c2;} m; | |
| 123 | 113 | Word w; |
| 124 | 114 | } CodeWord; |
| 125 | 115 | #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;} |
| 126 | 116 | |
| 127 | 117 | typedef union |
| 128 | 118 | { |
| 129 | − struct {char c1; char c2; char c3; char c4;} m; | |
| 119 | + struct {Byte c1; Byte c2; Byte c3; Byte c4;} m; | |
| 130 | 120 | float f; |
| 131 | 121 | } CodeFloat; |
| 132 | 122 | #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ |
| @@ -134,7 +124,7 @@ typedef union · 1 unmodified line | ||
| 134 | 124 | |
| 135 | 125 | typedef union |
| 136 | 126 | { |
| 137 | − struct {char c1; char c2; char c3; char c4;} m; | |
| 127 | + struct {Byte c1; Byte c2; Byte c3; Byte c4;} m; | |
| 138 | 128 | TFunc *tf; |
| 139 | 129 | } CodeCode; |
| 140 | 130 | #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ |
| @@ -142,16 +132,12 @@ typedef union · 1 unmodified line | ||
| 142 | 132 | |
| 143 | 133 | |
| 144 | 134 | /* Exported functions */ |
| 145 | −char *lua_strdup (char *l); | |
| 146 | − | |
| 147 | −void lua_setinput (Input fn); /* from "lex.c" module */ | |
| 148 | −char *lua_lasttext (void); /* from "lex.c" module */ | |
| 149 | −int yylex (void); /* from "lex.c" module */ | |
| 150 | 135 | void lua_parse (TFunc *tf); /* from "lua.stx" module */ |
| 151 | 136 | void luaI_codedebugline (int line); /* from "lua.stx" module */ |
| 152 | 137 | void lua_travstack (int (*fn)(Object *)); |
| 153 | 138 | Object *luaI_Address (lua_Object o); |
| 154 | 139 | void luaI_pushobject (Object *o); |
| 155 | 140 | void luaI_gcFB (Object *o); |
| 141 | +int luaI_dorun (TFunc *tf); | |
| 156 | 142 | |
| 157 | 143 | #endif |
| @@ -1,25 +1,26 @@ | ||
| 1 | 1 | #if defined (__cplusplus) || defined (c_plusplus) |
| 2 | 2 | #include <c_varieties.h> |
| 3 | 3 | #ifdef __EXTERN_C__ |
| 4 | − EXTERN_FUNCTION ( extern int yylex, ()); | |
| 4 | + EXTERN_FUNCTION ( extern int luaY_lex, ()); | |
| 5 | 5 | #else |
| 6 | − extern int yylex(); | |
| 6 | + extern int luaY_lex(); | |
| 7 | 7 | #endif |
| 8 | − extern void yyerror(char *); | |
| 9 | − extern int yyparse(); | |
| 8 | + extern void luaY_error(char *); | |
| 9 | + extern int luaY_parse(); | |
| 10 | 10 | #endif |
| 11 | 11 | |
| 12 | −#include <malloc.h> | |
| 12 | +#include <stdlib.h> | |
| 13 | 13 | |
| 14 | 14 | # line 2 "lua.stx" |
| 15 | 15 | |
| 16 | −char *rcs_luastx = "$Id: lua.stx,v 3.25 1995/10/26 17:02:50 roberto Exp $"; | |
| 16 | +char *rcs_luastx = "$Id: parser.c,v 1.1 1996/05/14 19:44:57 lhf Exp $"; | |
| 17 | 17 | |
| 18 | 18 | #include <stdio.h> |
| 19 | 19 | #include <stdlib.h> |
| 20 | −#include <string.h> | |
| 21 | 20 | |
| 21 | +#include "luadebug.h" | |
| 22 | 22 | #include "mem.h" |
| 23 | +#include "lex.h" | |
| 23 | 24 | #include "opcode.h" |
| 24 | 25 | #include "hash.h" |
| 25 | 26 | #include "inout.h" |
| @@ -29,7 +30,7 @@ char *rcs_luastx = "$Id: lua.stx,v 3.25 1995/10/26 17:02:50 roberto Exp $"; · 3 unmodified lines | ||
| 29 | 30 | #include "func.h" |
| 30 | 31 | |
| 31 | 32 | /* to avoid warnings generated by yacc */ |
| 32 | −int yyparse (void); | |
| 33 | +int luaY_parse (void); | |
| 33 | 34 | #define malloc luaI_malloc |
| 34 | 35 | #define realloc luaI_realloc |
| 35 | 36 | #define free luaI_free |
| @@ -43,7 +44,7 @@ int yyparse (void); · 7 unmodified lines | ||
| 43 | 44 | #endif |
| 44 | 45 | static int maxcode; |
| 45 | 46 | static int maxmain; |
| 46 | −static Long maxcurr; /* to allow maxcurr *= 2 without overflow */ | |
| 47 | +static int maxcurr; | |
| 47 | 48 | static Byte *funcCode = NULL; |
| 48 | 49 | static Byte **initcode; |
| 49 | 50 | static Byte *basepc; |
| @@ -57,35 +58,32 @@ static Long varbuffer[MAXVAR]; /* variables in an assignment list; · 7 unmodified lines | ||
| 57 | 58 | static int nvarbuffer=0; /* number of variables at a list */ |
| 58 | 59 | |
| 59 | 60 | #define MAXLOCALS 32 |
| 60 | −static Word localvar[MAXLOCALS]; /* store local variable names */ | |
| 61 | +static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ | |
| 61 | 62 | static int nlocalvar=0; /* number of local variables */ |
| 62 | 63 | |
| 63 | 64 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
| 64 | 65 | static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ |
| 65 | 66 | static int nfields=0; |
| 66 | 67 | |
| 68 | +int lua_debug = 0; | |
| 67 | 69 | |
| 68 | 70 | /* Internal functions */ |
| 69 | 71 | |
| 70 | −static void yyerror (char *s) | |
| 72 | +static void luaY_error (char *s) | |
| 71 | 73 | { |
| 72 | − static char msg[256]; | |
| 73 | − sprintf (msg,"%s near \"%s\" at line %d in file `%s'", | |
| 74 | − s, lua_lasttext (), lua_linenumber, lua_parsedfile); | |
| 74 | + char msg[256]; | |
| 75 | + char *token = lua_lasttext(); | |
| 76 | + if (token[0] == 0) | |
| 77 | + token = "<eof>"; | |
| 78 | + sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'", | |
| 79 | + s, token, lua_linenumber, lua_parsedfile); | |
| 75 | 80 | lua_error (msg); |
| 76 | 81 | } |
| 77 | 82 | |
| 78 | 83 | static void code_byte (Byte c) |
| 79 | 84 | { |
| 80 | 85 | if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ |
| 81 | − { | |
| 82 | − if (maxcurr >= MAX_INT) | |
| 83 | − lua_error("code size overflow"); | |
| 84 | − maxcurr *= 2; | |
| 85 | − if (maxcurr >= MAX_INT) | |
| 86 | − maxcurr = MAX_INT; | |
| 87 | − basepc = growvector(basepc, maxcurr, Byte); | |
| 88 | − } | |
| 86 | + maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT); | |
| 89 | 87 | basepc[pc++] = c; |
| 90 | 88 | } |
| 91 | 89 | |
| @@ -117,10 +115,12 @@ static void code_code (TFunc *tf) · 25 unmodified lines | ||
| 117 | 115 | code_byte(code.m.c4); |
| 118 | 116 | } |
| 119 | 117 | |
| 120 | −static void code_word_at (Byte *p, Word n) | |
| 118 | +static void code_word_at (Byte *p, int n) | |
| 121 | 119 | { |
| 122 | 120 | CodeWord code; |
| 123 | − code.w = n; | |
| 121 | + if ((Word)n != n) | |
| 122 | + luaY_error("block too big"); | |
| 123 | + code.w = (Word)n; | |
| 124 | 124 | *p++ = code.m.c1; |
| 125 | 125 | *p++ = code.m.c2; |
| 126 | 126 | } |
| @@ -130,7 +130,7 @@ static void push_field (Word name) · 3 unmodified lines | ||
| 130 | 130 | if (nfields < MAXFIELDS) |
| 131 | 131 | fields[nfields++] = name; |
| 132 | 132 | else |
| 133 | − lua_error ("too many fields in nested constructors"); | |
| 133 | + luaY_error ("too many fields in nested constructors"); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | static void flush_record (int n) |
| @@ -155,24 +155,24 @@ static void flush_list (int m, int n) · 18 unmodified lines | ||
| 155 | 155 | code_byte(m); |
| 156 | 156 | } |
| 157 | 157 | else |
| 158 | − lua_error ("list constructor too long"); | |
| 158 | + luaY_error ("list constructor too long"); | |
| 159 | 159 | code_byte(n); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | −static void add_localvar (Word name) | |
| 162 | +static void store_localvar (TaggedString *name, int n) | |
| 163 | 163 | { |
| 164 | − if (nlocalvar < MAXLOCALS) | |
| 165 | − localvar[nlocalvar++] = name; | |
| 164 | + if (nlocalvar+n < MAXLOCALS) | |
| 165 | + localvar[nlocalvar+n] = name; | |
| 166 | 166 | else |
| 167 | − lua_error ("too many local variables"); | |
| 167 | + luaY_error ("too many local variables"); | |
| 168 | + if (lua_debug) | |
| 169 | + luaI_registerlocalvar(name, lua_linenumber); | |
| 168 | 170 | } |
| 169 | 171 | |
| 170 | −static void store_localvar (Word name, int n) | |
| 172 | +static void add_localvar (TaggedString *name) | |
| 171 | 173 | { |
| 172 | − if (nlocalvar+n < MAXLOCALS) | |
| 173 | − localvar[nlocalvar+n] = name; | |
| 174 | − else | |
| 175 | − lua_error ("too many local variables"); | |
| 174 | + store_localvar(name, 0); | |
| 175 | + nlocalvar++; | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | static void add_varbuffer (Long var) |
| @@ -180,7 +180,7 @@ static void add_varbuffer (Long var) · 1 unmodified line | ||
| 180 | 180 | if (nvarbuffer < MAXVAR) |
| 181 | 181 | varbuffer[nvarbuffer++] = var; |
| 182 | 182 | else |
| 183 | − lua_error ("variable buffer overflow"); | |
| 183 | + luaY_error ("variable buffer overflow"); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | static void code_number (float f) |
| @@ -210,7 +210,7 @@ static void code_number (float f) · 23 unmodified lines | ||
| 210 | 210 | /* |
| 211 | 211 | ** Search a local name and if find return its index. If do not find return -1 |
| 212 | 212 | */ |
| 213 | −static int lua_localname (Word n) | |
| 213 | +static int lua_localname (TaggedString *n) | |
| 214 | 214 | { |
| 215 | 215 | int i; |
| 216 | 216 | for (i=nlocalvar-1; i >= 0; i--) |
| @@ -401,13 +401,12 @@ static void codeIf (Long thenAdd, Long elseAdd) · 184 unmodified lines | ||
| 401 | 401 | */ |
| 402 | 402 | void lua_parse (TFunc *tf) |
| 403 | 403 | { |
| 404 | − lua_debug = 0; | |
| 405 | 404 | initcode = &(tf->code); |
| 406 | 405 | *initcode = newvector(CODE_BLOCK, Byte); |
| 407 | 406 | maincode = 0; |
| 408 | 407 | maxmain = CODE_BLOCK; |
| 409 | 408 | change2main(); |
| 410 | − if (yyparse ()) lua_error("parse error"); | |
| 409 | + if (luaY_parse ()) lua_error("parse error"); | |
| 411 | 410 | savemain(); |
| 412 | 411 | (*initcode)[maincode++] = RETCODE0; |
| 413 | 412 | tf->size = maincode; |
| @@ -419,7 +418,7 @@ void lua_parse (TFunc *tf) · 5 unmodified lines | ||
| 419 | 418 | |
| 420 | 419 | |
| 421 | 420 | |
| 422 | −# line 411 "lua.stx" | |
| 421 | +# line 410 "lua.stx" | |
| 423 | 422 | typedef union |
| 424 | 423 | { |
| 425 | 424 | int vInt; |
| @@ -428,7 +427,7 @@ typedef union · 2 unmodified lines | ||
| 428 | 427 | Word vWord; |
| 429 | 428 | Long vLong; |
| 430 | 429 | TFunc *pFunc; |
| 431 | − TreeNode *pNode; | |
| 430 | + TaggedString *pTStr; | |
| 432 | 431 | } YYSTYPE; |
| 433 | 432 | # define WRONGTOKEN 257 |
| 434 | 433 | # define NIL 258 |
| @@ -457,244 +456,19 @@ typedef union · 22 unmodified lines | ||
| 457 | 456 | # define CONC 281 |
| 458 | 457 | # define UNARY 282 |
| 459 | 458 | # define NOT 283 |
| 460 | −#define yyclearin yychar = -1 | |
| 461 | −#define yyerrok yyerrflag = 0 | |
| 462 | −extern int yychar; | |
| 463 | −extern int yyerrflag; | |
| 459 | +#define luaY_clearin luaY_char = -1 | |
| 460 | +#define luaY_errok luaY_errflag = 0 | |
| 461 | +extern int luaY_char; | |
| 462 | +extern int luaY_errflag; | |
| 464 | 463 | #ifndef YYMAXDEPTH |
| 465 | 464 | #define YYMAXDEPTH 150 |
| 466 | 465 | #endif |
| 467 | −YYSTYPE yylval, yyval; | |
| 466 | +YYSTYPE luaY_lval, luaY_val; | |
| 468 | 467 | # define YYERRCODE 256 |
| 469 | 468 | |
| 470 | −# line 789 "lua.stx" | |
| 471 | − | |
| 472 | − | |
| 473 | −#if LISTING | |
| 474 | − | |
| 475 | −static void PrintCode (Byte *code, Byte *end) | |
| 476 | −{ | |
| 477 | − Byte *p = code; | |
| 478 | − printf ("\n\nCODE\n"); | |
| 479 | − while (p != end) | |
| 480 | − { | |
| 481 | − switch ((OpCode)*p) | |
| 482 | − { | |
| 483 | − case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break; | |
| 484 | − case PUSH0: case PUSH1: case PUSH2: | |
| 485 | − printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0'); | |
| 486 | − p++; | |
| 487 | − break; | |
| 488 | − case PUSHBYTE: | |
| 489 | − printf ("%d PUSHBYTE %d\n", p-code, *(++p)); | |
| 490 | − p++; | |
| 491 | − break; | |
| 492 | − case PUSHWORD: | |
| 493 | − { | |
| 494 | − CodeWord c; | |
| 495 | − int n = p-code; | |
| 496 | − p++; | |
| 497 | − get_word(c,p); | |
| 498 | − printf ("%d PUSHWORD %d\n", n, c.w); | |
| 499 | − } | |
| 500 | − break; | |
| 501 | − case PUSHFLOAT: | |
| 502 | − { | |
| 503 | − CodeFloat c; | |
| 504 | − int n = p-code; | |
| 505 | − p++; | |
| 506 | − get_float(c,p); | |
| 507 | − printf ("%d PUSHFLOAT %f\n", n, c.f); | |
| 508 | − } | |
| 509 | − break; | |
| 510 | − case PUSHSTRING: | |
| 511 | − { | |
| 512 | − CodeWord c; | |
| 513 | − int n = p-code; | |
| 514 | − p++; | |
| 515 | − get_word(c,p); | |
| 516 | − printf ("%d PUSHSTRING %d\n", n, c.w); | |
| 517 | − } | |
| 518 | − break; | |
| 519 | − case PUSHFUNCTION: | |
| 520 | − { | |
| 521 | − CodeCode c; | |
| 522 | − int n = p-code; | |
| 523 | − p++; | |
| 524 | − get_code(c,p); | |
| 525 | − printf ("%d PUSHFUNCTION %p\n", n, c.tf); | |
| 526 | − } | |
| 527 | − break; | |
| 528 | − | |
| 529 | − case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: | |
| 530 | − case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: | |
| 531 | − case PUSHLOCAL8: case PUSHLOCAL9: | |
| 532 | − printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0'); | |
| 533 | − p++; | |
| 534 | − break; | |
| 535 | − case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p)); | |
| 536 | − p++; | |
| 537 | − break; | |
| 538 | − case PUSHGLOBAL: | |
| 539 | − { | |
| 540 | − CodeWord c; | |
| 541 | − int n = p-code; | |
| 542 | − p++; | |
| 543 | − get_word(c,p); | |
| 544 | − printf ("%d PUSHGLOBAL %d\n", n, c.w); | |
| 545 | − } | |
| 546 | − break; | |
| 547 | − case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break; | |
| 548 | − case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: | |
| 549 | − case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: | |
| 550 | − case STORELOCAL8: case STORELOCAL9: | |
| 551 | − printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0'); | |
| 552 | − p++; | |
| 553 | − break; | |
| 554 | − case STORELOCAL: | |
| 555 | − printf ("%d STORELOCAL %d\n", p-code, *(++p)); | |
| 556 | − p++; | |
| 557 | − break; | |
| 558 | − case STOREGLOBAL: | |
| 559 | − { | |
| 560 | − CodeWord c; | |
| 561 | − int n = p-code; | |
| 562 | − p++; | |
| 563 | − get_word(c,p); | |
| 564 | − printf ("%d STOREGLOBAL %d\n", n, c.w); | |
| 565 | − } | |
| 566 | − break; | |
| 567 | − case PUSHSELF: | |
| 568 | − { | |
| 569 | − CodeWord c; | |
| 570 | − int n = p-code; | |
| 571 | − p++; | |
| 572 | − get_word(c,p); | |
| 573 | − printf ("%d PUSHSELF %d\n", n, c.w); | |
| 574 | − } | |
| 575 | − break; | |
| 576 | − case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break; | |
| 577 | − case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p)); | |
| 578 | − p++; | |
| 579 | − break; | |
| 580 | − case STORELIST0: | |
| 581 | − printf("%d STORELIST0 %d\n", p-code, *(++p)); | |
| 582 | − p++; | |
| 583 | − break; | |
| 584 | − case STORELIST: | |
| 585 | − printf("%d STORELIST %d %d\n", p-code, *(p+1), *(p+2)); | |
| 586 | − p+=3; | |
| 587 | − break; | |
| 588 | − case STORERECORD: | |
| 589 | − printf("%d STORERECORD %d\n", p-code, *(++p)); | |
| 590 | − p += *p*sizeof(Word) + 1; | |
| 591 | − break; | |
| 592 | − case ADJUST0: printf ("%d ADJUST0\n", (p++)-code); break; | |
| 593 | − case ADJUST: | |
| 594 | − printf ("%d ADJUST %d\n", p-code, *(++p)); | |
| 595 | − p++; | |
| 596 | − break; | |
| 597 | − case CREATEARRAY: | |
| 598 | − { | |
| 599 | − CodeWord c; | |
| 600 | − int n = p-code; | |
| 601 | − p++; | |
| 602 | − get_word(c,p); | |
| 603 | − printf ("%d CREATEARRAY %d\n", n, c.w); | |
| 604 | − break; | |
| 605 | − } | |
| 606 | − case EQOP: printf ("%d EQOP\n", (p++)-code); break; | |
| 607 | − case LTOP: printf ("%d LTOP\n", (p++)-code); break; | |
| 608 | − case LEOP: printf ("%d LEOP\n", (p++)-code); break; | |
| 609 | − case ADDOP: printf ("%d ADDOP\n", (p++)-code); break; | |
| 610 | − case SUBOP: printf ("%d SUBOP\n", (p++)-code); break; | |
| 611 | − case MULTOP: printf ("%d MULTOP\n", (p++)-code); break; | |
| 612 | − case DIVOP: printf ("%d DIVOP\n", (p++)-code); break; | |
| 613 | − case POWOP: printf ("%d POWOP\n", (p++)-code); break; | |
| 614 | − case CONCOP: printf ("%d CONCOP\n", (p++)-code); break; | |
| 615 | − case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break; | |
| 616 | − case NOTOP: printf ("%d NOTOP\n", (p++)-code); break; | |
| 617 | − case ONTJMP: | |
| 618 | − { | |
| 619 | − CodeWord c; | |
| 620 | − int n = p-code; | |
| 621 | − p++; | |
| 622 | − get_word(c,p); | |
| 623 | − printf ("%d ONTJMP %d\n", n, c.w); | |
| 624 | − } | |
| 625 | − break; | |
| 626 | − case ONFJMP: | |
| 627 | − { | |
| 628 | − CodeWord c; | |
| 629 | − int n = p-code; | |
| 630 | − p++; | |
| 631 | − get_word(c,p); | |
| 632 | − printf ("%d ONFJMP %d\n", n, c.w); | |
| 633 | − } | |
| 634 | − break; | |
| 635 | − case JMP: | |
| 636 | − { | |
| 637 | − CodeWord c; | |
| 638 | − int n = p-code; | |
| 639 | − p++; | |
| 640 | − get_word(c,p); | |
| 641 | − printf ("%d JMP %d\n", n, c.w); | |
| 642 | − } | |
| 643 | − break; | |
| 644 | − case UPJMP: | |
| 645 | − { | |
| 646 | − CodeWord c; | |
| 647 | − int n = p-code; | |
| 648 | − p++; | |
| 649 | − get_word(c,p); | |
| 650 | − printf ("%d UPJMP %d\n", n, c.w); | |
| 651 | − } | |
| 652 | − break; | |
| 653 | − case IFFJMP: | |
| 654 | − { | |
| 655 | − CodeWord c; | |
| 656 | − int n = p-code; | |
| 657 | − p++; | |
| 658 | − get_word(c,p); | |
| 659 | − printf ("%d IFFJMP %d\n", n, c.w); | |
| 660 | − } | |
| 661 | − break; | |
| 662 | − case IFFUPJMP: | |
| 663 | − { | |
| 664 | − CodeWord c; | |
| 665 | − int n = p-code; | |
| 666 | − p++; | |
| 667 | − get_word(c,p); | |
| 668 | − printf ("%d IFFUPJMP %d\n", n, c.w); | |
| 669 | − } | |
| 670 | − break; | |
| 671 | − case POP: printf ("%d POP\n", (p++)-code); break; | |
| 672 | − case CALLFUNC: | |
| 673 | − printf ("%d CALLFUNC %d %d\n", p-code, *(p+1), *(p+2)); | |
| 674 | − p+=3; | |
| 675 | − break; | |
| 676 | − case RETCODE0: printf ("%d RETCODE0\n", (p++)-code); break; | |
| 677 | − case RETCODE: | |
| 678 | − printf ("%d RETCODE %d\n", p-code, *(++p)); | |
| 679 | − p++; | |
| 680 | − break; | |
| 681 | − case SETLINE: | |
| 682 | − { | |
| 683 | − CodeWord c; | |
| 684 | − int n = p-code; | |
| 685 | − p++; | |
| 686 | − get_word(c,p); | |
| 687 | − printf ("%d SETLINE %d\n", n, c.w); | |
| 688 | − } | |
| 689 | − break; | |
| 690 | − | |
| 691 | − default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break; | |
| 692 | − } | |
| 693 | − } | |
| 694 | −} | |
| 695 | −#endif | |
| 469 | +# line 788 "lua.stx" | |
| 696 | 470 | |
| 697 | −int yyexca[] ={ | |
| 471 | +int luaY_exca[] ={ | |
| 698 | 472 | -1, 1, |
| 699 | 473 | 0, -1, |
| 700 | 474 | -2, 0, |
| @@ -760,7 +534,7 @@ int yyexca[] ={ · 59 unmodified lines | ||
| 760 | 534 | }; |
| 761 | 535 | # define YYNPROD 100 |
| 762 | 536 | # define YYLAST 311 |
| 763 | −int yyact[]={ | |
| 537 | +int luaY_act[]={ | |
| 764 | 538 | |
| 765 | 539 | 61, 59, 148, 60, 141, 62, 118, 61, 59, 90, |
| 766 | 540 | 60, 89, 62, 86, 84, 18, 42, 168, 54, 164, |
| @@ -794,7 +568,7 @@ int yyact[]={ · 27 unmodified lines | ||
| 794 | 568 | 0, 0, 0, 0, 0, 30, 31, 18, 30, 31, |
| 795 | 569 | 113, 0, 0, 0, 64, 0, 0, 34, 0, 0, |
| 796 | 570 | 34 }; |
| 797 | −int yypact[]={ | |
| 571 | +int luaY_pact[]={ | |
| 798 | 572 | |
| 799 | 573 | -1000, -188, -1000, -1000, 51, -1000, -258, 24, -1000, -1000, |
| 800 | 574 | 47, -1000, -257, -1000, -1000, 93, -1000, 73, -1000, -1000, |
| @@ -814,14 +588,14 @@ int yypact[]={ · 13 unmodified lines | ||
| 814 | 588 | -21, -1000, -1000, -1000, 51, -1000, -1000, -248, -1000, 24, |
| 815 | 589 | -1000, 69, -250, -1000, -1000, -1000, -42, -1000, -1000, -1000, |
| 816 | 590 | -1000, -1000, -212, -1000 }; |
| 817 | −int yypgo[]={ | |
| 591 | +int luaY_pgo[]={ | |
| 818 | 592 | |
| 819 | 593 | 0, 216, 54, 44, 138, 76, 57, 212, 211, 210, |
| 820 | 594 | 205, 202, 201, 199, 61, 198, 195, 194, 189, 159, |
| 821 | 595 | 188, 186, 185, 184, 182, 92, 37, 181, 130, 32, |
| 822 | 596 | 180, 88, 34, 177, 176, 175, 172, 141, 170, 168, |
| 823 | 597 | 165, 163, 154, 134, 51, 56 }; |
| 824 | −int yyr1[]={ | |
| 598 | +int luaY_r1[]={ | |
| 825 | 599 | |
| 826 | 600 | 0, 1, 1, 1, 23, 23, 24, 21, 21, 22, |
| 827 | 601 | 30, 30, 26, 26, 25, 33, 25, 34, 25, 25, |
| @@ -833,7 +607,7 @@ int yyr1[]={ · 5 unmodified lines | ||
| 833 | 607 | 42, 42, 43, 10, 10, 15, 15, 44, 44, 13, |
| 834 | 608 | 13, 14, 14, 45, 16, 16, 17, 17, 7, 7, |
| 835 | 609 | 19, 19, 19, 20, 28, 11, 11, 12, 12, 27 }; |
| 836 | −int yyr2[]={ | |
| 610 | +int luaY_r2[]={ | |
| 837 | 611 | |
| 838 | 612 | 0, 0, 4, 4, 4, 2, 7, 3, 7, 11, |
| 839 | 613 | 0, 6, 0, 2, 17, 1, 17, 1, 13, 7, |
| @@ -845,7 +619,7 @@ int yyr2[]={ · 5 unmodified lines | ||
| 845 | 619 | 3, 7, 1, 7, 5, 1, 5, 0, 2, 1, |
| 846 | 620 | 5, 3, 7, 7, 1, 5, 3, 7, 3, 7, |
| 847 | 621 | 3, 9, 7, 3, 3, 3, 7, 1, 5, 3 }; |
| 848 | −int yychk[]={ | |
| 622 | +int luaY_chk[]={ | |
| 849 | 623 | |
| 850 | 624 | -1000, -1, -23, -24, -25, -27, 270, 259, 263, 265, |
| 851 | 625 | -7, -5, 269, 274, -19, -9, -20, -28, 273, -26, |
| @@ -865,7 +639,7 @@ int yychk[]={ · 13 unmodified lines | ||
| 865 | 639 | -31, -29, -2, -26, -3, -6, 267, -32, 261, 262, |
| 866 | 640 | -13, -14, -2, -26, 267, -29, -31, -44, 267, 260, |
| 867 | 641 | -2, -29, -2, -32 }; |
| 868 | −int yydef[]={ | |
| 642 | +int luaY_def[]={ | |
| 869 | 643 | |
| 870 | 644 | 1, -2, 2, 3, 12, 5, 0, 56, 15, 17, |
| 871 | 645 | 0, 20, 0, 99, -2, 56, 90, 59, 93, 4, |
| @@ -885,14 +659,14 @@ int yydef[]={ · 13 unmodified lines | ||
| 885 | 659 | 83, 29, 18, 11, 12, -2, 9, 0, 25, 56, |
| 886 | 660 | 76, 77, 0, 28, 14, 23, 0, 80, 16, 29, |
| 887 | 661 | 25, 29, 22, 24 }; |
| 888 | −typedef struct { char *t_name; int t_val; } yytoktype; | |
| 662 | +typedef struct { char *t_name; int t_val; } luaY_toktype; | |
| 889 | 663 | #ifndef YYDEBUG |
| 890 | 664 | # define YYDEBUG 0 /* don't allow debugging */ |
| 891 | 665 | #endif |
| 892 | 666 | |
| 893 | 667 | #if YYDEBUG |
| 894 | 668 | |
| 895 | −yytoktype yytoks[] = | |
| 669 | +luaY_toktype luaY_toks[] = | |
| 896 | 670 | { |
| 897 | 671 | "WRONGTOKEN", 257, |
| 898 | 672 | "NIL", 258, |
| @@ -931,7 +705,7 @@ yytoktype yytoks[] = · 32 unmodified lines | ||
| 931 | 705 | "-unknown-", -1 /* ends search */ |
| 932 | 706 | }; |
| 933 | 707 | |
| 934 | −char * yyreds[] = | |
| 708 | +char * luaY_reds[] = | |
| 935 | 709 | { |
| 936 | 710 | "-no such reduction-", |
| 937 | 711 | "functionlist : /* empty */", |
| @@ -1048,24 +822,24 @@ char * yyreds[] = · 110 unmodified lines | ||
| 1048 | 822 | /* |
| 1049 | 823 | ** yacc user known macros and defines |
| 1050 | 824 | */ |
| 1051 | −#define YYERROR goto yyerrlab | |
| 825 | +#define YYERROR goto luaY_errlab | |
| 1052 | 826 | #define YYACCEPT return(0) |
| 1053 | 827 | #define YYABORT return(1) |
| 1054 | 828 | #define YYBACKUP( newtoken, newvalue )\ |
| 1055 | 829 | {\ |
| 1056 | − if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ | |
| 830 | + if ( luaY_char >= 0 || ( luaY_r2[ luaY_tmp ] >> 1 ) != 1 )\ | |
| 1057 | 831 | {\ |
| 1058 | − yyerror( "syntax error - cannot backup" );\ | |
| 1059 | − goto yyerrlab;\ | |
| 832 | + luaY_error( "syntax error - cannot backup" );\ | |
| 833 | + goto luaY_errlab;\ | |
| 1060 | 834 | }\ |
| 1061 | − yychar = newtoken;\ | |
| 1062 | − yystate = *yyps;\ | |
| 1063 | − yylval = newvalue;\ | |
| 1064 | − goto yynewstate;\ | |
| 835 | + luaY_char = newtoken;\ | |
| 836 | + luaY_state = *luaY_ps;\ | |
| 837 | + luaY_lval = newvalue;\ | |
| 838 | + goto luaY_newstate;\ | |
| 1065 | 839 | } |
| 1066 | −#define YYRECOVERING() (!!yyerrflag) | |
| 840 | +#define YYRECOVERING() (!!luaY_errflag) | |
| 1067 | 841 | #define YYCOPY(to, from, type) \ |
| 1068 | − (type *) memcpy(to, (char *) from, yynewmax * sizeof(type)) | |
| 842 | + (type *) memcpy(to, (char *) from, luaY_newmax * sizeof(type)) | |
| 1069 | 843 | #ifndef YYDEBUG |
| 1070 | 844 | # define YYDEBUG 1 /* make debugging available */ |
| 1071 | 845 | #endif |
| @@ -1085,7 +859,7 @@ EXTERN_FUNCTION ( extern void *memcpy, (void *, const void *, int) ); · 13 unmodified lines | ||
| 1085 | 859 | /* |
| 1086 | 860 | ** user known globals |
| 1087 | 861 | */ |
| 1088 | −int yydebug; /* set to 1 to get debugging */ | |
| 862 | +int luaY_debug; /* set to 1 to get debugging */ | |
| 1089 | 863 | |
| 1090 | 864 | /* |
| 1091 | 865 | ** driver internal defines |
| @@ -1095,50 +869,50 @@ int yydebug; /* set to 1 to get debugging */ · 3 unmodified lines | ||
| 1095 | 869 | /* |
| 1096 | 870 | ** static variables used by the parser |
| 1097 | 871 | */ |
| 1098 | −static YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv; /* value stack */ | |
| 1099 | −static int yy_yys[YYMAXDEPTH], *yys = yy_yys; /* state stack */ | |
| 872 | +static YYSTYPE luaY__luaY_v[YYMAXDEPTH], *luaY_v = luaY__luaY_v; /* value stack */ | |
| 873 | +static int luaY__luaY_s[YYMAXDEPTH], *luaY_s = luaY__luaY_s; /* state stack */ | |
| 1100 | 874 | |
| 1101 | −static YYSTYPE *yypv; /* top of value stack */ | |
| 1102 | −static int *yyps; /* top of state stack */ | |
| 875 | +static YYSTYPE *luaY_pv; /* top of value stack */ | |
| 876 | +static int *luaY_ps; /* top of state stack */ | |
| 1103 | 877 | |
| 1104 | −static int yystate; /* current state */ | |
| 1105 | −static int yytmp; /* extra var (lasts between blocks) */ | |
| 878 | +static int luaY_state; /* current state */ | |
| 879 | +static int luaY_tmp; /* extra var (lasts between blocks) */ | |
| 1106 | 880 | |
| 1107 | 881 | #if defined(__cplusplus) || defined(__STDC__) || defined(lint) |
| 1108 | 882 | static int __yaccpar_lint_hack__ = 0; |
| 1109 | 883 | /* if you change the value from 0 to |
| 1110 | 884 | something else, make sure you know |
| 1111 | − what to do with yyerrlab reference. | |
| 885 | + what to do with luaY_errlab reference. | |
| 1112 | 886 | This is a hack - to make sure C++ and |
| 1113 | 887 | lint are happy with the 4.1 yacc code. */ |
| 1114 | 888 | #endif |
| 1115 | 889 | |
| 1116 | −int yynerrs; /* number of errors */ | |
| 890 | +int luaY_nerrs; /* number of errors */ | |
| 1117 | 891 | |
| 1118 | −int yyerrflag; /* error recovery flag */ | |
| 1119 | −int yychar; /* current input token number */ | |
| 1120 | −static unsigned yymaxdepth = YYMAXDEPTH; | |
| 892 | +int luaY_errflag; /* error recovery flag */ | |
| 893 | +int luaY_char; /* current input token number */ | |
| 894 | +static unsigned luaY_maxdepth = YYMAXDEPTH; | |
| 1121 | 895 | |
| 1122 | 896 | |
| 1123 | 897 | /* |
| 1124 | −** yyparse - return 0 if worked, 1 if syntax error not recovered from | |
| 898 | +** luaY_parse - return 0 if worked, 1 if syntax error not recovered from | |
| 1125 | 899 | */ |
| 1126 | 900 | int |
| 1127 | −yyparse() | |
| 901 | +luaY_parse() | |
| 1128 | 902 | { |
| 1129 | − register YYSTYPE *yypvt = (YYSTYPE*)0 ; /* top of value stack for | |
| 903 | + register YYSTYPE *luaY_pvt = (YYSTYPE*)0 ; /* top of value stack for | |
| 1130 | 904 | $vars */ |
| 1131 | 905 | |
| 1132 | 906 | /* |
| 1133 | − ** Initialize externals - yyparse may be called more than once | |
| 907 | + ** Initialize externals - luaY_parse may be called more than once | |
| 1134 | 908 | */ |
| 1135 | − yypv = &yyv[-1]; | |
| 1136 | − yyps = &yys[-1]; | |
| 1137 | − yystate = 0; | |
| 1138 | − yytmp = 0; | |
| 1139 | − yynerrs = 0; | |
| 1140 | − yyerrflag = 0; | |
| 1141 | − yychar = -1; | |
| 909 | + luaY_pv = &luaY_v[-1]; | |
| 910 | + luaY_ps = &luaY_s[-1]; | |
| 911 | + luaY_state = 0; | |
| 912 | + luaY_tmp = 0; | |
| 913 | + luaY_nerrs = 0; | |
| 914 | + luaY_errflag = 0; | |
| 915 | + luaY_char = -1; | |
| 1142 | 916 | |
| 1143 | 917 | #if defined(__cplusplus) || defined(__STDC__) || defined(lint) |
| 1144 | 918 | /* |
| @@ -1147,42 +921,42 @@ $vars */ · 2 unmodified lines | ||
| 1147 | 921 | */ |
| 1148 | 922 | switch (__yaccpar_lint_hack__) |
| 1149 | 923 | { |
| 1150 | − case 1: goto yyerrlab; | |
| 1151 | − case 2: goto yynewstate; | |
| 924 | + case 1: goto luaY_errlab; | |
| 925 | + case 2: goto luaY_newstate; | |
| 1152 | 926 | } |
| 1153 | 927 | #endif |
| 1154 | 928 | |
| 1155 | 929 | { |
| 1156 | − register YYSTYPE *yy_pv; /* top of value stack */ | |
| 1157 | − register int *yy_ps; /* top of state stack */ | |
| 1158 | − register int yy_state; /* current state */ | |
| 1159 | − register int yy_n; /* internal state number info */ | |
| 930 | + register YYSTYPE *luaY__pv; /* top of value stack */ | |
| 931 | + register int *luaY__ps; /* top of state stack */ | |
| 932 | + register int luaY__state; /* current state */ | |
| 933 | + register int luaY__n; /* internal state number info */ | |
| 1160 | 934 | |
| 1161 | − goto yystack; | |
| 935 | + goto luaY_stack; | |
| 1162 | 936 | |
| 1163 | 937 | /* |
| 1164 | 938 | ** get globals into registers. |
| 1165 | 939 | ** branch to here only if YYBACKUP was called. |
| 1166 | 940 | */ |
| 1167 | − yynewstate: | |
| 1168 | − yy_pv = yypv; | |
| 1169 | − yy_ps = yyps; | |
| 1170 | − yy_state = yystate; | |
| 1171 | − goto yy_newstate; | |
| 941 | + luaY_newstate: | |
| 942 | + luaY__pv = luaY_pv; | |
| 943 | + luaY__ps = luaY_ps; | |
| 944 | + luaY__state = luaY_state; | |
| 945 | + goto luaY__newstate; | |
| 1172 | 946 | |
| 1173 | 947 | /* |
| 1174 | 948 | ** get globals into registers. |
| 1175 | 949 | ** either we just started, or we just finished a reduction |
| 1176 | 950 | */ |
| 1177 | − yystack: | |
| 1178 | − yy_pv = yypv; | |
| 1179 | − yy_ps = yyps; | |
| 1180 | − yy_state = yystate; | |
| 951 | + luaY_stack: | |
| 952 | + luaY__pv = luaY_pv; | |
| 953 | + luaY__ps = luaY_ps; | |
| 954 | + luaY__state = luaY_state; | |
| 1181 | 955 | |
| 1182 | 956 | /* |
| 1183 | 957 | ** top of for (;;) loop while no reductions done |
| 1184 | 958 | */ |
| 1185 | − yy_stack: | |
| 959 | + luaY__stack: | |
| 1186 | 960 | /* |
| 1187 | 961 | ** put a state and value onto the stacks |
| 1188 | 962 | */ |
| @@ -1193,153 +967,153 @@ $vars */ · 4 unmodified lines | ||
| 1193 | 967 | ** Note: linear search is used since time is not a real |
| 1194 | 968 | ** consideration while debugging. |
| 1195 | 969 | */ |
| 1196 | − if ( yydebug ) | |
| 970 | + if ( luaY_debug ) | |
| 1197 | 971 | { |
| 1198 | − register int yy_i; | |
| 972 | + register int luaY__i; | |
| 1199 | 973 | |
| 1200 | − (void)printf( "State %d, token ", yy_state ); | |
| 1201 | − if ( yychar == 0 ) | |
| 974 | + (void)printf( "State %d, token ", luaY__state ); | |
| 975 | + if ( luaY_char == 0 ) | |
| 1202 | 976 | (void)printf( "end-of-file\n" ); |
| 1203 | − else if ( yychar < 0 ) | |
| 977 | + else if ( luaY_char < 0 ) | |
| 1204 | 978 | (void)printf( "-none-\n" ); |
| 1205 | 979 | else |
| 1206 | 980 | { |
| 1207 | − for ( yy_i = 0; yytoks[yy_i].t_val >= 0; | |
| 1208 | − yy_i++ ) | |
| 981 | + for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; | |
| 982 | + luaY__i++ ) | |
| 1209 | 983 | { |
| 1210 | − if ( yytoks[yy_i].t_val == yychar ) | |
| 984 | + if ( luaY_toks[luaY__i].t_val == luaY_char ) | |
| 1211 | 985 | break; |
| 1212 | 986 | } |
| 1213 | − (void)printf( "%s\n", yytoks[yy_i].t_name ); | |
| 987 | + (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); | |
| 1214 | 988 | } |
| 1215 | 989 | } |
| 1216 | 990 | #endif /* YYDEBUG */ |
| 1217 | − if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */ | |
| 991 | + if ( ++luaY__ps >= &luaY_s[ luaY_maxdepth ] ) /* room on stack? */ | |
| 1218 | 992 | { |
| 1219 | 993 | /* |
| 1220 | 994 | ** reallocate and recover. Note that pointers |
| 1221 | 995 | ** have to be reset, or bad things will happen |
| 1222 | 996 | */ |
| 1223 | − int yyps_index = (yy_ps - yys); | |
| 1224 | − int yypv_index = (yy_pv - yyv); | |
| 1225 | − int yypvt_index = (yypvt - yyv); | |
| 1226 | − int yynewmax; | |
| 997 | + int luaY_ps_index = (luaY__ps - luaY_s); | |
| 998 | + int luaY_pv_index = (luaY__pv - luaY_v); | |
| 999 | + int luaY_pvt_index = (luaY_pvt - luaY_v); | |
| 1000 | + int luaY_newmax; | |
| 1227 | 1001 | |
| 1228 | − yynewmax = yymaxdepth + YYMAXDEPTH; | |
| 1229 | − if (yymaxdepth == YYMAXDEPTH) /* first time growth */ | |
| 1002 | + luaY_newmax = luaY_maxdepth + YYMAXDEPTH; | |
| 1003 | + if (luaY_maxdepth == YYMAXDEPTH) /* first time growth */ | |
| 1230 | 1004 | { |
| 1231 | − YYSTYPE *newyyv = (YYSTYPE*)malloc(yynewmax*sizeof(YYSTYPE)); | |
| 1232 | − int *newyys = (int*)malloc(yynewmax*sizeof(int)); | |
| 1233 | − if (newyys != 0 && newyyv != 0) | |
| 1005 | + YYSTYPE *newluaY_v = (YYSTYPE*)malloc(luaY_newmax*sizeof(YYSTYPE)); | |
| 1006 | + int *newluaY_s = (int*)malloc(luaY_newmax*sizeof(int)); | |
| 1007 | + if (newluaY_s != 0 && newluaY_v != 0) | |
| 1234 | 1008 | { |
| 1235 | − yys = YYCOPY(newyys, yys, int); | |
| 1236 | − yyv = YYCOPY(newyyv, yyv, YYSTYPE); | |
| 1009 | + luaY_s = YYCOPY(newluaY_s, luaY_s, int); | |
| 1010 | + luaY_v = YYCOPY(newluaY_v, luaY_v, YYSTYPE); | |
| 1237 | 1011 | } |
| 1238 | 1012 | else |
| 1239 | − yynewmax = 0; /* failed */ | |
| 1013 | + luaY_newmax = 0; /* failed */ | |
| 1240 | 1014 | } |
| 1241 | 1015 | else /* not first time */ |
| 1242 | 1016 | { |
| 1243 | − yyv = (YYSTYPE*)realloc((char*)yyv, | |
| 1244 | − yynewmax * sizeof(YYSTYPE)); | |
| 1245 | − yys = (int*)realloc((char*)yys, | |
| 1246 | − yynewmax * sizeof(int)); | |
| 1247 | − if (yys == 0 || yyv == 0) | |
| 1248 | − yynewmax = 0; /* failed */ | |
| 1017 | + luaY_v = (YYSTYPE*)realloc((char*)luaY_v, | |
| 1018 | + luaY_newmax * sizeof(YYSTYPE)); | |
| 1019 | + luaY_s = (int*)realloc((char*)luaY_s, | |
| 1020 | + luaY_newmax * sizeof(int)); | |
| 1021 | + if (luaY_s == 0 || luaY_v == 0) | |
| 1022 | + luaY_newmax = 0; /* failed */ | |
| 1249 | 1023 | } |
| 1250 | − if (yynewmax <= yymaxdepth) /* tables not expanded */ | |
| 1024 | + if (luaY_newmax <= luaY_maxdepth) /* tables not expanded */ | |
| 1251 | 1025 | { |
| 1252 | − yyerror( "yacc stack overflow" ); | |
| 1026 | + luaY_error( "yacc stack overflow" ); | |
| 1253 | 1027 | YYABORT; |
| 1254 | 1028 | } |
| 1255 | − yymaxdepth = yynewmax; | |
| 1029 | + luaY_maxdepth = luaY_newmax; | |
| 1256 | 1030 | |
| 1257 | − yy_ps = yys + yyps_index; | |
| 1258 | − yy_pv = yyv + yypv_index; | |
| 1259 | − yypvt = yyv + yypvt_index; | |
| 1031 | + luaY__ps = luaY_s + luaY_ps_index; | |
| 1032 | + luaY__pv = luaY_v + luaY_pv_index; | |
| 1033 | + luaY_pvt = luaY_v + luaY_pvt_index; | |
| 1260 | 1034 | } |
| 1261 | − *yy_ps = yy_state; | |
| 1262 | − *++yy_pv = yyval; | |
| 1035 | + *luaY__ps = luaY__state; | |
| 1036 | + *++luaY__pv = luaY_val; | |
| 1263 | 1037 | |
| 1264 | 1038 | /* |
| 1265 | 1039 | ** we have a new state - find out what to do |
| 1266 | 1040 | */ |
| 1267 | − yy_newstate: | |
| 1268 | − if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG ) | |
| 1269 | − goto yydefault; /* simple state */ | |
| 1041 | + luaY__newstate: | |
| 1042 | + if ( ( luaY__n = luaY_pact[ luaY__state ] ) <= YYFLAG ) | |
| 1043 | + goto luaY_default; /* simple state */ | |
| 1270 | 1044 | #if YYDEBUG |
| 1271 | 1045 | /* |
| 1272 | 1046 | ** if debugging, need to mark whether new token grabbed |
| 1273 | 1047 | */ |
| 1274 | − yytmp = yychar < 0; | |
| 1048 | + luaY_tmp = luaY_char < 0; | |
| 1275 | 1049 | #endif |
| 1276 | − if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) ) | |
| 1277 | − yychar = 0; /* reached EOF */ | |
| 1050 | + if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) ) | |
| 1051 | + luaY_char = 0; /* reached EOF */ | |
| 1278 | 1052 | #if YYDEBUG |
| 1279 | − if ( yydebug && yytmp ) | |
| 1053 | + if ( luaY_debug && luaY_tmp ) | |
| 1280 | 1054 | { |
| 1281 | − register int yy_i; | |
| 1055 | + register int luaY__i; | |
| 1282 | 1056 | |
| 1283 | 1057 | (void)printf( "Received token " ); |
| 1284 | − if ( yychar == 0 ) | |
| 1058 | + if ( luaY_char == 0 ) | |
| 1285 | 1059 | (void)printf( "end-of-file\n" ); |
| 1286 | − else if ( yychar < 0 ) | |
| 1060 | + else if ( luaY_char < 0 ) | |
| 1287 | 1061 | (void)printf( "-none-\n" ); |
| 1288 | 1062 | else |
| 1289 | 1063 | { |
| 1290 | − for ( yy_i = 0; yytoks[yy_i].t_val >= 0; | |
| 1291 | − yy_i++ ) | |
| 1064 | + for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; | |
| 1065 | + luaY__i++ ) | |
| 1292 | 1066 | { |
| 1293 | − if ( yytoks[yy_i].t_val == yychar ) | |
| 1067 | + if ( luaY_toks[luaY__i].t_val == luaY_char ) | |
| 1294 | 1068 | break; |
| 1295 | 1069 | } |
| 1296 | − (void)printf( "%s\n", yytoks[yy_i].t_name ); | |
| 1070 | + (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); | |
| 1297 | 1071 | } |
| 1298 | 1072 | } |
| 1299 | 1073 | #endif /* YYDEBUG */ |
| 1300 | − if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) ) | |
| 1301 | − goto yydefault; | |
| 1302 | − if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ) /*valid shift*/ | |
| 1074 | + if ( ( ( luaY__n += luaY_char ) < 0 ) || ( luaY__n >= YYLAST ) ) | |
| 1075 | + goto luaY_default; | |
| 1076 | + if ( luaY_chk[ luaY__n = luaY_act[ luaY__n ] ] == luaY_char ) /*valid shift*/ | |
| 1303 | 1077 | { |
| 1304 | − yychar = -1; | |
| 1305 | − yyval = yylval; | |
| 1306 | − yy_state = yy_n; | |
| 1307 | − if ( yyerrflag > 0 ) | |
| 1308 | − yyerrflag--; | |
| 1309 | − goto yy_stack; | |
| 1078 | + luaY_char = -1; | |
| 1079 | + luaY_val = luaY_lval; | |
| 1080 | + luaY__state = luaY__n; | |
| 1081 | + if ( luaY_errflag > 0 ) | |
| 1082 | + luaY_errflag--; | |
| 1083 | + goto luaY__stack; | |
| 1310 | 1084 | } |
| 1311 | 1085 | |
| 1312 | − yydefault: | |
| 1313 | − if ( ( yy_n = yydef[ yy_state ] ) == -2 ) | |
| 1086 | + luaY_default: | |
| 1087 | + if ( ( luaY__n = luaY_def[ luaY__state ] ) == -2 ) | |
| 1314 | 1088 | { |
| 1315 | 1089 | #if YYDEBUG |
| 1316 | − yytmp = yychar < 0; | |
| 1090 | + luaY_tmp = luaY_char < 0; | |
| 1317 | 1091 | #endif |
| 1318 | − if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) ) | |
| 1319 | − yychar = 0; /* reached EOF */ | |
| 1092 | + if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) ) | |
| 1093 | + luaY_char = 0; /* reached EOF */ | |
| 1320 | 1094 | #if YYDEBUG |
| 1321 | − if ( yydebug && yytmp ) | |
| 1095 | + if ( luaY_debug && luaY_tmp ) | |
| 1322 | 1096 | { |
| 1323 | − register int yy_i; | |
| 1097 | + register int luaY__i; | |
| 1324 | 1098 | |
| 1325 | 1099 | (void)printf( "Received token " ); |
| 1326 | − if ( yychar == 0 ) | |
| 1100 | + if ( luaY_char == 0 ) | |
| 1327 | 1101 | (void)printf( "end-of-file\n" ); |
| 1328 | − else if ( yychar < 0 ) | |
| 1102 | + else if ( luaY_char < 0 ) | |
| 1329 | 1103 | (void)printf( "-none-\n" ); |
| 1330 | 1104 | else |
| 1331 | 1105 | { |
| 1332 | − for ( yy_i = 0; | |
| 1333 | − yytoks[yy_i].t_val >= 0; | |
| 1334 | − yy_i++ ) | |
| 1106 | + for ( luaY__i = 0; | |
| 1107 | + luaY_toks[luaY__i].t_val >= 0; | |
| 1108 | + luaY__i++ ) | |
| 1335 | 1109 | { |
| 1336 | − if ( yytoks[yy_i].t_val | |
| 1337 | − == yychar ) | |
| 1110 | + if ( luaY_toks[luaY__i].t_val | |
| 1111 | + == luaY_char ) | |
| 1338 | 1112 | { |
| 1339 | 1113 | break; |
| 1340 | 1114 | } |
| 1341 | 1115 | } |
| 1342 | − (void)printf( "%s\n", yytoks[yy_i].t_name ); | |
| 1116 | + (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); | |
| 1343 | 1117 | } |
| 1344 | 1118 | } |
| 1345 | 1119 | #endif /* YYDEBUG */ |
| @@ -1347,17 +1121,17 @@ $vars */ · 1 unmodified line | ||
| 1347 | 1121 | ** look through exception table |
| 1348 | 1122 | */ |
| 1349 | 1123 | { |
| 1350 | − register int *yyxi = yyexca; | |
| 1124 | + register int *luaY_xi = luaY_exca; | |
| 1351 | 1125 | |
| 1352 | − while ( ( *yyxi != -1 ) || | |
| 1353 | − ( yyxi[1] != yy_state ) ) | |
| 1126 | + while ( ( *luaY_xi != -1 ) || | |
| 1127 | + ( luaY_xi[1] != luaY__state ) ) | |
| 1354 | 1128 | { |
| 1355 | − yyxi += 2; | |
| 1129 | + luaY_xi += 2; | |
| 1356 | 1130 | } |
| 1357 | − while ( ( *(yyxi += 2) >= 0 ) && | |
| 1358 | − ( *yyxi != yychar ) ) | |
| 1131 | + while ( ( *(luaY_xi += 2) >= 0 ) && | |
| 1132 | + ( *luaY_xi != luaY_char ) ) | |
| 1359 | 1133 | ; |
| 1360 | − if ( ( yy_n = yyxi[1] ) < 0 ) | |
| 1134 | + if ( ( luaY__n = luaY_xi[1] ) < 0 ) | |
| 1361 | 1135 | YYACCEPT; |
| 1362 | 1136 | } |
| 1363 | 1137 | } |
| @@ -1365,42 +1139,42 @@ $vars */ · 1 unmodified line | ||
| 1365 | 1139 | /* |
| 1366 | 1140 | ** check for syntax error |
| 1367 | 1141 | */ |
| 1368 | − if ( yy_n == 0 ) /* have an error */ | |
| 1142 | + if ( luaY__n == 0 ) /* have an error */ | |
| 1369 | 1143 | { |
| 1370 | 1144 | /* no worry about speed here! */ |
| 1371 | − switch ( yyerrflag ) | |
| 1145 | + switch ( luaY_errflag ) | |
| 1372 | 1146 | { |
| 1373 | 1147 | case 0: /* new error */ |
| 1374 | − yyerror( "syntax error" ); | |
| 1148 | + luaY_error( "syntax error" ); | |
| 1375 | 1149 | goto skip_init; |
| 1376 | − yyerrlab: | |
| 1150 | + luaY_errlab: | |
| 1377 | 1151 | /* |
| 1378 | 1152 | ** get globals into registers. |
| 1379 | 1153 | ** we have a user generated syntax type error |
| 1380 | 1154 | */ |
| 1381 | − yy_pv = yypv; | |
| 1382 | − yy_ps = yyps; | |
| 1383 | − yy_state = yystate; | |
| 1384 | − yynerrs++; | |
| 1155 | + luaY__pv = luaY_pv; | |
| 1156 | + luaY__ps = luaY_ps; | |
| 1157 | + luaY__state = luaY_state; | |
| 1158 | + luaY_nerrs++; | |
| 1385 | 1159 | skip_init: |
| 1386 | 1160 | case 1: |
| 1387 | 1161 | case 2: /* incompletely recovered error */ |
| 1388 | 1162 | /* try again... */ |
| 1389 | − yyerrflag = 3; | |
| 1163 | + luaY_errflag = 3; | |
| 1390 | 1164 | /* |
| 1391 | 1165 | ** find state where "error" is a legal |
| 1392 | 1166 | ** shift action |
| 1393 | 1167 | */ |
| 1394 | − while ( yy_ps >= yys ) | |
| 1168 | + while ( luaY__ps >= luaY_s ) | |
| 1395 | 1169 | { |
| 1396 | − yy_n = yypact[ *yy_ps ] + YYERRCODE; | |
| 1397 | − if ( yy_n >= 0 && yy_n < YYLAST && | |
| 1398 | − yychk[yyact[yy_n]] == YYERRCODE) { | |
| 1170 | + luaY__n = luaY_pact[ *luaY__ps ] + YYERRCODE; | |
| 1171 | + if ( luaY__n >= 0 && luaY__n < YYLAST && | |
| 1172 | + luaY_chk[luaY_act[luaY__n]] == YYERRCODE) { | |
| 1399 | 1173 | /* |
| 1400 | 1174 | ** simulate shift of "error" |
| 1401 | 1175 | */ |
| 1402 | − yy_state = yyact[ yy_n ]; | |
| 1403 | − goto yy_stack; | |
| 1176 | + luaY__state = luaY_act[ luaY__n ]; | |
| 1177 | + goto luaY__stack; | |
| 1404 | 1178 | } |
| 1405 | 1179 | /* |
| 1406 | 1180 | ** current state has no shift on |
| @@ -1408,13 +1182,13 @@ $vars */ · 1 unmodified line | ||
| 1408 | 1182 | */ |
| 1409 | 1183 | #if YYDEBUG |
| 1410 | 1184 | # define _POP_ "Error recovery pops state %d, uncovers state %d\n" |
| 1411 | − if ( yydebug ) | |
| 1412 | − (void)printf( _POP_, *yy_ps, | |
| 1413 | − yy_ps[-1] ); | |
| 1185 | + if ( luaY_debug ) | |
| 1186 | + (void)printf( _POP_, *luaY__ps, | |
| 1187 | + luaY__ps[-1] ); | |
| 1414 | 1188 | # undef _POP_ |
| 1415 | 1189 | #endif |
| 1416 | − yy_ps--; | |
| 1417 | − yy_pv--; | |
| 1190 | + luaY__ps--; | |
| 1191 | + luaY__pv--; | |
| 1418 | 1192 | } |
| 1419 | 1193 | /* |
| 1420 | 1194 | ** there is no state on stack with "error" as |
| @@ -1430,40 +1204,40 @@ $vars */ · 9 unmodified lines | ||
| 1430 | 1204 | ** debugging, it doesn't hurt to leave the |
| 1431 | 1205 | ** tests here. |
| 1432 | 1206 | */ |
| 1433 | − if ( yydebug ) | |
| 1207 | + if ( luaY_debug ) | |
| 1434 | 1208 | { |
| 1435 | − register int yy_i; | |
| 1209 | + register int luaY__i; | |
| 1436 | 1210 | |
| 1437 | 1211 | (void)printf( "Error recovery discards " ); |
| 1438 | − if ( yychar == 0 ) | |
| 1212 | + if ( luaY_char == 0 ) | |
| 1439 | 1213 | (void)printf( "token end-of-file\n" ); |
| 1440 | − else if ( yychar < 0 ) | |
| 1214 | + else if ( luaY_char < 0 ) | |
| 1441 | 1215 | (void)printf( "token -none-\n" ); |
| 1442 | 1216 | else |
| 1443 | 1217 | { |
| 1444 | − for ( yy_i = 0; | |
| 1445 | − yytoks[yy_i].t_val >= 0; | |
| 1446 | − yy_i++ ) | |
| 1218 | + for ( luaY__i = 0; | |
| 1219 | + luaY_toks[luaY__i].t_val >= 0; | |
| 1220 | + luaY__i++ ) | |
| 1447 | 1221 | { |
| 1448 | − if ( yytoks[yy_i].t_val | |
| 1449 | − == yychar ) | |
| 1222 | + if ( luaY_toks[luaY__i].t_val | |
| 1223 | + == luaY_char ) | |
| 1450 | 1224 | { |
| 1451 | 1225 | break; |
| 1452 | 1226 | } |
| 1453 | 1227 | } |
| 1454 | 1228 | (void)printf( "token %s\n", |
| 1455 | − yytoks[yy_i].t_name ); | |
| 1229 | + luaY_toks[luaY__i].t_name ); | |
| 1456 | 1230 | } |
| 1457 | 1231 | } |
| 1458 | 1232 | #endif /* YYDEBUG */ |
| 1459 | − if ( yychar == 0 ) /* reached EOF. quit */ | |
| 1233 | + if ( luaY_char == 0 ) /* reached EOF. quit */ | |
| 1460 | 1234 | YYABORT; |
| 1461 | − yychar = -1; | |
| 1462 | − goto yy_newstate; | |
| 1235 | + luaY_char = -1; | |
| 1236 | + goto luaY__newstate; | |
| 1463 | 1237 | } |
| 1464 | − }/* end if ( yy_n == 0 ) */ | |
| 1238 | + }/* end if ( luaY__n == 0 ) */ | |
| 1465 | 1239 | /* |
| 1466 | − ** reduction by production yy_n | |
| 1240 | + ** reduction by production luaY__n | |
| 1467 | 1241 | ** put stack tops, etc. so things right after switch |
| 1468 | 1242 | */ |
| 1469 | 1243 | #if YYDEBUG |
| @@ -1472,92 +1246,95 @@ $vars */ · 2 unmodified lines | ||
| 1472 | 1246 | ** specification of the reduction which is just about |
| 1473 | 1247 | ** to be done. |
| 1474 | 1248 | */ |
| 1475 | − if ( yydebug ) | |
| 1249 | + if ( luaY_debug ) | |
| 1476 | 1250 | (void)printf( "Reduce by (%d) \"%s\"\n", |
| 1477 | − yy_n, yyreds[ yy_n ] ); | |
| 1251 | + luaY__n, luaY_reds[ luaY__n ] ); | |
| 1478 | 1252 | #endif |
| 1479 | − yytmp = yy_n; /* value to switch over */ | |
| 1480 | − yypvt = yy_pv; /* $vars top of value stack */ | |
| 1253 | + luaY_tmp = luaY__n; /* value to switch over */ | |
| 1254 | + luaY_pvt = luaY__pv; /* $vars top of value stack */ | |
| 1481 | 1255 | /* |
| 1482 | 1256 | ** Look in goto table for next state |
| 1483 | − ** Sorry about using yy_state here as temporary | |
| 1257 | + ** Sorry about using luaY__state here as temporary | |
| 1484 | 1258 | ** register variable, but why not, if it works... |
| 1485 | − ** If yyr2[ yy_n ] doesn't have the low order bit | |
| 1259 | + ** If luaY_r2[ luaY__n ] doesn't have the low order bit | |
| 1486 | 1260 | ** set, then there is no action to be done for |
| 1487 | 1261 | ** this reduction. So, no saving & unsaving of |
| 1488 | 1262 | ** registers done. The only difference between the |
| 1489 | 1263 | ** code just after the if and the body of the if is |
| 1490 | − ** the goto yy_stack in the body. This way the test | |
| 1264 | + ** the goto luaY__stack in the body. This way the test | |
| 1491 | 1265 | ** can be made before the choice of what to do is needed. |
| 1492 | 1266 | */ |
| 1493 | 1267 | { |
| 1494 | 1268 | /* length of production doubled with extra bit */ |
| 1495 | − register int yy_len = yyr2[ yy_n ]; | |
| 1269 | + register int luaY__len = luaY_r2[ luaY__n ]; | |
| 1496 | 1270 | |
| 1497 | − if ( !( yy_len & 01 ) ) | |
| 1271 | + if ( !( luaY__len & 01 ) ) | |
| 1498 | 1272 | { |
| 1499 | − yy_len >>= 1; | |
| 1500 | − yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ | |
| 1501 | − yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + | |
| 1502 | − *( yy_ps -= yy_len ) + 1; | |
| 1503 | − if ( yy_state >= YYLAST || | |
| 1504 | − yychk[ yy_state = | |
| 1505 | − yyact[ yy_state ] ] != -yy_n ) | |
| 1273 | + luaY__len >>= 1; | |
| 1274 | + luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */ | |
| 1275 | + luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] + | |
| 1276 | + *( luaY__ps -= luaY__len ) + 1; | |
| 1277 | + if ( luaY__state >= YYLAST || | |
| 1278 | + luaY_chk[ luaY__state = | |
| 1279 | + luaY_act[ luaY__state ] ] != -luaY__n ) | |
| 1506 | 1280 | { |
| 1507 | − yy_state = yyact[ yypgo[ yy_n ] ]; | |
| 1281 | + luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ]; | |
| 1508 | 1282 | } |
| 1509 | − goto yy_stack; | |
| 1283 | + goto luaY__stack; | |
| 1510 | 1284 | } |
| 1511 | − yy_len >>= 1; | |
| 1512 | − yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ | |
| 1513 | − yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + | |
| 1514 | − *( yy_ps -= yy_len ) + 1; | |
| 1515 | − if ( yy_state >= YYLAST || | |
| 1516 | − yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) | |
| 1285 | + luaY__len >>= 1; | |
| 1286 | + luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */ | |
| 1287 | + luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] + | |
| 1288 | + *( luaY__ps -= luaY__len ) + 1; | |
| 1289 | + if ( luaY__state >= YYLAST || | |
| 1290 | + luaY_chk[ luaY__state = luaY_act[ luaY__state ] ] != -luaY__n ) | |
| 1517 | 1291 | { |
| 1518 | − yy_state = yyact[ yypgo[ yy_n ] ]; | |
| 1292 | + luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ]; | |
| 1519 | 1293 | } |
| 1520 | 1294 | } |
| 1521 | 1295 | /* save until reenter driver code */ |
| 1522 | − yystate = yy_state; | |
| 1523 | − yyps = yy_ps; | |
| 1524 | − yypv = yy_pv; | |
| 1296 | + luaY_state = luaY__state; | |
| 1297 | + luaY_ps = luaY__ps; | |
| 1298 | + luaY_pv = luaY__pv; | |
| 1525 | 1299 | } |
| 1526 | 1300 | /* |
| 1527 | 1301 | ** code supplied by user is placed in this switch |
| 1528 | 1302 | */ |
| 1529 | − switch( yytmp ) | |
| 1303 | + switch( luaY_tmp ) | |
| 1530 | 1304 | { |
| 1531 | 1305 | |
| 1532 | 1306 | case 6: |
| 1533 | −# line 470 "lua.stx" | |
| 1307 | +# line 469 "lua.stx" | |
| 1534 | 1308 | { |
| 1535 | 1309 | code_byte(PUSHFUNCTION); |
| 1536 | − code_code(yypvt[-0].pFunc); | |
| 1537 | − storesinglevar(yypvt[-1].vLong); | |
| 1310 | + code_code(luaY_pvt[-0].pFunc); | |
| 1311 | + storesinglevar(luaY_pvt[-1].vLong); | |
| 1538 | 1312 | } break; |
| 1539 | 1313 | case 7: |
| 1540 | −# line 477 "lua.stx" | |
| 1541 | −{ yyval.vLong =yypvt[-0].vLong; init_func(); } break; | |
| 1314 | +# line 476 "lua.stx" | |
| 1315 | +{ luaY_val.vLong =luaY_pvt[-0].vLong; init_func(); } break; | |
| 1542 | 1316 | case 8: |
| 1543 | −# line 479 "lua.stx" | |
| 1317 | +# line 478 "lua.stx" | |
| 1544 | 1318 | { |
| 1545 | 1319 | code_byte(PUSHSTRING); |
| 1546 | − code_word(luaI_findconstant(yypvt[-0].pNode)); | |
| 1547 | − yyval.vLong = 0; /* indexed variable */ | |
| 1320 | + code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); | |
| 1321 | + luaY_val.vLong = 0; /* indexed variable */ | |
| 1548 | 1322 | init_func(); |
| 1549 | − add_localvar(luaI_findsymbolbyname("self")); | |
| 1323 | + add_localvar(luaI_createfixedstring("self")); | |
| 1550 | 1324 | } break; |
| 1551 | 1325 | case 9: |
| 1552 | −# line 489 "lua.stx" | |
| 1326 | +# line 488 "lua.stx" | |
| 1553 | 1327 | { |
| 1554 | 1328 | codereturn(); |
| 1555 | − yyval.pFunc = new(TFunc); | |
| 1556 | − yyval.pFunc->size = pc; | |
| 1557 | − yyval.pFunc->code = newvector(pc, Byte); | |
| 1558 | − yyval.pFunc->fileName = lua_parsedfile; | |
| 1559 | − yyval.pFunc->lineDefined = yypvt[-3].vInt; | |
| 1560 | − memcpy(yyval.pFunc->code, basepc, pc*sizeof(Byte)); | |
| 1329 | + luaY_val.pFunc = new(TFunc); | |
| 1330 | + luaI_initTFunc(luaY_val.pFunc); | |
| 1331 | + luaY_val.pFunc->size = pc; | |
| 1332 | + luaY_val.pFunc->code = newvector(pc, Byte); | |
| 1333 | + luaY_val.pFunc->fileName = lua_parsedfile; | |
| 1334 | + luaY_val.pFunc->lineDefined = luaY_pvt[-3].vInt; | |
| 1335 | + memcpy(luaY_val.pFunc->code, basepc, pc*sizeof(Byte)); | |
| 1336 | + if (lua_debug) | |
| 1337 | + luaI_closelocalvars(luaY_val.pFunc); | |
| 1561 | 1338 | /* save func values */ |
| 1562 | 1339 | funcCode = basepc; maxcode=maxcurr; |
| 1563 | 1340 | #if LISTING |
| @@ -1566,346 +1343,345 @@ case 9: · 2 unmodified lines | ||
| 1566 | 1343 | change2main(); /* change back to main code */ |
| 1567 | 1344 | } break; |
| 1568 | 1345 | case 14: |
| 1569 | −# line 513 "lua.stx" | |
| 1570 | −{ codeIf(yypvt[-4].vLong, yypvt[-2].vLong); } break; | |
| 1571 | −case 15: | |
| 1572 | 1346 | # line 515 "lua.stx" |
| 1573 | −{yyval.vLong=pc;} break; | |
| 1347 | +{ codeIf(luaY_pvt[-4].vLong, luaY_pvt[-2].vLong); } break; | |
| 1348 | +case 15: | |
| 1349 | +# line 517 "lua.stx" | |
| 1350 | +{luaY_val.vLong=pc;} break; | |
| 1574 | 1351 | case 16: |
| 1575 | −# line 516 "lua.stx" | |
| 1352 | +# line 518 "lua.stx" | |
| 1576 | 1353 | { |
| 1577 | − basepc[yypvt[-3].vLong] = IFFJMP; | |
| 1578 | − code_word_at(basepc+yypvt[-3].vLong+1, pc - (yypvt[-3].vLong + sizeof(Word)+1)); | |
| 1579 | − basepc[yypvt[-1].vLong] = UPJMP; | |
| 1580 | − code_word_at(basepc+yypvt[-1].vLong+1, pc - (yypvt[-6].vLong)); | |
| 1354 | + basepc[luaY_pvt[-3].vLong] = IFFJMP; | |
| 1355 | + code_word_at(basepc+luaY_pvt[-3].vLong+1, pc - (luaY_pvt[-3].vLong + sizeof(Word)+1)); | |
| 1356 | + basepc[luaY_pvt[-1].vLong] = UPJMP; | |
| 1357 | + code_word_at(basepc+luaY_pvt[-1].vLong+1, pc - (luaY_pvt[-6].vLong)); | |
| 1581 | 1358 | } break; |
| 1582 | 1359 | case 17: |
| 1583 | −# line 523 "lua.stx" | |
| 1584 | −{yyval.vLong=pc;} break; | |
| 1360 | +# line 525 "lua.stx" | |
| 1361 | +{luaY_val.vLong=pc;} break; | |
| 1585 | 1362 | case 18: |
| 1586 | −# line 524 "lua.stx" | |
| 1363 | +# line 526 "lua.stx" | |
| 1587 | 1364 | { |
| 1588 | − basepc[yypvt[-0].vLong] = IFFUPJMP; | |
| 1589 | − code_word_at(basepc+yypvt[-0].vLong+1, pc - (yypvt[-4].vLong)); | |
| 1365 | + basepc[luaY_pvt[-0].vLong] = IFFUPJMP; | |
| 1366 | + code_word_at(basepc+luaY_pvt[-0].vLong+1, pc - (luaY_pvt[-4].vLong)); | |
| 1590 | 1367 | } break; |
| 1591 | 1368 | case 19: |
| 1592 | −# line 530 "lua.stx" | |
| 1369 | +# line 532 "lua.stx" | |
| 1593 | 1370 | { |
| 1594 | 1371 | { |
| 1595 | 1372 | int i; |
| 1596 | − adjust_mult_assign(nvarbuffer, yypvt[-0].vLong, yypvt[-2].vInt * 2 + nvarbuffer); | |
| 1373 | + adjust_mult_assign(nvarbuffer, luaY_pvt[-0].vLong, luaY_pvt[-2].vInt * 2 + nvarbuffer); | |
| 1597 | 1374 | for (i=nvarbuffer-1; i>=0; i--) |
| 1598 | 1375 | lua_codestore (i); |
| 1599 | − if (yypvt[-2].vInt > 1 || (yypvt[-2].vInt == 1 && varbuffer[0] != 0)) | |
| 1376 | + if (luaY_pvt[-2].vInt > 1 || (luaY_pvt[-2].vInt == 1 && varbuffer[0] != 0)) | |
| 1600 | 1377 | lua_codeadjust (0); |
| 1601 | 1378 | } |
| 1602 | 1379 | } break; |
| 1603 | 1380 | case 21: |
| 1604 | −# line 542 "lua.stx" | |
| 1605 | −{ nlocalvar += yypvt[-1].vInt; | |
| 1606 | − adjust_mult_assign(yypvt[-1].vInt, yypvt[-0].vInt, 0); | |
| 1381 | +# line 544 "lua.stx" | |
| 1382 | +{ nlocalvar += luaY_pvt[-1].vInt; | |
| 1383 | + adjust_mult_assign(luaY_pvt[-1].vInt, luaY_pvt[-0].vInt, 0); | |
| 1607 | 1384 | } break; |
| 1608 | 1385 | case 24: |
| 1609 | −# line 550 "lua.stx" | |
| 1610 | −{ codeIf(yypvt[-3].vLong, yypvt[-1].vLong); } break; | |
| 1386 | +# line 552 "lua.stx" | |
| 1387 | +{ codeIf(luaY_pvt[-3].vLong, luaY_pvt[-1].vLong); } break; | |
| 1611 | 1388 | case 25: |
| 1612 | −# line 553 "lua.stx" | |
| 1613 | −{yyval.vInt = nlocalvar;} break; | |
| 1389 | +# line 555 "lua.stx" | |
| 1390 | +{luaY_val.vInt = nlocalvar;} break; | |
| 1614 | 1391 | case 26: |
| 1615 | −# line 554 "lua.stx" | |
| 1392 | +# line 556 "lua.stx" | |
| 1616 | 1393 | { |
| 1617 | − if (nlocalvar != yypvt[-2].vInt) | |
| 1394 | + if (nlocalvar != luaY_pvt[-2].vInt) | |
| 1618 | 1395 | { |
| 1619 | − nlocalvar = yypvt[-2].vInt; | |
| 1396 | + if (lua_debug) | |
| 1397 | + for (; nlocalvar > luaY_pvt[-2].vInt; nlocalvar--) | |
| 1398 | + luaI_unregisterlocalvar(lua_linenumber); | |
| 1399 | + else | |
| 1400 | + nlocalvar = luaY_pvt[-2].vInt; | |
| 1620 | 1401 | lua_codeadjust (0); |
| 1621 | 1402 | } |
| 1622 | 1403 | } break; |
| 1623 | 1404 | case 28: |
| 1624 | −# line 565 "lua.stx" | |
| 1405 | +# line 571 "lua.stx" | |
| 1625 | 1406 | { |
| 1626 | − adjust_functioncall(yypvt[-1].vLong, MULT_RET); | |
| 1407 | + adjust_functioncall(luaY_pvt[-1].vLong, MULT_RET); | |
| 1627 | 1408 | codereturn(); |
| 1628 | 1409 | } break; |
| 1629 | 1410 | case 29: |
| 1630 | −# line 572 "lua.stx" | |
| 1411 | +# line 578 "lua.stx" | |
| 1631 | 1412 | { |
| 1632 | − yyval.vLong = pc; | |
| 1413 | + luaY_val.vLong = pc; | |
| 1633 | 1414 | code_byte(0); /* open space */ |
| 1634 | 1415 | code_word (0); |
| 1635 | 1416 | } break; |
| 1636 | 1417 | case 30: |
| 1637 | −# line 578 "lua.stx" | |
| 1638 | −{ adjust_functioncall(yypvt[-0].vLong, 1); } break; | |
| 1418 | +# line 584 "lua.stx" | |
| 1419 | +{ adjust_functioncall(luaY_pvt[-0].vLong, 1); } break; | |
| 1639 | 1420 | case 31: |
| 1640 | −# line 581 "lua.stx" | |
| 1641 | −{ yyval.vLong = yypvt[-1].vLong; } break; | |
| 1421 | +# line 587 "lua.stx" | |
| 1422 | +{ luaY_val.vLong = luaY_pvt[-1].vLong; } break; | |
| 1642 | 1423 | case 32: |
| 1643 | −# line 582 "lua.stx" | |
| 1644 | −{ code_byte(EQOP); yyval.vLong = 0; } break; | |
| 1424 | +# line 588 "lua.stx" | |
| 1425 | +{ code_byte(EQOP); luaY_val.vLong = 0; } break; | |
| 1645 | 1426 | case 33: |
| 1646 | −# line 583 "lua.stx" | |
| 1647 | −{ code_byte(LTOP); yyval.vLong = 0; } break; | |
| 1427 | +# line 589 "lua.stx" | |
| 1428 | +{ code_byte(LTOP); luaY_val.vLong = 0; } break; | |
| 1648 | 1429 | case 34: |
| 1649 | −# line 584 "lua.stx" | |
| 1650 | −{ code_byte(GTOP); yyval.vLong = 0; } break; | |
| 1430 | +# line 590 "lua.stx" | |
| 1431 | +{ code_byte(GTOP); luaY_val.vLong = 0; } break; | |
| 1651 | 1432 | case 35: |
| 1652 | −# line 585 "lua.stx" | |
| 1653 | −{ code_byte(EQOP); code_byte(NOTOP); yyval.vLong = 0; } break; | |
| 1433 | +# line 591 "lua.stx" | |
| 1434 | +{ code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; } break; | |
| 1654 | 1435 | case 36: |
| 1655 | −# line 586 "lua.stx" | |
| 1656 | −{ code_byte(LEOP); yyval.vLong = 0; } break; | |
| 1436 | +# line 592 "lua.stx" | |
| 1437 | +{ code_byte(LEOP); luaY_val.vLong = 0; } break; | |
| 1657 | 1438 | case 37: |
| 1658 | −# line 587 "lua.stx" | |
| 1659 | −{ code_byte(GEOP); yyval.vLong = 0; } break; | |
| 1439 | +# line 593 "lua.stx" | |
| 1440 | +{ code_byte(GEOP); luaY_val.vLong = 0; } break; | |
| 1660 | 1441 | case 38: |
| 1661 | −# line 588 "lua.stx" | |
| 1662 | −{ code_byte(ADDOP); yyval.vLong = 0; } break; | |
| 1442 | +# line 594 "lua.stx" | |
| 1443 | +{ code_byte(ADDOP); luaY_val.vLong = 0; } break; | |
| 1663 | 1444 | case 39: |
| 1664 | −# line 589 "lua.stx" | |
| 1665 | −{ code_byte(SUBOP); yyval.vLong = 0; } break; | |
| 1445 | +# line 595 "lua.stx" | |
| 1446 | +{ code_byte(SUBOP); luaY_val.vLong = 0; } break; | |
| 1666 | 1447 | case 40: |
| 1667 | −# line 590 "lua.stx" | |
| 1668 | −{ code_byte(MULTOP); yyval.vLong = 0; } break; | |
| 1448 | +# line 596 "lua.stx" | |
| 1449 | +{ code_byte(MULTOP); luaY_val.vLong = 0; } break; | |
| 1669 | 1450 | case 41: |
| 1670 | −# line 591 "lua.stx" | |
| 1671 | −{ code_byte(DIVOP); yyval.vLong = 0; } break; | |
| 1451 | +# line 597 "lua.stx" | |
| 1452 | +{ code_byte(DIVOP); luaY_val.vLong = 0; } break; | |
| 1672 | 1453 | case 42: |
| 1673 | −# line 592 "lua.stx" | |
| 1674 | −{ code_byte(POWOP); yyval.vLong = 0; } break; | |
| 1454 | +# line 598 "lua.stx" | |
| 1455 | +{ code_byte(POWOP); luaY_val.vLong = 0; } break; | |
| 1675 | 1456 | case 43: |
| 1676 | −# line 593 "lua.stx" | |
| 1677 | −{ code_byte(CONCOP); yyval.vLong = 0; } break; | |
| 1457 | +# line 599 "lua.stx" | |
| 1458 | +{ code_byte(CONCOP); luaY_val.vLong = 0; } break; | |
| 1678 | 1459 | case 44: |
| 1679 | −# line 594 "lua.stx" | |
| 1680 | −{ code_byte(MINUSOP); yyval.vLong = 0;} break; | |
| 1460 | +# line 600 "lua.stx" | |
| 1461 | +{ code_byte(MINUSOP); luaY_val.vLong = 0;} break; | |
| 1681 | 1462 | case 45: |
| 1682 | −# line 595 "lua.stx" | |
| 1683 | −{ yyval.vLong = 0; } break; | |
| 1463 | +# line 601 "lua.stx" | |
| 1464 | +{ luaY_val.vLong = 0; } break; | |
| 1684 | 1465 | case 46: |
| 1685 | −# line 596 "lua.stx" | |
| 1686 | −{ yyval.vLong = 0;} break; | |
| 1466 | +# line 602 "lua.stx" | |
| 1467 | +{ luaY_val.vLong = 0;} break; | |
| 1687 | 1468 | case 47: |
| 1688 | −# line 597 "lua.stx" | |
| 1689 | −{ code_number(yypvt[-0].vFloat); yyval.vLong = 0; } break; | |
| 1469 | +# line 603 "lua.stx" | |
| 1470 | +{ code_number(luaY_pvt[-0].vFloat); luaY_val.vLong = 0; } break; | |
| 1690 | 1471 | case 48: |
| 1691 | −# line 599 "lua.stx" | |
| 1472 | +# line 605 "lua.stx" | |
| 1692 | 1473 | { |
| 1693 | 1474 | code_byte(PUSHSTRING); |
| 1694 | − code_word(yypvt[-0].vWord); | |
| 1695 | − yyval.vLong = 0; | |
| 1475 | + code_word(luaY_pvt[-0].vWord); | |
| 1476 | + luaY_val.vLong = 0; | |
| 1696 | 1477 | } break; |
| 1697 | 1478 | case 49: |
| 1698 | −# line 604 "lua.stx" | |
| 1699 | −{code_byte(PUSHNIL); yyval.vLong = 0; } break; | |
| 1479 | +# line 610 "lua.stx" | |
| 1480 | +{code_byte(PUSHNIL); luaY_val.vLong = 0; } break; | |
| 1700 | 1481 | case 50: |
| 1701 | −# line 605 "lua.stx" | |
| 1702 | −{ yyval.vLong = yypvt[-0].vLong; } break; | |
| 1482 | +# line 611 "lua.stx" | |
| 1483 | +{ luaY_val.vLong = luaY_pvt[-0].vLong; } break; | |
| 1703 | 1484 | case 51: |
| 1704 | −# line 606 "lua.stx" | |
| 1705 | −{ code_byte(NOTOP); yyval.vLong = 0;} break; | |
| 1485 | +# line 612 "lua.stx" | |
| 1486 | +{ code_byte(NOTOP); luaY_val.vLong = 0;} break; | |
| 1706 | 1487 | case 52: |
| 1707 | −# line 607 "lua.stx" | |
| 1488 | +# line 613 "lua.stx" | |
| 1708 | 1489 | {code_byte(POP); } break; |
| 1709 | 1490 | case 53: |
| 1710 | −# line 608 "lua.stx" | |
| 1491 | +# line 614 "lua.stx" | |
| 1711 | 1492 | { |
| 1712 | − basepc[yypvt[-2].vLong] = ONFJMP; | |
| 1713 | − code_word_at(basepc+yypvt[-2].vLong+1, pc - (yypvt[-2].vLong + sizeof(Word)+1)); | |
| 1714 | − yyval.vLong = 0; | |
| 1493 | + basepc[luaY_pvt[-2].vLong] = ONFJMP; | |
| 1494 | + code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1)); | |
| 1495 | + luaY_val.vLong = 0; | |
| 1715 | 1496 | } break; |
| 1716 | 1497 | case 54: |
| 1717 | −# line 613 "lua.stx" | |
| 1498 | +# line 619 "lua.stx" | |
| 1718 | 1499 | {code_byte(POP); } break; |
| 1719 | 1500 | case 55: |
| 1720 | −# line 614 "lua.stx" | |
| 1501 | +# line 620 "lua.stx" | |
| 1721 | 1502 | { |
| 1722 | − basepc[yypvt[-2].vLong] = ONTJMP; | |
| 1723 | − code_word_at(basepc+yypvt[-2].vLong+1, pc - (yypvt[-2].vLong + sizeof(Word)+1)); | |
| 1724 | − yyval.vLong = 0; | |
| 1503 | + basepc[luaY_pvt[-2].vLong] = ONTJMP; | |
| 1504 | + code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1)); | |
| 1505 | + luaY_val.vLong = 0; | |
| 1725 | 1506 | } break; |
| 1726 | 1507 | case 56: |
| 1727 | −# line 622 "lua.stx" | |
| 1508 | +# line 628 "lua.stx" | |
| 1728 | 1509 | { |
| 1729 | 1510 | code_byte(CREATEARRAY); |
| 1730 | − yyval.vLong = pc; code_word(0); | |
| 1511 | + luaY_val.vLong = pc; code_word(0); | |
| 1731 | 1512 | } break; |
| 1732 | 1513 | case 57: |
| 1733 | −# line 627 "lua.stx" | |
| 1514 | +# line 633 "lua.stx" | |
| 1734 | 1515 | { |
| 1735 | − code_word_at(basepc+yypvt[-3].vLong, yypvt[-1].vInt); | |
| 1516 | + code_word_at(basepc+luaY_pvt[-3].vLong, luaY_pvt[-1].vInt); | |
| 1736 | 1517 | } break; |
| 1737 | 1518 | case 58: |
| 1738 | −# line 633 "lua.stx" | |
| 1519 | +# line 639 "lua.stx" | |
| 1739 | 1520 | { |
| 1740 | 1521 | code_byte(CALLFUNC); |
| 1741 | − code_byte(yypvt[-1].vInt+yypvt[-0].vInt); | |
| 1742 | − yyval.vLong = pc; | |
| 1522 | + code_byte(luaY_pvt[-1].vInt+luaY_pvt[-0].vInt); | |
| 1523 | + luaY_val.vLong = pc; | |
| 1743 | 1524 | code_byte(0); /* may be modified by other rules */ |
| 1744 | 1525 | } break; |
| 1745 | 1526 | case 59: |
| 1746 | −# line 641 "lua.stx" | |
| 1747 | −{ yyval.vInt = 0; } break; | |
| 1527 | +# line 647 "lua.stx" | |
| 1528 | +{ luaY_val.vInt = 0; } break; | |
| 1748 | 1529 | case 60: |
| 1749 | −# line 643 "lua.stx" | |
| 1530 | +# line 649 "lua.stx" | |
| 1750 | 1531 | { |
| 1751 | 1532 | code_byte(PUSHSELF); |
| 1752 | − code_word(luaI_findconstant(yypvt[-0].pNode)); | |
| 1753 | − yyval.vInt = 1; | |
| 1533 | + code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); | |
| 1534 | + luaY_val.vInt = 1; | |
| 1754 | 1535 | } break; |
| 1755 | 1536 | case 61: |
| 1756 | −# line 651 "lua.stx" | |
| 1757 | −{ yyval.vInt = adjust_functioncall(yypvt[-1].vLong, 1); } break; | |
| 1537 | +# line 657 "lua.stx" | |
| 1538 | +{ luaY_val.vInt = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break; | |
| 1758 | 1539 | case 62: |
| 1759 | −# line 652 "lua.stx" | |
| 1760 | −{ yyval.vInt = 1; } break; | |
| 1540 | +# line 658 "lua.stx" | |
| 1541 | +{ luaY_val.vInt = 1; } break; | |
| 1761 | 1542 | case 63: |
| 1762 | −# line 655 "lua.stx" | |
| 1763 | −{ yyval.vLong = 0; } break; | |
| 1543 | +# line 661 "lua.stx" | |
| 1544 | +{ luaY_val.vLong = 0; } break; | |
| 1764 | 1545 | case 64: |
| 1765 | −# line 656 "lua.stx" | |
| 1766 | −{ yyval.vLong = yypvt[-0].vLong; } break; | |
| 1546 | +# line 662 "lua.stx" | |
| 1547 | +{ luaY_val.vLong = luaY_pvt[-0].vLong; } break; | |
| 1767 | 1548 | case 65: |
| 1768 | −# line 659 "lua.stx" | |
| 1769 | −{ if (yypvt[-0].vLong != 0) yyval.vLong = yypvt[-0].vLong; else yyval.vLong = -1; } break; | |
| 1549 | +# line 665 "lua.stx" | |
| 1550 | +{ if (luaY_pvt[-0].vLong != 0) luaY_val.vLong = luaY_pvt[-0].vLong; else luaY_val.vLong = -1; } break; | |
| 1770 | 1551 | case 66: |
| 1771 | −# line 660 "lua.stx" | |
| 1772 | −{ yyval.vLong = adjust_functioncall(yypvt[-1].vLong, 1); } break; | |
| 1552 | +# line 666 "lua.stx" | |
| 1553 | +{ luaY_val.vLong = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break; | |
| 1773 | 1554 | case 67: |
| 1774 | −# line 661 "lua.stx" | |
| 1555 | +# line 667 "lua.stx" | |
| 1775 | 1556 | { |
| 1776 | − if (yypvt[-0].vLong == 0) yyval.vLong = -(yypvt[-1].vLong + 1); /* -length */ | |
| 1557 | + if (luaY_pvt[-0].vLong == 0) luaY_val.vLong = -(luaY_pvt[-1].vLong + 1); /* -length */ | |
| 1777 | 1558 | else |
| 1778 | 1559 | { |
| 1779 | − adjust_functioncall(yypvt[-0].vLong, yypvt[-1].vLong); | |
| 1780 | − yyval.vLong = yypvt[-0].vLong; | |
| 1560 | + adjust_functioncall(luaY_pvt[-0].vLong, luaY_pvt[-1].vLong); | |
| 1561 | + luaY_val.vLong = luaY_pvt[-0].vLong; | |
| 1781 | 1562 | } |
| 1782 | 1563 | } break; |
| 1783 | 1564 | case 68: |
| 1784 | −# line 671 "lua.stx" | |
| 1785 | −{ lua_codeadjust(0); yyval.vInt = lua_linenumber; } break; | |
| 1565 | +# line 677 "lua.stx" | |
| 1566 | +{ lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break; | |
| 1786 | 1567 | case 69: |
| 1787 | −# line 672 "lua.stx" | |
| 1788 | −{ lua_codeadjust(0); yyval.vInt = lua_linenumber; } break; | |
| 1568 | +# line 678 "lua.stx" | |
| 1569 | +{ lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break; | |
| 1789 | 1570 | case 70: |
| 1790 | −# line 676 "lua.stx" | |
| 1791 | −{ | |
| 1792 | − add_localvar(luaI_findsymbol(yypvt[-0].pNode)); | |
| 1793 | − } break; | |
| 1571 | +# line 681 "lua.stx" | |
| 1572 | +{ add_localvar(luaY_pvt[-0].pTStr); } break; | |
| 1794 | 1573 | case 71: |
| 1795 | −# line 680 "lua.stx" | |
| 1796 | −{ | |
| 1797 | − add_localvar(luaI_findsymbol(yypvt[-0].pNode)); | |
| 1798 | − } break; | |
| 1574 | +# line 682 "lua.stx" | |
| 1575 | +{ add_localvar(luaY_pvt[-0].pTStr); } break; | |
| 1799 | 1576 | case 72: |
| 1800 | 1577 | # line 686 "lua.stx" |
| 1801 | −{ flush_list(yypvt[-0].vInt/FIELDS_PER_FLUSH, yypvt[-0].vInt%FIELDS_PER_FLUSH); } break; | |
| 1578 | +{ flush_list(luaY_pvt[-0].vInt/FIELDS_PER_FLUSH, luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break; | |
| 1802 | 1579 | case 73: |
| 1803 | 1580 | # line 688 "lua.stx" |
| 1804 | −{ yyval.vInt = yypvt[-2].vInt+yypvt[-0].vInt; } break; | |
| 1581 | +{ luaY_val.vInt = luaY_pvt[-2].vInt+luaY_pvt[-0].vInt; } break; | |
| 1805 | 1582 | case 74: |
| 1806 | 1583 | # line 690 "lua.stx" |
| 1807 | −{ yyval.vInt = yypvt[-1].vInt; flush_record(yypvt[-1].vInt%FIELDS_PER_FLUSH); } break; | |
| 1584 | +{ luaY_val.vInt = luaY_pvt[-1].vInt; flush_record(luaY_pvt[-1].vInt%FIELDS_PER_FLUSH); } break; | |
| 1808 | 1585 | case 75: |
| 1809 | 1586 | # line 694 "lua.stx" |
| 1810 | −{ yyval.vInt = 0; } break; | |
| 1587 | +{ luaY_val.vInt = 0; } break; | |
| 1811 | 1588 | case 76: |
| 1812 | 1589 | # line 696 "lua.stx" |
| 1813 | −{ yyval.vInt = yypvt[-0].vInt; flush_record(yypvt[-0].vInt%FIELDS_PER_FLUSH); } break; | |
| 1590 | +{ luaY_val.vInt = luaY_pvt[-0].vInt; flush_record(luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break; | |
| 1814 | 1591 | case 79: |
| 1815 | 1592 | # line 703 "lua.stx" |
| 1816 | −{ yyval.vInt = 0; } break; | |
| 1593 | +{ luaY_val.vInt = 0; } break; | |
| 1817 | 1594 | case 80: |
| 1818 | 1595 | # line 704 "lua.stx" |
| 1819 | −{ yyval.vInt = yypvt[-1].vInt; } break; | |
| 1596 | +{ luaY_val.vInt = luaY_pvt[-1].vInt; } break; | |
| 1820 | 1597 | case 81: |
| 1821 | 1598 | # line 707 "lua.stx" |
| 1822 | −{yyval.vInt=1;} break; | |
| 1599 | +{luaY_val.vInt=1;} break; | |
| 1823 | 1600 | case 82: |
| 1824 | 1601 | # line 709 "lua.stx" |
| 1825 | 1602 | { |
| 1826 | − yyval.vInt=yypvt[-2].vInt+1; | |
| 1827 | − if (yyval.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH); | |
| 1603 | + luaY_val.vInt=luaY_pvt[-2].vInt+1; | |
| 1604 | + if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH); | |
| 1828 | 1605 | } break; |
| 1829 | 1606 | case 83: |
| 1830 | 1607 | # line 716 "lua.stx" |
| 1831 | 1608 | { |
| 1832 | − push_field(luaI_findconstant(yypvt[-2].pNode)); | |
| 1609 | + push_field(luaI_findconstant(luaY_pvt[-2].pTStr)); | |
| 1833 | 1610 | } break; |
| 1834 | 1611 | case 84: |
| 1835 | 1612 | # line 721 "lua.stx" |
| 1836 | −{ yyval.vInt = 0; } break; | |
| 1613 | +{ luaY_val.vInt = 0; } break; | |
| 1837 | 1614 | case 85: |
| 1838 | 1615 | # line 722 "lua.stx" |
| 1839 | −{ yyval.vInt = yypvt[-1].vInt; } break; | |
| 1616 | +{ luaY_val.vInt = luaY_pvt[-1].vInt; } break; | |
| 1840 | 1617 | case 86: |
| 1841 | 1618 | # line 725 "lua.stx" |
| 1842 | −{yyval.vInt=1;} break; | |
| 1619 | +{luaY_val.vInt=1;} break; | |
| 1843 | 1620 | case 87: |
| 1844 | 1621 | # line 727 "lua.stx" |
| 1845 | 1622 | { |
| 1846 | − yyval.vInt=yypvt[-2].vInt+1; | |
| 1847 | − if (yyval.vInt%FIELDS_PER_FLUSH == 0) | |
| 1848 | − flush_list(yyval.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH); | |
| 1623 | + luaY_val.vInt=luaY_pvt[-2].vInt+1; | |
| 1624 | + if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) | |
| 1625 | + flush_list(luaY_val.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH); | |
| 1849 | 1626 | } break; |
| 1850 | 1627 | case 88: |
| 1851 | 1628 | # line 735 "lua.stx" |
| 1852 | 1629 | { |
| 1853 | 1630 | nvarbuffer = 0; |
| 1854 | − add_varbuffer(yypvt[-0].vLong); | |
| 1855 | − yyval.vInt = (yypvt[-0].vLong == 0) ? 1 : 0; | |
| 1631 | + add_varbuffer(luaY_pvt[-0].vLong); | |
| 1632 | + luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? 1 : 0; | |
| 1856 | 1633 | } break; |
| 1857 | 1634 | case 89: |
| 1858 | 1635 | # line 741 "lua.stx" |
| 1859 | 1636 | { |
| 1860 | − add_varbuffer(yypvt[-0].vLong); | |
| 1861 | − yyval.vInt = (yypvt[-0].vLong == 0) ? yypvt[-2].vInt + 1 : yypvt[-2].vInt; | |
| 1637 | + add_varbuffer(luaY_pvt[-0].vLong); | |
| 1638 | + luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? luaY_pvt[-2].vInt + 1 : luaY_pvt[-2].vInt; | |
| 1862 | 1639 | } break; |
| 1863 | 1640 | case 90: |
| 1864 | 1641 | # line 747 "lua.stx" |
| 1865 | −{ yyval.vLong = yypvt[-0].vLong; } break; | |
| 1642 | +{ luaY_val.vLong = luaY_pvt[-0].vLong; } break; | |
| 1866 | 1643 | case 91: |
| 1867 | 1644 | # line 749 "lua.stx" |
| 1868 | 1645 | { |
| 1869 | − yyval.vLong = 0; /* indexed variable */ | |
| 1646 | + luaY_val.vLong = 0; /* indexed variable */ | |
| 1870 | 1647 | } break; |
| 1871 | 1648 | case 92: |
| 1872 | 1649 | # line 753 "lua.stx" |
| 1873 | 1650 | { |
| 1874 | 1651 | code_byte(PUSHSTRING); |
| 1875 | − code_word(luaI_findconstant(yypvt[-0].pNode)); | |
| 1876 | − yyval.vLong = 0; /* indexed variable */ | |
| 1652 | + code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); | |
| 1653 | + luaY_val.vLong = 0; /* indexed variable */ | |
| 1877 | 1654 | } break; |
| 1878 | 1655 | case 93: |
| 1879 | 1656 | # line 761 "lua.stx" |
| 1880 | 1657 | { |
| 1881 | − Word s = luaI_findsymbol(yypvt[-0].pNode); | |
| 1882 | − int local = lua_localname (s); | |
| 1658 | + int local = lua_localname(luaY_pvt[-0].pTStr); | |
| 1883 | 1659 | if (local == -1) /* global var */ |
| 1884 | − yyval.vLong = s + 1; /* return positive value */ | |
| 1660 | + luaY_val.vLong = luaI_findsymbol(luaY_pvt[-0].pTStr)+1; /* return positive value */ | |
| 1885 | 1661 | else |
| 1886 | − yyval.vLong = -(local+1); /* return negative value */ | |
| 1662 | + luaY_val.vLong = -(local+1); /* return negative value */ | |
| 1887 | 1663 | } break; |
| 1888 | 1664 | case 94: |
| 1889 | −# line 771 "lua.stx" | |
| 1890 | −{ lua_pushvar(yypvt[-0].vLong); } break; | |
| 1665 | +# line 770 "lua.stx" | |
| 1666 | +{ lua_pushvar(luaY_pvt[-0].vLong); } break; | |
| 1891 | 1667 | case 95: |
| 1892 | −# line 774 "lua.stx" | |
| 1893 | −{store_localvar(luaI_findsymbol(yypvt[-0].pNode), 0); yyval.vInt = 1;} break; | |
| 1668 | +# line 773 "lua.stx" | |
| 1669 | +{store_localvar(luaY_pvt[-0].pTStr, 0); luaY_val.vInt = 1;} break; | |
| 1894 | 1670 | case 96: |
| 1895 | −# line 776 "lua.stx" | |
| 1671 | +# line 775 "lua.stx" | |
| 1896 | 1672 | { |
| 1897 | − store_localvar(luaI_findsymbol(yypvt[-0].pNode), yypvt[-2].vInt); | |
| 1898 | − yyval.vInt = yypvt[-2].vInt+1; | |
| 1673 | + store_localvar(luaY_pvt[-0].pTStr, luaY_pvt[-2].vInt); | |
| 1674 | + luaY_val.vInt = luaY_pvt[-2].vInt+1; | |
| 1899 | 1675 | } break; |
| 1900 | 1676 | case 97: |
| 1901 | −# line 782 "lua.stx" | |
| 1902 | −{ yyval.vInt = 0; } break; | |
| 1677 | +# line 781 "lua.stx" | |
| 1678 | +{ luaY_val.vInt = 0; } break; | |
| 1903 | 1679 | case 98: |
| 1904 | −# line 783 "lua.stx" | |
| 1905 | −{ yyval.vInt = yypvt[-0].vLong; } break; | |
| 1680 | +# line 782 "lua.stx" | |
| 1681 | +{ luaY_val.vInt = luaY_pvt[-0].vLong; } break; | |
| 1906 | 1682 | case 99: |
| 1907 | −# line 786 "lua.stx" | |
| 1908 | −{ lua_debug = yypvt[-0].vInt; } break; | |
| 1683 | +# line 785 "lua.stx" | |
| 1684 | +{ lua_debug = luaY_pvt[-0].vInt; } break; | |
| 1909 | 1685 | } |
| 1910 | − goto yystack; /* reset registers in driver code */ | |
| 1686 | + goto luaY_stack; /* reset registers in driver code */ | |
| 1911 | 1687 | } |
| @@ -1,3 +1,4 @@ | ||
| 1 | + | |
| 1 | 2 | typedef union |
| 2 | 3 | { |
| 3 | 4 | int vInt; |
| @@ -6,9 +7,9 @@ typedef union · 2 unmodified lines | ||
| 6 | 7 | Word vWord; |
| 7 | 8 | Long vLong; |
| 8 | 9 | TFunc *pFunc; |
| 9 | − TreeNode *pNode; | |
| 10 | + TaggedString *pTStr; | |
| 10 | 11 | } YYSTYPE; |
| 11 | −extern YYSTYPE yylval; | |
| 12 | +extern YYSTYPE luaY_lval; | |
| 12 | 13 | # define WRONGTOKEN 257 |
| 13 | 14 | # define NIL 258 |
| 14 | 15 | # define IF 259 |
| @@ -3,9 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | ** Module to control static tables |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_table="$Id: table.c,v 2.38 1995/11/03 15:30:50 roberto Exp $"; | |
| 7 | − | |
| 8 | −/*#include <string.h>*/ | |
| 6 | +char *rcs_table="$Id: table.c,v 2.54 1996/05/06 14:29:35 roberto Exp $"; | |
| 9 | 7 | |
| 10 | 8 | #include "mem.h" |
| 11 | 9 | #include "opcode.h" |
| @@ -21,61 +19,66 @@ char *rcs_table="$Id: table.c,v 2.38 1995/11/03 15:30:50 roberto Exp $"; · 9 unmodified lines | ||
| 21 | 19 | #define BUFFER_BLOCK 256 |
| 22 | 20 | |
| 23 | 21 | Symbol *lua_table = NULL; |
| 24 | −static Word lua_ntable = 0; | |
| 22 | +Word lua_ntable = 0; | |
| 25 | 23 | static Long lua_maxsymbol = 0; |
| 26 | 24 | |
| 27 | 25 | TaggedString **lua_constant = NULL; |
| 28 | −static Word lua_nconstant = 0; | |
| 26 | +Word lua_nconstant = 0; | |
| 29 | 27 | static Long lua_maxconstant = 0; |
| 30 | 28 | |
| 31 | 29 | |
| 32 | −#define GARBAGE_BLOCK 1024 | |
| 33 | −#define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2) | |
| 30 | +#define GARBAGE_BLOCK 50 | |
| 34 | 31 | |
| 35 | 32 | static void lua_nextvar (void); |
| 36 | −static void setglobal (void); | |
| 37 | −static void getglobal (void); | |
| 38 | 33 | |
| 39 | 34 | /* |
| 40 | −** Initialise symbol table with internal functions | |
| 35 | +** Internal functions | |
| 41 | 36 | */ |
| 42 | −static void lua_initsymbol (void) | |
| 37 | +static struct { | |
| 38 | + char *name; | |
| 39 | + lua_CFunction func; | |
| 40 | +} int_funcs[] = { | |
| 41 | + {"assert", luaI_assert}, | |
| 42 | + {"dofile", lua_internaldofile}, | |
| 43 | + {"dostring", lua_internaldostring}, | |
| 44 | + {"error", luaI_error}, | |
| 45 | + {"getglobal", luaI_getglobal}, | |
| 46 | + {"next", lua_next}, | |
| 47 | + {"nextvar", lua_nextvar}, | |
| 48 | + {"print", luaI_print}, | |
| 49 | + {"setfallback", luaI_setfallback}, | |
| 50 | + {"setglobal", luaI_setglobal}, | |
| 51 | + {"tonumber", lua_obj2number}, | |
| 52 | + {"tostring", luaI_tostring}, | |
| 53 | + {"type", luaI_type} | |
| 54 | +}; | |
| 55 | + | |
| 56 | +#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0])) | |
| 57 | + | |
| 58 | + | |
| 59 | +void luaI_initsymbol (void) | |
| 43 | 60 | { |
| 44 | − Word n; | |
| 45 | − lua_maxsymbol = BUFFER_BLOCK; | |
| 46 | − lua_table = newvector(lua_maxsymbol, Symbol); | |
| 47 | − n = luaI_findsymbolbyname("next"); | |
| 48 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; | |
| 49 | − n = luaI_findsymbolbyname("dofile"); | |
| 50 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; | |
| 51 | − n = luaI_findsymbolbyname("setglobal"); | |
| 52 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = setglobal; | |
| 53 | − n = luaI_findsymbolbyname("getglobal"); | |
| 54 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = getglobal; | |
| 55 | − n = luaI_findsymbolbyname("nextvar"); | |
| 56 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; | |
| 57 | − n = luaI_findsymbolbyname("type"); | |
| 58 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type; | |
| 59 | − n = luaI_findsymbolbyname("tonumber"); | |
| 60 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; | |
| 61 | − n = luaI_findsymbolbyname("print"); | |
| 62 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; | |
| 63 | − n = luaI_findsymbolbyname("dostring"); | |
| 64 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | |
| 65 | − n = luaI_findsymbolbyname("setfallback"); | |
| 66 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; | |
| 67 | − n = luaI_findsymbolbyname("error"); | |
| 68 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; | |
| 61 | + int i; | |
| 62 | + lua_maxsymbol = BUFFER_BLOCK; | |
| 63 | + lua_table = newvector(lua_maxsymbol, Symbol); | |
| 64 | + for (i=0; i<INTFUNCSIZE; i++) | |
| 65 | + { | |
| 66 | + Word n = luaI_findsymbolbyname(int_funcs[i].name); | |
| 67 | + s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = int_funcs[i].func; | |
| 68 | + } | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | /* |
| 73 | 73 | ** Initialise constant table with pre-defined constants |
| 74 | 74 | */ |
| 75 | −void lua_initconstant (void) | |
| 75 | +void luaI_initconstant (void) | |
| 76 | 76 | { |
| 77 | 77 | lua_maxconstant = BUFFER_BLOCK; |
| 78 | 78 | lua_constant = newvector(lua_maxconstant, TaggedString *); |
| 79 | + /* pre-register mem error messages, to avoid loop when error arises */ | |
| 80 | + luaI_findconstantbyname(tableEM); | |
| 81 | + luaI_findconstantbyname(memEM); | |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | |
| @@ -83,22 +86,15 @@ void lua_initconstant (void) · 1 unmodified line | ||
| 83 | 86 | ** Given a name, search it at symbol table and return its index. If not |
| 84 | 87 | ** found, allocate it. |
| 85 | 88 | */ |
| 86 | −Word luaI_findsymbol (TreeNode *t) | |
| 89 | +Word luaI_findsymbol (TaggedString *t) | |
| 87 | 90 | { |
| 88 | − if (lua_table == NULL) | |
| 89 | − lua_initsymbol(); | |
| 90 | 91 | if (t->varindex == NOT_USED) |
| 91 | 92 | { |
| 92 | 93 | if (lua_ntable == lua_maxsymbol) |
| 93 | − { | |
| 94 | − if (lua_maxsymbol >= MAX_WORD) | |
| 95 | − lua_error("symbol table overflow"); | |
| 96 | − lua_maxsymbol *= 2; | |
| 97 | − if (lua_maxsymbol >= MAX_WORD) | |
| 98 | − lua_maxsymbol = MAX_WORD; | |
| 99 | − lua_table = growvector(lua_table, lua_maxsymbol, Symbol); | |
| 100 | − } | |
| 94 | + lua_maxsymbol = growvector(&lua_table, lua_maxsymbol, Symbol, | |
| 95 | + symbolEM, MAX_WORD); | |
| 101 | 96 | t->varindex = lua_ntable; |
| 97 | + lua_table[lua_ntable].varname = t; | |
| 102 | 98 | s_tag(lua_ntable) = LUA_T_NIL; |
| 103 | 99 | lua_ntable++; |
| 104 | 100 | } |
| @@ -108,7 +104,7 @@ Word luaI_findsymbol (TreeNode *t) · 3 unmodified lines | ||
| 108 | 104 | |
| 109 | 105 | Word luaI_findsymbolbyname (char *name) |
| 110 | 106 | { |
| 111 | − return luaI_findsymbol(lua_constcreate(name)); | |
| 107 | + return luaI_findsymbol(luaI_createfixedstring(name)); | |
| 112 | 108 | } |
| 113 | 109 | |
| 114 | 110 | |
| @@ -116,23 +112,15 @@ Word luaI_findsymbolbyname (char *name) · 1 unmodified line | ||
| 116 | 112 | ** Given a tree node, check it is has a correspondent constant index. If not, |
| 117 | 113 | ** allocate it. |
| 118 | 114 | */ |
| 119 | −Word luaI_findconstant (TreeNode *t) | |
| 115 | +Word luaI_findconstant (TaggedString *t) | |
| 120 | 116 | { |
| 121 | − if (lua_constant == NULL) | |
| 122 | − lua_initconstant(); | |
| 123 | 117 | if (t->constindex == NOT_USED) |
| 124 | 118 | { |
| 125 | 119 | if (lua_nconstant == lua_maxconstant) |
| 126 | − { | |
| 127 | − if (lua_maxconstant >= MAX_WORD) | |
| 128 | − lua_error("constant table overflow"); | |
| 129 | − lua_maxconstant *= 2; | |
| 130 | − if (lua_maxconstant >= MAX_WORD) | |
| 131 | − lua_maxconstant = MAX_WORD; | |
| 132 | − lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); | |
| 133 | − } | |
| 120 | + lua_maxconstant = growvector(&lua_constant, lua_maxconstant, TaggedString *, | |
| 121 | + constantEM, MAX_WORD); | |
| 134 | 122 | t->constindex = lua_nconstant; |
| 135 | − lua_constant[lua_nconstant] = &(t->ts); | |
| 123 | + lua_constant[lua_nconstant] = t; | |
| 136 | 124 | lua_nconstant++; |
| 137 | 125 | } |
| 138 | 126 | return t->constindex; |
| @@ -141,7 +129,15 @@ Word luaI_findconstant (TreeNode *t) · 2 unmodified lines | ||
| 141 | 129 | |
| 142 | 130 | Word luaI_findconstantbyname (char *name) |
| 143 | 131 | { |
| 144 | − return luaI_findconstant(lua_constcreate(name)); | |
| 132 | + return luaI_findconstant(luaI_createfixedstring(name)); | |
| 133 | +} | |
| 134 | + | |
| 135 | +TaggedString *luaI_createfixedstring (char *name) | |
| 136 | +{ | |
| 137 | + TaggedString *ts = lua_createstring(name); | |
| 138 | + if (!ts->marked) | |
| 139 | + ts->marked = 2; /* avoid GC */ | |
| 140 | + return ts; | |
| 145 | 141 | } |
| 146 | 142 | |
| 147 | 143 | |
| @@ -153,7 +149,7 @@ static char *lua_travsymbol (int (*fn)(Object *)) · 5 unmodified lines | ||
| 153 | 149 | Word i; |
| 154 | 150 | for (i=0; i<lua_ntable; i++) |
| 155 | 151 | if (fn(&s_object(i))) |
| 156 | − return luaI_nodebysymbol(i)->ts.str; | |
| 152 | + return lua_table[i].varname->str; | |
| 157 | 153 | return NULL; |
| 158 | 154 | } |
| 159 | 155 | |
| @@ -162,7 +158,7 @@ static char *lua_travsymbol (int (*fn)(Object *)) · 2 unmodified lines | ||
| 162 | 158 | ** Mark an object if it is a string or a unmarked array. |
| 163 | 159 | */ |
| 164 | 160 | int lua_markobject (Object *o) |
| 165 | −{ | |
| 161 | +{/* if already marked, does not change mark value */ | |
| 166 | 162 | if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked) |
| 167 | 163 | tsvalue(o)->marked = 1; |
| 168 | 164 | else if (tag(o) == LUA_T_ARRAY) |
| @@ -173,27 +169,52 @@ int lua_markobject (Object *o) · 4 unmodified lines | ||
| 173 | 169 | return 0; |
| 174 | 170 | } |
| 175 | 171 | |
| 172 | +/* | |
| 173 | +* returns 0 if the object is going to be (garbage) collected | |
| 174 | +*/ | |
| 175 | +int luaI_ismarked (Object *o) | |
| 176 | +{ | |
| 177 | + switch (o->tag) | |
| 178 | + { | |
| 179 | + case LUA_T_STRING: | |
| 180 | + return o->value.ts->marked; | |
| 181 | + case LUA_T_FUNCTION: | |
| 182 | + return o->value.tf->marked; | |
| 183 | + case LUA_T_ARRAY: | |
| 184 | + return o->value.a->mark; | |
| 185 | + default: /* nil, number, cfunction, or user data */ | |
| 186 | + return 1; | |
| 187 | + } | |
| 188 | +} | |
| 189 | + | |
| 176 | 190 | |
| 177 | 191 | /* |
| 178 | 192 | ** Garbage collection. |
| 179 | 193 | ** Delete all unused strings and arrays. |
| 180 | 194 | */ |
| 181 | −void lua_pack (void) | |
| 195 | +Long luaI_collectgarbage (void) | |
| 182 | 196 | { |
| 183 | − static Long block = GARBAGE_BLOCK; /* when garbage collector will be called */ | |
| 184 | − static Long nentity = 0; /* counter of new entities (strings and arrays) */ | |
| 185 | 197 | Long recovered = 0; |
| 186 | − if (nentity++ < block) return; | |
| 187 | 198 | lua_travstack(lua_markobject); /* mark stack objects */ |
| 188 | 199 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
| 189 | 200 | luaI_travlock(lua_markobject); /* mark locked objects */ |
| 190 | 201 | luaI_travfallbacks(lua_markobject); /* mark fallbacks */ |
| 202 | + luaI_invalidaterefs(); | |
| 191 | 203 | recovered += lua_strcollector(); |
| 192 | 204 | recovered += lua_hashcollector(); |
| 193 | 205 | recovered += luaI_funccollector(); |
| 194 | − nentity = 0; /* reset counter */ | |
| 195 | − block=(16*block-7*recovered)/12; /* adapt block size */ | |
| 196 | − if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK; | |
| 206 | + return recovered; | |
| 207 | +} | |
| 208 | + | |
| 209 | +void lua_pack (void) | |
| 210 | +{ | |
| 211 | + static unsigned long block = GARBAGE_BLOCK; | |
| 212 | + static unsigned long nentity = 0; /* total of strings, arrays, etc */ | |
| 213 | + unsigned long recovered = 0; | |
| 214 | + if (nentity++ < block) return; | |
| 215 | + recovered = luaI_collectgarbage(); | |
| 216 | + block = block*2*(1.0 - (float)recovered/nentity); | |
| 217 | + nentity -= recovered; | |
| 197 | 218 | } |
| 198 | 219 | |
| 199 | 220 | |
| @@ -225,36 +246,12 @@ static void lua_nextvar (void) · 25 unmodified lines | ||
| 225 | 246 | } |
| 226 | 247 | else |
| 227 | 248 | { |
| 228 | − TreeNode *t = luaI_nodebysymbol(next); | |
| 229 | − Object name; | |
| 230 | − tag(&name) = LUA_T_STRING; | |
| 231 | − tsvalue(&name) = &(t->ts); | |
| 232 | − luaI_pushobject(&name); | |
| 249 | + lua_pushstring(lua_table[next].varname->str); | |
| 233 | 250 | luaI_pushobject(&s_object(next)); |
| 234 | 251 | } |
| 235 | 252 | } |
| 236 | 253 | |
| 237 | 254 | |
| 238 | −static void setglobal (void) | |
| 239 | −{ | |
| 240 | − lua_Object name = lua_getparam(1); | |
| 241 | − lua_Object value = lua_getparam(2); | |
| 242 | − if (!lua_isstring(name)) | |
| 243 | − lua_error("incorrect argument to function `setglobal'"); | |
| 244 | − lua_pushobject(value); | |
| 245 | − lua_storeglobal(lua_getstring(name)); | |
| 246 | −} | |
| 247 | − | |
| 248 | − | |
| 249 | −static void getglobal (void) | |
| 250 | −{ | |
| 251 | − lua_Object name = lua_getparam(1); | |
| 252 | − if (!lua_isstring(name)) | |
| 253 | − lua_error("incorrect argument to function `getglobal'"); | |
| 254 | − lua_pushobject(lua_getglobal(lua_getstring(name))); | |
| 255 | −} | |
| 256 | − | |
| 257 | − | |
| 258 | 255 | static Object *functofind; |
| 259 | 256 | static int checkfunc (Object *o) |
| 260 | 257 | { |
| @@ -270,7 +267,7 @@ static int checkfunc (Object *o) · 9 unmodified lines | ||
| 270 | 267 | } |
| 271 | 268 | |
| 272 | 269 | |
| 273 | −char *getobjname (lua_Object o, char **name) | |
| 270 | +char *lua_getobjname (lua_Object o, char **name) | |
| 274 | 271 | { /* try to find a name for given function */ |
| 275 | 272 | functofind = luaI_Address(o); |
| 276 | 273 | if ((*name = luaI_travfallbacks(checkfunc)) != NULL) |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** Module to control static tables |
| 3 | 3 | ** TeCGraf - PUC-Rio |
| 4 | −** $Id: table.h,v 2.13 1995/10/26 14:21:56 roberto Exp $ | |
| 4 | +** $Id: table.h,v 2.21 1996/04/22 18:00:37 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef table_h |
| @@ -10,19 +10,28 @@ · 2 unmodified lines | ||
| 10 | 10 | #include "tree.h" |
| 11 | 11 | #include "opcode.h" |
| 12 | 12 | |
| 13 | −extern Symbol *lua_table; | |
| 14 | −extern TaggedString **lua_constant; | |
| 13 | +typedef struct | |
| 14 | +{ | |
| 15 | + Object object; | |
| 16 | + TaggedString *varname; | |
| 17 | +} Symbol; | |
| 15 | 18 | |
| 16 | −extern char *lua_file[]; | |
| 17 | −extern int lua_nfile; | |
| 18 | 19 | |
| 20 | +extern Symbol *lua_table; | |
| 21 | +extern Word lua_ntable; | |
| 22 | +extern TaggedString **lua_constant; | |
| 23 | +extern Word lua_nconstant; | |
| 19 | 24 | |
| 20 | −void lua_initconstant (void); | |
| 25 | +void luaI_initsymbol (void); | |
| 26 | +void luaI_initconstant (void); | |
| 21 | 27 | Word luaI_findsymbolbyname (char *name); |
| 22 | −Word luaI_findsymbol (TreeNode *t); | |
| 23 | −Word luaI_findconstant (TreeNode *t); | |
| 28 | +Word luaI_findsymbol (TaggedString *t); | |
| 29 | +Word luaI_findconstant (TaggedString *t); | |
| 24 | 30 | Word luaI_findconstantbyname (char *name); |
| 31 | +TaggedString *luaI_createfixedstring (char *str); | |
| 25 | 32 | int lua_markobject (Object *o); |
| 33 | +int luaI_ismarked (Object *o); | |
| 34 | +Long luaI_collectgarbage (void); | |
| 26 | 35 | void lua_pack (void); |
| 27 | 36 | |
| 28 | 37 | |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_tree="$Id: tree.c,v 1.14 1995/10/17 11:53:53 roberto Exp $"; | |
| 6 | +char *rcs_tree="$Id: tree.c,v 1.20 1996/03/14 15:56:26 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | #include <string.h> |
| @@ -11,66 +11,104 @@ char *rcs_tree="$Id: tree.c,v 1.14 1995/10/17 11:53:53 roberto Exp $"; · 1 unmodified line | ||
| 11 | 11 | #include "mem.h" |
| 12 | 12 | #include "lua.h" |
| 13 | 13 | #include "tree.h" |
| 14 | +#include "lex.h" | |
| 15 | +#include "hash.h" | |
| 14 | 16 | #include "table.h" |
| 15 | 17 | |
| 16 | 18 | |
| 17 | −#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) | |
| 19 | +#define NUM_HASHS 64 | |
| 18 | 20 | |
| 21 | +typedef struct { | |
| 22 | + int size; | |
| 23 | + int nuse; /* number of elements (including EMPTYs) */ | |
| 24 | + TaggedString **hash; | |
| 25 | +} stringtable; | |
| 19 | 26 | |
| 20 | −typedef struct StringNode { | |
| 21 | − struct StringNode *next; | |
| 22 | − TaggedString ts; | |
| 23 | −} StringNode; | |
| 27 | +static int initialized = 0; | |
| 24 | 28 | |
| 25 | −static StringNode *string_root = NULL; | |
| 29 | +static stringtable string_root[NUM_HASHS]; | |
| 26 | 30 | |
| 27 | −static TreeNode *constant_root = NULL; | |
| 31 | +static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 2, {0}}; | |
| 28 | 32 | |
| 29 | −/* | |
| 30 | −** Insert a new constant/variable at the tree. | |
| 31 | −*/ | |
| 32 | −static TreeNode *tree_create (TreeNode **node, char *str) | |
| 33 | + | |
| 34 | +static unsigned long hash (char *str) | |
| 33 | 35 | { |
| 34 | − if (*node == NULL) | |
| 35 | − { | |
| 36 | − *node = (TreeNode *) luaI_malloc(sizeof(TreeNode)+strlen(str)); | |
| 37 | − (*node)->left = (*node)->right = NULL; | |
| 38 | − strcpy((*node)->ts.str, str); | |
| 39 | − (*node)->ts.marked = 0; | |
| 40 | − (*node)->ts.hash = 0; | |
| 41 | − (*node)->varindex = (*node)->constindex = NOT_USED; | |
| 42 | − return *node; | |
| 43 | − } | |
| 44 | − else | |
| 45 | − { | |
| 46 | − int c = lua_strcmp(str, (*node)->ts.str); | |
| 47 | − if (c < 0) | |
| 48 | − return tree_create(&(*node)->left, str); | |
| 49 | − else if (c > 0) | |
| 50 | − return tree_create(&(*node)->right, str); | |
| 51 | − else | |
| 52 | − return *node; | |
| 53 | − } | |
| 36 | + unsigned long h = 0; | |
| 37 | + while (*str) | |
| 38 | + h = ((h<<5)-h)^(unsigned char)*(str++); | |
| 39 | + return h; | |
| 54 | 40 | } |
| 55 | 41 | |
| 56 | −TaggedString *lua_createstring (char *str) | |
| 42 | +static void initialize (void) | |
| 57 | 43 | { |
| 58 | − StringNode *newString; | |
| 59 | − if (str == NULL) return NULL; | |
| 60 | − lua_pack(); | |
| 61 | − newString = (StringNode *)luaI_malloc(sizeof(StringNode)+strlen(str)); | |
| 62 | − newString->ts.marked = 0; | |
| 63 | − newString->ts.hash = 0; | |
| 64 | − strcpy(newString->ts.str, str); | |
| 65 | − newString->next = string_root; | |
| 66 | − string_root = newString; | |
| 67 | − return &(newString->ts); | |
| 44 | + initialized = 1; | |
| 45 | + luaI_addReserved(); | |
| 46 | + luaI_initsymbol(); | |
| 47 | + luaI_initconstant(); | |
| 48 | +} | |
| 49 | + | |
| 50 | + | |
| 51 | +static void grow (stringtable *tb) | |
| 52 | +{ | |
| 53 | + int newsize = luaI_redimension(tb->size); | |
| 54 | + TaggedString **newhash = newvector(newsize, TaggedString *); | |
| 55 | + int i; | |
| 56 | + for (i=0; i<newsize; i++) | |
| 57 | + newhash[i] = NULL; | |
| 58 | + /* rehash */ | |
| 59 | + tb->nuse = 0; | |
| 60 | + for (i=0; i<tb->size; i++) | |
| 61 | + if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) | |
| 62 | + { | |
| 63 | + int h = tb->hash[i]->hash%newsize; | |
| 64 | + while (newhash[h]) | |
| 65 | + h = (h+1)%newsize; | |
| 66 | + newhash[h] = tb->hash[i]; | |
| 67 | + tb->nuse++; | |
| 68 | + } | |
| 69 | + luaI_free(tb->hash); | |
| 70 | + tb->size = newsize; | |
| 71 | + tb->hash = newhash; | |
| 68 | 72 | } |
| 69 | 73 | |
| 74 | +static TaggedString *insert (char *str, stringtable *tb) | |
| 75 | +{ | |
| 76 | + TaggedString *ts; | |
| 77 | + unsigned long h = hash(str); | |
| 78 | + int i; | |
| 79 | + int j = -1; | |
| 80 | + if ((Long)tb->nuse*3 >= (Long)tb->size*2) | |
| 81 | + { | |
| 82 | + if (!initialized) | |
| 83 | + initialize(); | |
| 84 | + grow(tb); | |
| 85 | + } | |
| 86 | + i = h%tb->size; | |
| 87 | + while (tb->hash[i]) | |
| 88 | + { | |
| 89 | + if (tb->hash[i] == &EMPTY) | |
| 90 | + j = i; | |
| 91 | + else if (strcmp(str, tb->hash[i]->str) == 0) | |
| 92 | + return tb->hash[i]; | |
| 93 | + i = (i+1)%tb->size; | |
| 94 | + } | |
| 95 | + /* not found */ | |
| 96 | + lua_pack(); | |
| 97 | + if (j != -1) /* is there an EMPTY space? */ | |
| 98 | + i = j; | |
| 99 | + else | |
| 100 | + tb->nuse++; | |
| 101 | + ts = tb->hash[i] = (TaggedString *)luaI_malloc(sizeof(TaggedString)+strlen(str)); | |
| 102 | + strcpy(ts->str, str); | |
| 103 | + ts->marked = 0; | |
| 104 | + ts->hash = h; | |
| 105 | + ts->varindex = ts->constindex = NOT_USED; | |
| 106 | + return ts; | |
| 107 | +} | |
| 70 | 108 | |
| 71 | −TreeNode *lua_constcreate (char *str) | |
| 109 | +TaggedString *lua_createstring (char *str) | |
| 72 | 110 | { |
| 73 | − return tree_create(&constant_root, str); | |
| 111 | + return insert(str, &string_root[(unsigned)str[0]%NUM_HASHS]); | |
| 74 | 112 | } |
| 75 | 113 | |
| 76 | 114 | |
| @@ -80,44 +118,28 @@ TreeNode *lua_constcreate (char *str) · 3 unmodified lines | ||
| 80 | 118 | */ |
| 81 | 119 | Long lua_strcollector (void) |
| 82 | 120 | { |
| 83 | − StringNode *curr = string_root, *prev = NULL; | |
| 84 | 121 | Long counter = 0; |
| 85 | − while (curr) | |
| 122 | + int i; | |
| 123 | + for (i=0; i<NUM_HASHS; i++) | |
| 86 | 124 | { |
| 87 | − StringNode *next = curr->next; | |
| 88 | − if (!curr->ts.marked) | |
| 89 | − { | |
| 90 | − if (prev == NULL) string_root = next; | |
| 91 | − else prev->next = next; | |
| 92 | − luaI_free(curr); | |
| 93 | − ++counter; | |
| 94 | − } | |
| 95 | − else | |
| 125 | + stringtable *tb = &string_root[i]; | |
| 126 | + int j; | |
| 127 | + for (j=0; j<tb->size; j++) | |
| 96 | 128 | { |
| 97 | − curr->ts.marked = 0; | |
| 98 | − prev = curr; | |
| 129 | + TaggedString *t = tb->hash[j]; | |
| 130 | + if (t != NULL && t->marked <= 1) | |
| 131 | + { | |
| 132 | + if (t->marked) | |
| 133 | + t->marked = 0; | |
| 134 | + else | |
| 135 | + { | |
| 136 | + luaI_free(t); | |
| 137 | + tb->hash[j] = &EMPTY; | |
| 138 | + counter++; | |
| 139 | + } | |
| 140 | + } | |
| 99 | 141 | } |
| 100 | − curr = next; | |
| 101 | 142 | } |
| 102 | 143 | return counter; |
| 103 | 144 | } |
| 104 | 145 | |
| 105 | − | |
| 106 | −/* | |
| 107 | −** Traverse the constant tree looking for a specific symbol number | |
| 108 | −*/ | |
| 109 | −static TreeNode *nodebysymbol (TreeNode *root, Word symbol) | |
| 110 | −{ | |
| 111 | − TreeNode *t; | |
| 112 | − if (root == NULL) return NULL; | |
| 113 | − if (root->varindex == symbol) return root; | |
| 114 | − t = nodebysymbol(root->left, symbol); | |
| 115 | − if (t) return t; | |
| 116 | − return nodebysymbol(root->right, symbol); | |
| 117 | −} | |
| 118 | − | |
| 119 | −TreeNode *luaI_nodebysymbol (Word symbol) | |
| 120 | −{ | |
| 121 | − return nodebysymbol(constant_root, symbol); | |
| 122 | −} | |
| 123 | − | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** tree.h |
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | −** $Id: tree.h,v 1.10 1995/10/17 11:53:53 roberto Exp $ | |
| 4 | +** $Id: tree.h,v 1.14 1996/02/26 17:07:49 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef tree_h |
| @@ -14,24 +14,15 @@ · 6 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | typedef struct TaggedString |
| 16 | 16 | { |
| 17 | + Word varindex; /* != NOT_USED if this is a symbol */ | |
| 18 | + Word constindex; /* != NOT_USED if this is a constant */ | |
| 17 | 19 | unsigned long hash; /* 0 if not initialized */ |
| 18 | − char marked; /* for garbage collection */ | |
| 20 | + int marked; /* for garbage collection; never collect (nor change) if > 1 */ | |
| 19 | 21 | char str[1]; /* \0 byte already reserved */ |
| 20 | 22 | } TaggedString; |
| 21 | 23 | |
| 22 | −typedef struct TreeNode | |
| 23 | −{ | |
| 24 | − struct TreeNode *right; | |
| 25 | − struct TreeNode *left; | |
| 26 | − unsigned short varindex; /* != NOT_USED if this is a symbol */ | |
| 27 | − unsigned short constindex; /* != NOT_USED if this is a constant */ | |
| 28 | − TaggedString ts; | |
| 29 | −} TreeNode; | |
| 30 | − | |
| 31 | 24 | |
| 32 | 25 | TaggedString *lua_createstring (char *str); |
| 33 | −TreeNode *lua_constcreate (char *str); | |
| 34 | 26 | Long lua_strcollector (void); |
| 35 | −TreeNode *luaI_nodebysymbol (Word symbol); | |
| 36 | 27 | |
| 37 | 28 | #endif |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** TeCGraf - PUC-Rio |
| 3 | −** $Id: types.h,v 1.3 1995/02/06 19:32:43 roberto Exp $ | |
| 3 | +** $Id: types.h,v 1.4 1996/02/07 14:13:17 roberto Exp $ | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | #ifndef types_h |
| @@ -12,8 +12,6 @@ · 5 unmodified lines | ||
| 12 | 12 | #define real float |
| 13 | 13 | #endif |
| 14 | 14 | |
| 15 | −typedef int Bool; /* boolean values */ | |
| 16 | − | |
| 17 | 15 | #define Byte lua_Byte /* some systems have Byte as a predefined type */ |
| 18 | 16 | typedef unsigned char Byte; /* unsigned 8 bits */ |
| 19 | 17 | |
| @@ -1,36 +0,0 @@ | ||
| 1 | −/* | |
| 2 | −** ugly.h | |
| 3 | −** TecCGraf - PUC-Rio | |
| 4 | −** $Id: ugly.h,v 1.2 1994/11/13 14:39:04 roberto Stab $ | |
| 5 | −*/ | |
| 6 | − | |
| 7 | −#ifndef ugly_h | |
| 8 | −#define ugly_h | |
| 9 | − | |
| 10 | −/* This enum must have the same order of the array 'reserved' in lex.c */ | |
| 11 | − | |
| 12 | −enum { | |
| 13 | − U_and=128, | |
| 14 | − U_do, | |
| 15 | − U_else, | |
| 16 | − U_elseif, | |
| 17 | − U_end, | |
| 18 | − U_function, | |
| 19 | − U_if, | |
| 20 | − U_local, | |
| 21 | − U_nil, | |
| 22 | − U_not, | |
| 23 | − U_or, | |
| 24 | − U_repeat, | |
| 25 | − U_return, | |
| 26 | − U_then, | |
| 27 | − U_until, | |
| 28 | − U_while, | |
| 29 | − U_eq = '='+128, | |
| 30 | − U_le = '<'+128, | |
| 31 | − U_ge = '>'+128, | |
| 32 | − U_ne = '~'+128, | |
| 33 | − U_sc = '.'+128 | |
| 34 | −}; | |
| 35 | − | |
| 36 | −#endif | |
| @@ -0,0 +1,326 @@ | ||
| 1 | +/* | |
| 2 | +** undump.c | |
| 3 | +** load bytecodes from files | |
| 4 | +*/ | |
| 5 | + | |
| 6 | +char* rcs_undump="$Id: undump.c,v 1.14 1996/03/14 17:31:15 lhf Exp $"; | |
| 7 | + | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <string.h> | |
| 10 | +#include "opcode.h" | |
| 11 | +#include "mem.h" | |
| 12 | +#include "table.h" | |
| 13 | +#include "undump.h" | |
| 14 | + | |
| 15 | +static int swapword=0; | |
| 16 | +static int swapfloat=0; | |
| 17 | +static TFunc* Main=NULL; /* functions in a chunk */ | |
| 18 | +static TFunc* lastF=NULL; | |
| 19 | + | |
| 20 | +static void warn(char* s) /* TODO: remove */ | |
| 21 | +{ | |
| 22 | +#if 0 | |
| 23 | + fprintf(stderr,"undump: %s\n",s); | |
| 24 | +#endif | |
| 25 | +} | |
| 26 | + | |
| 27 | +static void FixCode(Byte* code, Byte* end) /* swap words */ | |
| 28 | +{ | |
| 29 | + Byte* p; | |
| 30 | + for (p=code; p!=end;) | |
| 31 | + { | |
| 32 | + OpCode op=(OpCode)*p; | |
| 33 | + switch (op) | |
| 34 | + { | |
| 35 | + case PUSHNIL: | |
| 36 | + case PUSH0: | |
| 37 | + case PUSH1: | |
| 38 | + case PUSH2: | |
| 39 | + case PUSHLOCAL0: | |
| 40 | + case PUSHLOCAL1: | |
| 41 | + case PUSHLOCAL2: | |
| 42 | + case PUSHLOCAL3: | |
| 43 | + case PUSHLOCAL4: | |
| 44 | + case PUSHLOCAL5: | |
| 45 | + case PUSHLOCAL6: | |
| 46 | + case PUSHLOCAL7: | |
| 47 | + case PUSHLOCAL8: | |
| 48 | + case PUSHLOCAL9: | |
| 49 | + case PUSHINDEXED: | |
| 50 | + case STORELOCAL0: | |
| 51 | + case STORELOCAL1: | |
| 52 | + case STORELOCAL2: | |
| 53 | + case STORELOCAL3: | |
| 54 | + case STORELOCAL4: | |
| 55 | + case STORELOCAL5: | |
| 56 | + case STORELOCAL6: | |
| 57 | + case STORELOCAL7: | |
| 58 | + case STORELOCAL8: | |
| 59 | + case STORELOCAL9: | |
| 60 | + case STOREINDEXED0: | |
| 61 | + case ADJUST0: | |
| 62 | + case EQOP: | |
| 63 | + case LTOP: | |
| 64 | + case LEOP: | |
| 65 | + case GTOP: | |
| 66 | + case GEOP: | |
| 67 | + case ADDOP: | |
| 68 | + case SUBOP: | |
| 69 | + case MULTOP: | |
| 70 | + case DIVOP: | |
| 71 | + case POWOP: | |
| 72 | + case CONCOP: | |
| 73 | + case MINUSOP: | |
| 74 | + case NOTOP: | |
| 75 | + case POP: | |
| 76 | + case RETCODE0: | |
| 77 | + p++; | |
| 78 | + break; | |
| 79 | + case PUSHBYTE: | |
| 80 | + case PUSHLOCAL: | |
| 81 | + case STORELOCAL: | |
| 82 | + case STOREINDEXED: | |
| 83 | + case STORELIST0: | |
| 84 | + case ADJUST: | |
| 85 | + case RETCODE: | |
| 86 | + p+=2; | |
| 87 | + break; | |
| 88 | + case STORELIST: | |
| 89 | + case CALLFUNC: | |
| 90 | + p+=3; | |
| 91 | + break; | |
| 92 | + case PUSHFUNCTION: | |
| 93 | + p+=5; | |
| 94 | + break; | |
| 95 | + case PUSHWORD: | |
| 96 | + case PUSHSELF: | |
| 97 | + case CREATEARRAY: | |
| 98 | + case ONTJMP: | |
| 99 | + case ONFJMP: | |
| 100 | + case JMP: | |
| 101 | + case UPJMP: | |
| 102 | + case IFFJMP: | |
| 103 | + case IFFUPJMP: | |
| 104 | + case SETLINE: | |
| 105 | + case PUSHSTRING: | |
| 106 | + case PUSHGLOBAL: | |
| 107 | + case STOREGLOBAL: | |
| 108 | + { | |
| 109 | + Byte t; | |
| 110 | + t=p[1]; p[1]=p[2]; p[2]=t; | |
| 111 | + p+=3; | |
| 112 | + break; | |
| 113 | + } | |
| 114 | + case PUSHFLOAT: | |
| 115 | + { | |
| 116 | + Byte t; | |
| 117 | + t=p[1]; p[1]=p[4]; p[4]=t; | |
| 118 | + t=p[2]; p[2]=p[3]; p[3]=t; | |
| 119 | + p+=5; | |
| 120 | + break; | |
| 121 | + } | |
| 122 | + case STORERECORD: | |
| 123 | + { | |
| 124 | + int n=*++p; | |
| 125 | + p++; | |
| 126 | + while (n--) | |
| 127 | + { | |
| 128 | + Byte t; | |
| 129 | + t=p[0]; p[0]=p[1]; p[1]=t; | |
| 130 | + p+=2; | |
| 131 | + } | |
| 132 | + break; | |
| 133 | + } | |
| 134 | + default: | |
| 135 | + lua_error("corrupt binary file"); | |
| 136 | + break; | |
| 137 | + } | |
| 138 | + } | |
| 139 | +} | |
| 140 | + | |
| 141 | +static void Unthread(Byte* code, int i, int v) | |
| 142 | +{ | |
| 143 | + while (i!=0) | |
| 144 | + { | |
| 145 | + CodeWord c; | |
| 146 | + Byte* p=code+i; | |
| 147 | + get_word(c,p); | |
| 148 | + i=c.w; | |
| 149 | + c.w=v; | |
| 150 | + p[-2]=c.m.c1; | |
| 151 | + p[-1]=c.m.c2; | |
| 152 | + } | |
| 153 | +} | |
| 154 | + | |
| 155 | +static int LoadWord(FILE* D) | |
| 156 | +{ | |
| 157 | + Word w; | |
| 158 | + fread(&w,sizeof(w),1,D); | |
| 159 | + if (swapword) | |
| 160 | + { | |
| 161 | + Byte* p=(Byte*)&w; /* TODO: need union? */ | |
| 162 | + Byte t; | |
| 163 | + t=p[0]; p[0]=p[1]; p[1]=t; | |
| 164 | + } | |
| 165 | + return w; | |
| 166 | +} | |
| 167 | + | |
| 168 | +static int LoadSize(FILE* D) | |
| 169 | +{ | |
| 170 | + Word hi=LoadWord(D); | |
| 171 | + Word lo=LoadWord(D); | |
| 172 | + int s=(hi<<16)|lo; | |
| 173 | + if ((Word)s != s) lua_error("code too long"); | |
| 174 | + return s; | |
| 175 | +} | |
| 176 | + | |
| 177 | +static char* LoadBlock(int size, FILE* D) | |
| 178 | +{ | |
| 179 | + char* b=luaI_malloc(size); | |
| 180 | + fread(b,size,1,D); | |
| 181 | + return b; | |
| 182 | +} | |
| 183 | + | |
| 184 | +static char* LoadString(FILE* D) | |
| 185 | +{ | |
| 186 | + int size=LoadWord(D); | |
| 187 | + char *b=luaI_buffer(size); | |
| 188 | + fread(b,size,1,D); | |
| 189 | + return b; | |
| 190 | +} | |
| 191 | + | |
| 192 | +static char* LoadNewString(FILE* D) | |
| 193 | +{ | |
| 194 | + return LoadBlock(LoadWord(D),D); | |
| 195 | +} | |
| 196 | + | |
| 197 | +static void LoadFunction(FILE* D) | |
| 198 | +{ | |
| 199 | + TFunc* tf=new(TFunc); | |
| 200 | + tf->next=NULL; | |
| 201 | + tf->locvars=NULL; | |
| 202 | + tf->size=LoadSize(D); | |
| 203 | + tf->lineDefined=LoadWord(D); | |
| 204 | + if (IsMain(tf)) /* new main */ | |
| 205 | + { | |
| 206 | + tf->fileName=LoadNewString(D); | |
| 207 | + Main=lastF=tf; | |
| 208 | + } | |
| 209 | + else /* fix PUSHFUNCTION */ | |
| 210 | + { | |
| 211 | + CodeCode c; | |
| 212 | + Byte* p; | |
| 213 | + tf->marked=LoadWord(D); | |
| 214 | + tf->fileName=Main->fileName; | |
| 215 | + p=Main->code+tf->marked; | |
| 216 | + c.tf=tf; | |
| 217 | + *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4; | |
| 218 | + lastF=lastF->next=tf; | |
| 219 | + } | |
| 220 | + tf->code=LoadBlock(tf->size,D); | |
| 221 | + if (swapword || swapfloat) FixCode(tf->code,tf->code+tf->size); | |
| 222 | + while (1) /* unthread */ | |
| 223 | + { | |
| 224 | + int c=getc(D); | |
| 225 | + if (c==ID_VAR) /* global var */ | |
| 226 | + { | |
| 227 | + int i=LoadWord(D); | |
| 228 | + char* s=LoadString(D); | |
| 229 | + int v=luaI_findsymbolbyname(s); | |
| 230 | + Unthread(tf->code,i,v); | |
| 231 | + } | |
| 232 | + else if (c==ID_STR) /* constant string */ | |
| 233 | + { | |
| 234 | + int i=LoadWord(D); | |
| 235 | + char* s=LoadString(D); | |
| 236 | + int v=luaI_findconstantbyname(s); | |
| 237 | + Unthread(tf->code,i,v); | |
| 238 | + } | |
| 239 | + else | |
| 240 | + { | |
| 241 | + ungetc(c,D); | |
| 242 | + break; | |
| 243 | + } | |
| 244 | + } | |
| 245 | +} | |
| 246 | + | |
| 247 | +static void LoadSignature(FILE* D) | |
| 248 | +{ | |
| 249 | + char* s=SIGNATURE; | |
| 250 | + while (*s!=0 && getc(D)==*s) | |
| 251 | + ++s; | |
| 252 | + if (*s!=0) lua_error("bad signature"); | |
| 253 | +} | |
| 254 | + | |
| 255 | +static void LoadHeader(FILE* D) /* TODO: error handling */ | |
| 256 | +{ | |
| 257 | + Word w,tw=TEST_WORD; | |
| 258 | + float f,tf=TEST_FLOAT; | |
| 259 | + LoadSignature(D); | |
| 260 | + getc(D); /* skip version */ | |
| 261 | + fread(&w,sizeof(w),1,D); /* test word */ | |
| 262 | + if (w!=tw) | |
| 263 | + { | |
| 264 | + swapword=1; | |
| 265 | + warn("different byte order"); | |
| 266 | + } | |
| 267 | + fread(&f,sizeof(f),1,D); /* test float */ | |
| 268 | + if (f!=tf) | |
| 269 | + { | |
| 270 | + Byte* p=(Byte*)&f; /* TODO: need union? */ | |
| 271 | + Byte t; | |
| 272 | + swapfloat=1; | |
| 273 | + t=p[0]; p[0]=p[3]; p[3]=t; | |
| 274 | + t=p[1]; p[1]=p[2]; p[2]=t; | |
| 275 | + if (f!=tf) /* TODO: try another perm? */ | |
| 276 | + lua_error("different float representation"); | |
| 277 | + else | |
| 278 | + warn("different byte order in floats"); | |
| 279 | + } | |
| 280 | +} | |
| 281 | + | |
| 282 | +static void LoadChunk(FILE* D) | |
| 283 | +{ | |
| 284 | + LoadHeader(D); | |
| 285 | + while (1) | |
| 286 | + { | |
| 287 | + int c=getc(D); | |
| 288 | + if (c==ID_FUN) LoadFunction(D); else { ungetc(c,D); break; } | |
| 289 | + } | |
| 290 | +} | |
| 291 | + | |
| 292 | +/* | |
| 293 | +** load one chunk from a file. | |
| 294 | +** return list of functions found, headed by main, or NULL at EOF. | |
| 295 | +*/ | |
| 296 | +TFunc* luaI_undump1(FILE* D) | |
| 297 | +{ | |
| 298 | + while (1) | |
| 299 | + { | |
| 300 | + int c=getc(D); | |
| 301 | + if (c==ID_CHUNK) | |
| 302 | + { | |
| 303 | + LoadChunk(D); | |
| 304 | + return Main; | |
| 305 | + } | |
| 306 | + else if (c==EOF) | |
| 307 | + return NULL; | |
| 308 | + else | |
| 309 | + lua_error("not a lua binary file"); | |
| 310 | + } | |
| 311 | +} | |
| 312 | + | |
| 313 | +/* | |
| 314 | +** load and run all chunks in a file | |
| 315 | +*/ | |
| 316 | +int luaI_undump(FILE* D) | |
| 317 | +{ | |
| 318 | + TFunc* m; | |
| 319 | + while ((m=luaI_undump1(D))) | |
| 320 | + { | |
| 321 | + int status=luaI_dorun(m); | |
| 322 | + luaI_freefunc(m); | |
| 323 | + if (status!=0) return status; | |
| 324 | + } | |
| 325 | + return 0; | |
| 326 | +} | |
| @@ -0,0 +1,23 @@ | ||
| 1 | +/* | |
| 2 | +** undump.h | |
| 3 | +** definitions for lua decompiler | |
| 4 | +** $Id: undump.h,v 1.2 1996/03/11 21:59:41 lhf Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#include "func.h" | |
| 8 | + | |
| 9 | +#define IsMain(f) (f->lineDefined==0) | |
| 10 | + | |
| 11 | +/* definitions for chunk headers */ | |
| 12 | + | |
| 13 | +#define ID_CHUNK 27 /* ESC */ | |
| 14 | +#define ID_FUN 'F' | |
| 15 | +#define ID_VAR 'V' | |
| 16 | +#define ID_STR 'S' | |
| 17 | +#define SIGNATURE "Lua" | |
| 18 | +#define VERSION 0x23 /* 2.3 */ | |
| 19 | +#define TEST_WORD 0x1234 /* a word for testing byte ordering */ | |
| 20 | +#define TEST_FLOAT 0.123456789e-23 /* a float for testing representation */ | |
| 21 | + | |
| 22 | +TFunc* luaI_undump1(FILE* D); /* load one chunk */ | |
| 23 | +int luaI_undump(FILE* D); /* load all chunks */ | |