Showing the changes to src (33 of 78 files). Show all
Unified · Split
| @@ -4,19 +4,23 @@ LUA= .. · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | include $(LUA)/config |
| 6 | 6 | |
| 7 | −OBJS= fallback.o\ | |
| 7 | +OBJS= auxlib.o\ | |
| 8 | + fallback.o\ | |
| 8 | 9 | func.o\ |
| 9 | 10 | hash.o\ |
| 10 | 11 | inout.o\ |
| 11 | 12 | lex.o\ |
| 12 | − mem.o\ | |
| 13 | + luamem.o\ | |
| 13 | 14 | opcode.o\ |
| 14 | 15 | parser.o\ |
| 15 | 16 | table.o\ |
| 16 | 17 | tree.o\ |
| 17 | − undump.o | |
| 18 | + undump.o\ | |
| 19 | + zio.o | |
| 18 | 20 | |
| 19 | −SRCS= fallback.c\ | |
| 21 | +SRCS= auxlib.c\ | |
| 22 | + auxlib.h\ | |
| 23 | + fallback.c\ | |
| 20 | 24 | fallback.h\ |
| 21 | 25 | func.c\ |
| 22 | 26 | func.h\ |
| @@ -26,8 +30,8 @@ SRCS= fallback.c\ · 3 unmodified lines | ||
| 26 | 30 | inout.h\ |
| 27 | 31 | lex.c\ |
| 28 | 32 | lex.h\ |
| 29 | − mem.c\ | |
| 30 | − mem.h\ | |
| 33 | + luamem.c\ | |
| 34 | + luamem.h\ | |
| 31 | 35 | opcode.c\ |
| 32 | 36 | opcode.h\ |
| 33 | 37 | parser.c\ |
| @@ -39,6 +43,8 @@ SRCS= fallback.c\ · 5 unmodified lines | ||
| 39 | 43 | types.h\ |
| 40 | 44 | undump.c\ |
| 41 | 45 | undump.h\ |
| 46 | + zio.c\ | |
| 47 | + zio.h\ | |
| 42 | 48 | lua.stx |
| 43 | 49 | |
| 44 | 50 | SLIB= $(LIB)/liblua.a |
| @@ -0,0 +1,81 @@ | ||
| 1 | +char *rcs_auxlib="$Id: auxlib.c,v 1.5 1997/04/14 15:30:03 roberto Exp $"; | |
| 2 | + | |
| 3 | +#include <stdio.h> | |
| 4 | +#include <stdarg.h> | |
| 5 | +#include <string.h> | |
| 6 | + | |
| 7 | +#include "lua.h" | |
| 8 | +#include "auxlib.h" | |
| 9 | +#include "luadebug.h" | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | +int luaI_findstring (char *name, char *list[]) | |
| 14 | +{ | |
| 15 | + int i; | |
| 16 | + for (i=0; list[i]; i++) | |
| 17 | + if (strcmp(list[i], name) == 0) | |
| 18 | + return i; | |
| 19 | + return -1; /* name not found */ | |
| 20 | +} | |
| 21 | + | |
| 22 | + | |
| 23 | +void luaL_arg_check(int cond, int numarg, char *extramsg) | |
| 24 | +{ | |
| 25 | + if (!cond) { | |
| 26 | + char *funcname; | |
| 27 | + lua_getobjname(lua_stackedfunction(0), &funcname); | |
| 28 | + if (funcname == NULL) | |
| 29 | + funcname = "???"; | |
| 30 | + if (extramsg == NULL) | |
| 31 | + luaL_verror("bad argument #%d to function `%s'", numarg, funcname); | |
| 32 | + else | |
| 33 | + luaL_verror("bad argument #%d to function `%s' (%s)", | |
| 34 | + numarg, funcname, extramsg); | |
| 35 | + } | |
| 36 | +} | |
| 37 | + | |
| 38 | +char *luaL_check_string (int numArg) | |
| 39 | +{ | |
| 40 | + lua_Object o = lua_getparam(numArg); | |
| 41 | + luaL_arg_check(lua_isstring(o), numArg, "string expected"); | |
| 42 | + return lua_getstring(o); | |
| 43 | +} | |
| 44 | + | |
| 45 | +char *luaL_opt_string (int numArg, char *def) | |
| 46 | +{ | |
| 47 | + return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | |
| 48 | + luaL_check_string(numArg); | |
| 49 | +} | |
| 50 | + | |
| 51 | +double luaL_check_number (int numArg) | |
| 52 | +{ | |
| 53 | + lua_Object o = lua_getparam(numArg); | |
| 54 | + luaL_arg_check(lua_isnumber(o), numArg, "number expected"); | |
| 55 | + return lua_getnumber(o); | |
| 56 | +} | |
| 57 | + | |
| 58 | + | |
| 59 | +double luaL_opt_number (int numArg, double def) | |
| 60 | +{ | |
| 61 | + return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | |
| 62 | + luaL_check_number(numArg); | |
| 63 | +} | |
| 64 | + | |
| 65 | +void luaL_openlib (struct luaL_reg *l, int n) | |
| 66 | +{ | |
| 67 | + int i; | |
| 68 | + for (i=0; i<n; i++) | |
| 69 | + lua_register(l[i].name, l[i].func); | |
| 70 | +} | |
| 71 | + | |
| 72 | + | |
| 73 | +void luaL_verror (char *fmt, ...) | |
| 74 | +{ | |
| 75 | + char buff[1000]; | |
| 76 | + va_list argp; | |
| 77 | + va_start(argp, fmt); | |
| 78 | + vsprintf(buff, fmt, argp); | |
| 79 | + va_end(argp); | |
| 80 | + lua_error(buff); | |
| 81 | +} | |
| @@ -0,0 +1,30 @@ | ||
| 1 | +/* | |
| 2 | +** $Id: auxlib.h,v 1.3 1997/04/07 14:48:53 roberto Exp $ | |
| 3 | +*/ | |
| 4 | + | |
| 5 | +#ifndef auxlib_h | |
| 6 | +#define auxlib_h | |
| 7 | + | |
| 8 | +#include "lua.h" | |
| 9 | + | |
| 10 | +struct luaL_reg { | |
| 11 | + char *name; | |
| 12 | + lua_CFunction func; | |
| 13 | +}; | |
| 14 | + | |
| 15 | +void luaL_openlib (struct luaL_reg *l, int n); | |
| 16 | +void luaL_arg_check(int cond, int numarg, char *extramsg); | |
| 17 | +char *luaL_check_string (int numArg); | |
| 18 | +char *luaL_opt_string (int numArg, char *def); | |
| 19 | +double luaL_check_number (int numArg); | |
| 20 | +double luaL_opt_number (int numArg, double def); | |
| 21 | +void luaL_verror (char *fmt, ...); | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | +/* -- private part (only for Lua modules */ | |
| 26 | + | |
| 27 | +int luaI_findstring (char *name, char *list[]); | |
| 28 | + | |
| 29 | + | |
| 30 | +#endif | |
| @@ -3,130 +3,37 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_fallback="$Id: fallback.c,v 1.25 1996/04/25 14:10:00 roberto Exp $"; | |
| 6 | +char *rcs_fallback="$Id: fallback.c,v 2.9 1997/06/23 18:27:53 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <string.h> |
| 10 | 10 | |
| 11 | −#include "mem.h" | |
| 11 | +#include "auxlib.h" | |
| 12 | +#include "luamem.h" | |
| 12 | 13 | #include "fallback.h" |
| 13 | 14 | #include "opcode.h" |
| 14 | 15 | #include "lua.h" |
| 15 | 16 | #include "table.h" |
| 17 | +#include "tree.h" | |
| 18 | +#include "hash.h" | |
| 16 | 19 | |
| 17 | 20 | |
| 18 | −static void errorFB (void); | |
| 19 | −static void indexFB (void); | |
| 20 | −static void gettableFB (void); | |
| 21 | −static void arithFB (void); | |
| 22 | −static void concatFB (void); | |
| 23 | −static void orderFB (void); | |
| 24 | −static void GDFB (void); | |
| 25 | −static void funcFB (void); | |
| 26 | 21 | |
| 27 | − | |
| 28 | −/* | |
| 29 | −** Warning: This list must be in the same order as the #define's | |
| 30 | −*/ | |
| 31 | −struct FB luaI_fallBacks[] = { | |
| 32 | −{"error", {LUA_T_CFUNCTION, {errorFB}}, 1, 0}, | |
| 33 | −{"index", {LUA_T_CFUNCTION, {indexFB}}, 2, 1}, | |
| 34 | −{"gettable", {LUA_T_CFUNCTION, {gettableFB}}, 2, 1}, | |
| 35 | −{"arith", {LUA_T_CFUNCTION, {arithFB}}, 3, 1}, | |
| 36 | −{"order", {LUA_T_CFUNCTION, {orderFB}}, 3, 1}, | |
| 37 | −{"concat", {LUA_T_CFUNCTION, {concatFB}}, 2, 1}, | |
| 38 | −{"settable", {LUA_T_CFUNCTION, {gettableFB}}, 3, 0}, | |
| 39 | −{"gc", {LUA_T_CFUNCTION, {GDFB}}, 1, 0}, | |
| 40 | −{"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1}, | |
| 41 | − /* no fixed number of params or results */ | |
| 42 | −{"getglobal", {LUA_T_CFUNCTION, {indexFB}}, 1, 1} | |
| 43 | − /* same default behavior of index FB */ | |
| 44 | −}; | |
| 45 | − | |
| 46 | −#define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) | |
| 47 | − | |
| 48 | −void luaI_setfallback (void) | |
| 49 | −{ | |
| 50 | − int i; | |
| 51 | − char *name = lua_getstring(lua_getparam(1)); | |
| 52 | − lua_Object func = lua_getparam(2); | |
| 53 | − if (name == NULL || !lua_isfunction(func)) | |
| 54 | − lua_error("incorrect argument to function `setfallback'"); | |
| 55 | − for (i=0; i<N_FB; i++) | |
| 56 | − { | |
| 57 | − if (strcmp(luaI_fallBacks[i].kind, name) == 0) | |
| 58 | − { | |
| 59 | − luaI_pushobject(&luaI_fallBacks[i].function); | |
| 60 | − luaI_fallBacks[i].function = *luaI_Address(func); | |
| 61 | − return; | |
| 62 | − } | |
| 63 | − } | |
| 64 | − /* name not found */ | |
| 65 | − lua_error("incorrect argument to function `setfallback'"); | |
| 66 | −} | |
| 67 | − | |
| 68 | − | |
| 69 | −static void errorFB (void) | |
| 70 | −{ | |
| 71 | − lua_Object o = lua_getparam(1); | |
| 72 | − if (lua_isstring(o)) | |
| 73 | − fprintf (stderr, "lua: %s\n", lua_getstring(o)); | |
| 74 | − else | |
| 75 | − fprintf(stderr, "lua: unknown error\n"); | |
| 76 | −} | |
| 77 | − | |
| 78 | − | |
| 79 | −static void indexFB (void) | |
| 80 | −{ | |
| 81 | − lua_pushnil(); | |
| 82 | −} | |
| 83 | − | |
| 84 | − | |
| 85 | −static void gettableFB (void) | |
| 86 | −{ | |
| 87 | − lua_error("indexed expression not a table"); | |
| 88 | −} | |
| 89 | − | |
| 90 | − | |
| 91 | −static void arithFB (void) | |
| 92 | −{ | |
| 93 | − lua_error("unexpected type at conversion to number"); | |
| 94 | −} | |
| 95 | − | |
| 96 | −static void concatFB (void) | |
| 97 | −{ | |
| 98 | − lua_error("unexpected type at conversion to string"); | |
| 99 | −} | |
| 100 | − | |
| 101 | − | |
| 102 | −static void orderFB (void) | |
| 103 | −{ | |
| 104 | − lua_error("unexpected type at comparison"); | |
| 105 | −} | |
| 106 | − | |
| 107 | −static void GDFB (void) { } | |
| 108 | − | |
| 109 | −static void funcFB (void) | |
| 110 | −{ | |
| 111 | − lua_error("call expression not a function"); | |
| 112 | −} | |
| 113 | − | |
| 114 | − | |
| 115 | −/* | |
| 22 | +/* ------------------------------------------- | |
| 116 | 23 | ** Reference routines |
| 117 | 24 | */ |
| 118 | 25 | |
| 119 | 26 | static struct ref { |
| 120 | − Object o; | |
| 27 | + TObject o; | |
| 121 | 28 | enum {LOCK, HOLD, FREE, COLLECTED} status; |
| 122 | 29 | } *refArray = NULL; |
| 123 | 30 | static int refSize = 0; |
| 124 | 31 | |
| 125 | −int luaI_ref (Object *object, int lock) | |
| 32 | +int luaI_ref (TObject *object, int lock) | |
| 126 | 33 | { |
| 127 | 34 | int i; |
| 128 | 35 | int oldSize; |
| 129 | − if (tag(object) == LUA_T_NIL) | |
| 36 | + if (ttype(object) == LUA_T_NIL) | |
| 130 | 37 | return -1; /* special ref for nil */ |
| 131 | 38 | for (i=0; i<refSize; i++) |
| 132 | 39 | if (refArray[i].status == FREE) |
| @@ -151,9 +58,9 @@ void lua_unref (int ref) · 18 unmodified lines | ||
| 151 | 58 | } |
| 152 | 59 | |
| 153 | 60 | |
| 154 | −Object *luaI_getref (int ref) | |
| 61 | +TObject *luaI_getref (int ref) | |
| 155 | 62 | { |
| 156 | − static Object nul = {LUA_T_NIL, {0}}; | |
| 63 | + static TObject nul = {LUA_T_NIL, {0}}; | |
| 157 | 64 | if (ref == -1) |
| 158 | 65 | return &nul; |
| 159 | 66 | if (ref >= 0 && ref < refSize && |
| @@ -164,7 +71,7 @@ Object *luaI_getref (int ref) · 4 unmodified lines | ||
| 164 | 71 | } |
| 165 | 72 | |
| 166 | 73 | |
| 167 | −void luaI_travlock (int (*fn)(Object *)) | |
| 74 | +void luaI_travlock (int (*fn)(TObject *)) | |
| 168 | 75 | { |
| 169 | 76 | int i; |
| 170 | 77 | for (i=0; i<refSize; i++) |
| @@ -181,11 +88,281 @@ void luaI_invalidaterefs (void) · 10 unmodified lines | ||
| 181 | 88 | refArray[i].status = COLLECTED; |
| 182 | 89 | } |
| 183 | 90 | |
| 184 | −char *luaI_travfallbacks (int (*fn)(Object *)) | |
| 91 | + | |
| 92 | +/* ------------------------------------------- | |
| 93 | +* Internal Methods | |
| 94 | +*/ | |
| 95 | + | |
| 96 | +char *luaI_eventname[] = { /* ORDER IM */ | |
| 97 | + "gettable", "settable", "index", "getglobal", "setglobal", "add", | |
| 98 | + "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge", | |
| 99 | + "concat", "gc", "function", | |
| 100 | + NULL | |
| 101 | +}; | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | +static int luaI_checkevent (char *name, char *list[]) | |
| 106 | +{ | |
| 107 | + int e = luaI_findstring(name, list); | |
| 108 | + if (e < 0) | |
| 109 | + luaL_verror("`%s' is not a valid event name", name); | |
| 110 | + return e; | |
| 111 | +} | |
| 112 | + | |
| 113 | + | |
| 114 | +struct IM *luaI_IMtable = NULL; | |
| 115 | + | |
| 116 | +static int IMtable_size = 0; | |
| 117 | +static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ | |
| 118 | + | |
| 119 | + | |
| 120 | +/* events in LUA_T_LINE are all allowed, since this is used as a | |
| 121 | +* 'placeholder' for "default" fallbacks | |
| 122 | +*/ | |
| 123 | +static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */ | |
| 124 | +{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ | |
| 125 | +{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_LINE */ | |
| 126 | +{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_CMARK */ | |
| 127 | +{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_MARK */ | |
| 128 | +{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CFUNCTION */ | |
| 129 | +{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_FUNCTION */ | |
| 130 | +{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_ARRAY */ | |
| 131 | +{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ | |
| 132 | +{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ | |
| 133 | +{1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ | |
| 134 | +}; | |
| 135 | + | |
| 136 | +static int validevent (lua_Type t, int e) | |
| 137 | +{ /* ORDER LUA_T */ | |
| 138 | + return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; | |
| 139 | +} | |
| 140 | + | |
| 141 | + | |
| 142 | +static void init_entry (int tag) | |
| 185 | 143 | { |
| 186 | 144 | int i; |
| 187 | − for (i=0; i<N_FB; i++) | |
| 188 | − if (fn(&luaI_fallBacks[i].function)) | |
| 189 | − return luaI_fallBacks[i].kind; | |
| 145 | + for (i=0; i<IM_N; i++) | |
| 146 | + ttype(luaI_getim(tag, i)) = LUA_T_NIL; | |
| 147 | +} | |
| 148 | + | |
| 149 | +void luaI_initfallbacks (void) | |
| 150 | +{ | |
| 151 | + if (luaI_IMtable == NULL) { | |
| 152 | + int i; | |
| 153 | + IMtable_size = NUM_TYPES+10; | |
| 154 | + luaI_IMtable = newvector(IMtable_size, struct IM); | |
| 155 | + for (i=LUA_T_NIL; i<=LUA_T_USERDATA; i++) | |
| 156 | + init_entry(i); | |
| 157 | + } | |
| 158 | +} | |
| 159 | + | |
| 160 | +int lua_newtag (void) | |
| 161 | +{ | |
| 162 | + --last_tag; | |
| 163 | + if ((-last_tag) >= IMtable_size) { | |
| 164 | + luaI_initfallbacks(); | |
| 165 | + IMtable_size = growvector(&luaI_IMtable, IMtable_size, | |
| 166 | + struct IM, memEM, MAX_INT); | |
| 167 | + } | |
| 168 | + init_entry(last_tag); | |
| 169 | + return last_tag; | |
| 170 | +} | |
| 171 | + | |
| 172 | + | |
| 173 | +static void checktag (int tag) | |
| 174 | +{ | |
| 175 | + if (!(last_tag <= tag && tag <= 0)) | |
| 176 | + luaL_verror("%d is not a valid tag", tag); | |
| 177 | +} | |
| 178 | + | |
| 179 | +void luaI_realtag (int tag) | |
| 180 | +{ | |
| 181 | + if (!(last_tag <= tag && tag < LUA_T_NIL)) | |
| 182 | + luaL_verror("tag %d is not result of `newtag'", tag); | |
| 183 | +} | |
| 184 | + | |
| 185 | + | |
| 186 | +void luaI_settag (int tag, TObject *o) | |
| 187 | +{ | |
| 188 | + luaI_realtag(tag); | |
| 189 | + switch (ttype(o)) { | |
| 190 | + case LUA_T_ARRAY: | |
| 191 | + o->value.a->htag = tag; | |
| 192 | + break; | |
| 193 | + case LUA_T_USERDATA: | |
| 194 | + o->value.ts->tag = tag; | |
| 195 | + break; | |
| 196 | + default: | |
| 197 | + luaL_verror("cannot change the tag of a %s", luaI_typenames[-ttype(o)]); | |
| 198 | + } | |
| 199 | +} | |
| 200 | + | |
| 201 | + | |
| 202 | +int luaI_efectivetag (TObject *o) | |
| 203 | +{ | |
| 204 | + lua_Type t = ttype(o); | |
| 205 | + if (t == LUA_T_USERDATA) { | |
| 206 | + int tag = o->value.ts->tag; | |
| 207 | + return (tag >= 0) ? LUA_T_USERDATA : tag; | |
| 208 | + } | |
| 209 | + else if (t == LUA_T_ARRAY) | |
| 210 | + return o->value.a->htag; | |
| 211 | + else return t; | |
| 212 | +} | |
| 213 | + | |
| 214 | + | |
| 215 | +void luaI_gettagmethod (void) | |
| 216 | +{ | |
| 217 | + int t = (int)luaL_check_number(1); | |
| 218 | + int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); | |
| 219 | + checktag(t); | |
| 220 | + if (validevent(t, e)) | |
| 221 | + luaI_pushobject(luaI_getim(t,e)); | |
| 222 | +} | |
| 223 | + | |
| 224 | + | |
| 225 | +void luaI_settagmethod (void) | |
| 226 | +{ | |
| 227 | + int t = (int)luaL_check_number(1); | |
| 228 | + int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); | |
| 229 | + lua_Object func = lua_getparam(3); | |
| 230 | + checktag(t); | |
| 231 | + if (!validevent(t, e)) | |
| 232 | + luaL_verror("cannot change internal method `%s' for tag %d", | |
| 233 | + luaI_eventname[e], t); | |
| 234 | + luaL_arg_check(lua_isnil(func) || lua_isfunction(func), | |
| 235 | + 3, "function expected"); | |
| 236 | + luaI_pushobject(luaI_getim(t,e)); | |
| 237 | + *luaI_getim(t, e) = *luaI_Address(func); | |
| 238 | +} | |
| 239 | + | |
| 240 | + | |
| 241 | +static void stderrorim (void) | |
| 242 | +{ | |
| 243 | + lua_Object s = lua_getparam(1); | |
| 244 | + if (lua_isstring(s)) | |
| 245 | + fprintf(stderr, "lua: %s\n", lua_getstring(s)); | |
| 246 | +} | |
| 247 | + | |
| 248 | +static TObject errorim = {LUA_T_CFUNCTION, {stderrorim}}; | |
| 249 | + | |
| 250 | + | |
| 251 | +TObject *luaI_geterrorim (void) | |
| 252 | +{ | |
| 253 | + return &errorim; | |
| 254 | +} | |
| 255 | + | |
| 256 | +void luaI_seterrormethod (void) | |
| 257 | +{ | |
| 258 | + lua_Object func = lua_getparam(1); | |
| 259 | + luaL_arg_check(lua_isnil(func) || lua_isfunction(func), | |
| 260 | + 1, "function expected"); | |
| 261 | + luaI_pushobject(&errorim); | |
| 262 | + errorim = *luaI_Address(func); | |
| 263 | +} | |
| 264 | + | |
| 265 | +char *luaI_travfallbacks (int (*fn)(TObject *)) | |
| 266 | +{ | |
| 267 | + int e; | |
| 268 | + if (fn(&errorim)) | |
| 269 | + return "error"; | |
| 270 | + for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ | |
| 271 | + int t; | |
| 272 | + for (t=0; t>=last_tag; t--) | |
| 273 | + if (fn(luaI_getim(t,e))) | |
| 274 | + return luaI_eventname[e]; | |
| 275 | + } | |
| 190 | 276 | return NULL; |
| 191 | 277 | } |
| 278 | + | |
| 279 | + | |
| 280 | +/* | |
| 281 | +* =================================================================== | |
| 282 | +* compatibility with old fallback system | |
| 283 | +*/ | |
| 284 | +#if LUA_COMPAT2_5 | |
| 285 | + | |
| 286 | +static void errorFB (void) | |
| 287 | +{ | |
| 288 | + lua_Object o = lua_getparam(1); | |
| 289 | + if (lua_isstring(o)) | |
| 290 | + fprintf (stderr, "lua: %s\n", lua_getstring(o)); | |
| 291 | + else | |
| 292 | + fprintf(stderr, "lua: unknown error\n"); | |
| 293 | +} | |
| 294 | + | |
| 295 | + | |
| 296 | +static void nilFB (void) { } | |
| 297 | + | |
| 298 | + | |
| 299 | +static void typeFB (void) | |
| 300 | +{ | |
| 301 | + lua_error("unexpected type"); | |
| 302 | +} | |
| 303 | + | |
| 304 | + | |
| 305 | +static void fillvalids (IMS e, TObject *func) | |
| 306 | +{ | |
| 307 | + int t; | |
| 308 | + for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) | |
| 309 | + if (validevent(t, e)) | |
| 310 | + *luaI_getim(t, e) = *func; | |
| 311 | +} | |
| 312 | + | |
| 313 | + | |
| 314 | +void luaI_setfallback (void) | |
| 315 | +{ | |
| 316 | + static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL}; | |
| 317 | + TObject oldfunc; | |
| 318 | + lua_CFunction replace; | |
| 319 | + char *name = luaL_check_string(1); | |
| 320 | + lua_Object func = lua_getparam(2); | |
| 321 | + luaI_initfallbacks(); | |
| 322 | + luaL_arg_check(lua_isfunction(func), 2, "function expected"); | |
| 323 | + switch (luaI_findstring(name, oldnames)) { | |
| 324 | + case 0: /* old error fallback */ | |
| 325 | + oldfunc = errorim; | |
| 326 | + errorim = *luaI_Address(func); | |
| 327 | + replace = errorFB; | |
| 328 | + break; | |
| 329 | + case 1: /* old getglobal fallback */ | |
| 330 | + oldfunc = *luaI_getim(LUA_T_NIL, IM_GETGLOBAL); | |
| 331 | + *luaI_getim(LUA_T_NIL, IM_GETGLOBAL) = *luaI_Address(func); | |
| 332 | + replace = nilFB; | |
| 333 | + break; | |
| 334 | + case 2: { /* old arith fallback */ | |
| 335 | + int i; | |
| 336 | + oldfunc = *luaI_getim(LUA_T_NUMBER, IM_POW); | |
| 337 | + for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ | |
| 338 | + fillvalids(i, luaI_Address(func)); | |
| 339 | + replace = typeFB; | |
| 340 | + break; | |
| 341 | + } | |
| 342 | + case 3: { /* old order fallback */ | |
| 343 | + int i; | |
| 344 | + oldfunc = *luaI_getim(LUA_T_LINE, IM_LT); | |
| 345 | + for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ | |
| 346 | + fillvalids(i, luaI_Address(func)); | |
| 347 | + replace = typeFB; | |
| 348 | + break; | |
| 349 | + } | |
| 350 | + default: { | |
| 351 | + int e; | |
| 352 | + if ((e = luaI_findstring(name, luaI_eventname)) >= 0) { | |
| 353 | + oldfunc = *luaI_getim(LUA_T_LINE, e); | |
| 354 | + fillvalids(e, luaI_Address(func)); | |
| 355 | + replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; | |
| 356 | + } | |
| 357 | + else { | |
| 358 | + luaL_verror("`%s' is not a valid fallback name", name); | |
| 359 | + replace = NULL; /* to avoid warnings */ | |
| 360 | + } | |
| 361 | + } | |
| 362 | + } | |
| 363 | + if (oldfunc.ttype != LUA_T_NIL) | |
| 364 | + luaI_pushobject(&oldfunc); | |
| 365 | + else | |
| 366 | + lua_pushcfunction(replace); | |
| 367 | +} | |
| 368 | +#endif | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: fallback.h,v 1.13 1996/04/25 14:10:00 roberto Exp $ | |
| 2 | +** $Id: fallback.h,v 1.23 1997/04/24 22:59:57 roberto Exp $ | |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | #ifndef fallback_h |
| @@ -8,30 +8,58 @@ · 2 unmodified lines | ||
| 8 | 8 | #include "lua.h" |
| 9 | 9 | #include "opcode.h" |
| 10 | 10 | |
| 11 | −extern struct FB { | |
| 12 | − char *kind; | |
| 13 | − Object function; | |
| 14 | − int nParams; | |
| 15 | − int nResults; | |
| 16 | −} luaI_fallBacks[]; | |
| 17 | − | |
| 18 | −#define FB_ERROR 0 | |
| 19 | −#define FB_INDEX 1 | |
| 20 | −#define FB_GETTABLE 2 | |
| 21 | −#define FB_ARITH 3 | |
| 22 | −#define FB_ORDER 4 | |
| 23 | −#define FB_CONCAT 5 | |
| 24 | −#define FB_SETTABLE 6 | |
| 25 | −#define FB_GC 7 | |
| 26 | −#define FB_FUNCTION 8 | |
| 27 | −#define FB_GETGLOBAL 9 | |
| 11 | +/* | |
| 12 | +* WARNING: if you change the order of this enumeration, | |
| 13 | +* grep "ORDER IM" | |
| 14 | +*/ | |
| 15 | +typedef enum { | |
| 16 | + IM_GETTABLE = 0, | |
| 17 | + IM_SETTABLE, | |
| 18 | + IM_INDEX, | |
| 19 | + IM_GETGLOBAL, | |
| 20 | + IM_SETGLOBAL, | |
| 21 | + IM_ADD, | |
| 22 | + IM_SUB, | |
| 23 | + IM_MUL, | |
| 24 | + IM_DIV, | |
| 25 | + IM_POW, | |
| 26 | + IM_UNM, | |
| 27 | + IM_LT, | |
| 28 | + IM_LE, | |
| 29 | + IM_GT, | |
| 30 | + IM_GE, | |
| 31 | + IM_CONCAT, | |
| 32 | + IM_GC, | |
| 33 | + IM_FUNCTION | |
| 34 | +} IMS; | |
| 35 | + | |
| 36 | +#define IM_N 18 | |
| 37 | + | |
| 38 | + | |
| 39 | +extern struct IM { | |
| 40 | + TObject int_method[IM_N]; | |
| 41 | +} *luaI_IMtable; | |
| 42 | + | |
| 43 | +extern char *luaI_eventname[]; | |
| 44 | + | |
| 45 | +#define luaI_getim(tag,event) (&luaI_IMtable[-(tag)].int_method[event]) | |
| 46 | +#define luaI_getimbyObj(o,e) (luaI_getim(luaI_efectivetag(o),(e))) | |
| 28 | 47 | |
| 29 | 48 | void luaI_setfallback (void); |
| 30 | −int luaI_ref (Object *object, int lock); | |
| 31 | −Object *luaI_getref (int ref); | |
| 32 | −void luaI_travlock (int (*fn)(Object *)); | |
| 49 | +int luaI_ref (TObject *object, int lock); | |
| 50 | +TObject *luaI_getref (int ref); | |
| 51 | +void luaI_travlock (int (*fn)(TObject *)); | |
| 33 | 52 | void luaI_invalidaterefs (void); |
| 34 | −char *luaI_travfallbacks (int (*fn)(Object *)); | |
| 53 | +char *luaI_travfallbacks (int (*fn)(TObject *)); | |
| 54 | + | |
| 55 | +void luaI_settag (int tag, TObject *o); | |
| 56 | +void luaI_realtag (int tag); | |
| 57 | +TObject *luaI_geterrorim (void); | |
| 58 | +int luaI_efectivetag (TObject *o); | |
| 59 | +void luaI_settagmethod (void); | |
| 60 | +void luaI_gettagmethod (void); | |
| 61 | +void luaI_seterrormethod (void); | |
| 62 | +void luaI_initfallbacks (void); | |
| 35 | 63 | |
| 36 | 64 | #endif |
| 37 | 65 | |
| @@ -2,9 +2,10 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | #include "luadebug.h" |
| 4 | 4 | #include "table.h" |
| 5 | −#include "mem.h" | |
| 5 | +#include "luamem.h" | |
| 6 | 6 | #include "func.h" |
| 7 | 7 | #include "opcode.h" |
| 8 | +#include "inout.h" | |
| 8 | 9 | |
| 9 | 10 | |
| 10 | 11 | static TFunc *function_root = NULL; |
| @@ -23,7 +24,7 @@ void luaI_initTFunc (TFunc *f) · 12 unmodified lines | ||
| 23 | 24 | f->size = 0; |
| 24 | 25 | f->code = NULL; |
| 25 | 26 | f->lineDefined = 0; |
| 26 | − f->fileName = NULL; | |
| 27 | + f->fileName = lua_parsedfile; | |
| 27 | 28 | f->locvars = NULL; |
| 28 | 29 | } |
| 29 | 30 | |
| @@ -49,47 +50,56 @@ void luaI_freefunc (TFunc *f) · 19 unmodified lines | ||
| 49 | 50 | luaI_free (f); |
| 50 | 51 | } |
| 51 | 52 | |
| 53 | + | |
| 54 | +void luaI_funcfree (TFunc *l) | |
| 55 | +{ | |
| 56 | + while (l) { | |
| 57 | + TFunc *next = l->next; | |
| 58 | + luaI_freefunc(l); | |
| 59 | + l = next; | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 52 | 63 | /* |
| 53 | 64 | ** Garbage collection function. |
| 54 | −** This function traverse the function list freeing unindexed functions | |
| 55 | 65 | */ |
| 56 | −Long luaI_funccollector (void) | |
| 66 | +TFunc *luaI_funccollector (long *acum) | |
| 57 | 67 | { |
| 58 | 68 | TFunc *curr = function_root; |
| 59 | 69 | TFunc *prev = NULL; |
| 60 | − Long counter = 0; | |
| 61 | − while (curr) | |
| 62 | − { | |
| 70 | + TFunc *frees = NULL; | |
| 71 | + long counter = 0; | |
| 72 | + while (curr) { | |
| 63 | 73 | TFunc *next = curr->next; |
| 64 | − if (!curr->marked) | |
| 65 | − { | |
| 74 | + if (!curr->marked) { | |
| 66 | 75 | if (prev == NULL) |
| 67 | 76 | function_root = next; |
| 68 | 77 | else |
| 69 | 78 | prev->next = next; |
| 70 | − luaI_freefunc (curr); | |
| 79 | + curr->next = frees; | |
| 80 | + frees = curr; | |
| 71 | 81 | ++counter; |
| 72 | 82 | } |
| 73 | − else | |
| 74 | − { | |
| 83 | + else { | |
| 75 | 84 | curr->marked = 0; |
| 76 | 85 | prev = curr; |
| 77 | 86 | } |
| 78 | 87 | curr = next; |
| 79 | 88 | } |
| 80 | − return counter; | |
| 89 | + *acum += counter; | |
| 90 | + return frees; | |
| 81 | 91 | } |
| 82 | 92 | |
| 83 | 93 | |
| 84 | 94 | void lua_funcinfo (lua_Object func, char **filename, int *linedefined) |
| 85 | 95 | { |
| 86 | − Object *f = luaI_Address(func); | |
| 87 | − if (f->tag == LUA_T_MARK || f->tag == LUA_T_FUNCTION) | |
| 96 | + TObject *f = luaI_Address(func); | |
| 97 | + if (f->ttype == LUA_T_MARK || f->ttype == LUA_T_FUNCTION) | |
| 88 | 98 | { |
| 89 | 99 | *filename = f->value.tf->fileName; |
| 90 | 100 | *linedefined = f->value.tf->lineDefined; |
| 91 | 101 | } |
| 92 | − else if (f->tag == LUA_T_CMARK || f->tag == LUA_T_CFUNCTION) | |
| 102 | + else if (f->ttype == LUA_T_CMARK || f->ttype == LUA_T_CFUNCTION) | |
| 93 | 103 | { |
| 94 | 104 | *filename = "(C)"; |
| 95 | 105 | *linedefined = -1; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: func.h,v 1.8 1996/03/14 15:54:20 roberto Exp $ | |
| 2 | +** $Id: func.h,v 1.9 1997/05/14 18:38:29 roberto Exp $ | |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | #ifndef func_h |
| @@ -30,7 +30,8 @@ typedef struct TFunc · 24 unmodified lines | ||
| 30 | 30 | LocVar *locvars; |
| 31 | 31 | } TFunc; |
| 32 | 32 | |
| 33 | −Long luaI_funccollector (void); | |
| 33 | +TFunc *luaI_funccollector (long *cont); | |
| 34 | +void luaI_funcfree (TFunc *l); | |
| 34 | 35 | void luaI_insertfunction (TFunc *f); |
| 35 | 36 | |
| 36 | 37 | void luaI_initTFunc (TFunc *f); |
| @@ -3,14 +3,15 @@ · 2 unmodified lines | ||
| 3 | 3 | ** hash manager for lua |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_hash="$Id: hash.c,v 2.32 1996/11/18 13:48:44 roberto Exp $"; | |
| 6 | +char *rcs_hash="$Id: hash.c,v 2.43 1997/05/14 18:38:29 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | −#include "mem.h" | |
| 9 | +#include "luamem.h" | |
| 10 | 10 | #include "opcode.h" |
| 11 | 11 | #include "hash.h" |
| 12 | 12 | #include "table.h" |
| 13 | 13 | #include "lua.h" |
| 14 | +#include "auxlib.h" | |
| 14 | 15 | |
| 15 | 16 | |
| 16 | 17 | #define nhash(t) ((t)->nhash) |
| @@ -24,13 +25,15 @@ char *rcs_hash="$Id: hash.c,v 2.32 1996/11/18 13:48:44 roberto Exp $"; · 7 unmodified lines | ||
| 24 | 25 | |
| 25 | 26 | #define REHASH_LIMIT 0.70 /* avoid more than this % full */ |
| 26 | 27 | |
| 28 | +#define TagDefault LUA_T_ARRAY; | |
| 29 | + | |
| 27 | 30 | |
| 28 | 31 | static Hash *listhead = NULL; |
| 29 | 32 | |
| 30 | 33 | |
| 31 | 34 | /* hash dimensions values */ |
| 32 | 35 | static Long dimensions[] = |
| 33 | − {3L, 5L, 7L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, | |
| 36 | + {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, | |
| 34 | 37 | 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L, |
| 35 | 38 | 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT}; |
| 36 | 39 | |
| @@ -46,16 +49,32 @@ int luaI_redimension (int nhash) · 9 unmodified lines | ||
| 46 | 49 | return 0; /* to avoid warnings */ |
| 47 | 50 | } |
| 48 | 51 | |
| 49 | −static int hashindex (Hash *t, Object *ref) /* hash function */ | |
| 52 | + | |
| 53 | +int lua_equalObj (TObject *t1, TObject *t2) | |
| 54 | +{ | |
| 55 | + if (ttype(t1) != ttype(t2)) return 0; | |
| 56 | + switch (ttype(t1)) | |
| 57 | + { | |
| 58 | + case LUA_T_NIL: return 1; | |
| 59 | + case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); | |
| 60 | + case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); | |
| 61 | + case LUA_T_ARRAY: return avalue(t1) == avalue(t2); | |
| 62 | + case LUA_T_FUNCTION: return t1->value.tf == t2->value.tf; | |
| 63 | + case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); | |
| 64 | + default: | |
| 65 | + lua_error("internal error in `lua_equalObj'"); | |
| 66 | + return 0; /* UNREACHEABLE */ | |
| 67 | + } | |
| 68 | +} | |
| 69 | + | |
| 70 | + | |
| 71 | +static long int hashindex (TObject *ref) | |
| 50 | 72 | { |
| 51 | 73 | long int h; |
| 52 | − switch (tag(ref)) { | |
| 53 | − case LUA_T_NIL: | |
| 54 | − lua_error ("unexpected type to index table"); | |
| 55 | − h = 0; /* UNREACHEABLE */ | |
| 74 | + switch (ttype(ref)) { | |
| 56 | 75 | case LUA_T_NUMBER: |
| 57 | 76 | h = (long int)nvalue(ref); break; |
| 58 | − case LUA_T_STRING: | |
| 77 | + case LUA_T_STRING: case LUA_T_USERDATA: | |
| 59 | 78 | h = tsvalue(ref)->hash; break; |
| 60 | 79 | case LUA_T_FUNCTION: |
| 61 | 80 | h = (IntPoint)ref->value.tf; break; |
| @@ -63,38 +82,29 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ · 1 unmodified line | ||
| 63 | 82 | h = (IntPoint)fvalue(ref); break; |
| 64 | 83 | case LUA_T_ARRAY: |
| 65 | 84 | h = (IntPoint)avalue(ref); break; |
| 66 | − default: /* user data */ | |
| 67 | − h = (IntPoint)uvalue(ref); break; | |
| 85 | + default: | |
| 86 | + lua_error ("unexpected type to index table"); | |
| 87 | + h = 0; /* UNREACHEABLE */ | |
| 68 | 88 | } |
| 69 | 89 | if (h < 0) h = -h; |
| 70 | − return h%nhash(t); /* make it a valid index */ | |
| 90 | + return h; | |
| 71 | 91 | } |
| 72 | 92 | |
| 73 | −int lua_equalObj (Object *t1, Object *t2) | |
| 93 | + | |
| 94 | +static int present (Hash *t, TObject *key) | |
| 74 | 95 | { |
| 75 | − if (tag(t1) != tag(t2)) return 0; | |
| 76 | − switch (tag(t1)) | |
| 77 | − { | |
| 78 | − case LUA_T_NIL: return 1; | |
| 79 | − case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); | |
| 80 | − case LUA_T_STRING: return svalue(t1) == svalue(t2); | |
| 81 | − case LUA_T_ARRAY: return avalue(t1) == avalue(t2); | |
| 82 | − case LUA_T_FUNCTION: return t1->value.tf == t2->value.tf; | |
| 83 | − case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); | |
| 84 | − default: return uvalue(t1) == uvalue(t2); | |
| 96 | + long int h = hashindex(key); | |
| 97 | + int tsize = nhash(t); | |
| 98 | + int h1 = h%tsize; | |
| 99 | + TObject *rf = ref(node(t, h1)); | |
| 100 | + if (ttype(rf) != LUA_T_NIL && !lua_equalObj(key, rf)) { | |
| 101 | + int h2 = h%(tsize-2) + 1; | |
| 102 | + do { | |
| 103 | + h1 = (h1+h2)%tsize; | |
| 104 | + rf = ref(node(t, h1)); | |
| 105 | + } while (ttype(rf) != LUA_T_NIL && !lua_equalObj(key, rf)); | |
| 85 | 106 | } |
| 86 | −} | |
| 87 | − | |
| 88 | −static int present (Hash *t, Object *ref) | |
| 89 | −{ | |
| 90 | − int h = hashindex(t, ref); | |
| 91 | − while (tag(ref(node(t, h))) != LUA_T_NIL) | |
| 92 | − { | |
| 93 | − if (lua_equalObj(ref, ref(node(t, h)))) | |
| 94 | − return h; | |
| 95 | − h = (h+1) % nhash(t); | |
| 96 | − } | |
| 97 | − return h; | |
| 107 | + return h1; | |
| 98 | 108 | } |
| 99 | 109 | |
| 100 | 110 | |
| @@ -106,7 +116,7 @@ static Node *hashnodecreate (int nhash) · 5 unmodified lines | ||
| 106 | 116 | int i; |
| 107 | 117 | Node *v = newvector (nhash, Node); |
| 108 | 118 | for (i=0; i<nhash; i++) |
| 109 | − tag(ref(&v[i])) = LUA_T_NIL; | |
| 119 | + ttype(ref(&v[i])) = LUA_T_NIL; | |
| 110 | 120 | return v; |
| 111 | 121 | } |
| 112 | 122 | |
| @@ -121,6 +131,7 @@ static Hash *hashcreate (int nhash) · 8 unmodified lines | ||
| 121 | 131 | nhash(t) = nhash; |
| 122 | 132 | nuse(t) = 0; |
| 123 | 133 | markarray(t) = 0; |
| 134 | + t->htag = TagDefault; | |
| 124 | 135 | return t; |
| 125 | 136 | } |
| 126 | 137 | |
| @@ -146,7 +157,7 @@ void lua_hashmark (Hash *h) · 19 unmodified lines | ||
| 146 | 157 | for (i=0; i<nhash(h); i++) |
| 147 | 158 | { |
| 148 | 159 | Node *n = node(h,i); |
| 149 | − if (tag(ref(n)) != LUA_T_NIL) | |
| 160 | + if (ttype(ref(n)) != LUA_T_NIL) | |
| 150 | 161 | { |
| 151 | 162 | lua_markobject(&n->ref); |
| 152 | 163 | lua_markobject(&n->val); |
| @@ -156,49 +167,50 @@ void lua_hashmark (Hash *h) · 3 unmodified lines | ||
| 156 | 167 | } |
| 157 | 168 | |
| 158 | 169 | |
| 159 | −static void call_fallbacks (void) | |
| 170 | +void luaI_hashcallIM (Hash *l) | |
| 160 | 171 | { |
| 161 | − Hash *curr_array; | |
| 162 | − Object t; | |
| 163 | − tag(&t) = LUA_T_ARRAY; | |
| 164 | − for (curr_array = listhead; curr_array; curr_array = curr_array->next) | |
| 165 | − if (markarray(curr_array) != 1) | |
| 166 | − { | |
| 167 | − avalue(&t) = curr_array; | |
| 168 | − luaI_gcFB(&t); | |
| 169 | − } | |
| 170 | − tag(&t) = LUA_T_NIL; | |
| 171 | − luaI_gcFB(&t); /* end of list */ | |
| 172 | + TObject t; | |
| 173 | + ttype(&t) = LUA_T_ARRAY; | |
| 174 | + for (; l; l=l->next) { | |
| 175 | + avalue(&t) = l; | |
| 176 | + luaI_gcIM(&t); | |
| 177 | + } | |
| 172 | 178 | } |
| 173 | 179 | |
| 174 | − | |
| 175 | −/* | |
| 176 | −** Garbage collection to arrays | |
| 177 | −** Delete all unmarked arrays. | |
| 178 | −*/ | |
| 179 | −Long lua_hashcollector (void) | |
| 180 | + | |
| 181 | +void luaI_hashfree (Hash *frees) | |
| 180 | 182 | { |
| 181 | − Hash *curr_array = listhead, *prev = NULL; | |
| 182 | − Long counter = 0; | |
| 183 | − call_fallbacks(); | |
| 184 | − while (curr_array != NULL) | |
| 185 | − { | |
| 186 | − Hash *next = curr_array->next; | |
| 187 | − if (markarray(curr_array) != 1) | |
| 188 | − { | |
| 189 | − if (prev == NULL) listhead = next; | |
| 190 | − else prev->next = next; | |
| 191 | − hashdelete(curr_array); | |
| 192 | − ++counter; | |
| 183 | + while (frees) { | |
| 184 | + Hash *next = frees->next; | |
| 185 | + hashdelete(frees); | |
| 186 | + frees = next; | |
| 193 | 187 | } |
| 194 | − else | |
| 195 | − { | |
| 196 | − markarray(curr_array) = 0; | |
| 197 | − prev = curr_array; | |
| 188 | +} | |
| 189 | + | |
| 190 | + | |
| 191 | +Hash *luaI_hashcollector (long *acum) | |
| 192 | +{ | |
| 193 | + Hash *curr_array = listhead, *prev = NULL, *frees = NULL; | |
| 194 | + long counter = 0; | |
| 195 | + while (curr_array != NULL) { | |
| 196 | + Hash *next = curr_array->next; | |
| 197 | + if (markarray(curr_array) != 1) { | |
| 198 | + if (prev == NULL) | |
| 199 | + listhead = next; | |
| 200 | + else | |
| 201 | + prev->next = next; | |
| 202 | + curr_array->next = frees; | |
| 203 | + frees = curr_array; | |
| 204 | + ++counter; | |
| 205 | + } | |
| 206 | + else { | |
| 207 | + markarray(curr_array) = 0; | |
| 208 | + prev = curr_array; | |
| 209 | + } | |
| 210 | + curr_array = next; | |
| 198 | 211 | } |
| 199 | − curr_array = next; | |
| 200 | − } | |
| 201 | − return counter; | |
| 212 | + *acum += counter; | |
| 213 | + return frees; | |
| 202 | 214 | } |
| 203 | 215 | |
| 204 | 216 | |
| @@ -220,32 +232,45 @@ Hash *lua_createarray (int nhash) · 15 unmodified lines | ||
| 220 | 232 | |
| 221 | 233 | |
| 222 | 234 | /* |
| 223 | −** Re-hash | |
| 235 | +** Rehash: | |
| 236 | +** Check if table has deleted slots. It it has, it does not need to | |
| 237 | +** grow, since rehash will reuse them. | |
| 224 | 238 | */ |
| 239 | +static int emptyslots (Hash *t) | |
| 240 | +{ | |
| 241 | + int i; | |
| 242 | + for (i=nhash(t)-1; i>=0; i--) { | |
| 243 | + Node *n = node(t, i); | |
| 244 | + if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) == LUA_T_NIL) | |
| 245 | + return 1; | |
| 246 | + } | |
| 247 | + return 0; | |
| 248 | +} | |
| 249 | + | |
| 225 | 250 | static void rehash (Hash *t) |
| 226 | 251 | { |
| 227 | − int i; | |
| 228 | − int nold = nhash(t); | |
| 229 | − Node *vold = nodevector(t); | |
| 230 | − nhash(t) = luaI_redimension(nhash(t)); | |
| 231 | − nodevector(t) = hashnodecreate(nhash(t)); | |
| 232 | − for (i=0; i<nold; i++) | |
| 233 | − { | |
| 234 | − Node *n = vold+i; | |
| 235 | − if (tag(ref(n)) != LUA_T_NIL && tag(val(n)) != LUA_T_NIL) | |
| 236 | − *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */ | |
| 237 | − } | |
| 238 | − luaI_free(vold); | |
| 252 | + int nold = nhash(t); | |
| 253 | + Node *vold = nodevector(t); | |
| 254 | + int i; | |
| 255 | + if (!emptyslots(t)) | |
| 256 | + nhash(t) = luaI_redimension(nhash(t)); | |
| 257 | + nodevector(t) = hashnodecreate(nhash(t)); | |
| 258 | + for (i=0; i<nold; i++) { | |
| 259 | + Node *n = vold+i; | |
| 260 | + if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL) | |
| 261 | + *node(t, present(t, ref(n))) = *n; /* copy old node to new hash */ | |
| 262 | + } | |
| 263 | + luaI_free(vold); | |
| 239 | 264 | } |
| 240 | 265 | |
| 241 | 266 | /* |
| 242 | 267 | ** If the hash node is present, return its pointer, otherwise return |
| 243 | 268 | ** null. |
| 244 | 269 | */ |
| 245 | −Object *lua_hashget (Hash *t, Object *ref) | |
| 270 | +TObject *lua_hashget (Hash *t, TObject *ref) | |
| 246 | 271 | { |
| 247 | 272 | int h = present(t, ref); |
| 248 | − if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); | |
| 273 | + if (ttype(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); | |
| 249 | 274 | else return NULL; |
| 250 | 275 | } |
| 251 | 276 | |
| @@ -254,25 +279,19 @@ Object *lua_hashget (Hash *t, Object *ref) · 2 unmodified lines | ||
| 254 | 279 | ** If the hash node is present, return its pointer, otherwise create a new |
| 255 | 280 | ** node for the given reference and also return its pointer. |
| 256 | 281 | */ |
| 257 | −Object *lua_hashdefine (Hash *t, Object *ref) | |
| 282 | +TObject *lua_hashdefine (Hash *t, TObject *ref) | |
| 258 | 283 | { |
| 259 | − int h; | |
| 260 | − Node *n; | |
| 261 | − h = present(t, ref); | |
| 262 | − n = node(t, h); | |
| 263 | − if (tag(ref(n)) == LUA_T_NIL) | |
| 264 | − { | |
| 265 | − nuse(t)++; | |
| 266 | − if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT) | |
| 267 | − { | |
| 268 | − rehash(t); | |
| 269 | − h = present(t, ref); | |
| 270 | − n = node(t, h); | |
| 284 | + Node *n = node(t, present(t, ref)); | |
| 285 | + if (ttype(ref(n)) == LUA_T_NIL) { | |
| 286 | + nuse(t)++; | |
| 287 | + if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT) { | |
| 288 | + rehash(t); | |
| 289 | + n = node(t, present(t, ref)); | |
| 290 | + } | |
| 291 | + *ref(n) = *ref; | |
| 292 | + ttype(val(n)) = LUA_T_NIL; | |
| 271 | 293 | } |
| 272 | − *ref(n) = *ref; | |
| 273 | − tag(val(n)) = LUA_T_NIL; | |
| 274 | − } | |
| 275 | − return (val(n)); | |
| 294 | + return (val(n)); | |
| 276 | 295 | } |
| 277 | 296 | |
| 278 | 297 | |
| @@ -284,36 +303,30 @@ Object *lua_hashdefine (Hash *t, Object *ref) · 5 unmodified lines | ||
| 284 | 303 | */ |
| 285 | 304 | static void hashnext (Hash *t, int i) |
| 286 | 305 | { |
| 287 | − if (i >= nhash(t)) | |
| 288 | − return; | |
| 289 | − while (tag(ref(node(t,i))) == LUA_T_NIL || tag(val(node(t,i))) == LUA_T_NIL) | |
| 290 | − { | |
| 291 | − if (++i >= nhash(t)) | |
| 292 | − return; | |
| 293 | − } | |
| 294 | − luaI_pushobject(ref(node(t,i))); | |
| 295 | − luaI_pushobject(val(node(t,i))); | |
| 306 | + Node *n; | |
| 307 | + int tsize = nhash(t); | |
| 308 | + if (i >= tsize) | |
| 309 | + return; | |
| 310 | + n = node(t, i); | |
| 311 | + while (ttype(ref(n)) == LUA_T_NIL || ttype(val(n)) == LUA_T_NIL) { | |
| 312 | + if (++i >= tsize) | |
| 313 | + return; | |
| 314 | + n = node(t, i); | |
| 315 | + } | |
| 316 | + luaI_pushobject(ref(node(t,i))); | |
| 317 | + luaI_pushobject(val(node(t,i))); | |
| 296 | 318 | } |
| 297 | 319 | |
| 298 | 320 | void lua_next (void) |
| 299 | 321 | { |
| 300 | − Hash *t; | |
| 301 | − lua_Object o = lua_getparam(1); | |
| 302 | − lua_Object r = lua_getparam(2); | |
| 303 | − if (o == LUA_NOOBJECT || r == LUA_NOOBJECT) | |
| 304 | − lua_error ("too few arguments to function `next'"); | |
| 305 | − if (lua_getparam(3) != LUA_NOOBJECT) | |
| 306 | − lua_error ("too many arguments to function `next'"); | |
| 307 | − if (!lua_istable(o)) | |
| 308 | − lua_error ("first argument of function `next' is not a table"); | |
| 309 | − t = avalue(luaI_Address(o)); | |
| 310 | − if (lua_isnil(r)) | |
| 311 | − { | |
| 312 | − hashnext(t, 0); | |
| 313 | − } | |
| 314 | − else | |
| 315 | − { | |
| 316 | − int h = present (t, luaI_Address(r)); | |
| 317 | − hashnext(t, h+1); | |
| 318 | − } | |
| 322 | + Hash *t; | |
| 323 | + lua_Object o = lua_getparam(1); | |
| 324 | + lua_Object r = lua_getparam(2); | |
| 325 | + luaL_arg_check(lua_istable(o), 1, "table expected"); | |
| 326 | + luaL_arg_check(r != LUA_NOOBJECT, 2, "value expected"); | |
| 327 | + t = avalue(luaI_Address(o)); | |
| 328 | + if (lua_isnil(r)) | |
| 329 | + hashnext(t, 0); | |
| 330 | + else | |
| 331 | + hashnext(t, present(t, luaI_Address(r))+1); | |
| 319 | 332 | } |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** hash.h |
| 3 | 3 | ** hash manager for lua |
| 4 | −** $Id: hash.h,v 2.12 1996/05/06 14:30:27 roberto Exp $ | |
| 4 | +** $Id: hash.h,v 2.16 1997/05/14 18:38:29 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef hash_h |
| @@ -10,29 +10,30 @@ · 2 unmodified lines | ||
| 10 | 10 | #include "types.h" |
| 11 | 11 | #include "opcode.h" |
| 12 | 12 | |
| 13 | −typedef struct node | |
| 14 | −{ | |
| 15 | − Object ref; | |
| 16 | − Object val; | |
| 13 | +typedef struct node { | |
| 14 | + TObject ref; | |
| 15 | + TObject val; | |
| 17 | 16 | } Node; |
| 18 | 17 | |
| 19 | −typedef struct Hash | |
| 20 | −{ | |
| 21 | − struct Hash *next; | |
| 22 | − Node *node; | |
| 23 | − int nhash; | |
| 24 | − int nuse; | |
| 25 | − char mark; | |
| 18 | +typedef struct Hash { | |
| 19 | + struct Hash *next; | |
| 20 | + Node *node; | |
| 21 | + int nhash; | |
| 22 | + int nuse; | |
| 23 | + int htag; | |
| 24 | + char mark; | |
| 26 | 25 | } Hash; |
| 27 | 26 | |
| 28 | 27 | |
| 29 | −int lua_equalObj (Object *t1, Object *t2); | |
| 28 | +int lua_equalObj (TObject *t1, TObject *t2); | |
| 30 | 29 | int luaI_redimension (int nhash); |
| 31 | 30 | Hash *lua_createarray (int nhash); |
| 32 | 31 | void lua_hashmark (Hash *h); |
| 33 | −Long lua_hashcollector (void); | |
| 34 | −Object *lua_hashget (Hash *t, Object *ref); | |
| 35 | −Object *lua_hashdefine (Hash *t, Object *ref); | |
| 32 | +Hash *luaI_hashcollector (long *count); | |
| 33 | +void luaI_hashcallIM (Hash *l); | |
| 34 | +void luaI_hashfree (Hash *frees); | |
| 35 | +TObject *lua_hashget (Hash *t, TObject *ref); | |
| 36 | +TObject *lua_hashdefine (Hash *t, TObject *ref); | |
| 36 | 37 | void lua_next (void); |
| 37 | 38 | |
| 38 | 39 | #endif |
| @@ -5,18 +5,24 @@ · 4 unmodified lines | ||
| 5 | 5 | ** Also provides some predefined lua functions. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | −char *rcs_inout="$Id: inout.c,v 2.43 1996/09/25 12:57:22 roberto Exp $"; | |
| 8 | +char *rcs_inout="$Id: inout.c,v 2.69 1997/06/27 22:38:49 roberto Exp $"; | |
| 9 | 9 | |
| 10 | 10 | #include <stdio.h> |
| 11 | 11 | #include <string.h> |
| 12 | 12 | |
| 13 | +#include "auxlib.h" | |
| 14 | +#include "fallback.h" | |
| 15 | +#include "hash.h" | |
| 16 | +#include "inout.h" | |
| 13 | 17 | #include "lex.h" |
| 18 | +#include "lua.h" | |
| 19 | +#include "luamem.h" | |
| 20 | +#include "luamem.h" | |
| 14 | 21 | #include "opcode.h" |
| 15 | −#include "inout.h" | |
| 16 | 22 | #include "table.h" |
| 17 | 23 | #include "tree.h" |
| 18 | −#include "lua.h" | |
| 19 | −#include "mem.h" | |
| 24 | +#include "undump.h" | |
| 25 | +#include "zio.h" | |
| 20 | 26 | |
| 21 | 27 | |
| 22 | 28 | /* Exported variables */ |
| @@ -24,92 +30,93 @@ Word lua_linenumber; · 1 unmodified line | ||
| 24 | 30 | char *lua_parsedfile; |
| 25 | 31 | |
| 26 | 32 | |
| 27 | −static FILE *fp; | |
| 28 | −static char *st; | |
| 33 | +char *luaI_typenames[] = { /* ORDER LUA_T */ | |
| 34 | + "userdata", "line", "cmark", "mark", "function", | |
| 35 | + "function", "table", "string", "number", "nil", | |
| 36 | + NULL | |
| 37 | +}; | |
| 29 | 38 | |
| 30 | −/* | |
| 31 | −** Function to get the next character from the input file | |
| 32 | −*/ | |
| 33 | −static int fileinput (void) | |
| 34 | −{ | |
| 35 | − int c = fgetc(fp); | |
| 36 | − return (c == EOF) ? 0 : c; | |
| 37 | −} | |
| 38 | 39 | |
| 39 | −/* | |
| 40 | −** Function to get the next character from the input string | |
| 41 | −*/ | |
| 42 | −static int stringinput (void) | |
| 40 | + | |
| 41 | +void luaI_setparsedfile (char *name) | |
| 43 | 42 | { |
| 44 | − return *st++; | |
| 43 | + lua_parsedfile = luaI_createfixedstring(name)->str; | |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | −/* | |
| 48 | −** Function to open a file to be input unit. | |
| 49 | −** Return the file. | |
| 50 | −*/ | |
| 51 | −FILE *lua_openfile (char *fn) | |
| 46 | + | |
| 47 | +int lua_doFILE (FILE *f, int bin) | |
| 52 | 48 | { |
| 53 | − lua_setinput (fileinput); | |
| 54 | − if (fn == NULL) | |
| 55 | − { | |
| 56 | − fp = stdin; | |
| 57 | − fn = "(stdin)"; | |
| 58 | − } | |
| 59 | − else | |
| 60 | − fp = fopen (fn, "r"); | |
| 61 | − if (fp == NULL) | |
| 62 | − return NULL; | |
| 63 | − lua_parsedfile = luaI_createfixedstring(fn)->str; | |
| 64 | − return fp; | |
| 65 | −} | |
| 49 | + ZIO z; | |
| 50 | + luaZ_Fopen(&z, f); | |
| 51 | + if (bin) | |
| 52 | + return luaI_undump(&z); | |
| 53 | + else { | |
| 54 | + lua_setinput(&z); | |
| 55 | + return lua_domain(); | |
| 56 | + } | |
| 57 | +} | |
| 66 | 58 | |
| 67 | −/* | |
| 68 | −** Function to close an opened file | |
| 69 | −*/ | |
| 70 | −void lua_closefile (void) | |
| 59 | + | |
| 60 | +int lua_dofile (char *filename) | |
| 71 | 61 | { |
| 72 | − if (fp != NULL && fp != stdin) | |
| 73 | − { | |
| 74 | − fclose (fp); | |
| 75 | − fp = NULL; | |
| 76 | − } | |
| 77 | −} | |
| 62 | + int status; | |
| 63 | + int c; | |
| 64 | + FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | |
| 65 | + if (f == NULL) | |
| 66 | + return 2; | |
| 67 | + luaI_setparsedfile(filename?filename:"(stdin)"); | |
| 68 | + c = fgetc(f); | |
| 69 | + ungetc(c, f); | |
| 70 | + if (c == ID_CHUNK) { | |
| 71 | + f = freopen(filename, "rb", f); /* set binary mode */ | |
| 72 | + status = lua_doFILE(f, 1); | |
| 73 | + } | |
| 74 | + else { | |
| 75 | + if (c == '#') | |
| 76 | + while ((c=fgetc(f)) != '\n') /* skip first line */; | |
| 77 | + status = lua_doFILE(f, 0); | |
| 78 | + } | |
| 79 | + if (f != stdin) | |
| 80 | + fclose(f); | |
| 81 | + return status; | |
| 82 | +} | |
| 83 | + | |
| 84 | + | |
| 78 | 85 | |
| 79 | −/* | |
| 80 | −** Function to open a string to be input unit | |
| 81 | −*/ | |
| 82 | 86 | #define SIZE_PREF 20 /* size of string prefix to appear in error messages */ |
| 83 | −void lua_openstring (char *s) | |
| 84 | −{ | |
| 85 | − char buff[SIZE_PREF+25]; | |
| 86 | − lua_setinput(stringinput); | |
| 87 | − st = s; | |
| 88 | − strcpy(buff, "(dostring) >> "); | |
| 89 | − strncat(buff, s, SIZE_PREF); | |
| 90 | − if (strlen(s) > SIZE_PREF) strcat(buff, "..."); | |
| 91 | − lua_parsedfile = luaI_createfixedstring(buff)->str; | |
| 92 | −} | |
| 93 | 87 | |
| 94 | −/* | |
| 95 | −** Function to close an opened string | |
| 96 | −*/ | |
| 97 | −void lua_closestring (void) | |
| 88 | + | |
| 89 | +int lua_dobuffer (char *buff, int size) | |
| 98 | 90 | { |
| 91 | + int status; | |
| 92 | + ZIO z; | |
| 93 | + luaI_setparsedfile("(buffer)"); | |
| 94 | + luaZ_mopen(&z, buff, size); | |
| 95 | + status = luaI_undump(&z); | |
| 96 | + return status; | |
| 99 | 97 | } |
| 100 | 98 | |
| 101 | 99 | |
| 102 | −static void check_arg (int cond, char *func) | |
| 100 | +int lua_dostring (char *str) | |
| 103 | 101 | { |
| 104 | − if (!cond) | |
| 105 | − { | |
| 106 | − char buff[100]; | |
| 107 | − sprintf(buff, "incorrect argument to function `%s'", func); | |
| 108 | − lua_error(buff); | |
| 109 | − } | |
| 102 | + int status; | |
| 103 | + char buff[SIZE_PREF+25]; | |
| 104 | + char *temp; | |
| 105 | + ZIO z; | |
| 106 | + if (str == NULL) return 1; | |
| 107 | + sprintf(buff, "(dostring) >> %.20s", str); | |
| 108 | + temp = strchr(buff, '\n'); | |
| 109 | + if (temp) *temp = 0; /* end string after first line */ | |
| 110 | + luaI_setparsedfile(buff); | |
| 111 | + luaZ_sopen(&z, str); | |
| 112 | + lua_setinput(&z); | |
| 113 | + status = lua_domain(); | |
| 114 | + return status; | |
| 110 | 115 | } |
| 111 | 116 | |
| 112 | 117 | |
| 118 | + | |
| 119 | + | |
| 113 | 120 | static int passresults (void) |
| 114 | 121 | { |
| 115 | 122 | int arg = 0; |
| @@ -118,30 +125,53 @@ static int passresults (void) · 2 unmodified lines | ||
| 118 | 125 | lua_pushobject(obj); |
| 119 | 126 | return arg-1; |
| 120 | 127 | } |
| 128 | + | |
| 129 | + | |
| 130 | +static void packresults (void) | |
| 131 | +{ | |
| 132 | + int arg = 0; | |
| 133 | + lua_Object obj; | |
| 134 | + lua_Object table = lua_createtable(); | |
| 135 | + while ((obj = lua_getresult(++arg)) != LUA_NOOBJECT) { | |
| 136 | + lua_pushobject(table); | |
| 137 | + lua_pushnumber(arg); | |
| 138 | + lua_pushobject(obj); | |
| 139 | + lua_rawsettable(); | |
| 140 | + } | |
| 141 | + lua_pushobject(table); | |
| 142 | + lua_pushstring("n"); | |
| 143 | + lua_pushnumber(arg-1); | |
| 144 | + lua_rawsettable(); | |
| 145 | + lua_pushobject(table); /* final result */ | |
| 146 | +} | |
| 121 | 147 | |
| 122 | 148 | /* |
| 123 | 149 | ** Internal function: do a string |
| 124 | 150 | */ |
| 125 | −void lua_internaldostring (void) | |
| 151 | +static void lua_internaldostring (void) | |
| 126 | 152 | { |
| 127 | − lua_Object obj = lua_getparam (1); | |
| 128 | − if (lua_isstring(obj) && lua_dostring(lua_getstring(obj)) == 0) | |
| 153 | + lua_Object err = lua_getparam(2); | |
| 154 | + if (err != LUA_NOOBJECT) { /* set new error method */ | |
| 155 | + luaL_arg_check(lua_isnil(err) || lua_isfunction(err), 2, | |
| 156 | + "must be a valid error handler"); | |
| 157 | + lua_pushobject(err); | |
| 158 | + err = lua_seterrormethod(); | |
| 159 | + } | |
| 160 | + if (lua_dostring(luaL_check_string(1)) == 0) | |
| 129 | 161 | if (passresults() == 0) |
| 130 | 162 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ |
| 163 | + if (err != LUA_NOOBJECT) { /* restore old error method */ | |
| 164 | + lua_pushobject(err); | |
| 165 | + lua_seterrormethod(); | |
| 166 | + } | |
| 131 | 167 | } |
| 132 | 168 | |
| 133 | 169 | /* |
| 134 | 170 | ** Internal function: do a file |
| 135 | 171 | */ |
| 136 | −void lua_internaldofile (void) | |
| 172 | +static void lua_internaldofile (void) | |
| 137 | 173 | { |
| 138 | − lua_Object obj = lua_getparam (1); | |
| 139 | − char *fname = NULL; | |
| 140 | − if (lua_isstring(obj)) | |
| 141 | − fname = lua_getstring(obj); | |
| 142 | − else if (obj != LUA_NOOBJECT) | |
| 143 | − lua_error("invalid argument to function `dofile'"); | |
| 144 | − /* else fname = NULL */ | |
| 174 | + char *fname = luaL_opt_string(1, NULL); | |
| 145 | 175 | if (lua_dofile(fname) == 0) |
| 146 | 176 | if (passresults() == 0) |
| 147 | 177 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ |
| @@ -150,36 +180,28 @@ void lua_internaldofile (void) · 2 unmodified lines | ||
| 150 | 180 | |
| 151 | 181 | static char *tostring (lua_Object obj) |
| 152 | 182 | { |
| 153 | − char *buff = luaI_buffer(20); | |
| 154 | − if (lua_isstring(obj)) /* get strings and numbers */ | |
| 155 | − return lua_getstring(obj); | |
| 156 | − else switch(lua_type(obj)) | |
| 157 | − { | |
| 158 | − case LUA_T_FUNCTION: | |
| 159 | − sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf); | |
| 160 | − break; | |
| 161 | − case LUA_T_CFUNCTION: | |
| 162 | − sprintf(buff, "cfunction: %p", lua_getcfunction(obj)); | |
| 163 | − break; | |
| 164 | − case LUA_T_ARRAY: | |
| 165 | − sprintf(buff, "table: %p", avalue(luaI_Address(obj))); | |
| 166 | − break; | |
| 167 | − case LUA_T_NIL: | |
| 168 | − sprintf(buff, "nil"); | |
| 169 | − break; | |
| 170 | − default: | |
| 171 | − sprintf(buff, "userdata: %p", lua_getuserdata(obj)); | |
| 172 | − break; | |
| 183 | + TObject *o = luaI_Address(obj); | |
| 184 | + switch (ttype(o)) { | |
| 185 | + case LUA_T_NUMBER: case LUA_T_STRING: | |
| 186 | + return lua_getstring(obj); | |
| 187 | + case LUA_T_ARRAY: case LUA_T_FUNCTION: | |
| 188 | + case LUA_T_CFUNCTION: case LUA_T_NIL: | |
| 189 | + return luaI_typenames[-ttype(o)]; | |
| 190 | + case LUA_T_USERDATA: { | |
| 191 | + char *buff = luaI_buffer(30); | |
| 192 | + sprintf(buff, "userdata: %p", o->value.ts->u.v); | |
| 193 | + return buff; | |
| 194 | + } | |
| 195 | + default: return "<unknown object>"; | |
| 173 | 196 | } |
| 174 | − return buff; | |
| 175 | 197 | } |
| 176 | 198 | |
| 177 | −void luaI_tostring (void) | |
| 199 | +static void luaI_tostring (void) | |
| 178 | 200 | { |
| 179 | 201 | lua_pushstring(tostring(lua_getparam(1))); |
| 180 | 202 | } |
| 181 | 203 | |
| 182 | −void luaI_print (void) | |
| 204 | +static void luaI_print (void) | |
| 183 | 205 | { |
| 184 | 206 | int i = 1; |
| 185 | 207 | lua_Object obj; |
| @@ -187,45 +209,18 @@ void luaI_print (void) · 1 unmodified line | ||
| 187 | 209 | printf("%s\n", tostring(obj)); |
| 188 | 210 | } |
| 189 | 211 | |
| 190 | −/* | |
| 191 | −** Internal function: return an object type. | |
| 192 | −*/ | |
| 193 | −void luaI_type (void) | |
| 212 | +static void luaI_type (void) | |
| 194 | 213 | { |
| 195 | 214 | lua_Object o = lua_getparam(1); |
| 196 | − int t; | |
| 197 | − if (o == LUA_NOOBJECT) | |
| 198 | − lua_error("no parameter to function 'type'"); | |
| 199 | − t = lua_type(o); | |
| 200 | − switch (t) | |
| 201 | − { | |
| 202 | − case LUA_T_NIL : | |
| 203 | − lua_pushliteral("nil"); | |
| 204 | − break; | |
| 205 | − case LUA_T_NUMBER : | |
| 206 | − lua_pushliteral("number"); | |
| 207 | − break; | |
| 208 | − case LUA_T_STRING : | |
| 209 | − lua_pushliteral("string"); | |
| 210 | − break; | |
| 211 | − case LUA_T_ARRAY : | |
| 212 | − lua_pushliteral("table"); | |
| 213 | − break; | |
| 214 | − case LUA_T_FUNCTION : | |
| 215 | − case LUA_T_CFUNCTION : | |
| 216 | − lua_pushliteral("function"); | |
| 217 | − break; | |
| 218 | − default : | |
| 219 | − lua_pushliteral("userdata"); | |
| 220 | − break; | |
| 221 | − } | |
| 222 | − lua_pushnumber(t); | |
| 215 | + luaL_arg_check(o != LUA_NOOBJECT, 1, "no argument"); | |
| 216 | + lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]); | |
| 217 | + lua_pushnumber(lua_tag(o)); | |
| 223 | 218 | } |
| 224 | − | |
| 219 | + | |
| 225 | 220 | /* |
| 226 | 221 | ** Internal function: convert an object to a number |
| 227 | 222 | */ |
| 228 | −void lua_obj2number (void) | |
| 223 | +static void lua_obj2number (void) | |
| 229 | 224 | { |
| 230 | 225 | lua_Object o = lua_getparam(1); |
| 231 | 226 | if (lua_isnumber(o)) |
| @@ -233,68 +228,181 @@ void lua_obj2number (void) · 1 unmodified line | ||
| 233 | 228 | } |
| 234 | 229 | |
| 235 | 230 | |
| 236 | −void luaI_error (void) | |
| 231 | +static void luaI_error (void) | |
| 237 | 232 | { |
| 238 | 233 | char *s = lua_getstring(lua_getparam(1)); |
| 239 | 234 | if (s == NULL) s = "(no message)"; |
| 240 | 235 | lua_error(s); |
| 241 | 236 | } |
| 242 | 237 | |
| 243 | −void luaI_assert (void) | |
| 238 | +static void luaI_assert (void) | |
| 244 | 239 | { |
| 245 | 240 | lua_Object p = lua_getparam(1); |
| 246 | 241 | if (p == LUA_NOOBJECT || lua_isnil(p)) |
| 247 | 242 | lua_error("assertion failed!"); |
| 248 | 243 | } |
| 249 | 244 | |
| 250 | −void luaI_setglobal (void) | |
| 245 | +static void luaI_setglobal (void) | |
| 246 | +{ | |
| 247 | + lua_Object value = lua_getparam(2); | |
| 248 | + luaL_arg_check(value != LUA_NOOBJECT, 2, NULL); | |
| 249 | + lua_pushobject(value); | |
| 250 | + lua_setglobal(luaL_check_string(1)); | |
| 251 | + lua_pushobject(value); /* return given value */ | |
| 252 | +} | |
| 253 | + | |
| 254 | +static void luaI_rawsetglobal (void) | |
| 251 | 255 | { |
| 252 | − lua_Object name = lua_getparam(1); | |
| 253 | 256 | lua_Object value = lua_getparam(2); |
| 254 | − check_arg(lua_isstring(name), "setglobal"); | |
| 257 | + luaL_arg_check(value != LUA_NOOBJECT, 2, NULL); | |
| 255 | 258 | lua_pushobject(value); |
| 256 | − lua_storeglobal(lua_getstring(name)); | |
| 259 | + lua_rawsetglobal(luaL_check_string(1)); | |
| 257 | 260 | lua_pushobject(value); /* return given value */ |
| 258 | 261 | } |
| 259 | 262 | |
| 260 | −void luaI_getglobal (void) | |
| 263 | +static void luaI_getglobal (void) | |
| 261 | 264 | { |
| 262 | − lua_Object name = lua_getparam(1); | |
| 263 | − check_arg(lua_isstring(name), "getglobal"); | |
| 264 | − lua_pushobject(lua_getglobal(lua_getstring(name))); | |
| 265 | + lua_pushobject(lua_getglobal(luaL_check_string(1))); | |
| 265 | 266 | } |
| 266 | 267 | |
| 267 | −#define MAXPARAMS 256 | |
| 268 | −void luaI_call (void) | |
| 268 | +static void luaI_rawgetglobal (void) | |
| 269 | +{ | |
| 270 | + lua_pushobject(lua_rawgetglobal(luaL_check_string(1))); | |
| 271 | +} | |
| 272 | + | |
| 273 | +static void luatag (void) | |
| 274 | +{ | |
| 275 | + lua_pushnumber(lua_tag(lua_getparam(1))); | |
| 276 | +} | |
| 277 | + | |
| 278 | + | |
| 279 | +static int getnarg (lua_Object table) | |
| 280 | +{ | |
| 281 | + lua_Object temp; | |
| 282 | + /* temp = table.n */ | |
| 283 | + lua_pushobject(table); lua_pushstring("n"); temp = lua_gettable(); | |
| 284 | + return (lua_isnumber(temp) ? lua_getnumber(temp) : MAX_WORD); | |
| 285 | +} | |
| 286 | + | |
| 287 | +static void luaI_call (void) | |
| 269 | 288 | { |
| 270 | 289 | lua_Object f = lua_getparam(1); |
| 271 | 290 | lua_Object arg = lua_getparam(2); |
| 272 | − lua_Object temp, params[MAXPARAMS]; | |
| 291 | + int withtable = (strcmp(luaL_opt_string(3, ""), "pack") == 0); | |
| 273 | 292 | int narg, i; |
| 274 | − check_arg(lua_istable(arg), "call"); | |
| 275 | − check_arg(lua_isfunction(f), "call"); | |
| 276 | − /* narg = arg.n */ | |
| 277 | − lua_pushobject(arg); | |
| 278 | − lua_pushstring("n"); | |
| 279 | − temp = lua_getsubscript(); | |
| 280 | − narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1; | |
| 281 | − /* read arg[1...n] */ | |
| 293 | + luaL_arg_check(lua_isfunction(f), 1, "function expected"); | |
| 294 | + luaL_arg_check(lua_istable(arg), 2, "table expected"); | |
| 295 | + narg = getnarg(arg); | |
| 296 | + /* push arg[1...n] */ | |
| 282 | 297 | for (i=0; i<narg; i++) { |
| 283 | − if (i>=MAXPARAMS) | |
| 284 | − lua_error("argument list too long in function `call'"); | |
| 285 | − lua_pushobject(arg); | |
| 286 | − lua_pushnumber(i+1); | |
| 287 | − params[i] = lua_getsubscript(); | |
| 288 | − if (narg == MAXPARAMS+1 && lua_isnil(params[i])) { | |
| 289 | − narg = i; | |
| 298 | + lua_Object temp; | |
| 299 | + /* temp = arg[i+1] */ | |
| 300 | + lua_pushobject(arg); lua_pushnumber(i+1); temp = lua_gettable(); | |
| 301 | + if (narg == MAX_WORD && lua_isnil(temp)) | |
| 290 | 302 | break; |
| 291 | − } | |
| 303 | + lua_pushobject(temp); | |
| 292 | 304 | } |
| 293 | − /* push parameters and do the call */ | |
| 294 | − for (i=0; i<narg; i++) | |
| 295 | − lua_pushobject(params[i]); | |
| 296 | 305 | if (lua_callfunction(f)) |
| 297 | 306 | lua_error(NULL); |
| 307 | + else if (withtable) | |
| 308 | + packresults(); | |
| 298 | 309 | else |
| 299 | 310 | passresults(); |
| 300 | 311 | } |
| 312 | + | |
| 313 | +static void luaIl_settag (void) | |
| 314 | +{ | |
| 315 | + lua_Object o = lua_getparam(1); | |
| 316 | + luaL_arg_check(lua_istable(o), 1, "table expected"); | |
| 317 | + lua_pushobject(o); | |
| 318 | + lua_settag(luaL_check_number(2)); | |
| 319 | +} | |
| 320 | + | |
| 321 | +static void luaIl_newtag (void) | |
| 322 | +{ | |
| 323 | + lua_pushnumber(lua_newtag()); | |
| 324 | +} | |
| 325 | + | |
| 326 | +static void rawgettable (void) | |
| 327 | +{ | |
| 328 | + lua_Object t = lua_getparam(1); | |
| 329 | + lua_Object i = lua_getparam(2); | |
| 330 | + luaL_arg_check(t != LUA_NOOBJECT, 1, NULL); | |
| 331 | + luaL_arg_check(i != LUA_NOOBJECT, 2, NULL); | |
| 332 | + lua_pushobject(t); | |
| 333 | + lua_pushobject(i); | |
| 334 | + lua_pushobject(lua_rawgettable()); | |
| 335 | +} | |
| 336 | + | |
| 337 | +static void rawsettable (void) | |
| 338 | +{ | |
| 339 | + lua_Object t = lua_getparam(1); | |
| 340 | + lua_Object i = lua_getparam(2); | |
| 341 | + lua_Object v = lua_getparam(3); | |
| 342 | + luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, | |
| 343 | + 0, NULL); | |
| 344 | + lua_pushobject(t); | |
| 345 | + lua_pushobject(i); | |
| 346 | + lua_pushobject(v); | |
| 347 | + lua_rawsettable(); | |
| 348 | +} | |
| 349 | + | |
| 350 | + | |
| 351 | +static void luaI_collectgarbage (void) | |
| 352 | +{ | |
| 353 | + lua_pushnumber(lua_collectgarbage(luaL_opt_number(1, 0))); | |
| 354 | +} | |
| 355 | + | |
| 356 | + | |
| 357 | +/* | |
| 358 | +** Internal functions | |
| 359 | +*/ | |
| 360 | +static struct { | |
| 361 | + char *name; | |
| 362 | + lua_CFunction func; | |
| 363 | +} int_funcs[] = { | |
| 364 | + {"assert", luaI_assert}, | |
| 365 | + {"call", luaI_call}, | |
| 366 | + {"collectgarbage", luaI_collectgarbage}, | |
| 367 | + {"dofile", lua_internaldofile}, | |
| 368 | + {"dostring", lua_internaldostring}, | |
| 369 | + {"error", luaI_error}, | |
| 370 | + {"getglobal", luaI_getglobal}, | |
| 371 | + {"newtag", luaIl_newtag}, | |
| 372 | + {"next", lua_next}, | |
| 373 | + {"nextvar", luaI_nextvar}, | |
| 374 | + {"print", luaI_print}, | |
| 375 | + {"rawgetglobal", luaI_rawgetglobal}, | |
| 376 | + {"rawgettable", rawgettable}, | |
| 377 | + {"rawsetglobal", luaI_rawsetglobal}, | |
| 378 | + {"rawsettable", rawsettable}, | |
| 379 | + {"seterrormethod", luaI_seterrormethod}, | |
| 380 | +#if LUA_COMPAT2_5 | |
| 381 | + {"setfallback", luaI_setfallback}, | |
| 382 | +#endif | |
| 383 | + {"setglobal", luaI_setglobal}, | |
| 384 | + {"settagmethod", luaI_settagmethod}, | |
| 385 | + {"gettagmethod", luaI_gettagmethod}, | |
| 386 | + {"settag", luaIl_settag}, | |
| 387 | + {"tonumber", lua_obj2number}, | |
| 388 | + {"tostring", luaI_tostring}, | |
| 389 | + {"tag", luatag}, | |
| 390 | + {"type", luaI_type} | |
| 391 | +}; | |
| 392 | + | |
| 393 | +#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0])) | |
| 394 | + | |
| 395 | + | |
| 396 | +void luaI_predefine (void) | |
| 397 | +{ | |
| 398 | + int i; | |
| 399 | + Word n; | |
| 400 | + for (i=0; i<INTFUNCSIZE; i++) { | |
| 401 | + n = luaI_findsymbolbyname(int_funcs[i].name); | |
| 402 | + s_ttype(n) = LUA_T_CFUNCTION; s_fvalue(n) = int_funcs[i].func; | |
| 403 | + } | |
| 404 | + n = luaI_findsymbolbyname("_VERSION"); | |
| 405 | + s_ttype(n) = LUA_T_STRING; s_tsvalue(n) = lua_createstring(LUA_VERSION); | |
| 406 | +} | |
| 407 | + | |
| 408 | + | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: inout.h,v 1.16 1996/05/28 21:07:32 roberto Exp $ | |
| 2 | +** $Id: inout.h,v 1.20 1997/06/19 18:04:34 roberto Exp $ | |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | |
| @@ -14,21 +14,12 @@ extern Word lua_linenumber; · 8 unmodified lines | ||
| 14 | 14 | extern Word lua_debugline; |
| 15 | 15 | extern char *lua_parsedfile; |
| 16 | 16 | |
| 17 | −FILE *lua_openfile (char *fn); | |
| 18 | −void lua_closefile (void); | |
| 19 | −void lua_openstring (char *s); | |
| 20 | −void lua_closestring (void); | |
| 21 | − | |
| 22 | −void lua_internaldofile (void); | |
| 23 | −void lua_internaldostring (void); | |
| 24 | −void luaI_tostring (void); | |
| 25 | −void luaI_print (void); | |
| 26 | −void luaI_type (void); | |
| 27 | −void lua_obj2number (void); | |
| 28 | −void luaI_error (void); | |
| 29 | −void luaI_assert (void); | |
| 30 | −void luaI_setglobal (void); | |
| 31 | −void luaI_getglobal (void); | |
| 32 | −void luaI_call (void); | |
| 17 | +void luaI_setparsedfile (char *name); | |
| 18 | + | |
| 19 | +void luaI_predefine (void); | |
| 20 | + | |
| 21 | +int lua_dobuffer (char *buff, int size); | |
| 22 | +int lua_doFILE (FILE *f, int bin); | |
| 23 | + | |
| 33 | 24 | |
| 34 | 25 | #endif |
| @@ -1,10 +1,11 @@ | ||
| 1 | −char *rcs_lex = "$Id: lex.c,v 2.39 1996/11/08 19:08:30 roberto Exp $"; | |
| 1 | +char *rcs_lex = "$Id: lex.c,v 3.5 1997/06/16 16:50:22 roberto Exp $"; | |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | #include <ctype.h> |
| 5 | 5 | #include <string.h> |
| 6 | 6 | |
| 7 | −#include "mem.h" | |
| 7 | +#include "auxlib.h" | |
| 8 | +#include "luamem.h" | |
| 8 | 9 | #include "tree.h" |
| 9 | 10 | #include "table.h" |
| 10 | 11 | #include "lex.h" |
| @@ -12,33 +13,58 @@ char *rcs_lex = "$Id: lex.c,v 2.39 1996/11/08 19:08:30 roberto Exp $"; · 1 unmodified line | ||
| 12 | 13 | #include "luadebug.h" |
| 13 | 14 | #include "parser.h" |
| 14 | 15 | |
| 15 | −#define MINBUFF 260 | |
| 16 | +#define MINBUFF 250 | |
| 16 | 17 | |
| 17 | −#define next() (current = input()) | |
| 18 | +static int current; /* look ahead character */ | |
| 19 | +static ZIO *lex_z; | |
| 20 | + | |
| 21 | + | |
| 22 | +#define next() (current = zgetc(lex_z)) | |
| 18 | 23 | #define save(x) (yytext[tokensize++] = (x)) |
| 19 | 24 | #define save_and_next() (save(current), next()) |
| 20 | 25 | |
| 21 | 26 | |
| 22 | −static int current; /* look ahead character */ | |
| 23 | −static Input input; /* input function */ | |
| 27 | +#define MAX_IFS 5 | |
| 28 | + | |
| 29 | +/* "ifstate" keeps the state of each nested $if the lexical is dealing with. */ | |
| 30 | + | |
| 31 | +static struct { | |
| 32 | + int elsepart; /* true if its in the $else part */ | |
| 33 | + int condition; /* true if $if condition is true */ | |
| 34 | + int skip; /* true if part must be skiped */ | |
| 35 | +} ifstate[MAX_IFS]; | |
| 36 | + | |
| 37 | +static int iflevel; /* level of nested $if's */ | |
| 24 | 38 | |
| 25 | 39 | |
| 26 | −void lua_setinput (Input fn) | |
| 40 | +void lua_setinput (ZIO *z) | |
| 27 | 41 | { |
| 28 | 42 | current = '\n'; |
| 29 | 43 | lua_linenumber = 0; |
| 30 | − input = fn; | |
| 44 | + iflevel = 0; | |
| 45 | + ifstate[0].skip = 0; | |
| 46 | + ifstate[0].elsepart = 1; /* to avoid a free $else */ | |
| 47 | + lex_z = z; | |
| 31 | 48 | } |
| 32 | 49 | |
| 33 | −void luaI_syntaxerror (char *s) | |
| 50 | + | |
| 51 | +static void luaI_auxsyntaxerror (char *s) | |
| 52 | +{ | |
| 53 | + luaL_verror("%s;\n> at line %d in file %s", | |
| 54 | + s, lua_linenumber, lua_parsedfile); | |
| 55 | +} | |
| 56 | + | |
| 57 | +static void luaI_auxsynterrbf (char *s, char *token) | |
| 34 | 58 | { |
| 35 | − char msg[256]; | |
| 36 | − char *token = luaI_buffer(1); | |
| 37 | 59 | if (token[0] == 0) |
| 38 | 60 | token = "<eof>"; |
| 39 | − sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s", | |
| 61 | + luaL_verror("%s;\n> last token read: \"%s\" at line %d in file %s", | |
| 40 | 62 | s, token, lua_linenumber, lua_parsedfile); |
| 41 | − lua_error (msg); | |
| 63 | +} | |
| 64 | + | |
| 65 | +void luaI_syntaxerror (char *s) | |
| 66 | +{ | |
| 67 | + luaI_auxsynterrbf(s, luaI_buffer(1)); | |
| 42 | 68 | } |
| 43 | 69 | |
| 44 | 70 | |
| @@ -78,26 +104,122 @@ void luaI_addReserved (void) · 33 unmodified lines | ||
| 78 | 104 | } |
| 79 | 105 | } |
| 80 | 106 | |
| 81 | −static int inclinenumber (int pragma_allowed) | |
| 107 | + | |
| 108 | +/* | |
| 109 | +** Pragma handling | |
| 110 | +*/ | |
| 111 | + | |
| 112 | +#define PRAGMASIZE 20 | |
| 113 | + | |
| 114 | +static void skipspace (void) | |
| 115 | +{ | |
| 116 | + while (current == ' ' || current == '\t') next(); | |
| 117 | +} | |
| 118 | + | |
| 119 | + | |
| 120 | +static int checkcond (char *buff) | |
| 121 | +{ | |
| 122 | + static char *opts[] = {"nil", "1"}; | |
| 123 | + int i = luaI_findstring(buff, opts); | |
| 124 | + if (i >= 0) return i; | |
| 125 | + else if (isalpha((unsigned char)buff[0]) || buff[0] == '_') | |
| 126 | + return luaI_globaldefined(buff); | |
| 127 | + else { | |
| 128 | + luaI_auxsynterrbf("invalid $if condition", buff); | |
| 129 | + return 0; /* to avoid warnings */ | |
| 130 | + } | |
| 131 | +} | |
| 132 | + | |
| 133 | + | |
| 134 | +static void readname (char *buff) | |
| 135 | +{ | |
| 136 | + int i = 0; | |
| 137 | + skipspace(); | |
| 138 | + while (isalnum((unsigned char)current) || current == '_') { | |
| 139 | + if (i >= PRAGMASIZE) { | |
| 140 | + buff[PRAGMASIZE] = 0; | |
| 141 | + luaI_auxsynterrbf("pragma too long", buff); | |
| 142 | + } | |
| 143 | + buff[i++] = current; | |
| 144 | + next(); | |
| 145 | + } | |
| 146 | + buff[i] = 0; | |
| 147 | +} | |
| 148 | + | |
| 149 | + | |
| 150 | +static void inclinenumber (void); | |
| 151 | + | |
| 152 | + | |
| 153 | +static void ifskip (void) | |
| 154 | +{ | |
| 155 | + while (ifstate[iflevel].skip) { | |
| 156 | + if (current == '\n') | |
| 157 | + inclinenumber(); | |
| 158 | + else if (current == EOZ) | |
| 159 | + luaI_auxsyntaxerror("input ends inside a $if"); | |
| 160 | + else next(); | |
| 161 | + } | |
| 162 | +} | |
| 163 | + | |
| 164 | + | |
| 165 | +static void inclinenumber (void) | |
| 82 | 166 | { |
| 167 | + static char *pragmas [] = | |
| 168 | + {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL}; | |
| 169 | + next(); /* skip '\n' */ | |
| 83 | 170 | ++lua_linenumber; |
| 84 | − if (pragma_allowed && current == '$') { /* is a pragma? */ | |
| 85 | − char *buff = luaI_buffer(MINBUFF+1); | |
| 86 | − int i = 0; | |
| 171 | + if (current == '$') { /* is a pragma? */ | |
| 172 | + char buff[PRAGMASIZE+1]; | |
| 173 | + int ifnot = 0; | |
| 174 | + int skip = ifstate[iflevel].skip; | |
| 87 | 175 | next(); /* skip $ */ |
| 88 | − while (isalnum(current)) { | |
| 89 | − if (i >= MINBUFF) luaI_syntaxerror("pragma too long"); | |
| 90 | − buff[i++] = current; | |
| 91 | − next(); | |
| 176 | + readname(buff); | |
| 177 | + switch (luaI_findstring(buff, pragmas)) { | |
| 178 | + case 0: /* debug */ | |
| 179 | + if (!skip) lua_debug = 1; | |
| 180 | + break; | |
| 181 | + case 1: /* nodebug */ | |
| 182 | + if (!skip) lua_debug = 0; | |
| 183 | + break; | |
| 184 | + case 2: /* endinput */ | |
| 185 | + if (!skip) { | |
| 186 | + current = EOZ; | |
| 187 | + iflevel = 0; /* to allow $endinput inside a $if */ | |
| 188 | + } | |
| 189 | + break; | |
| 190 | + case 3: /* end */ | |
| 191 | + if (iflevel-- == 0) | |
| 192 | + luaI_auxsyntaxerror("unmatched $endif"); | |
| 193 | + break; | |
| 194 | + case 4: /* ifnot */ | |
| 195 | + ifnot = 1; | |
| 196 | + /* go through */ | |
| 197 | + case 5: /* if */ | |
| 198 | + if (iflevel == MAX_IFS-1) | |
| 199 | + luaI_auxsyntaxerror("too many nested `$ifs'"); | |
| 200 | + readname(buff); | |
| 201 | + iflevel++; | |
| 202 | + ifstate[iflevel].elsepart = 0; | |
| 203 | + ifstate[iflevel].condition = checkcond(buff) ? !ifnot : ifnot; | |
| 204 | + ifstate[iflevel].skip = skip || !ifstate[iflevel].condition; | |
| 205 | + break; | |
| 206 | + case 6: /* else */ | |
| 207 | + if (ifstate[iflevel].elsepart) | |
| 208 | + luaI_auxsyntaxerror("unmatched $else"); | |
| 209 | + ifstate[iflevel].elsepart = 1; | |
| 210 | + ifstate[iflevel].skip = | |
| 211 | + ifstate[iflevel-1].skip || ifstate[iflevel].condition; | |
| 212 | + break; | |
| 213 | + default: | |
| 214 | + luaI_auxsynterrbf("invalid pragma", buff); | |
| 92 | 215 | } |
| 93 | − buff[i] = 0; | |
| 94 | − if (strcmp(buff, "debug") == 0) | |
| 95 | − lua_debug = 1; | |
| 96 | − else if (strcmp(buff, "nodebug") == 0) | |
| 97 | − lua_debug = 0; | |
| 98 | − else luaI_syntaxerror("invalid pragma"); | |
| 216 | + skipspace(); | |
| 217 | + if (current == '\n') /* pragma must end with a '\n' ... */ | |
| 218 | + inclinenumber(); | |
| 219 | + else if (current != EOZ) /* or eof */ | |
| 220 | + luaI_auxsyntaxerror("invalid pragma format"); | |
| 221 | + ifskip(); | |
| 99 | 222 | } |
| 100 | − return lua_linenumber; | |
| 101 | 223 | } |
| 102 | 224 | |
| 103 | 225 | static int read_long_string (char *yytext, int buffsize) |
| @@ -110,7 +232,7 @@ static int read_long_string (char *yytext, int buffsize) · 6 unmodified lines | ||
| 110 | 232 | yytext = luaI_buffer(buffsize *= 2); |
| 111 | 233 | switch (current) |
| 112 | 234 | { |
| 113 | − case 0: | |
| 235 | + case EOZ: | |
| 114 | 236 | save(0); |
| 115 | 237 | return WRONGTOKEN; |
| 116 | 238 | case '[': |
| @@ -131,8 +253,8 @@ static int read_long_string (char *yytext, int buffsize) · 14 unmodified lines | ||
| 131 | 253 | } |
| 132 | 254 | continue; |
| 133 | 255 | case '\n': |
| 134 | − save_and_next(); | |
| 135 | − inclinenumber(0); | |
| 256 | + save('\n'); | |
| 257 | + inclinenumber(); | |
| 136 | 258 | continue; |
| 137 | 259 | default: |
| 138 | 260 | save_and_next(); |
| @@ -162,8 +284,8 @@ int luaY_lex (void) · 23 unmodified lines | ||
| 162 | 284 | switch (current) |
| 163 | 285 | { |
| 164 | 286 | case '\n': |
| 165 | − next(); | |
| 166 | − linelasttoken = inclinenumber(1); | |
| 287 | + inclinenumber(); | |
| 288 | + linelasttoken = lua_linenumber; | |
| 167 | 289 | continue; |
| 168 | 290 | |
| 169 | 291 | case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ |
| @@ -173,7 +295,7 @@ int luaY_lex (void) · 3 unmodified lines | ||
| 173 | 295 | case '-': |
| 174 | 296 | save_and_next(); |
| 175 | 297 | if (current != '-') return '-'; |
| 176 | − do { next(); } while (current != '\n' && current != 0); | |
| 298 | + do { next(); } while (current != '\n' && current != EOZ); | |
| 177 | 299 | continue; |
| 178 | 300 | |
| 179 | 301 | case '[': |
| @@ -216,7 +338,7 @@ int luaY_lex (void) · 36 unmodified lines | ||
| 216 | 338 | yytext = luaI_buffer(buffsize *= 2); |
| 217 | 339 | switch (current) |
| 218 | 340 | { |
| 219 | − case 0: | |
| 341 | + case EOZ: | |
| 220 | 342 | case '\n': |
| 221 | 343 | save(0); |
| 222 | 344 | return WRONGTOKEN; |
| @@ -227,7 +349,7 @@ int luaY_lex (void) · 4 unmodified lines | ||
| 227 | 349 | case 'n': save('\n'); next(); break; |
| 228 | 350 | case 't': save('\t'); next(); break; |
| 229 | 351 | case 'r': save('\r'); next(); break; |
| 230 | − case '\n': save_and_next(); inclinenumber(0); break; | |
| 352 | + case '\n': save('\n'); inclinenumber(); break; | |
| 231 | 353 | default : save_and_next(); break; |
| 232 | 354 | } |
| 233 | 355 | break; |
| @@ -258,7 +380,9 @@ int luaY_lex (void) · 24 unmodified lines | ||
| 258 | 380 | case '_': |
| 259 | 381 | { |
| 260 | 382 | TaggedString *ts; |
| 261 | − do { save_and_next(); } while (isalnum(current) || current == '_'); | |
| 383 | + do { | |
| 384 | + save_and_next(); | |
| 385 | + } while (isalnum((unsigned char)current) || current == '_'); | |
| 262 | 386 | save(0); |
| 263 | 387 | ts = lua_createstring(yytext); |
| 264 | 388 | if (ts->marked > 2) |
| @@ -280,7 +404,7 @@ int luaY_lex (void) · 15 unmodified lines | ||
| 280 | 404 | } |
| 281 | 405 | else return CONC; /* .. */ |
| 282 | 406 | } |
| 283 | − else if (!isdigit(current)) return '.'; | |
| 407 | + else if (!isdigit((unsigned char)current)) return '.'; | |
| 284 | 408 | /* current is a digit: goes through to number */ |
| 285 | 409 | a=0.0; |
| 286 | 410 | goto fraction; |
| @@ -291,7 +415,7 @@ int luaY_lex (void) · 4 unmodified lines | ||
| 291 | 415 | do { |
| 292 | 416 | a=10.0*a+(current-'0'); |
| 293 | 417 | save_and_next(); |
| 294 | − } while (isdigit(current)); | |
| 418 | + } while (isdigit((unsigned char)current)); | |
| 295 | 419 | if (current == '.') { |
| 296 | 420 | save_and_next(); |
| 297 | 421 | if (current == '.') |
| @@ -300,7 +424,7 @@ int luaY_lex (void) · 2 unmodified lines | ||
| 300 | 424 | } |
| 301 | 425 | fraction: |
| 302 | 426 | { double da=0.1; |
| 303 | − while (isdigit(current)) | |
| 427 | + while (isdigit((unsigned char)current)) | |
| 304 | 428 | { |
| 305 | 429 | a+=(current-'0')*da; |
| 306 | 430 | da/=10.0; |
| @@ -314,11 +438,12 @@ int luaY_lex (void) · 7 unmodified lines | ||
| 314 | 438 | save_and_next(); |
| 315 | 439 | neg=(current=='-'); |
| 316 | 440 | if (current == '+' || current == '-') save_and_next(); |
| 317 | − if (!isdigit(current)) { save(0); return WRONGTOKEN; } | |
| 441 | + if (!isdigit((unsigned char)current)) { | |
| 442 | + save(0); return WRONGTOKEN; } | |
| 318 | 443 | do { |
| 319 | 444 | e=10.0*e+(current-'0'); |
| 320 | 445 | save_and_next(); |
| 321 | − } while (isdigit(current)); | |
| 446 | + } while (isdigit((unsigned char)current)); | |
| 322 | 447 | for (ea=neg?0.1:10.0; e>0; e>>=1) |
| 323 | 448 | { |
| 324 | 449 | if (e & 1) a*=ea; |
| @@ -330,11 +455,15 @@ int luaY_lex (void) · 5 unmodified lines | ||
| 330 | 455 | return NUMBER; |
| 331 | 456 | } |
| 332 | 457 | |
| 333 | − default: /* also end of program (0) */ | |
| 334 | − { | |
| 458 | + case EOZ: | |
| 459 | + save(0); | |
| 460 | + if (iflevel > 0) | |
| 461 | + luaI_syntaxerror("missing $endif"); | |
| 462 | + return 0; | |
| 463 | + | |
| 464 | + default: | |
| 335 | 465 | save_and_next(); |
| 336 | 466 | return yytext[0]; |
| 337 | − } | |
| 338 | 467 | } |
| 339 | 468 | } |
| 340 | 469 | } |
| @@ -1,16 +1,15 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** lex.h |
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | −** $Id: lex.h,v 1.3 1996/11/08 12:49:35 roberto Exp $ | |
| 4 | +** $Id: lex.h,v 1.4 1997/06/16 16:50:22 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef lex_h |
| 8 | 8 | #define lex_h |
| 9 | 9 | |
| 10 | +#include "zio.h" | |
| 10 | 11 | |
| 11 | −typedef int (*Input) (void); | |
| 12 | − | |
| 13 | −void lua_setinput (Input fn); | |
| 12 | +void lua_setinput (ZIO *z); | |
| 14 | 13 | void luaI_syntaxerror (char *s); |
| 15 | 14 | int luaY_lex (void); |
| 16 | 15 | void luaI_addReserved (void); |
| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | %{ |
| 2 | 2 | |
| 3 | −char *rcs_luastx = "$Id: lua.stx,v 3.41 1996/11/08 12:49:35 roberto Exp $"; | |
| 3 | +char *rcs_luastx = "$Id: lua.stx,v 3.47 1997/06/19 17:46:12 roberto Exp $"; | |
| 4 | 4 | |
| 5 | 5 | #include <stdio.h> |
| 6 | 6 | #include <stdlib.h> |
| 7 | 7 | #include <string.h> |
| 8 | 8 | |
| 9 | 9 | #include "luadebug.h" |
| 10 | −#include "mem.h" | |
| 10 | +#include "luamem.h" | |
| 11 | 11 | #include "lex.h" |
| 12 | 12 | #include "opcode.h" |
| 13 | 13 | #include "hash.h" |
| @@ -50,8 +50,6 @@ static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ · 36 unmodified lines | ||
| 50 | 50 | static int nlocalvar=0; /* number of local variables */ |
| 51 | 51 | |
| 52 | 52 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
| 53 | −static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ | |
| 54 | −static int nfields=0; | |
| 55 | 53 | |
| 56 | 54 | int lua_debug = 0; |
| 57 | 55 | |
| @@ -103,22 +101,11 @@ static void code_word_at (Byte *p, int n) · 45 unmodified lines | ||
| 103 | 101 | memcpy(p, &w, sizeof(Word)); |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | −static void push_field (Word name) | |
| 107 | −{ | |
| 108 | − if (nfields < MAXFIELDS) | |
| 109 | − fields[nfields++] = name; | |
| 110 | − else | |
| 111 | − yyerror ("too many fields in nested constructors"); | |
| 112 | −} | |
| 113 | − | |
| 114 | 104 | static void flush_record (int n) |
| 115 | 105 | { |
| 116 | − int i; | |
| 117 | 106 | if (n == 0) return; |
| 118 | − code_byte(STORERECORD); | |
| 107 | + code_byte(STOREMAP); | |
| 119 | 108 | code_byte(n); |
| 120 | − for (i=0; i<n; i++) | |
| 121 | − code_word(fields[--nfields]); | |
| 122 | 109 | } |
| 123 | 110 | |
| 124 | 111 | static void flush_list (int m, int n) |
| @@ -161,11 +148,22 @@ static void add_varbuffer (Long var) · 36 unmodified lines | ||
| 161 | 148 | yyerror ("variable buffer overflow"); |
| 162 | 149 | } |
| 163 | 150 | |
| 151 | +static void code_string (Word w) | |
| 152 | +{ | |
| 153 | + code_byte(PUSHSTRING); | |
| 154 | + code_word(w); | |
| 155 | +} | |
| 156 | + | |
| 157 | +static void code_constant (TaggedString *s) | |
| 158 | +{ | |
| 159 | + code_string(luaI_findconstant(s)); | |
| 160 | +} | |
| 161 | + | |
| 164 | 162 | static void code_number (float f) |
| 165 | 163 | { |
| 166 | − Word i = (Word)f; | |
| 167 | − if (f == (float)i) /* f has an (short) integer value */ | |
| 168 | − { | |
| 164 | + Word i; | |
| 165 | + if (f >= 0 && f <= (float)MAX_WORD && (float)(i=(Word)f) == f) { | |
| 166 | + /* f has an (short) integer value */ | |
| 169 | 167 | if (i <= 2) code_byte(PUSH0 + i); |
| 170 | 168 | else if (i <= 255) |
| 171 | 169 | { |
| @@ -459,7 +457,7 @@ void lua_parse (TFunc *tf) · 287 unmodified lines | ||
| 459 | 457 | |
| 460 | 458 | %% /* beginning of rules section */ |
| 461 | 459 | |
| 462 | −chunk : chunklist ret | |
| 460 | +chunk : chunklist ret ; | |
| 463 | 461 | |
| 464 | 462 | chunklist : /* empty */ |
| 465 | 463 | | chunklist stat sc |
| @@ -477,8 +475,7 @@ function : FUNCTION funcname body · 11 unmodified lines | ||
| 477 | 475 | funcname : var { $$ =$1; init_func(); } |
| 478 | 476 | | varexp ':' NAME |
| 479 | 477 | { |
| 480 | − code_byte(PUSHSTRING); | |
| 481 | − code_word(luaI_findconstant($3)); | |
| 478 | + code_constant($3); | |
| 482 | 479 | $$ = 0; /* indexed variable */ |
| 483 | 480 | init_func(); |
| 484 | 481 | add_localvar(luaI_createfixedstring("self")); |
| @@ -492,7 +489,6 @@ body : '(' parlist ')' block END · 7 unmodified lines | ||
| 492 | 489 | luaI_initTFunc($$); |
| 493 | 490 | $$->size = pc; |
| 494 | 491 | $$->code = newvector(pc, Byte); |
| 495 | − $$->fileName = lua_parsedfile; | |
| 496 | 492 | $$->lineDefined = $2; |
| 497 | 493 | memcpy($$->code, basepc, pc*sizeof(Byte)); |
| 498 | 494 | if (lua_debug) |
| @@ -540,7 +536,7 @@ stat : IF expr1 THEN PrepJump block PrepJump elsepart END · 41 unmodified lines | ||
| 540 | 536 | lua_codeadjust (0); |
| 541 | 537 | } |
| 542 | 538 | } |
| 543 | − | functioncall | |
| 539 | + | functioncall {;} | |
| 544 | 540 | | LOCAL localdeclist decinit |
| 545 | 541 | { nlocalvar += $2; |
| 546 | 542 | adjust_mult_assign($2, $3, 0); |
| @@ -605,9 +601,8 @@ expr : '(' expr ')' { $$ = $2; } · 58 unmodified lines | ||
| 605 | 601 | | NUMBER { code_number($1); $$ = 0; } |
| 606 | 602 | | STRING |
| 607 | 603 | { |
| 608 | − code_byte(PUSHSTRING); | |
| 609 | − code_word($1); | |
| 610 | − $$ = 0; | |
| 604 | + code_string($1); | |
| 605 | + $$ = 0; | |
| 611 | 606 | } |
| 612 | 607 | | NIL {code_byte(PUSHNIL); $$ = 0; } |
| 613 | 608 | | functioncall { $$ = $1; } |
| @@ -723,12 +718,13 @@ ffieldlist1 : ffield {$$=1;} · 109 unmodified lines | ||
| 723 | 718 | } |
| 724 | 719 | ; |
| 725 | 720 | |
| 726 | −ffield : NAME '=' expr1 | |
| 727 | − { | |
| 728 | − push_field(luaI_findconstant($1)); | |
| 729 | − } | |
| 721 | +ffield : ffieldkey '=' expr1 | |
| 730 | 722 | ; |
| 731 | 723 | |
| 724 | +ffieldkey : '[' expr1 ']' | |
| 725 | + | NAME { code_constant($1); } | |
| 726 | + ; | |
| 727 | + | |
| 732 | 728 | lfieldlist : /* empty */ { $$ = 0; } |
| 733 | 729 | | lfieldlist1 lastcomma { $$ = $1; } |
| 734 | 730 | ; |
| @@ -762,9 +758,8 @@ var : singlevar { $$ = $1; } · 27 unmodified lines | ||
| 762 | 758 | } |
| 763 | 759 | | varexp '.' NAME |
| 764 | 760 | { |
| 765 | − code_byte(PUSHSTRING); | |
| 766 | − code_word(luaI_findconstant($3)); | |
| 767 | − $$ = 0; /* indexed variable */ | |
| 761 | + code_constant($3); | |
| 762 | + $$ = 0; /* indexed variable */ | |
| 768 | 763 | } |
| 769 | 764 | ; |
| 770 | 765 | |
| @@ -3,15 +3,13 @@ · 2 unmodified lines | ||
| 3 | 3 | ** thread and save bytecodes to file |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char* rcs_dump="$Id: dump.c,v 1.17 1996/11/18 11:18:29 lhf Exp $"; | |
| 6 | +char* rcs_dump="$Id: dump.c,v 1.20 1997/06/19 14:56:04 lhf Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <stdlib.h> |
| 10 | 10 | #include <string.h> |
| 11 | 11 | #include "luac.h" |
| 12 | 12 | |
| 13 | −static TFunc* lastF=NULL; /* list of functions seen in code */ | |
| 14 | − | |
| 15 | 13 | static int SawVar(int i, int at) |
| 16 | 14 | { |
| 17 | 15 | int old=VarLoc(i); |
| @@ -34,7 +32,7 @@ static void ThreadCode(Byte* code, Byte* end) · 16 unmodified lines | ||
| 34 | 32 | for (i=0; i<lua_nconstant; i++) StrLoc(i)=0; |
| 35 | 33 | for (p=code; p!=end;) |
| 36 | 34 | { |
| 37 | − OpCode op=(OpCode)*p; | |
| 35 | + int op=*p; | |
| 38 | 36 | int at=p-code+1; |
| 39 | 37 | switch (op) |
| 40 | 38 | { |
| @@ -89,6 +87,8 @@ static void ThreadCode(Byte* code, Byte* end) · 48 unmodified lines | ||
| 89 | 87 | case STORELIST0: |
| 90 | 88 | case ADJUST: |
| 91 | 89 | case RETCODE: |
| 90 | + case VARARGS: | |
| 91 | + case STOREMAP: | |
| 92 | 92 | p+=2; |
| 93 | 93 | break; |
| 94 | 94 | case PUSHWORD: |
| @@ -107,8 +107,11 @@ static void ThreadCode(Byte* code, Byte* end) · 12 unmodified lines | ||
| 107 | 107 | case PUSHFLOAT: |
| 108 | 108 | p+=5; /* assumes sizeof(float)==4 */ |
| 109 | 109 | break; |
| 110 | − case PUSHSELF: | |
| 110 | + case PUSHFUNCTION: | |
| 111 | + p+=sizeof(TFunc*)+1; | |
| 112 | + break; | |
| 111 | 113 | case PUSHSTRING: |
| 114 | + case PUSHSELF: | |
| 112 | 115 | { |
| 113 | 116 | Word w; |
| 114 | 117 | p++; |
| @@ -117,16 +120,6 @@ static void ThreadCode(Byte* code, Byte* end) · 2 unmodified lines | ||
| 117 | 120 | memcpy(p-2,&w,sizeof(w)); |
| 118 | 121 | break; |
| 119 | 122 | } |
| 120 | − case PUSHFUNCTION: | |
| 121 | − { | |
| 122 | − TFunc* tf; | |
| 123 | − p++; | |
| 124 | − get_code(tf,p); | |
| 125 | − tf->marked=at; | |
| 126 | − tf->next=NULL; /* TODO: remove? */ | |
| 127 | − lastF=lastF->next=tf; | |
| 128 | − break; | |
| 129 | − } | |
| 130 | 123 | case PUSHGLOBAL: |
| 131 | 124 | case STOREGLOBAL: |
| 132 | 125 | { |
| @@ -151,8 +144,8 @@ static void ThreadCode(Byte* code, Byte* end) · 18 unmodified lines | ||
| 151 | 144 | } |
| 152 | 145 | break; |
| 153 | 146 | } |
| 154 | − default: | |
| 155 | − fprintf(stderr,"luac: cannot happen: opcode=%d",*p); | |
| 147 | + default: /* cannot happen */ | |
| 148 | + fprintf(stderr,"luac: bad opcode %d at %d\n",*p,(int)(p-code)); | |
| 156 | 149 | exit(1); |
| 157 | 150 | break; |
| 158 | 151 | } |
| @@ -186,7 +179,7 @@ static void DumpString(char* s, FILE* D) · 27 unmodified lines | ||
| 186 | 179 | int n=strlen(s)+1; |
| 187 | 180 | if ((Word)n != n) |
| 188 | 181 | { |
| 189 | − fprintf(stderr,"luac: string too long: \"%.32s...\"\n",s); | |
| 182 | + fprintf(stderr,"luac: string too long (%d bytes): \"%.32s...\"\n",n,s); | |
| 190 | 183 | exit(1); |
| 191 | 184 | } |
| 192 | 185 | DumpWord(n,D); |
| @@ -220,7 +213,6 @@ static void DumpStrings(FILE* D) · 27 unmodified lines | ||
| 220 | 213 | |
| 221 | 214 | void DumpFunction(TFunc* tf, FILE* D) |
| 222 | 215 | { |
| 223 | − lastF=tf; | |
| 224 | 216 | ThreadCode(tf->code,tf->code+tf->size); |
| 225 | 217 | fputc(ID_FUN,D); |
| 226 | 218 | DumpSize(tf->size,D); |
| @@ -1,25 +1,39 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** luac.c |
| 3 | −** lua compiler (saves bytecodes to files) | |
| 3 | +** lua compiler (saves bytecodes to files; also list binary files) | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char* rcs_luac="$Id: luac.c,v 1.18 1996/11/16 20:14:23 lhf Exp $"; | |
| 6 | +char* rcs_luac="$Id: luac.c,v 1.23 1997/06/20 20:34:04 lhf Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <stdlib.h> |
| 10 | 10 | #include <string.h> |
| 11 | 11 | #include "luac.h" |
| 12 | +#include "lex.h" | |
| 13 | +#include "zio.h" | |
| 12 | 14 | |
| 13 | 15 | static void compile(char* filename); |
| 16 | +static void undump(char* filename); | |
| 14 | 17 | |
| 15 | 18 | static int listing=0; /* list bytecodes? */ |
| 16 | 19 | static int dumping=1; /* dump bytecodes? */ |
| 20 | +static int undumping=0; /* undump bytecodes? */ | |
| 17 | 21 | static FILE* D; /* output file */ |
| 18 | 22 | |
| 19 | 23 | static void usage(void) |
| 20 | 24 | { |
| 21 | − fprintf(stderr,"usage: luac [-dlpv] [-o output] file ...\n"); | |
| 22 | − exit(0); | |
| 25 | + fprintf(stderr, | |
| 26 | + "usage: luac [-c | -u] [-d] [-l] [-p] [-q] [-v] [-o output] file ...\n" | |
| 27 | + " -c\tcompile (default)\n" | |
| 28 | + " -u\tundump\n" | |
| 29 | + " -d\tgenerate debugging information\n" | |
| 30 | + " -l\tlist (default for -u)\n" | |
| 31 | + " -o\toutput file for -c (default \"luac.out\")\n" | |
| 32 | + " -p\tparse only\n" | |
| 33 | + " -q\tquiet (default for -c)\n" | |
| 34 | + " -v\tshow version information\n" | |
| 35 | + ); | |
| 36 | + exit(1); | |
| 23 | 37 | } |
| 24 | 38 | |
| 25 | 39 | #define IS(s) (strcmp(argv[i],s)==0) |
| @@ -34,6 +48,11 @@ int main(int argc, char* argv[]) · 8 unmodified lines | ||
| 34 | 48 | break; |
| 35 | 49 | else if (IS("-")) /* use stdin */ |
| 36 | 50 | break; |
| 51 | + else if (IS("-c")) /* compile (and dump) */ | |
| 52 | + { | |
| 53 | + dumping=1; | |
| 54 | + undumping=0; | |
| 55 | + } | |
| 37 | 56 | else if (IS("-d")) /* debug */ |
| 38 | 57 | lua_debug=1; |
| 39 | 58 | else if (IS("-l")) /* list */ |
| @@ -42,6 +61,14 @@ int main(int argc, char* argv[]) · 2 unmodified lines | ||
| 42 | 61 | d=argv[++i]; |
| 43 | 62 | else if (IS("-p")) /* parse only (for timing purposes) */ |
| 44 | 63 | dumping=0; |
| 64 | + else if (IS("-q")) /* quiet */ | |
| 65 | + listing=0; | |
| 66 | + else if (IS("-u")) /* undump */ | |
| 67 | + { | |
| 68 | + dumping=0; | |
| 69 | + undumping=1; | |
| 70 | + listing=1; | |
| 71 | + } | |
| 45 | 72 | else if (IS("-v")) /* show version */ |
| 46 | 73 | printf("%s %s\n(written by %s)\n\n",LUA_VERSION,LUA_COPYRIGHT,LUA_AUTHORS); |
| 47 | 74 | else /* unknown option */ |
| @@ -50,56 +77,114 @@ int main(int argc, char* argv[]) · 2 unmodified lines | ||
| 50 | 77 | --i; /* fake new argv[0] */ |
| 51 | 78 | argc-=i; |
| 52 | 79 | argv+=i; |
| 53 | − if (argc<2) usage(); | |
| 54 | − for (i=1; i<argc; i++) | |
| 55 | − if (IS(d)) | |
| 80 | + if (dumping) | |
| 81 | + { | |
| 82 | + if (argc<2) usage(); | |
| 83 | + for (i=1; i<argc; i++) /* play safe with output file */ | |
| 84 | + if (IS(d)) | |
| 85 | + { | |
| 86 | + fprintf(stderr,"luac: will not overwrite input file \"%s\"\n",d); | |
| 87 | + exit(1); | |
| 88 | + } | |
| 89 | + D=fopen(d,"wb"); /* must open in binary mode */ | |
| 90 | + if (D==NULL) | |
| 56 | 91 | { |
| 57 | − fprintf(stderr,"luac: will not overwrite input file \"%s\"\n",d); | |
| 92 | + fprintf(stderr,"luac: cannot open "); | |
| 93 | + perror(d); | |
| 58 | 94 | exit(1); |
| 59 | 95 | } |
| 60 | − D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */ | |
| 61 | − if (D==NULL) | |
| 96 | + for (i=1; i<argc; i++) compile(IS("-")? NULL : argv[i]); | |
| 97 | + fclose(D); | |
| 98 | + } | |
| 99 | + if (undumping) | |
| 62 | 100 | { |
| 63 | − fprintf(stderr,"luac: cannot open "); | |
| 64 | − perror(d); | |
| 65 | − exit(1); | |
| 101 | + if (argc<2) | |
| 102 | + undump("luac.out"); | |
| 103 | + else | |
| 104 | + for (i=1; i<argc; i++) undump(IS("-")? NULL : argv[i]); | |
| 66 | 105 | } |
| 67 | − for (i=1; i<argc; i++) compile(IS("-")? NULL : argv[i]); | |
| 68 | − fclose(D); | |
| 69 | 106 | return 0; |
| 70 | 107 | } |
| 71 | 108 | |
| 72 | −static void do_dump(TFunc* tf) /* only for tf==main */ | |
| 109 | +static void do_dump(TFunc* Main) | |
| 73 | 110 | { |
| 74 | − if (dumping) DumpHeader(D); | |
| 75 | − while (tf!=NULL) | |
| 111 | + TFunc* tf; | |
| 112 | + LinkFunctions(Main); | |
| 113 | + if (listing) | |
| 114 | + { | |
| 115 | + for (tf=Main; tf!=NULL; tf=tf->next) PrintFunction(tf,Main); | |
| 116 | + } | |
| 117 | + if (dumping) | |
| 76 | 118 | { |
| 77 | − TFunc* nf; | |
| 78 | − if (listing) PrintFunction(tf); | |
| 79 | − if (dumping) DumpFunction(tf,D); | |
| 80 | − nf=tf->next; /* list only built after first main */ | |
| 119 | + DumpHeader(D); | |
| 120 | + for (tf=Main; tf!=NULL; tf=tf->next) DumpFunction(tf,D); | |
| 121 | + } | |
| 122 | + for (tf=Main; tf!=NULL; ) | |
| 123 | + { | |
| 124 | + TFunc* nf=tf->next; | |
| 81 | 125 | luaI_freefunc(tf); |
| 82 | 126 | tf=nf; |
| 83 | 127 | } |
| 84 | 128 | } |
| 85 | 129 | |
| 86 | −static void do_compile(void) | |
| 130 | +static void do_compile(ZIO* z) | |
| 87 | 131 | { |
| 88 | 132 | TFunc* tf=new(TFunc); |
| 133 | + lua_setinput(z); | |
| 89 | 134 | luaI_initTFunc(tf); |
| 90 | − tf->fileName = lua_parsedfile; | |
| 135 | + tf->fileName=lua_parsedfile; | |
| 91 | 136 | lua_parse(tf); |
| 92 | 137 | do_dump(tf); |
| 93 | 138 | } |
| 94 | 139 | |
| 95 | 140 | static void compile(char* filename) |
| 96 | 141 | { |
| 97 | − if (lua_openfile(filename)==NULL) | |
| 142 | + FILE* f= (filename==NULL) ? stdin : fopen(filename, "r"); | |
| 143 | + if (f==NULL) | |
| 144 | + { | |
| 145 | + fprintf(stderr,"luac: cannot open "); | |
| 146 | + perror(filename); | |
| 147 | + exit(1); | |
| 148 | + } | |
| 149 | + else | |
| 150 | + { | |
| 151 | + ZIO z; | |
| 152 | + zFopen(&z,f); | |
| 153 | + luaI_setparsedfile(filename?filename:"(stdin)"); | |
| 154 | + do_compile(&z); | |
| 155 | + fclose(f); | |
| 156 | + } | |
| 157 | +} | |
| 158 | + | |
| 159 | +static void do_undump(ZIO* z) | |
| 160 | +{ | |
| 161 | + TFunc* Main; | |
| 162 | + while ((Main=luaI_undump1(z))) | |
| 163 | + { | |
| 164 | + if (listing) | |
| 165 | + { | |
| 166 | + TFunc* tf; | |
| 167 | + for (tf=Main; tf!=NULL; tf=tf->next) | |
| 168 | + PrintFunction(tf,Main); | |
| 169 | + } | |
| 170 | + luaI_freefunc(Main); /* TODO: free others */ | |
| 171 | + } | |
| 172 | +} | |
| 173 | + | |
| 174 | +static void undump(char* filename) | |
| 175 | +{ | |
| 176 | + FILE* f= (filename==NULL) ? stdin : fopen(filename, "rb"); | |
| 177 | + if (f==NULL) | |
| 98 | 178 | { |
| 99 | 179 | fprintf(stderr,"luac: cannot open "); |
| 100 | 180 | perror(filename); |
| 101 | 181 | exit(1); |
| 102 | 182 | } |
| 103 | − do_compile(); | |
| 104 | − lua_closefile(); | |
| 183 | + else | |
| 184 | + { | |
| 185 | + ZIO z; | |
| 186 | + zFopen(&z,f); | |
| 187 | + do_undump(&z); | |
| 188 | + fclose(f); | |
| 189 | + } | |
| 105 | 190 | } |
| @@ -1,24 +1,25 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** luac.h |
| 3 | 3 | ** definitions for luac compiler |
| 4 | −** $Id: luac.h,v 1.5 1996/03/08 21:41:47 lhf Exp $ | |
| 4 | +** $Id: luac.h,v 1.8 1997/06/19 17:32:08 lhf Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #include "inout.h" |
| 8 | −#include "mem.h" | |
| 8 | +#include "luamem.h" | |
| 9 | 9 | #include "opcode.h" |
| 10 | 10 | #include "table.h" |
| 11 | 11 | #include "undump.h" |
| 12 | 12 | |
| 13 | 13 | #define VarStr(i) (lua_table[i].varname->str) |
| 14 | −#define VarLoc(i) (lua_table[i].varname->varindex) | |
| 14 | +#define VarLoc(i) (lua_table[i].varname->u.s.varindex) | |
| 15 | 15 | #define StrStr(i) (lua_constant[i]->str) |
| 16 | −#define StrLoc(i) (lua_constant[i]->constindex) | |
| 16 | +#define StrLoc(i) (lua_constant[i]->u.s.constindex) | |
| 17 | 17 | |
| 18 | 18 | extern Word lua_ntable; |
| 19 | 19 | extern Word lua_nconstant; |
| 20 | 20 | extern int lua_debug; |
| 21 | 21 | |
| 22 | +void LinkFunctions(TFunc* tf); | |
| 23 | +void PrintFunction(TFunc* tf, TFunc* Main); | |
| 22 | 24 | void DumpHeader(FILE* D); |
| 23 | 25 | void DumpFunction(TFunc* tf, FILE* D); |
| 24 | −void PrintFunction(TFunc* tf); | |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | ** print bytecodes |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char* rcs_print="$Id: print.c,v 1.11 1996/11/18 11:24:16 lhf Exp $"; | |
| 6 | +char* rcs_print="$Id: print.c,v 1.17 1997/06/25 17:07:28 lhf Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <stdlib.h> |
| @@ -11,20 +11,134 @@ char* rcs_print="$Id: print.c,v 1.11 1996/11/18 11:24:16 lhf Exp $"; · 1 unmodified line | ||
| 11 | 11 | #include "luac.h" |
| 12 | 12 | #include "print.h" |
| 13 | 13 | |
| 14 | −static LocVar* V=NULL; | |
| 15 | − | |
| 16 | −static char* LocStr(int i) | |
| 14 | +void LinkFunctions(TFunc* m) | |
| 17 | 15 | { |
| 18 | − if (V==NULL) return ""; else return V[i].varname->str; | |
| 16 | + static TFunc* lastF; /* list of functions seen in code */ | |
| 17 | + Byte* code=m->code; | |
| 18 | + Byte* end=code+m->size; | |
| 19 | + Byte* p; | |
| 20 | + if (IsMain(m)) lastF=m; | |
| 21 | + for (p=code; p!=end;) | |
| 22 | + { | |
| 23 | + int op=*p; | |
| 24 | + int at=p-code+1; | |
| 25 | + switch (op) | |
| 26 | + { | |
| 27 | + case PUSHNIL: | |
| 28 | + case PUSH0: | |
| 29 | + case PUSH1: | |
| 30 | + case PUSH2: | |
| 31 | + case PUSHLOCAL0: | |
| 32 | + case PUSHLOCAL1: | |
| 33 | + case PUSHLOCAL2: | |
| 34 | + case PUSHLOCAL3: | |
| 35 | + case PUSHLOCAL4: | |
| 36 | + case PUSHLOCAL5: | |
| 37 | + case PUSHLOCAL6: | |
| 38 | + case PUSHLOCAL7: | |
| 39 | + case PUSHLOCAL8: | |
| 40 | + case PUSHLOCAL9: | |
| 41 | + case PUSHINDEXED: | |
| 42 | + case STORELOCAL0: | |
| 43 | + case STORELOCAL1: | |
| 44 | + case STORELOCAL2: | |
| 45 | + case STORELOCAL3: | |
| 46 | + case STORELOCAL4: | |
| 47 | + case STORELOCAL5: | |
| 48 | + case STORELOCAL6: | |
| 49 | + case STORELOCAL7: | |
| 50 | + case STORELOCAL8: | |
| 51 | + case STORELOCAL9: | |
| 52 | + case STOREINDEXED0: | |
| 53 | + case ADJUST0: | |
| 54 | + case EQOP: | |
| 55 | + case LTOP: | |
| 56 | + case LEOP: | |
| 57 | + case GTOP: | |
| 58 | + case GEOP: | |
| 59 | + case ADDOP: | |
| 60 | + case SUBOP: | |
| 61 | + case MULTOP: | |
| 62 | + case DIVOP: | |
| 63 | + case POWOP: | |
| 64 | + case CONCOP: | |
| 65 | + case MINUSOP: | |
| 66 | + case NOTOP: | |
| 67 | + case POP: | |
| 68 | + case RETCODE0: | |
| 69 | + p++; | |
| 70 | + break; | |
| 71 | + case PUSHBYTE: | |
| 72 | + case PUSHLOCAL: | |
| 73 | + case STORELOCAL: | |
| 74 | + case STOREINDEXED: | |
| 75 | + case STORELIST0: | |
| 76 | + case ADJUST: | |
| 77 | + case RETCODE: | |
| 78 | + case VARARGS: | |
| 79 | + case STOREMAP: | |
| 80 | + p+=2; | |
| 81 | + break; | |
| 82 | + case PUSHWORD: | |
| 83 | + case PUSHSTRING: | |
| 84 | + case PUSHGLOBAL: | |
| 85 | + case PUSHSELF: | |
| 86 | + case STOREGLOBAL: | |
| 87 | + case CREATEARRAY: | |
| 88 | + case ONTJMP: | |
| 89 | + case ONFJMP: | |
| 90 | + case JMP: | |
| 91 | + case UPJMP: | |
| 92 | + case IFFJMP: | |
| 93 | + case IFFUPJMP: | |
| 94 | + case CALLFUNC: | |
| 95 | + case SETLINE: | |
| 96 | + case STORELIST: | |
| 97 | + p+=3; | |
| 98 | + break; | |
| 99 | + case PUSHFLOAT: | |
| 100 | + p+=5; /* assumes sizeof(float)==4 */ | |
| 101 | + break; | |
| 102 | + case PUSHFUNCTION: | |
| 103 | + { | |
| 104 | + TFunc* tf; | |
| 105 | + p++; | |
| 106 | + get_code(tf,p); | |
| 107 | + tf->marked=at; | |
| 108 | + tf->next=NULL; /* TODO: remove? */ | |
| 109 | + lastF=lastF->next=tf; | |
| 110 | + break; | |
| 111 | + } | |
| 112 | + case STORERECORD: | |
| 113 | + { | |
| 114 | + int n=*++p; | |
| 115 | + p+=2*n+1; | |
| 116 | + break; | |
| 117 | + } | |
| 118 | + default: /* cannot happen */ | |
| 119 | + fprintf(stderr,"luac: bad opcode %d at %d\n",*p,(int)(p-code)); | |
| 120 | + exit(1); | |
| 121 | + break; | |
| 122 | + } | |
| 123 | + } | |
| 19 | 124 | } |
| 20 | 125 | |
| 21 | −static void PrintCode(Byte* code, Byte* end) | |
| 126 | +#define LocStr(i) luaI_getlocalname(tf,i+1,line) | |
| 127 | + | |
| 128 | +static void PrintCode(TFunc* tf) | |
| 22 | 129 | { |
| 130 | + Byte* code=tf->code; | |
| 131 | + Byte* end=code+tf->size; | |
| 23 | 132 | Byte* p; |
| 133 | + int line=0; | |
| 24 | 134 | for (p=code; p!=end;) |
| 25 | 135 | { |
| 26 | − OpCode op=(OpCode)*p; | |
| 27 | − if (op>SETLINE) op=SETLINE+1; | |
| 136 | + int op=*p; | |
| 137 | + if (op>=NOPCODES) | |
| 138 | + { | |
| 139 | + fprintf(stderr,"luac: bad opcode %d at %d\n",op,(int)(p-code)); | |
| 140 | + exit(1); | |
| 141 | + } | |
| 28 | 142 | printf("%6d\t%s",(int)(p-code),OpCodeName[op]); |
| 29 | 143 | switch (op) |
| 30 | 144 | { |
| @@ -64,7 +178,7 @@ static void PrintCode(Byte* code, Byte* end) · 33 unmodified lines | ||
| 64 | 178 | case PUSHLOCAL9: |
| 65 | 179 | { |
| 66 | 180 | int i=op-PUSHLOCAL0; |
| 67 | − printf("\t%d\t; %s",i,LocStr(i)); | |
| 181 | + if (tf->locvars) printf("\t\t; %s",LocStr(i)); | |
| 68 | 182 | p++; |
| 69 | 183 | break; |
| 70 | 184 | } |
| @@ -80,7 +194,7 @@ static void PrintCode(Byte* code, Byte* end) · 9 unmodified lines | ||
| 80 | 194 | case STORELOCAL9: |
| 81 | 195 | { |
| 82 | 196 | int i=op-STORELOCAL0; |
| 83 | − printf("\t%d\t; %s",i,LocStr(i)); | |
| 197 | + if (tf->locvars) printf("\t\t; %s",LocStr(i)); | |
| 84 | 198 | p++; |
| 85 | 199 | break; |
| 86 | 200 | } |
| @@ -88,7 +202,7 @@ static void PrintCode(Byte* code, Byte* end) · 1 unmodified line | ||
| 88 | 202 | case STORELOCAL: |
| 89 | 203 | { |
| 90 | 204 | int i=*(p+1); |
| 91 | − printf("\t%d\t; %s",i,LocStr(i)); | |
| 205 | + if (tf->locvars) printf("\t%d\t; %s",i,LocStr(i)); | |
| 92 | 206 | p+=2; |
| 93 | 207 | break; |
| 94 | 208 | } |
| @@ -97,23 +211,40 @@ static void PrintCode(Byte* code, Byte* end) · 2 unmodified lines | ||
| 97 | 211 | case STORELIST0: |
| 98 | 212 | case ADJUST: |
| 99 | 213 | case RETCODE: |
| 214 | + case VARARGS: | |
| 215 | + case STOREMAP: | |
| 100 | 216 | printf("\t%d",*(p+1)); |
| 101 | 217 | p+=2; |
| 102 | 218 | break; |
| 103 | 219 | case PUSHWORD: |
| 104 | 220 | case CREATEARRAY: |
| 221 | + case SETLINE: | |
| 222 | + { | |
| 223 | + Word w; | |
| 224 | + p++; | |
| 225 | + get_word(w,p); | |
| 226 | + printf("\t%d",w); | |
| 227 | + if (op==SETLINE) line=w; | |
| 228 | + break; | |
| 229 | + } | |
| 105 | 230 | case ONTJMP: |
| 106 | 231 | case ONFJMP: |
| 107 | 232 | case JMP: |
| 108 | − case UPJMP: | |
| 109 | 233 | case IFFJMP: |
| 234 | + { /* suggested by Norman Ramsey <nr@cs.virginia.edu> */ | |
| 235 | + Word w; | |
| 236 | + p++; | |
| 237 | + get_word(w,p); | |
| 238 | + printf("\t%d\t\t; to %d",w,(int)(p-code)+w); | |
| 239 | + break; | |
| 240 | + } | |
| 241 | + case UPJMP: | |
| 110 | 242 | case IFFUPJMP: |
| 111 | − case SETLINE: | |
| 112 | − { | |
| 243 | + { /* suggested by Norman Ramsey <nr@cs.virginia.edu> */ | |
| 113 | 244 | Word w; |
| 114 | 245 | p++; |
| 115 | 246 | get_word(w,p); |
| 116 | − printf("\t%d",w); | |
| 247 | + printf("\t%d\t\t; to %d",w,(int)(p-code)-w); | |
| 117 | 248 | break; |
| 118 | 249 | } |
| 119 | 250 | case PUSHFLOAT: |
| @@ -170,7 +301,8 @@ static void PrintCode(Byte* code, Byte* end) · 50 unmodified lines | ||
| 170 | 301 | break; |
| 171 | 302 | } |
| 172 | 303 | default: |
| 173 | − printf("\tcannot happen: opcode=%d",*p); | |
| 304 | + printf("\tcannot happen: opcode=%d\n",*p); | |
| 305 | + fprintf(stderr,"luac: bad opcode %d at %d\n",op,(int)(p-code)); | |
| 174 | 306 | exit(1); |
| 175 | 307 | break; |
| 176 | 308 | } |
| @@ -178,13 +310,74 @@ static void PrintCode(Byte* code, Byte* end) · 1 unmodified line | ||
| 178 | 310 | } |
| 179 | 311 | } |
| 180 | 312 | |
| 181 | −void PrintFunction(TFunc* tf) | |
| 313 | +#undef LocStr | |
| 314 | + | |
| 315 | +static void PrintLocals(LocVar* v, int n) | |
| 182 | 316 | { |
| 317 | + int i=0; | |
| 318 | + if (v==NULL || v->varname==NULL) return; | |
| 319 | + if (n>0) | |
| 320 | + { | |
| 321 | + printf("parameters:"); | |
| 322 | + for (i=0; i<n; v++,i++) printf(" %s[%d@%d]",v->varname->str,i,v->line); | |
| 323 | + printf("\n"); | |
| 324 | + } | |
| 325 | + if (v->varname!=NULL) | |
| 326 | + { | |
| 327 | + printf("locals:"); | |
| 328 | + for (; v->line>=0; v++) | |
| 329 | + { | |
| 330 | + if (v->varname==NULL) | |
| 331 | +#if 0 | |
| 332 | + printf(" %s[%d@%d]","*",--i,v->line); | |
| 333 | +#else | |
| 334 | + --i; | |
| 335 | +#endif | |
| 336 | + else | |
| 337 | + printf(" %s[%d@%d]",v->varname->str,i++,v->line); | |
| 338 | + } | |
| 339 | + printf("\n"); | |
| 340 | + } | |
| 341 | +} | |
| 342 | + | |
| 343 | +void PrintFunction(TFunc* tf, TFunc* Main) | |
| 344 | +{ | |
| 345 | + int n=0; | |
| 183 | 346 | if (IsMain(tf)) |
| 184 | 347 | printf("\nmain of \"%s\" (%d bytes at %p)\n",tf->fileName,tf->size,tf); |
| 185 | 348 | else |
| 186 | − printf("\nfunction \"%s\":%d (%d bytes at %p); used at main+%d\n", | |
| 349 | + { | |
| 350 | + Byte* p; | |
| 351 | + p=tf->code; /* get number of parameters */ | |
| 352 | + while (*p==SETLINE) p+=3; | |
| 353 | + if (*p==ADJUST) n=p[1]; | |
| 354 | + p=Main->code+tf->marked+sizeof(TFunc*); | |
| 355 | + printf("\nfunction "); | |
| 356 | + switch (*p) /* try to get name */ | |
| 357 | + { | |
| 358 | + case STOREGLOBAL: | |
| 359 | + { | |
| 360 | + Word w; | |
| 361 | + p++; get_word(w,p); printf("%s defined at ",VarStr(w)); | |
| 362 | + break; | |
| 363 | + } | |
| 364 | + case STOREINDEXED0: /* try method definition */ | |
| 365 | + { | |
| 366 | + if (p[-11]==PUSHGLOBAL && p[-8]==PUSHSTRING) | |
| 367 | + { | |
| 368 | + Word w; | |
| 369 | + Byte* op=p; | |
| 370 | + int c=(tf->locvars && n>0 && strcmp(tf->locvars->varname->str,"self")==0) | |
| 371 | + ? ':' : '.'; | |
| 372 | + p=op-11; p++; get_word(w,p); printf("%s%c",VarStr(w),c); | |
| 373 | + p=op-8; p++; get_word(w,p); printf("%s defined at ",StrStr(w)); | |
| 374 | + } | |
| 375 | + break; | |
| 376 | + } | |
| 377 | + } | |
| 378 | + printf("\"%s\":%d (%d bytes at %p); used at main+%d\n", | |
| 187 | 379 | tf->fileName,tf->lineDefined,tf->size,tf,tf->marked); |
| 188 | − V=tf->locvars; | |
| 189 | − PrintCode(tf->code,tf->code+tf->size); | |
| 380 | + } | |
| 381 | + PrintLocals(tf->locvars,n); | |
| 382 | + PrintCode(tf); | |
| 190 | 383 | } |
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** print.h |
| 3 | 3 | ** opcode names |
| 4 | −** $Id: print.h,v 1.1 1996/02/23 19:04:13 lhf Exp $ | |
| 4 | +** $Id: print.h,v 1.3 1997/04/14 14:42:50 lhf Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | −static char* OpCodeName[]={ /* attention: same order as enum in opcode.h */ | |
| 7 | +static char* OpCodeName[]={ /* ATTENTION: same order as enum in opcode.h */ | |
| 8 | 8 | "PUSHNIL", |
| 9 | 9 | "PUSH0", |
| 10 | 10 | "PUSH1", |
| @@ -72,5 +72,8 @@ static char* OpCodeName[]={ /* attention: same order as enum in opcode.h */ · 61 unmodified lines | ||
| 72 | 72 | "RETCODE0", |
| 73 | 73 | "RETCODE", |
| 74 | 74 | "SETLINE", |
| 75 | − "" | |
| 75 | + "VARARGS", | |
| 76 | + "STOREMAP" | |
| 76 | 77 | }; |
| 78 | + | |
| 79 | +#define NOPCODES (sizeof(OpCodeName)/sizeof(OpCodeName[0])) | |
| @@ -0,0 +1,159 @@ | ||
| 1 | +/* | |
| 2 | +** mem.c | |
| 3 | +** TecCGraf - PUC-Rio | |
| 4 | +*/ | |
| 5 | + | |
| 6 | +char *rcs_luamem = "$Id: luamem.c,v 1.16 1997/04/01 21:23:20 roberto Exp $"; | |
| 7 | + | |
| 8 | +#include <stdlib.h> | |
| 9 | + | |
| 10 | +#include "luamem.h" | |
| 11 | +#include "lua.h" | |
| 12 | + | |
| 13 | + | |
| 14 | +#define DEBUG 0 | |
| 15 | + | |
| 16 | +#if !DEBUG | |
| 17 | + | |
| 18 | +void luaI_free (void *block) | |
| 19 | +{ | |
| 20 | + if (block) | |
| 21 | + { | |
| 22 | + *((char *)block) = -1; /* to catch errors */ | |
| 23 | + free(block); | |
| 24 | + } | |
| 25 | +} | |
| 26 | + | |
| 27 | + | |
| 28 | +void *luaI_realloc (void *oldblock, unsigned long size) | |
| 29 | +{ | |
| 30 | + void *block; | |
| 31 | + size_t s = (size_t)size; | |
| 32 | + if (s != size) | |
| 33 | + lua_error("Allocation Error: Block too big"); | |
| 34 | + block = oldblock ? realloc(oldblock, s) : malloc(s); | |
| 35 | + if (block == NULL) | |
| 36 | + lua_error(memEM); | |
| 37 | + return block; | |
| 38 | +} | |
| 39 | + | |
| 40 | + | |
| 41 | +int luaI_growvector (void **block, unsigned long nelems, int size, | |
| 42 | + char *errormsg, unsigned long limit) | |
| 43 | +{ | |
| 44 | + if (nelems >= limit) | |
| 45 | + lua_error(errormsg); | |
| 46 | + nelems = (nelems == 0) ? 20 : nelems*2; | |
| 47 | + if (nelems > limit) | |
| 48 | + nelems = limit; | |
| 49 | + *block = luaI_realloc(*block, nelems*size); | |
| 50 | + return (int)nelems; | |
| 51 | +} | |
| 52 | + | |
| 53 | + | |
| 54 | +void* luaI_buffer (unsigned long size) | |
| 55 | +{ | |
| 56 | + static unsigned long buffsize = 0; | |
| 57 | + static char* buffer = NULL; | |
| 58 | + if (size > buffsize) | |
| 59 | + buffer = luaI_realloc(buffer, buffsize=size); | |
| 60 | + return buffer; | |
| 61 | +} | |
| 62 | + | |
| 63 | +#else | |
| 64 | +/* DEBUG */ | |
| 65 | + | |
| 66 | +#include <stdio.h> | |
| 67 | + | |
| 68 | +# define assert(ex) {if (!(ex)){(void)fprintf(stderr, \ | |
| 69 | + "Assertion failed: file \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}} | |
| 70 | + | |
| 71 | +#define MARK 55 | |
| 72 | + | |
| 73 | +static unsigned long numblocks = 0; | |
| 74 | +static unsigned long totalmem = 0; | |
| 75 | + | |
| 76 | + | |
| 77 | +static void message (void) | |
| 78 | +{ | |
| 79 | +#define inrange(x,y) ((x) < (((y)*3)/2) && (x) > (((y)*2)/3)) | |
| 80 | + static int count = 0; | |
| 81 | + static unsigned long lastnumblocks = 0; | |
| 82 | + static unsigned long lasttotalmem = 0; | |
| 83 | + if (!inrange(numblocks, lastnumblocks) || !inrange(totalmem, lasttotalmem) | |
| 84 | + || count++ >= 5000) | |
| 85 | + { | |
| 86 | + fprintf(stderr,"blocks = %lu mem = %luK\n", numblocks, totalmem/1000); | |
| 87 | + count = 0; | |
| 88 | + lastnumblocks = numblocks; | |
| 89 | + lasttotalmem = totalmem; | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | + | |
| 94 | +void luaI_free (void *block) | |
| 95 | +{ | |
| 96 | + if (block) | |
| 97 | + { | |
| 98 | + unsigned long *b = (unsigned long *)block - 1; | |
| 99 | + unsigned long size = *b; | |
| 100 | + assert(*(((char *)b)+size+sizeof(unsigned long)) == MARK); | |
| 101 | + numblocks--; | |
| 102 | + totalmem -= size; | |
| 103 | + free(b); | |
| 104 | + message(); | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 108 | + | |
| 109 | +void *luaI_realloc (void *oldblock, unsigned long size) | |
| 110 | +{ | |
| 111 | + unsigned long *block; | |
| 112 | + unsigned long realsize = sizeof(unsigned long)+size+sizeof(char); | |
| 113 | + if (realsize != (size_t)realsize) | |
| 114 | + lua_error("Allocation Error: Block too big"); | |
| 115 | + if (oldblock) | |
| 116 | + { | |
| 117 | + unsigned long *b = (unsigned long *)oldblock - 1; | |
| 118 | + unsigned long oldsize = *b; | |
| 119 | + assert(*(((char *)b)+oldsize+sizeof(unsigned long)) == MARK); | |
| 120 | + totalmem -= oldsize; | |
| 121 | + numblocks--; | |
| 122 | + block = (unsigned long *)realloc(b, realsize); | |
| 123 | + } | |
| 124 | + else | |
| 125 | + block = (unsigned long *)malloc(realsize); | |
| 126 | + if (block == NULL) | |
| 127 | + lua_error("not enough memory"); | |
| 128 | + totalmem += size; | |
| 129 | + numblocks++; | |
| 130 | + *block = size; | |
| 131 | + *(((char *)block)+size+sizeof(unsigned long)) = MARK; | |
| 132 | + message(); | |
| 133 | + return block+1; | |
| 134 | +} | |
| 135 | + | |
| 136 | + | |
| 137 | +int luaI_growvector (void **block, unsigned long nelems, int size, | |
| 138 | + char *errormsg, unsigned long limit) | |
| 139 | +{ | |
| 140 | + if (nelems >= limit) | |
| 141 | + lua_error(errormsg); | |
| 142 | + nelems = (nelems == 0) ? 20 : nelems*2; | |
| 143 | + if (nelems > limit) | |
| 144 | + nelems = limit; | |
| 145 | + *block = luaI_realloc(*block, nelems*size); | |
| 146 | + return (int)nelems; | |
| 147 | +} | |
| 148 | + | |
| 149 | + | |
| 150 | +void* luaI_buffer (unsigned long size) | |
| 151 | +{ | |
| 152 | + static unsigned long buffsize = 0; | |
| 153 | + static char* buffer = NULL; | |
| 154 | + if (size > buffsize) | |
| 155 | + buffer = luaI_realloc(buffer, buffsize=size); | |
| 156 | + return buffer; | |
| 157 | +} | |
| 158 | + | |
| 159 | +#endif | |
| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** mem.c |
| 3 | 3 | ** memory manager for lua |
| 4 | −** $Id: mem.h,v 1.8 1996/05/24 14:31:10 roberto Exp $ | |
| 4 | +** $Id: luamem.h,v 1.9 1997/03/31 14:10:11 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | −#ifndef mem_h | |
| 8 | −#define mem_h | |
| 7 | +#ifndef luamem_h | |
| 8 | +#define luamem_h | |
| 9 | 9 | |
| 10 | 10 | #ifndef NULL |
| 11 | 11 | #define NULL 0 |
| @@ -1,58 +0,0 @@ | ||
| 1 | −/* | |
| 2 | −** mem.c | |
| 3 | −** TecCGraf - PUC-Rio | |
| 4 | −*/ | |
| 5 | − | |
| 6 | −char *rcs_mem = "$Id: mem.c,v 1.13 1996/05/24 14:31:10 roberto Exp $"; | |
| 7 | − | |
| 8 | −#include <stdlib.h> | |
| 9 | − | |
| 10 | −#include "mem.h" | |
| 11 | −#include "lua.h" | |
| 12 | − | |
| 13 | − | |
| 14 | −void luaI_free (void *block) | |
| 15 | −{ | |
| 16 | − if (block) | |
| 17 | − { | |
| 18 | − *((int *)block) = -1; /* to catch errors */ | |
| 19 | − free(block); | |
| 20 | − } | |
| 21 | −} | |
| 22 | − | |
| 23 | − | |
| 24 | −void *luaI_realloc (void *oldblock, unsigned long size) | |
| 25 | −{ | |
| 26 | − void *block; | |
| 27 | − size_t s = (size_t)size; | |
| 28 | − if (s != size) | |
| 29 | − lua_error("Allocation Error: Block too big"); | |
| 30 | − block = oldblock ? realloc(oldblock, s) : malloc(s); | |
| 31 | − if (block == NULL) | |
| 32 | − lua_error(memEM); | |
| 33 | − return block; | |
| 34 | −} | |
| 35 | − | |
| 36 | − | |
| 37 | −int luaI_growvector (void **block, unsigned long nelems, int size, | |
| 38 | − char *errormsg, unsigned long limit) | |
| 39 | −{ | |
| 40 | − if (nelems >= limit) | |
| 41 | − lua_error(errormsg); | |
| 42 | − nelems = (nelems == 0) ? 20 : nelems*2; | |
| 43 | − if (nelems > limit) | |
| 44 | − nelems = limit; | |
| 45 | − *block = luaI_realloc(*block, nelems*size); | |
| 46 | − return (int)nelems; | |
| 47 | −} | |
| 48 | − | |
| 49 | − | |
| 50 | −void* luaI_buffer (unsigned long size) | |
| 51 | −{ | |
| 52 | − static unsigned long buffsize = 0; | |
| 53 | − static char* buffer = NULL; | |
| 54 | − if (size > buffsize) | |
| 55 | − buffer = luaI_realloc(buffer, buffsize=size); | |
| 56 | − return buffer; | |
| 57 | −} | |
| 58 | − | |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp $"; | |
| 6 | +char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <setjmp.h> |
| 9 | 9 | #include <stdio.h> |
| @@ -11,17 +11,18 @@ char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp $"; · 1 unmodified line | ||
| 11 | 11 | #include <stdlib.h> |
| 12 | 12 | |
| 13 | 13 | #include "luadebug.h" |
| 14 | −#include "mem.h" | |
| 14 | +#include "luamem.h" | |
| 15 | 15 | #include "opcode.h" |
| 16 | 16 | #include "hash.h" |
| 17 | 17 | #include "inout.h" |
| 18 | 18 | #include "table.h" |
| 19 | 19 | #include "lua.h" |
| 20 | 20 | #include "fallback.h" |
| 21 | −#include "undump.h" | |
| 21 | +#include "auxlib.h" | |
| 22 | +#include "lex.h" | |
| 22 | 23 | |
| 23 | −#define tonumber(o) ((tag(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) | |
| 24 | −#define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) | |
| 24 | +#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) | |
| 25 | +#define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) | |
| 25 | 26 | |
| 26 | 27 | |
| 27 | 28 | #define STACK_SIZE 128 |
| @@ -32,14 +33,14 @@ char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp $"; · 4 unmodified lines | ||
| 32 | 33 | |
| 33 | 34 | typedef int StkId; /* index to stack elements */ |
| 34 | 35 | |
| 35 | −static Object initial_stack; | |
| 36 | +static TObject initial_stack; | |
| 36 | 37 | |
| 37 | −static Object *stackLimit = &initial_stack+1; | |
| 38 | −static Object *stack = &initial_stack; | |
| 39 | −static Object *top = &initial_stack; | |
| 38 | +static TObject *stackLimit = &initial_stack+1; | |
| 39 | +static TObject *stack = &initial_stack; | |
| 40 | +static TObject *top = &initial_stack; | |
| 40 | 41 | |
| 41 | 42 | |
| 42 | −/* macros to convert from lua_Object to (Object *) and back */ | |
| 43 | +/* macros to convert from lua_Object to (TObject *) and back */ | |
| 43 | 44 | |
| 44 | 45 | #define Address(lo) ((lo)+stack-1) |
| 45 | 46 | #define Ref(st) ((st)-stack+1) |
| @@ -51,13 +52,13 @@ static Object *top = &initial_stack; · 5 unmodified lines | ||
| 51 | 52 | #define incr_top if (++top >= stackLimit) growstack() |
| 52 | 53 | |
| 53 | 54 | struct C_Lua_Stack { |
| 54 | − StkId base; /* when Lua calls C or C calls Lua, points to */ | |
| 55 | − /* the first slot after the last parameter. */ | |
| 56 | − int num; /* when Lua calls C, has the number of parameters; */ | |
| 57 | − /* when C calls Lua, has the number of results. */ | |
| 55 | + StkId base; /* when Lua calls C or C calls Lua, points to */ | |
| 56 | + /* the first slot after the last parameter. */ | |
| 57 | + StkId lua2C; /* points to first element of "array" lua2C */ | |
| 58 | + int num; /* size of "array" lua2C */ | |
| 58 | 59 | }; |
| 59 | 60 | |
| 60 | −static struct C_Lua_Stack CLS_current = {0, 0}; | |
| 61 | +static struct C_Lua_Stack CLS_current = {0, 0, 0}; | |
| 61 | 62 | |
| 62 | 63 | static jmp_buf *errorJmp = NULL; /* current error recover point */ |
| 63 | 64 | |
| @@ -72,7 +73,7 @@ static void do_call (StkId base, int nResults); · 8 unmodified lines | ||
| 72 | 73 | |
| 73 | 74 | |
| 74 | 75 | |
| 75 | −Object *luaI_Address (lua_Object o) | |
| 76 | +TObject *luaI_Address (lua_Object o) | |
| 76 | 77 | { |
| 77 | 78 | return Address(o); |
| 78 | 79 | } |
| @@ -84,7 +85,7 @@ Object *luaI_Address (lua_Object o) · 5 unmodified lines | ||
| 84 | 85 | static void lua_initstack (void) |
| 85 | 86 | { |
| 86 | 87 | Long maxstack = STACK_SIZE; |
| 87 | − stack = newvector(maxstack, Object); | |
| 88 | + stack = newvector(maxstack, TObject); | |
| 88 | 89 | stackLimit = stack+maxstack; |
| 89 | 90 | top = stack; |
| 90 | 91 | *(top++) = initial_stack; |
| @@ -105,7 +106,7 @@ static void growstack (void) · 14 unmodified lines | ||
| 105 | 106 | static int limit = STACK_LIMIT; |
| 106 | 107 | StkId t = top-stack; |
| 107 | 108 | Long stacksize = stackLimit - stack; |
| 108 | − stacksize = growvector(&stack, stacksize, Object, stackEM, limit+100); | |
| 109 | + stacksize = growvector(&stack, stacksize, TObject, stackEM, limit+100); | |
| 109 | 110 | stackLimit = stack+stacksize; |
| 110 | 111 | top = stack + t; |
| 111 | 112 | if (stacksize >= limit) |
| @@ -134,16 +135,16 @@ static char *lua_strconc (char *l, char *r) · 22 unmodified lines | ||
| 134 | 135 | ** Convert, if possible, to a number object. |
| 135 | 136 | ** Return 0 if success, not 0 if error. |
| 136 | 137 | */ |
| 137 | −static int lua_tonumber (Object *obj) | |
| 138 | +static int lua_tonumber (TObject *obj) | |
| 138 | 139 | { |
| 139 | 140 | float t; |
| 140 | 141 | char c; |
| 141 | − if (tag(obj) != LUA_T_STRING) | |
| 142 | + if (ttype(obj) != LUA_T_STRING) | |
| 142 | 143 | return 1; |
| 143 | 144 | else if (sscanf(svalue(obj), "%f %c",&t, &c) == 1) |
| 144 | 145 | { |
| 145 | 146 | nvalue(obj) = t; |
| 146 | − tag(obj) = LUA_T_NUMBER; | |
| 147 | + ttype(obj) = LUA_T_NUMBER; | |
| 147 | 148 | return 0; |
| 148 | 149 | } |
| 149 | 150 | else |
| @@ -152,39 +153,54 @@ static int lua_tonumber (Object *obj) · 2 unmodified lines | ||
| 152 | 153 | |
| 153 | 154 | |
| 154 | 155 | /* |
| 155 | −** Convert, if possible, to a string tag | |
| 156 | +** Convert, if possible, to a string ttype | |
| 156 | 157 | ** Return 0 in success or not 0 on error. |
| 157 | 158 | */ |
| 158 | −static int lua_tostring (Object *obj) | |
| 159 | +static int lua_tostring (TObject *obj) | |
| 159 | 160 | { |
| 160 | − char s[256]; | |
| 161 | − if (tag(obj) != LUA_T_NUMBER) | |
| 162 | − return 1; | |
| 163 | − if ((int) nvalue(obj) == nvalue(obj)) | |
| 164 | − sprintf (s, "%d", (int) nvalue(obj)); | |
| 165 | − else | |
| 166 | − sprintf (s, "%g", nvalue(obj)); | |
| 167 | − tsvalue(obj) = lua_createstring(s); | |
| 168 | − tag(obj) = LUA_T_STRING; | |
| 169 | − return 0; | |
| 161 | + if (ttype(obj) != LUA_T_NUMBER) | |
| 162 | + return 1; | |
| 163 | + else { | |
| 164 | + char s[60]; | |
| 165 | + real f = nvalue(obj); | |
| 166 | + int i; | |
| 167 | + if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) | |
| 168 | + sprintf (s, "%d", i); | |
| 169 | + else | |
| 170 | + sprintf (s, "%g", nvalue(obj)); | |
| 171 | + tsvalue(obj) = lua_createstring(s); | |
| 172 | + ttype(obj) = LUA_T_STRING; | |
| 173 | + return 0; | |
| 174 | + } | |
| 170 | 175 | } |
| 171 | 176 | |
| 172 | 177 | |
| 173 | 178 | /* |
| 174 | 179 | ** Adjust stack. Set top to the given value, pushing NILs if needed. |
| 175 | 180 | */ |
| 176 | −static void adjust_top (StkId newtop) | |
| 181 | +static void adjust_top_aux (StkId newtop) | |
| 177 | 182 | { |
| 178 | − Object *nt; | |
| 183 | + TObject *nt; | |
| 179 | 184 | lua_checkstack(stack+newtop); |
| 180 | 185 | nt = stack+newtop; /* warning: previous call may change stack */ |
| 181 | − while (top < nt) tag(top++) = LUA_T_NIL; | |
| 182 | − top = nt; /* top could be bigger than newtop */ | |
| 186 | + while (top < nt) ttype(top++) = LUA_T_NIL; | |
| 183 | 187 | } |
| 184 | 188 | |
| 189 | + | |
| 190 | +#define adjust_top(newtop) { if (newtop <= top-stack) \ | |
| 191 | + top = stack+newtop; \ | |
| 192 | + else adjust_top_aux(newtop); } | |
| 193 | + | |
| 185 | 194 | #define adjustC(nParams) adjust_top(CLS_current.base+nParams) |
| 186 | 195 | |
| 187 | 196 | |
| 197 | +static void checkCparams (int nParams) | |
| 198 | +{ | |
| 199 | + if (top-stack < CLS_current.base+nParams) | |
| 200 | + lua_error("API error - wrong number of arguments in C2lua stack"); | |
| 201 | +} | |
| 202 | + | |
| 203 | + | |
| 188 | 204 | /* |
| 189 | 205 | ** Open a hole below "nelems" from the top. |
| 190 | 206 | */ |
| @@ -197,13 +213,37 @@ static void open_stack (int nelems) · 6 unmodified lines | ||
| 197 | 213 | } |
| 198 | 214 | |
| 199 | 215 | |
| 216 | +static lua_Object put_luaObject (TObject *o) | |
| 217 | +{ | |
| 218 | + open_stack((top-stack)-CLS_current.base); | |
| 219 | + stack[CLS_current.base++] = *o; | |
| 220 | + return CLS_current.base; /* this is +1 real position (see Ref) */ | |
| 221 | +} | |
| 222 | + | |
| 223 | + | |
| 224 | +static lua_Object put_luaObjectonTop (void) | |
| 225 | +{ | |
| 226 | + open_stack((top-stack)-CLS_current.base); | |
| 227 | + stack[CLS_current.base++] = *(--top); | |
| 228 | + return CLS_current.base; /* this is +1 real position (see Ref) */ | |
| 229 | +} | |
| 230 | + | |
| 231 | + | |
| 232 | +lua_Object lua_pop (void) | |
| 233 | +{ | |
| 234 | + checkCparams(1); | |
| 235 | + return put_luaObjectonTop(); | |
| 236 | +} | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 200 | 240 | /* |
| 201 | 241 | ** call Line hook |
| 202 | 242 | */ |
| 203 | 243 | static void lineHook (int line) |
| 204 | 244 | { |
| 205 | 245 | struct C_Lua_Stack oldCLS = CLS_current; |
| 206 | − StkId old_top = CLS_current.base = top-stack; | |
| 246 | + StkId old_top = CLS_current.lua2C = CLS_current.base = top-stack; | |
| 207 | 247 | CLS_current.num = 0; |
| 208 | 248 | (*lua_linehook)(line); |
| 209 | 249 | top = stack+old_top; |
| @@ -218,13 +258,13 @@ static void lineHook (int line) · 8 unmodified lines | ||
| 218 | 258 | static void callHook (StkId base, lua_Type type, int isreturn) |
| 219 | 259 | { |
| 220 | 260 | struct C_Lua_Stack oldCLS = CLS_current; |
| 221 | − StkId old_top = CLS_current.base = top-stack; | |
| 261 | + StkId old_top = CLS_current.lua2C = CLS_current.base = top-stack; | |
| 222 | 262 | CLS_current.num = 0; |
| 223 | 263 | if (isreturn) |
| 224 | 264 | (*lua_callhook)(LUA_NOOBJECT, "(return)", 0); |
| 225 | 265 | else |
| 226 | 266 | { |
| 227 | − Object *f = stack+base-1; | |
| 267 | + TObject *f = stack+base-1; | |
| 228 | 268 | if (type == LUA_T_MARK) |
| 229 | 269 | (*lua_callhook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined); |
| 230 | 270 | else |
| @@ -246,6 +286,7 @@ static StkId callC (lua_CFunction func, StkId base) · 15 unmodified lines | ||
| 246 | 286 | StkId firstResult; |
| 247 | 287 | CLS_current.num = (top-stack) - base; |
| 248 | 288 | /* incorporate parameters on the stack */ |
| 289 | + CLS_current.lua2C = base; | |
| 249 | 290 | CLS_current.base = base+CLS_current.num; /* == top-stack */ |
| 250 | 291 | if (lua_callhook) |
| 251 | 292 | callHook(base, LUA_T_CMARK, 0); |
| @@ -257,15 +298,11 @@ static StkId callC (lua_CFunction func, StkId base) · 5 unmodified lines | ||
| 257 | 298 | return firstResult; |
| 258 | 299 | } |
| 259 | 300 | |
| 260 | −/* | |
| 261 | −** Call the specified fallback, putting it on the stack below its arguments | |
| 262 | −*/ | |
| 263 | −static void callFB (int fb) | |
| 301 | +static void callIM (TObject *f, int nParams, int nResults) | |
| 264 | 302 | { |
| 265 | − int nParams = luaI_fallBacks[fb].nParams; | |
| 266 | 303 | open_stack(nParams); |
| 267 | − *(top-nParams-1) = luaI_fallBacks[fb].function; | |
| 268 | − do_call((top-stack)-nParams, luaI_fallBacks[fb].nResults); | |
| 304 | + *(top-nParams-1) = *f; | |
| 305 | + do_call((top-stack)-nParams, nResults); | |
| 269 | 306 | } |
| 270 | 307 | |
| 271 | 308 | |
| @@ -278,28 +315,28 @@ static void callFB (int fb) · 6 unmodified lines | ||
| 278 | 315 | static void do_call (StkId base, int nResults) |
| 279 | 316 | { |
| 280 | 317 | StkId firstResult; |
| 281 | − Object *func = stack+base-1; | |
| 318 | + TObject *func = stack+base-1; | |
| 282 | 319 | int i; |
| 283 | − if (tag(func) == LUA_T_CFUNCTION) | |
| 284 | − { | |
| 285 | − tag(func) = LUA_T_CMARK; | |
| 320 | + if (ttype(func) == LUA_T_CFUNCTION) { | |
| 321 | + ttype(func) = LUA_T_CMARK; | |
| 286 | 322 | firstResult = callC(fvalue(func), base); |
| 287 | 323 | } |
| 288 | − else if (tag(func) == LUA_T_FUNCTION) | |
| 289 | − { | |
| 290 | − tag(func) = LUA_T_MARK; | |
| 324 | + else if (ttype(func) == LUA_T_FUNCTION) { | |
| 325 | + ttype(func) = LUA_T_MARK; | |
| 291 | 326 | firstResult = lua_execute(func->value.tf->code, base); |
| 292 | 327 | } |
| 293 | − else | |
| 294 | − { /* func is not a function */ | |
| 295 | − /* Call the fallback for invalid functions */ | |
| 328 | + else { /* func is not a function */ | |
| 329 | + /* Check the tag method for invalid functions */ | |
| 330 | + TObject *im = luaI_getimbyObj(func, IM_FUNCTION); | |
| 331 | + if (ttype(im) == LUA_T_NIL) | |
| 332 | + lua_error("call expression not a function"); | |
| 296 | 333 | open_stack((top-stack)-(base-1)); |
| 297 | − stack[base-1] = luaI_fallBacks[FB_FUNCTION].function; | |
| 334 | + stack[base-1] = *im; | |
| 298 | 335 | do_call(base, nResults); |
| 299 | 336 | return; |
| 300 | 337 | } |
| 301 | 338 | /* adjust the number of results */ |
| 302 | − if (nResults != MULT_RET && top - (stack+firstResult) != nResults) | |
| 339 | + if (nResults != MULT_RET) | |
| 303 | 340 | adjust_top(firstResult+nResults); |
| 304 | 341 | /* move results to base-1 (to erase parameters and function) */ |
| 305 | 342 | base--; |
| @@ -316,58 +353,110 @@ static void do_call (StkId base, int nResults) · 10 unmodified lines | ||
| 316 | 353 | */ |
| 317 | 354 | static void pushsubscript (void) |
| 318 | 355 | { |
| 319 | − if (tag(top-2) != LUA_T_ARRAY) | |
| 320 | − callFB(FB_GETTABLE); | |
| 321 | − else | |
| 322 | − { | |
| 323 | − Object *h = lua_hashget(avalue(top-2), top-1); | |
| 324 | − if (h == NULL || tag(h) == LUA_T_NIL) | |
| 325 | − callFB(FB_INDEX); | |
| 326 | − else | |
| 327 | − { | |
| 328 | − --top; | |
| 329 | − *(top-1) = *h; | |
| 356 | + TObject *im; | |
| 357 | + if (ttype(top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */ | |
| 358 | + im = luaI_getimbyObj(top-2, IM_GETTABLE); | |
| 359 | + else { /* object is a table... */ | |
| 360 | + int tg = (top-2)->value.a->htag; | |
| 361 | + im = luaI_getim(tg, IM_GETTABLE); | |
| 362 | + if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ | |
| 363 | + TObject *h = lua_hashget(avalue(top-2), top-1); | |
| 364 | + if (h != NULL && ttype(h) != LUA_T_NIL) { | |
| 365 | + --top; | |
| 366 | + *(top-1) = *h; | |
| 367 | + } | |
| 368 | + else if (ttype(im=luaI_getim(tg, IM_INDEX)) != LUA_T_NIL) | |
| 369 | + callIM(im, 2, 1); | |
| 370 | + else { | |
| 371 | + --top; | |
| 372 | + ttype(top-1) = LUA_T_NIL; | |
| 373 | + } | |
| 374 | + return; | |
| 330 | 375 | } |
| 376 | + /* else it has a "gettable" method, go through to next command */ | |
| 377 | + } | |
| 378 | + /* object is not a table, or it has a "gettable" method */ | |
| 379 | + if (ttype(im) != LUA_T_NIL) | |
| 380 | + callIM(im, 2, 1); | |
| 381 | + else | |
| 382 | + lua_error("indexed expression not a table"); | |
| 383 | +} | |
| 384 | + | |
| 385 | + | |
| 386 | +lua_Object lua_rawgettable (void) | |
| 387 | +{ | |
| 388 | + checkCparams(2); | |
| 389 | + if (ttype(top-2) != LUA_T_ARRAY) | |
| 390 | + lua_error("indexed expression not a table in raw gettable"); | |
| 391 | + else { | |
| 392 | + TObject *h = lua_hashget(avalue(top-2), top-1); | |
| 393 | + --top; | |
| 394 | + if (h != NULL) | |
| 395 | + *(top-1) = *h; | |
| 396 | + else | |
| 397 | + ttype(top-1) = LUA_T_NIL; | |
| 331 | 398 | } |
| 399 | + return put_luaObjectonTop(); | |
| 332 | 400 | } |
| 333 | 401 | |
| 334 | 402 | |
| 335 | 403 | /* |
| 336 | 404 | ** Function to store indexed based on values at the top |
| 405 | +** mode = 0: raw store (without internal methods) | |
| 406 | +** mode = 1: normal store (with internal methods) | |
| 407 | +** mode = 2: "deep stack" store (with internal methods) | |
| 337 | 408 | */ |
| 338 | −static void storesubscript (void) | |
| 409 | +static void storesubscript (TObject *t, int mode) | |
| 339 | 410 | { |
| 340 | − if (tag(top-3) != LUA_T_ARRAY) | |
| 341 | − callFB(FB_SETTABLE); | |
| 342 | − else | |
| 343 | − { | |
| 344 | − Object *h = lua_hashdefine (avalue(top-3), top-2); | |
| 345 | − *h = *(top-1); | |
| 346 | − top -= 3; | |
| 347 | − } | |
| 411 | + TObject *im = (mode == 0) ? NULL : luaI_getimbyObj(t, IM_SETTABLE); | |
| 412 | + if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) { | |
| 413 | + TObject *h = lua_hashdefine(avalue(t), t+1); | |
| 414 | + *h = *(top-1); | |
| 415 | + top -= (mode == 2) ? 1 : 3; | |
| 416 | + } | |
| 417 | + else { /* object is not a table, and/or has a specific "settable" method */ | |
| 418 | + if (im && ttype(im) != LUA_T_NIL) { | |
| 419 | + if (mode == 2) { | |
| 420 | + lua_checkstack(top+2); | |
| 421 | + *(top+1) = *(top-1); | |
| 422 | + *(top) = *(t+1); | |
| 423 | + *(top-1) = *t; | |
| 424 | + top += 2; | |
| 425 | + } | |
| 426 | + callIM(im, 3, 0); | |
| 427 | + } | |
| 428 | + else | |
| 429 | + lua_error("indexed expression not a table"); | |
| 430 | + } | |
| 348 | 431 | } |
| 349 | 432 | |
| 350 | 433 | |
| 351 | 434 | static void getglobal (Word n) |
| 352 | 435 | { |
| 353 | − *top = lua_table[n].object; | |
| 354 | − incr_top; | |
| 355 | − if (tag(top-1) == LUA_T_NIL) | |
| 356 | − { /* must call getglobal fallback */ | |
| 357 | − tag(top-1) = LUA_T_STRING; | |
| 358 | − tsvalue(top-1) = lua_table[n].varname; | |
| 359 | − callFB(FB_GETGLOBAL); | |
| 436 | + TObject *value = &lua_table[n].object; | |
| 437 | + TObject *im = luaI_getimbyObj(value, IM_GETGLOBAL); | |
| 438 | + if (ttype(im) == LUA_T_NIL) { /* default behavior */ | |
| 439 | + *top = *value; | |
| 440 | + incr_top; | |
| 360 | 441 | } |
| 442 | + else { | |
| 443 | + ttype(top) = LUA_T_STRING; | |
| 444 | + tsvalue(top) = lua_table[n].varname; | |
| 445 | + incr_top; | |
| 446 | + *top = *value; | |
| 447 | + incr_top; | |
| 448 | + callIM(im, 2, 1); | |
| 449 | + } | |
| 361 | 450 | } |
| 362 | 451 | |
| 363 | 452 | /* |
| 364 | 453 | ** Traverse all objects on stack |
| 365 | 454 | */ |
| 366 | −void lua_travstack (int (*fn)(Object *)) | |
| 455 | +void lua_travstack (int (*fn)(TObject *)) | |
| 367 | 456 | { |
| 368 | − Object *o; | |
| 369 | − for (o = top-1; o >= stack; o--) | |
| 370 | − fn (o); | |
| 457 | + StkId i; | |
| 458 | + for (i = (top-1)-stack; i>=0; i--) | |
| 459 | + fn (stack+i); | |
| 371 | 460 | } |
| 372 | 461 | |
| 373 | 462 | |
| @@ -377,8 +466,11 @@ void lua_travstack (int (*fn)(Object *)) · 3 unmodified lines | ||
| 377 | 466 | |
| 378 | 467 | static void lua_message (char *s) |
| 379 | 468 | { |
| 380 | − lua_pushstring(s); | |
| 381 | − callFB(FB_ERROR); | |
| 469 | + TObject *im = luaI_geterrorim(); | |
| 470 | + if (ttype(im) != LUA_T_NIL) { | |
| 471 | + lua_pushstring(s); | |
| 472 | + callIM(im, 1, 0); | |
| 473 | + } | |
| 382 | 474 | } |
| 383 | 475 | |
| 384 | 476 | /* |
| @@ -399,25 +491,25 @@ void lua_error (char *s) · 14 unmodified lines | ||
| 399 | 491 | |
| 400 | 492 | lua_Function lua_stackedfunction (int level) |
| 401 | 493 | { |
| 402 | − Object *p = top; | |
| 403 | − while (--p >= stack) | |
| 404 | − if (p->tag == LUA_T_MARK || p->tag == LUA_T_CMARK) | |
| 494 | + StkId i; | |
| 495 | + for (i = (top-1)-stack; i>=0; i--) | |
| 496 | + if (stack[i].ttype == LUA_T_MARK || stack[i].ttype == LUA_T_CMARK) | |
| 405 | 497 | if (level-- == 0) |
| 406 | − return Ref(p); | |
| 498 | + return Ref(stack+i); | |
| 407 | 499 | return LUA_NOOBJECT; |
| 408 | 500 | } |
| 409 | 501 | |
| 410 | 502 | |
| 411 | 503 | int lua_currentline (lua_Function func) |
| 412 | 504 | { |
| 413 | − Object *f = Address(func); | |
| 414 | − return (f+1 < top && (f+1)->tag == LUA_T_LINE) ? (f+1)->value.i : -1; | |
| 505 | + TObject *f = Address(func); | |
| 506 | + return (f+1 < top && (f+1)->ttype == LUA_T_LINE) ? (f+1)->value.i : -1; | |
| 415 | 507 | } |
| 416 | 508 | |
| 417 | 509 | |
| 418 | 510 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name) |
| 419 | 511 | { |
| 420 | − Object *f = luaI_Address(func); | |
| 512 | + TObject *f = luaI_Address(func); | |
| 421 | 513 | *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); |
| 422 | 514 | if (*name) |
| 423 | 515 | { |
| @@ -431,9 +523,9 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name) · 7 unmodified lines | ||
| 431 | 523 | |
| 432 | 524 | int lua_setlocal (lua_Function func, int local_number) |
| 433 | 525 | { |
| 434 | − Object *f = Address(func); | |
| 526 | + TObject *f = Address(func); | |
| 435 | 527 | char *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); |
| 436 | − adjustC(1); | |
| 528 | + checkCparams(1); | |
| 437 | 529 | --top; |
| 438 | 530 | if (name) |
| 439 | 531 | { |
| @@ -446,6 +538,29 @@ int lua_setlocal (lua_Function func, int local_number) · 6 unmodified lines | ||
| 446 | 538 | return 0; |
| 447 | 539 | } |
| 448 | 540 | |
| 541 | +/* | |
| 542 | +** Call the function at CLS_current.base, and incorporate results on | |
| 543 | +** the Lua2C structure. | |
| 544 | +*/ | |
| 545 | +static void do_callinc (int nResults) | |
| 546 | +{ | |
| 547 | + StkId base = CLS_current.base; | |
| 548 | + do_call(base+1, nResults); | |
| 549 | + CLS_current.lua2C = base; /* position of the new results */ | |
| 550 | + CLS_current.num = (top-stack) - base; /* number of results */ | |
| 551 | + CLS_current.base = base + CLS_current.num; /* incorporate results on stack */ | |
| 552 | +} | |
| 553 | + | |
| 554 | + | |
| 555 | +static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) | |
| 556 | +{ | |
| 557 | + StkId base = (top-stack)-nParams; | |
| 558 | + open_stack(nParams); | |
| 559 | + stack[base].ttype = LUA_T_CFUNCTION; | |
| 560 | + stack[base].value.f = f; | |
| 561 | + do_call(base+1, nResults); | |
| 562 | +} | |
| 563 | + | |
| 449 | 564 | |
| 450 | 565 | /* |
| 451 | 566 | ** Execute a protected call. Assumes that function is at CLS_current.base and |
| @@ -458,15 +573,11 @@ static int do_protectedrun (int nResults) · 6 unmodified lines | ||
| 458 | 573 | struct C_Lua_Stack oldCLS = CLS_current; |
| 459 | 574 | jmp_buf *oldErr = errorJmp; |
| 460 | 575 | errorJmp = &myErrorJmp; |
| 461 | − if (setjmp(myErrorJmp) == 0) | |
| 462 | − { | |
| 463 | − do_call(CLS_current.base+1, nResults); | |
| 464 | − CLS_current.num = (top-stack) - CLS_current.base; /* number of results */ | |
| 465 | − CLS_current.base += CLS_current.num; /* incorporate results on the stack */ | |
| 576 | + if (setjmp(myErrorJmp) == 0) { | |
| 577 | + do_callinc(nResults); | |
| 466 | 578 | status = 0; |
| 467 | 579 | } |
| 468 | − else | |
| 469 | − { /* an error occurred: restore CLS_current and top */ | |
| 580 | + else { /* an error occurred: restore CLS_current and top */ | |
| 470 | 581 | CLS_current = oldCLS; |
| 471 | 582 | top = stack+CLS_current.base; |
| 472 | 583 | status = 1; |
| @@ -479,13 +590,14 @@ int luaI_dorun (TFunc *tf) · 6 unmodified lines | ||
| 479 | 590 | { |
| 480 | 591 | int status; |
| 481 | 592 | adjustC(1); /* one slot for the pseudo-function */ |
| 482 | − stack[CLS_current.base].tag = LUA_T_FUNCTION; | |
| 593 | + stack[CLS_current.base].ttype = LUA_T_FUNCTION; | |
| 483 | 594 | stack[CLS_current.base].value.tf = tf; |
| 484 | 595 | status = do_protectedrun(MULT_RET); |
| 485 | 596 | return status; |
| 486 | 597 | } |
| 487 | 598 | |
| 488 | −static int do_protectedmain (void) | |
| 599 | + | |
| 600 | +int lua_domain (void) | |
| 489 | 601 | { |
| 490 | 602 | TFunc tf; |
| 491 | 603 | int status; |
| @@ -493,23 +605,21 @@ static int do_protectedmain (void) · 1 unmodified line | ||
| 493 | 605 | jmp_buf *oldErr = errorJmp; |
| 494 | 606 | errorJmp = &myErrorJmp; |
| 495 | 607 | luaI_initTFunc(&tf); |
| 496 | − tf.fileName = lua_parsedfile; | |
| 497 | − if (setjmp(myErrorJmp) == 0) | |
| 498 | − { | |
| 608 | + if (setjmp(myErrorJmp) == 0) { | |
| 499 | 609 | lua_parse(&tf); |
| 500 | − status = luaI_dorun(&tf); | |
| 610 | + status = 0; | |
| 501 | 611 | } |
| 502 | − else | |
| 503 | − { | |
| 504 | − status = 1; | |
| 612 | + else { | |
| 505 | 613 | adjustC(0); /* erase extra slot */ |
| 614 | + status = 1; | |
| 506 | 615 | } |
| 616 | + if (status == 0) | |
| 617 | + status = luaI_dorun(&tf); | |
| 507 | 618 | errorJmp = oldErr; |
| 508 | 619 | luaI_free(tf.code); |
| 509 | 620 | return status; |
| 510 | 621 | } |
| 511 | 622 | |
| 512 | − | |
| 513 | 623 | /* |
| 514 | 624 | ** Execute the given lua function. Return 0 on success or 1 on error. |
| 515 | 625 | */ |
| @@ -526,71 +636,31 @@ int lua_callfunction (lua_Object function) · 10 unmodified lines | ||
| 526 | 636 | } |
| 527 | 637 | |
| 528 | 638 | |
| 529 | −int lua_call (char *funcname) | |
| 639 | +lua_Object lua_gettagmethod (int tag, char *event) | |
| 530 | 640 | { |
| 531 | − Word n = luaI_findsymbolbyname(funcname); | |
| 532 | − open_stack((top-stack)-CLS_current.base); | |
| 533 | − stack[CLS_current.base] = s_object(n); | |
| 534 | − return do_protectedrun(MULT_RET); | |
| 641 | + lua_pushnumber(tag); | |
| 642 | + lua_pushstring(event); | |
| 643 | + do_unprotectedrun(luaI_gettagmethod, 2, 1); | |
| 644 | + return put_luaObjectonTop(); | |
| 535 | 645 | } |
| 536 | 646 | |
| 537 | − | |
| 538 | −/* | |
| 539 | −** Open file, generate opcode and execute global statement. Return 0 on | |
| 540 | −** success or non 0 on error. | |
| 541 | −*/ | |
| 542 | −int lua_dofile (char *filename) | |
| 647 | +lua_Object lua_settagmethod (int tag, char *event) | |
| 543 | 648 | { |
| 544 | − int status; | |
| 545 | − int c; | |
| 546 | − FILE *f = lua_openfile(filename); | |
| 547 | − if (f == NULL) | |
| 548 | − return 2; | |
| 549 | − c = fgetc(f); | |
| 550 | − ungetc(c, f); | |
| 551 | − if (c == ID_CHUNK) { | |
| 552 | − f = freopen(filename, "rb", f); /* set binary mode */ | |
| 553 | − status = luaI_undump(f); | |
| 554 | − } | |
| 555 | − else { | |
| 556 | − if (c == '#') | |
| 557 | − while ((c=fgetc(f)) != '\n') /* skip first line */; | |
| 558 | − status = do_protectedmain(); | |
| 559 | − } | |
| 560 | − lua_closefile(); | |
| 561 | − return status; | |
| 649 | + TObject newmethod; | |
| 650 | + checkCparams(1); | |
| 651 | + newmethod = *(--top); | |
| 652 | + lua_pushnumber(tag); | |
| 653 | + lua_pushstring(event); | |
| 654 | + *top = newmethod; incr_top; | |
| 655 | + do_unprotectedrun(luaI_settagmethod, 3, 1); | |
| 656 | + return put_luaObjectonTop(); | |
| 562 | 657 | } |
| 563 | 658 | |
| 564 | −/* | |
| 565 | −** Generate opcode stored on string and execute global statement. Return 0 on | |
| 566 | −** success or non 0 on error. | |
| 567 | −*/ | |
| 568 | −int lua_dostring (char *str) | |
| 659 | +lua_Object lua_seterrormethod (void) | |
| 569 | 660 | { |
| 570 | − int status; | |
| 571 | − if (str == NULL) | |
| 572 | − return 1; | |
| 573 | − lua_openstring(str); | |
| 574 | − status = do_protectedmain(); | |
| 575 | − lua_closestring(); | |
| 576 | − return status; | |
| 577 | −} | |
| 578 | − | |
| 579 | − | |
| 580 | −/* | |
| 581 | −** API: set a function as a fallback | |
| 582 | −*/ | |
| 583 | −lua_Object lua_setfallback (char *name, lua_CFunction fallback) | |
| 584 | −{ | |
| 585 | − adjustC(1); /* one slot for the pseudo-function */ | |
| 586 | − stack[CLS_current.base].tag = LUA_T_CFUNCTION; | |
| 587 | − stack[CLS_current.base].value.f = luaI_setfallback; | |
| 588 | − lua_pushstring(name); | |
| 589 | − lua_pushcfunction(fallback); | |
| 590 | − if (do_protectedrun(1) == 0) | |
| 591 | − return (Ref(top-1)); | |
| 592 | − else | |
| 593 | − return LUA_NOOBJECT; | |
| 661 | + checkCparams(1); | |
| 662 | + do_unprotectedrun(luaI_seterrormethod, 1, 1); | |
| 663 | + return put_luaObjectonTop(); | |
| 594 | 664 | } |
| 595 | 665 | |
| 596 | 666 | |
| @@ -598,12 +668,11 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback) · 1 unmodified line | ||
| 598 | 668 | ** API: receives on the stack the table and the index. |
| 599 | 669 | ** returns the value. |
| 600 | 670 | */ |
| 601 | −lua_Object lua_getsubscript (void) | |
| 671 | +lua_Object lua_gettable (void) | |
| 602 | 672 | { |
| 603 | − adjustC(2); | |
| 673 | + checkCparams(2); | |
| 604 | 674 | pushsubscript(); |
| 605 | − CLS_current.base++; /* incorporate object in the stack */ | |
| 606 | − return (Ref(top-1)); | |
| 675 | + return put_luaObjectonTop(); | |
| 607 | 676 | } |
| 608 | 677 | |
| 609 | 678 | |
| @@ -633,13 +702,25 @@ void lua_endblock (void) · 23 unmodified lines | ||
| 633 | 702 | adjustC(0); |
| 634 | 703 | } |
| 635 | 704 | |
| 705 | +void lua_settag (int tag) | |
| 706 | +{ | |
| 707 | + checkCparams(1); | |
| 708 | + luaI_settag(tag, --top); | |
| 709 | +} | |
| 710 | + | |
| 636 | 711 | /* |
| 637 | 712 | ** API: receives on the stack the table, the index, and the new value. |
| 638 | 713 | */ |
| 639 | −void lua_storesubscript (void) | |
| 714 | +void lua_settable (void) | |
| 640 | 715 | { |
| 641 | − adjustC(3); | |
| 642 | − storesubscript(); | |
| 716 | + checkCparams(3); | |
| 717 | + storesubscript(top-3, 1); | |
| 718 | +} | |
| 719 | + | |
| 720 | +void lua_rawsettable (void) | |
| 721 | +{ | |
| 722 | + checkCparams(3); | |
| 723 | + storesubscript(top-3, 0); | |
| 643 | 724 | } |
| 644 | 725 | |
| 645 | 726 | /* |
| @@ -647,40 +728,59 @@ void lua_storesubscript (void) · 1 unmodified line | ||
| 647 | 728 | */ |
| 648 | 729 | lua_Object lua_createtable (void) |
| 649 | 730 | { |
| 650 | − adjustC(0); | |
| 651 | − avalue(top) = lua_createarray(0); | |
| 652 | − tag(top) = LUA_T_ARRAY; | |
| 653 | − incr_top; | |
| 654 | − CLS_current.base++; /* incorporate object in the stack */ | |
| 655 | − return Ref(top-1); | |
| 731 | + TObject o; | |
| 732 | + avalue(&o) = lua_createarray(0); | |
| 733 | + ttype(&o) = LUA_T_ARRAY; | |
| 734 | + return put_luaObject(&o); | |
| 656 | 735 | } |
| 657 | 736 | |
| 658 | 737 | /* |
| 659 | 738 | ** Get a parameter, returning the object handle or LUA_NOOBJECT on error. |
| 660 | 739 | ** 'number' must be 1 to get the first parameter. |
| 661 | 740 | */ |
| 662 | −lua_Object lua_getparam (int number) | |
| 741 | +lua_Object lua_lua2C (int number) | |
| 742 | +{ | |
| 743 | + if (number <= 0 || number > CLS_current.num) return LUA_NOOBJECT; | |
| 744 | + /* Ref(stack+(CLS_current.lua2C+number-1)) == | |
| 745 | + stack+(CLS_current.lua2C+number-1)-stack+1 == */ | |
| 746 | + return CLS_current.lua2C+number; | |
| 747 | +} | |
| 748 | + | |
| 749 | +int lua_isnil (lua_Object o) | |
| 750 | +{ | |
| 751 | + return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL); | |
| 752 | +} | |
| 753 | + | |
| 754 | +int lua_istable (lua_Object o) | |
| 755 | +{ | |
| 756 | + return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY); | |
| 757 | +} | |
| 758 | + | |
| 759 | +int lua_isuserdata (lua_Object o) | |
| 663 | 760 | { |
| 664 | − if (number <= 0 || number > CLS_current.num) return LUA_NOOBJECT; | |
| 665 | − /* Ref(stack+(CLS_current.base-CLS_current.num+number-1)) == | |
| 666 | − stack+(CLS_current.base-CLS_current.num+number-1)-stack+1 == */ | |
| 667 | − return CLS_current.base-CLS_current.num+number; | |
| 761 | + return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA); | |
| 668 | 762 | } |
| 669 | 763 | |
| 670 | −int lua_isnumber (lua_Object object) | |
| 764 | +int lua_iscfunction (lua_Object o) | |
| 671 | 765 | { |
| 672 | − return (object != LUA_NOOBJECT) && (tonumber(Address(object)) == 0); | |
| 766 | + int t = lua_tag(o); | |
| 767 | + return (t == LUA_T_CMARK) || (t == LUA_T_CFUNCTION); | |
| 673 | 768 | } |
| 674 | 769 | |
| 675 | −int lua_isstring (lua_Object object) | |
| 770 | +int lua_isnumber (lua_Object o) | |
| 676 | 771 | { |
| 677 | − int t = lua_type(object); | |
| 772 | + return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0); | |
| 773 | +} | |
| 774 | + | |
| 775 | +int lua_isstring (lua_Object o) | |
| 776 | +{ | |
| 777 | + int t = lua_tag(o); | |
| 678 | 778 | return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); |
| 679 | 779 | } |
| 680 | 780 | |
| 681 | −int lua_isfunction (lua_Object object) | |
| 781 | +int lua_isfunction (lua_Object o) | |
| 682 | 782 | { |
| 683 | − int t = lua_type(object); | |
| 783 | + int t = lua_tag(o); | |
| 684 | 784 | return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION) || |
| 685 | 785 | (t == LUA_T_MARK) || (t == LUA_T_CMARK); |
| 686 | 786 | } |
| @@ -700,57 +800,44 @@ real lua_getnumber (lua_Object object) · 13 unmodified lines | ||
| 700 | 800 | */ |
| 701 | 801 | char *lua_getstring (lua_Object object) |
| 702 | 802 | { |
| 703 | − if (object == LUA_NOOBJECT) return NULL; | |
| 704 | − if (tostring (Address(object))) return NULL; | |
| 705 | − else return (svalue(Address(object))); | |
| 803 | + if (object == LUA_NOOBJECT || tostring (Address(object))) | |
| 804 | + return NULL; | |
| 805 | + else return (svalue(Address(object))); | |
| 706 | 806 | } |
| 707 | 807 | |
| 708 | −/* | |
| 709 | −** Given an object handle, return its cfuntion pointer. On error, return NULL. | |
| 710 | −*/ | |
| 711 | −lua_CFunction lua_getcfunction (lua_Object object) | |
| 808 | + | |
| 809 | +void *lua_getuserdata (lua_Object object) | |
| 712 | 810 | { |
| 713 | − if (object == LUA_NOOBJECT || ((tag(Address(object)) != LUA_T_CFUNCTION) && | |
| 714 | − (tag(Address(object)) != LUA_T_CMARK))) | |
| 715 | − return NULL; | |
| 716 | − else return (fvalue(Address(object))); | |
| 811 | + if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) | |
| 812 | + return NULL; | |
| 813 | + else return tsvalue(Address(object))->u.v; | |
| 717 | 814 | } |
| 718 | 815 | |
| 816 | + | |
| 719 | 817 | /* |
| 720 | −** Given an object handle, return its user data. On error, return NULL. | |
| 818 | +** Given an object handle, return its cfuntion pointer. On error, return NULL. | |
| 721 | 819 | */ |
| 722 | −void *lua_getuserdata (lua_Object object) | |
| 820 | +lua_CFunction lua_getcfunction (lua_Object object) | |
| 723 | 821 | { |
| 724 | − if (object == LUA_NOOBJECT || tag(Address(object)) < LUA_T_USERDATA) | |
| 822 | + if (object == LUA_NOOBJECT || ((ttype(Address(object)) != LUA_T_CFUNCTION) && | |
| 823 | + (ttype(Address(object)) != LUA_T_CMARK))) | |
| 725 | 824 | return NULL; |
| 726 | − else return (uvalue(Address(object))); | |
| 825 | + else return (fvalue(Address(object))); | |
| 727 | 826 | } |
| 728 | 827 | |
| 729 | 828 | |
| 730 | 829 | lua_Object lua_getref (int ref) |
| 731 | 830 | { |
| 732 | − Object *o = luaI_getref(ref); | |
| 831 | + TObject *o = luaI_getref(ref); | |
| 733 | 832 | if (o == NULL) |
| 734 | 833 | return LUA_NOOBJECT; |
| 735 | − adjustC(0); | |
| 736 | − luaI_pushobject(o); | |
| 737 | − CLS_current.base++; /* incorporate object in the stack */ | |
| 738 | − return Ref(top-1); | |
| 739 | −} | |
| 740 | − | |
| 741 | − | |
| 742 | −void lua_pushref (int ref) | |
| 743 | −{ | |
| 744 | − Object *o = luaI_getref(ref); | |
| 745 | − if (o == NULL) | |
| 746 | − lua_error("access to invalid (possibly garbage collected) reference"); | |
| 747 | − luaI_pushobject(o); | |
| 834 | + return put_luaObject(o); | |
| 748 | 835 | } |
| 749 | 836 | |
| 750 | 837 | |
| 751 | 838 | int lua_ref (int lock) |
| 752 | 839 | { |
| 753 | − adjustC(1); | |
| 840 | + checkCparams(1); | |
| 754 | 841 | return luaI_ref(--top, lock); |
| 755 | 842 | } |
| 756 | 843 | |
| @@ -761,20 +848,50 @@ int lua_ref (int lock) · 4 unmodified lines | ||
| 761 | 848 | */ |
| 762 | 849 | lua_Object lua_getglobal (char *name) |
| 763 | 850 | { |
| 764 | − adjustC(0); | |
| 765 | − getglobal(luaI_findsymbolbyname(name)); | |
| 766 | − CLS_current.base++; /* incorporate object in the stack */ | |
| 767 | − return Ref(top-1); | |
| 851 | + getglobal(luaI_findsymbolbyname(name)); | |
| 852 | + return put_luaObjectonTop(); | |
| 853 | +} | |
| 854 | + | |
| 855 | + | |
| 856 | +lua_Object lua_rawgetglobal (char *name) | |
| 857 | +{ | |
| 858 | + return put_luaObject(&lua_table[luaI_findsymbolbyname(name)].object); | |
| 768 | 859 | } |
| 769 | 860 | |
| 861 | + | |
| 770 | 862 | /* |
| 771 | 863 | ** Store top of the stack at a global variable array field. |
| 772 | 864 | */ |
| 773 | −void lua_storeglobal (char *name) | |
| 865 | +static void setglobal (Word n) | |
| 866 | +{ | |
| 867 | + TObject *oldvalue = &lua_table[n].object; | |
| 868 | + TObject *im = luaI_getimbyObj(oldvalue, IM_SETGLOBAL); | |
| 869 | + if (ttype(im) == LUA_T_NIL) /* default behavior */ | |
| 870 | + s_object(n) = *(--top); | |
| 871 | + else { | |
| 872 | + TObject newvalue = *(top-1); | |
| 873 | + ttype(top-1) = LUA_T_STRING; | |
| 874 | + tsvalue(top-1) = lua_table[n].varname; | |
| 875 | + *top = *oldvalue; | |
| 876 | + incr_top; | |
| 877 | + *top = newvalue; | |
| 878 | + incr_top; | |
| 879 | + callIM(im, 3, 0); | |
| 880 | + } | |
| 881 | +} | |
| 882 | + | |
| 883 | + | |
| 884 | +void lua_setglobal (char *name) | |
| 774 | 885 | { |
| 775 | − Word n = luaI_findsymbolbyname(name); | |
| 776 | − adjustC(1); | |
| 777 | − s_object(n) = *(--top); | |
| 886 | + checkCparams(1); | |
| 887 | + setglobal(luaI_findsymbolbyname(name)); | |
| 888 | +} | |
| 889 | + | |
| 890 | +void lua_rawsetglobal (char *name) | |
| 891 | +{ | |
| 892 | + Word n = luaI_findsymbolbyname(name); | |
| 893 | + checkCparams(1); | |
| 894 | + s_object(n) = *(--top); | |
| 778 | 895 | } |
| 779 | 896 | |
| 780 | 897 | /* |
| @@ -782,60 +899,59 @@ void lua_storeglobal (char *name) · 1 unmodified line | ||
| 782 | 899 | */ |
| 783 | 900 | void lua_pushnil (void) |
| 784 | 901 | { |
| 785 | − tag(top) = LUA_T_NIL; | |
| 786 | − incr_top; | |
| 902 | + ttype(top) = LUA_T_NIL; | |
| 903 | + incr_top; | |
| 787 | 904 | } |
| 788 | 905 | |
| 789 | 906 | /* |
| 790 | −** Push an object (tag=number) to stack. | |
| 907 | +** Push an object (ttype=number) to stack. | |
| 791 | 908 | */ |
| 792 | 909 | void lua_pushnumber (real n) |
| 793 | 910 | { |
| 794 | − tag(top) = LUA_T_NUMBER; nvalue(top) = n; | |
| 911 | + ttype(top) = LUA_T_NUMBER; nvalue(top) = n; | |
| 795 | 912 | incr_top; |
| 796 | 913 | } |
| 797 | 914 | |
| 798 | 915 | /* |
| 799 | −** Push an object (tag=string) to stack. | |
| 916 | +** Push an object (ttype=string) to stack. | |
| 800 | 917 | */ |
| 801 | 918 | void lua_pushstring (char *s) |
| 802 | 919 | { |
| 803 | 920 | if (s == NULL) |
| 804 | − tag(top) = LUA_T_NIL; | |
| 921 | + ttype(top) = LUA_T_NIL; | |
| 805 | 922 | else |
| 806 | 923 | { |
| 807 | 924 | tsvalue(top) = lua_createstring(s); |
| 808 | − tag(top) = LUA_T_STRING; | |
| 925 | + ttype(top) = LUA_T_STRING; | |
| 809 | 926 | } |
| 810 | 927 | incr_top; |
| 811 | 928 | } |
| 812 | −/*>>>>>>>>>#undef lua_pushliteral | |
| 813 | −void lua_pushliteral(char *s) { lua_pushstring(s); }*/ | |
| 929 | + | |
| 814 | 930 | |
| 815 | 931 | /* |
| 816 | −** Push an object (tag=cfunction) to stack. | |
| 932 | +** Push an object (ttype=cfunction) to stack. | |
| 817 | 933 | */ |
| 818 | 934 | void lua_pushcfunction (lua_CFunction fn) |
| 819 | 935 | { |
| 820 | − tag(top) = LUA_T_CFUNCTION; fvalue(top) = fn; | |
| 936 | + ttype(top) = LUA_T_CFUNCTION; fvalue(top) = fn; | |
| 821 | 937 | incr_top; |
| 822 | 938 | } |
| 823 | 939 | |
| 824 | −/* | |
| 825 | −** Push an object (tag=userdata) to stack. | |
| 826 | −*/ | |
| 940 | + | |
| 941 | + | |
| 827 | 942 | void lua_pushusertag (void *u, int tag) |
| 828 | 943 | { |
| 829 | − if (tag < LUA_T_USERDATA) | |
| 830 | − lua_error("invalid tag in `lua_pushusertag'"); | |
| 831 | − tag(top) = tag; uvalue(top) = u; | |
| 832 | − incr_top; | |
| 944 | + if (tag < 0 && tag != LUA_ANYTAG) | |
| 945 | + luaI_realtag(tag); /* error if tag is not valid */ | |
| 946 | + tsvalue(top) = luaI_createudata(u, tag); | |
| 947 | + ttype(top) = LUA_T_USERDATA; | |
| 948 | + incr_top; | |
| 833 | 949 | } |
| 834 | 950 | |
| 835 | 951 | /* |
| 836 | 952 | ** Push an object on the stack. |
| 837 | 953 | */ |
| 838 | −void luaI_pushobject (Object *o) | |
| 954 | +void luaI_pushobject (TObject *o) | |
| 839 | 955 | { |
| 840 | 956 | *top = *o; |
| 841 | 957 | incr_top; |
| @@ -847,78 +963,102 @@ void luaI_pushobject (Object *o) · 5 unmodified lines | ||
| 847 | 963 | void lua_pushobject (lua_Object o) |
| 848 | 964 | { |
| 849 | 965 | if (o == LUA_NOOBJECT) |
| 850 | − lua_error("attempt to push a NOOBJECT"); | |
| 966 | + lua_error("API error - attempt to push a NOOBJECT"); | |
| 851 | 967 | *top = *Address(o); |
| 852 | − if (tag(top) == LUA_T_MARK) tag(top) = LUA_T_FUNCTION; | |
| 853 | − else if (tag(top) == LUA_T_CMARK) tag(top) = LUA_T_CFUNCTION; | |
| 968 | + if (ttype(top) == LUA_T_MARK) ttype(top) = LUA_T_FUNCTION; | |
| 969 | + else if (ttype(top) == LUA_T_CMARK) ttype(top) = LUA_T_CFUNCTION; | |
| 854 | 970 | incr_top; |
| 855 | 971 | } |
| 856 | 972 | |
| 857 | −int lua_type (lua_Object o) | |
| 973 | +int lua_tag (lua_Object lo) | |
| 858 | 974 | { |
| 859 | − if (o == LUA_NOOBJECT) | |
| 860 | − return LUA_T_NIL; | |
| 861 | − else | |
| 862 | − return tag(Address(o)); | |
| 975 | + if (lo == LUA_NOOBJECT) return LUA_T_NIL; | |
| 976 | + else { | |
| 977 | + TObject *o = Address(lo); | |
| 978 | + lua_Type t = ttype(o); | |
| 979 | + if (t == LUA_T_USERDATA) | |
| 980 | + return o->value.ts->tag; | |
| 981 | + else if (t == LUA_T_ARRAY) | |
| 982 | + return o->value.a->htag; | |
| 983 | + else return t; | |
| 984 | + } | |
| 863 | 985 | } |
| 864 | 986 | |
| 865 | 987 | |
| 866 | −void luaI_gcFB (Object *o) | |
| 988 | +void luaI_gcIM (TObject *o) | |
| 867 | 989 | { |
| 868 | − *top = *o; | |
| 869 | − incr_top; | |
| 870 | − callFB(FB_GC); | |
| 990 | + TObject *im = luaI_getimbyObj(o, IM_GC); | |
| 991 | + if (ttype(im) != LUA_T_NIL) { | |
| 992 | + *top = *o; | |
| 993 | + incr_top; | |
| 994 | + callIM(im, 1, 0); | |
| 995 | + } | |
| 996 | +} | |
| 997 | + | |
| 998 | + | |
| 999 | +static void call_binTM (IMS event, char *msg) | |
| 1000 | +{ | |
| 1001 | + TObject *im = luaI_getimbyObj(top-2, event); /* try first operand */ | |
| 1002 | + if (ttype(im) == LUA_T_NIL) { | |
| 1003 | + im = luaI_getimbyObj(top-1, event); /* try second operand */ | |
| 1004 | + if (ttype(im) == LUA_T_NIL) { | |
| 1005 | + im = luaI_getim(0, event); /* try a 'global' i.m. */ | |
| 1006 | + if (ttype(im) == LUA_T_NIL) | |
| 1007 | + lua_error(msg); | |
| 1008 | + } | |
| 1009 | + } | |
| 1010 | + lua_pushstring(luaI_eventname[event]); | |
| 1011 | + callIM(im, 3, 1); | |
| 871 | 1012 | } |
| 872 | 1013 | |
| 873 | 1014 | |
| 874 | −static void call_arith (char *op) | |
| 1015 | +static void call_arith (IMS event) | |
| 875 | 1016 | { |
| 876 | − lua_pushstring(op); | |
| 877 | − callFB(FB_ARITH); | |
| 1017 | + call_binTM(event, "unexpected type at arithmetic operation"); | |
| 878 | 1018 | } |
| 879 | 1019 | |
| 880 | −static void comparison (lua_Type tag_less, lua_Type tag_equal, | |
| 881 | − lua_Type tag_great, char *op) | |
| 1020 | + | |
| 1021 | +static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | |
| 1022 | + lua_Type ttype_great, IMS op) | |
| 882 | 1023 | { |
| 883 | − Object *l = top-2; | |
| 884 | − Object *r = top-1; | |
| 1024 | + TObject *l = top-2; | |
| 1025 | + TObject *r = top-1; | |
| 885 | 1026 | int result; |
| 886 | − if (tag(l) == LUA_T_NUMBER && tag(r) == LUA_T_NUMBER) | |
| 1027 | + if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) | |
| 887 | 1028 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; |
| 888 | − else if (tostring(l) || tostring(r)) | |
| 889 | − { | |
| 890 | − lua_pushstring(op); | |
| 891 | − callFB(FB_ORDER); | |
| 1029 | + else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) | |
| 1030 | + result = strcmp(svalue(l), svalue(r)); | |
| 1031 | + else { | |
| 1032 | + call_binTM(op, "unexpected type at comparison"); | |
| 892 | 1033 | return; |
| 893 | 1034 | } |
| 894 | − else | |
| 895 | − result = strcmp(svalue(l), svalue(r)); | |
| 896 | 1035 | top--; |
| 897 | 1036 | nvalue(top-1) = 1; |
| 898 | − tag(top-1) = (result < 0) ? tag_less : (result == 0) ? tag_equal : tag_great; | |
| 1037 | + ttype(top-1) = (result < 0) ? ttype_less : | |
| 1038 | + (result == 0) ? ttype_equal : ttype_great; | |
| 899 | 1039 | } |
| 900 | 1040 | |
| 901 | 1041 | |
| 902 | 1042 | static void adjust_varargs (StkId first_extra_arg) |
| 903 | 1043 | { |
| 904 | − Object arg; | |
| 905 | − Object *firstelem = stack+first_extra_arg; | |
| 1044 | + TObject arg; | |
| 1045 | + TObject *firstelem = stack+first_extra_arg; | |
| 906 | 1046 | int nvararg = top-firstelem; |
| 907 | 1047 | int i; |
| 908 | 1048 | if (nvararg < 0) nvararg = 0; |
| 909 | 1049 | avalue(&arg) = lua_createarray(nvararg+1); /* +1 for field 'n' */ |
| 910 | − tag(&arg) = LUA_T_ARRAY; | |
| 1050 | + ttype(&arg) = LUA_T_ARRAY; | |
| 911 | 1051 | for (i=0; i<nvararg; i++) { |
| 912 | − Object index; | |
| 913 | − tag(&index) = LUA_T_NUMBER; | |
| 1052 | + TObject index; | |
| 1053 | + ttype(&index) = LUA_T_NUMBER; | |
| 914 | 1054 | nvalue(&index) = i+1; |
| 915 | 1055 | *(lua_hashdefine(avalue(&arg), &index)) = *(firstelem+i); |
| 916 | 1056 | } |
| 917 | 1057 | /* store counter in field "n" */ { |
| 918 | − Object index, extra; | |
| 919 | − tag(&index) = LUA_T_STRING; | |
| 1058 | + TObject index, extra; | |
| 1059 | + ttype(&index) = LUA_T_STRING; | |
| 920 | 1060 | tsvalue(&index) = lua_createstring("n"); |
| 921 | − tag(&extra) = LUA_T_NUMBER; | |
| 1061 | + ttype(&extra) = LUA_T_NUMBER; | |
| 922 | 1062 | nvalue(&extra) = nvararg; |
| 923 | 1063 | *(lua_hashdefine(avalue(&arg), &index)) = extra; |
| 924 | 1064 | } |
| @@ -942,22 +1082,22 @@ static StkId lua_execute (Byte *pc, StkId base) · 17 unmodified lines | ||
| 942 | 1082 | OpCode opcode; |
| 943 | 1083 | switch (opcode = (OpCode)*pc++) |
| 944 | 1084 | { |
| 945 | − case PUSHNIL: tag(top) = LUA_T_NIL; incr_top; break; | |
| 1085 | + case PUSHNIL: ttype(top) = LUA_T_NIL; incr_top; break; | |
| 946 | 1086 | |
| 947 | 1087 | case PUSH0: case PUSH1: case PUSH2: |
| 948 | − tag(top) = LUA_T_NUMBER; | |
| 1088 | + ttype(top) = LUA_T_NUMBER; | |
| 949 | 1089 | nvalue(top) = opcode-PUSH0; |
| 950 | 1090 | incr_top; |
| 951 | 1091 | break; |
| 952 | 1092 | |
| 953 | 1093 | case PUSHBYTE: |
| 954 | − tag(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; break; | |
| 1094 | + ttype(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; break; | |
| 955 | 1095 | |
| 956 | 1096 | case PUSHWORD: |
| 957 | 1097 | { |
| 958 | 1098 | Word w; |
| 959 | 1099 | get_word(w,pc); |
| 960 | − tag(top) = LUA_T_NUMBER; nvalue(top) = w; | |
| 1100 | + ttype(top) = LUA_T_NUMBER; nvalue(top) = w; | |
| 961 | 1101 | incr_top; |
| 962 | 1102 | } |
| 963 | 1103 | break; |
| @@ -966,7 +1106,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 2 unmodified lines | ||
| 966 | 1106 | { |
| 967 | 1107 | real num; |
| 968 | 1108 | get_float(num,pc); |
| 969 | − tag(top) = LUA_T_NUMBER; nvalue(top) = num; | |
| 1109 | + ttype(top) = LUA_T_NUMBER; nvalue(top) = num; | |
| 970 | 1110 | incr_top; |
| 971 | 1111 | } |
| 972 | 1112 | break; |
| @@ -975,7 +1115,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 2 unmodified lines | ||
| 975 | 1115 | { |
| 976 | 1116 | Word w; |
| 977 | 1117 | get_word(w,pc); |
| 978 | − tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 1118 | + ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 979 | 1119 | incr_top; |
| 980 | 1120 | } |
| 981 | 1121 | break; |
| @@ -985,7 +1125,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 3 unmodified lines | ||
| 985 | 1125 | TFunc *f; |
| 986 | 1126 | get_code(f,pc); |
| 987 | 1127 | luaI_insertfunction(f); /* may take part in GC */ |
| 988 | − top->tag = LUA_T_FUNCTION; | |
| 1128 | + top->ttype = LUA_T_FUNCTION; | |
| 989 | 1129 | top->value.tf = f; |
| 990 | 1130 | incr_top; |
| 991 | 1131 | } |
| @@ -1013,10 +1153,10 @@ static StkId lua_execute (Byte *pc, StkId base) · 21 unmodified lines | ||
| 1013 | 1153 | |
| 1014 | 1154 | case PUSHSELF: |
| 1015 | 1155 | { |
| 1016 | − Object receiver = *(top-1); | |
| 1156 | + TObject receiver = *(top-1); | |
| 1017 | 1157 | Word w; |
| 1018 | 1158 | get_word(w,pc); |
| 1019 | − tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 1159 | + ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 1020 | 1160 | incr_top; |
| 1021 | 1161 | pushsubscript(); |
| 1022 | 1162 | *top = receiver; |
| @@ -1037,47 +1177,32 @@ static StkId lua_execute (Byte *pc, StkId base) · 14 unmodified lines | ||
| 1037 | 1177 | { |
| 1038 | 1178 | Word w; |
| 1039 | 1179 | get_word(w,pc); |
| 1040 | − s_object(w) = *(--top); | |
| 1180 | + setglobal(w); | |
| 1041 | 1181 | } |
| 1042 | 1182 | break; |
| 1043 | 1183 | |
| 1044 | 1184 | case STOREINDEXED0: |
| 1045 | − storesubscript(); | |
| 1185 | + storesubscript(top-3, 1); | |
| 1046 | 1186 | break; |
| 1047 | 1187 | |
| 1048 | − case STOREINDEXED: | |
| 1049 | − { | |
| 1050 | − int n = *pc++; | |
| 1051 | − if (tag(top-3-n) != LUA_T_ARRAY) | |
| 1052 | − { | |
| 1053 | − lua_checkstack(top+2); | |
| 1054 | − *(top+1) = *(top-1); | |
| 1055 | − *(top) = *(top-2-n); | |
| 1056 | − *(top-1) = *(top-3-n); | |
| 1057 | − top += 2; | |
| 1058 | − callFB(FB_SETTABLE); | |
| 1059 | − } | |
| 1060 | − else | |
| 1061 | − { | |
| 1062 | − Object *h = lua_hashdefine (avalue(top-3-n), top-2-n); | |
| 1063 | − *h = *(top-1); | |
| 1064 | − top--; | |
| 1065 | − } | |
| 1188 | + case STOREINDEXED: { | |
| 1189 | + int n = *pc++; | |
| 1190 | + storesubscript(top-3-n, 2); | |
| 1191 | + break; | |
| 1066 | 1192 | } |
| 1067 | − break; | |
| 1068 | 1193 | |
| 1069 | 1194 | case STORELIST0: |
| 1070 | 1195 | case STORELIST: |
| 1071 | 1196 | { |
| 1072 | 1197 | int m, n; |
| 1073 | − Object *arr; | |
| 1198 | + TObject *arr; | |
| 1074 | 1199 | if (opcode == STORELIST0) m = 0; |
| 1075 | 1200 | else m = *(pc++) * FIELDS_PER_FLUSH; |
| 1076 | 1201 | n = *(pc++); |
| 1077 | 1202 | arr = top-n-1; |
| 1078 | 1203 | while (n) |
| 1079 | 1204 | { |
| 1080 | − tag(top) = LUA_T_NUMBER; nvalue(top) = n+m; | |
| 1205 | + ttype(top) = LUA_T_NUMBER; nvalue(top) = n+m; | |
| 1081 | 1206 | *(lua_hashdefine (avalue(arr), top)) = *(top-1); |
| 1082 | 1207 | top--; |
| 1083 | 1208 | n--; |
| @@ -1085,15 +1210,15 @@ static StkId lua_execute (Byte *pc, StkId base) · 1 unmodified line | ||
| 1085 | 1210 | } |
| 1086 | 1211 | break; |
| 1087 | 1212 | |
| 1088 | − case STORERECORD: | |
| 1213 | + case STORERECORD: /* opcode obsolete: supersed by STOREMAP */ | |
| 1089 | 1214 | { |
| 1090 | 1215 | int n = *(pc++); |
| 1091 | − Object *arr = top-n-1; | |
| 1216 | + TObject *arr = top-n-1; | |
| 1092 | 1217 | while (n) |
| 1093 | 1218 | { |
| 1094 | 1219 | Word w; |
| 1095 | 1220 | get_word(w,pc); |
| 1096 | − tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 1221 | + ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; | |
| 1097 | 1222 | *(lua_hashdefine (avalue(arr), top)) = *(top-1); |
| 1098 | 1223 | top--; |
| 1099 | 1224 | n--; |
| @@ -1101,13 +1226,25 @@ static StkId lua_execute (Byte *pc, StkId base) · 1 unmodified line | ||
| 1101 | 1226 | } |
| 1102 | 1227 | break; |
| 1103 | 1228 | |
| 1229 | + case STOREMAP: { | |
| 1230 | + int n = *(pc++); | |
| 1231 | + TObject *arr = top-(2*n)-1; | |
| 1232 | + while (n--) { | |
| 1233 | + *(lua_hashdefine (avalue(arr), top-2)) = *(top-1); | |
| 1234 | + top-=2; | |
| 1235 | + } | |
| 1236 | + } | |
| 1237 | + break; | |
| 1238 | + | |
| 1104 | 1239 | case ADJUST0: |
| 1105 | 1240 | adjust_top(base); |
| 1106 | 1241 | break; |
| 1107 | 1242 | |
| 1108 | − case ADJUST: | |
| 1109 | − adjust_top(base + *(pc++)); | |
| 1243 | + case ADJUST: { | |
| 1244 | + StkId newtop = base + *(pc++); | |
| 1245 | + adjust_top(newtop); | |
| 1110 | 1246 | break; |
| 1247 | + } | |
| 1111 | 1248 | |
| 1112 | 1249 | case VARARGS: |
| 1113 | 1250 | adjust_varargs(base + *(pc++)); |
| @@ -1118,7 +1255,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 4 unmodified lines | ||
| 1118 | 1255 | Word size; |
| 1119 | 1256 | get_word(size,pc); |
| 1120 | 1257 | avalue(top) = lua_createarray(size); |
| 1121 | − tag(top) = LUA_T_ARRAY; | |
| 1258 | + ttype(top) = LUA_T_ARRAY; | |
| 1122 | 1259 | incr_top; |
| 1123 | 1260 | } |
| 1124 | 1261 | break; |
| @@ -1127,33 +1264,33 @@ static StkId lua_execute (Byte *pc, StkId base) · 2 unmodified lines | ||
| 1127 | 1264 | { |
| 1128 | 1265 | int res = lua_equalObj(top-2, top-1); |
| 1129 | 1266 | --top; |
| 1130 | − tag(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; | |
| 1267 | + ttype(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; | |
| 1131 | 1268 | nvalue(top-1) = 1; |
| 1132 | 1269 | } |
| 1133 | 1270 | break; |
| 1134 | 1271 | |
| 1135 | 1272 | case LTOP: |
| 1136 | − comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, "lt"); | |
| 1273 | + comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); | |
| 1137 | 1274 | break; |
| 1138 | 1275 | |
| 1139 | 1276 | case LEOP: |
| 1140 | − comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, "le"); | |
| 1277 | + comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); | |
| 1141 | 1278 | break; |
| 1142 | 1279 | |
| 1143 | 1280 | case GTOP: |
| 1144 | − comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, "gt"); | |
| 1281 | + comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); | |
| 1145 | 1282 | break; |
| 1146 | 1283 | |
| 1147 | 1284 | case GEOP: |
| 1148 | − comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, "ge"); | |
| 1285 | + comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); | |
| 1149 | 1286 | break; |
| 1150 | 1287 | |
| 1151 | 1288 | case ADDOP: |
| 1152 | 1289 | { |
| 1153 | − Object *l = top-2; | |
| 1154 | − Object *r = top-1; | |
| 1290 | + TObject *l = top-2; | |
| 1291 | + TObject *r = top-1; | |
| 1155 | 1292 | if (tonumber(r) || tonumber(l)) |
| 1156 | − call_arith("add"); | |
| 1293 | + call_arith(IM_ADD); | |
| 1157 | 1294 | else |
| 1158 | 1295 | { |
| 1159 | 1296 | nvalue(l) += nvalue(r); |
| @@ -1164,10 +1301,10 @@ static StkId lua_execute (Byte *pc, StkId base) · 4 unmodified lines | ||
| 1164 | 1301 | |
| 1165 | 1302 | case SUBOP: |
| 1166 | 1303 | { |
| 1167 | − Object *l = top-2; | |
| 1168 | − Object *r = top-1; | |
| 1304 | + TObject *l = top-2; | |
| 1305 | + TObject *r = top-1; | |
| 1169 | 1306 | if (tonumber(r) || tonumber(l)) |
| 1170 | − call_arith("sub"); | |
| 1307 | + call_arith(IM_SUB); | |
| 1171 | 1308 | else |
| 1172 | 1309 | { |
| 1173 | 1310 | nvalue(l) -= nvalue(r); |
| @@ -1178,10 +1315,10 @@ static StkId lua_execute (Byte *pc, StkId base) · 4 unmodified lines | ||
| 1178 | 1315 | |
| 1179 | 1316 | case MULTOP: |
| 1180 | 1317 | { |
| 1181 | − Object *l = top-2; | |
| 1182 | − Object *r = top-1; | |
| 1318 | + TObject *l = top-2; | |
| 1319 | + TObject *r = top-1; | |
| 1183 | 1320 | if (tonumber(r) || tonumber(l)) |
| 1184 | − call_arith("mul"); | |
| 1321 | + call_arith(IM_MUL); | |
| 1185 | 1322 | else |
| 1186 | 1323 | { |
| 1187 | 1324 | nvalue(l) *= nvalue(r); |
| @@ -1192,10 +1329,10 @@ static StkId lua_execute (Byte *pc, StkId base) · 4 unmodified lines | ||
| 1192 | 1329 | |
| 1193 | 1330 | case DIVOP: |
| 1194 | 1331 | { |
| 1195 | − Object *l = top-2; | |
| 1196 | − Object *r = top-1; | |
| 1332 | + TObject *l = top-2; | |
| 1333 | + TObject *r = top-1; | |
| 1197 | 1334 | if (tonumber(r) || tonumber(l)) |
| 1198 | − call_arith("div"); | |
| 1335 | + call_arith(IM_DIV); | |
| 1199 | 1336 | else |
| 1200 | 1337 | { |
| 1201 | 1338 | nvalue(l) /= nvalue(r); |
| @@ -1205,36 +1342,34 @@ static StkId lua_execute (Byte *pc, StkId base) · 3 unmodified lines | ||
| 1205 | 1342 | break; |
| 1206 | 1343 | |
| 1207 | 1344 | case POWOP: |
| 1208 | − call_arith("pow"); | |
| 1345 | + call_arith(IM_POW); | |
| 1209 | 1346 | break; |
| 1210 | 1347 | |
| 1211 | − case CONCOP: | |
| 1212 | − { | |
| 1213 | − Object *l = top-2; | |
| 1214 | − Object *r = top-1; | |
| 1215 | − if (tostring(r) || tostring(l)) | |
| 1216 | − callFB(FB_CONCAT); | |
| 1217 | − else | |
| 1218 | − { | |
| 1219 | − tsvalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r))); | |
| 1220 | − --top; | |
| 1221 | − } | |
| 1348 | + case CONCOP: { | |
| 1349 | + TObject *l = top-2; | |
| 1350 | + TObject *r = top-1; | |
| 1351 | + if (tostring(l) || tostring(r)) | |
| 1352 | + call_binTM(IM_CONCAT, "unexpected type for concatenation"); | |
| 1353 | + else { | |
| 1354 | + tsvalue(l) = lua_createstring(lua_strconc(svalue(l),svalue(r))); | |
| 1355 | + --top; | |
| 1356 | + } | |
| 1222 | 1357 | } |
| 1223 | 1358 | break; |
| 1224 | 1359 | |
| 1225 | 1360 | case MINUSOP: |
| 1226 | 1361 | if (tonumber(top-1)) |
| 1227 | 1362 | { |
| 1228 | − tag(top) = LUA_T_NIL; | |
| 1363 | + ttype(top) = LUA_T_NIL; | |
| 1229 | 1364 | incr_top; |
| 1230 | − call_arith("unm"); | |
| 1365 | + call_arith(IM_UNM); | |
| 1231 | 1366 | } |
| 1232 | 1367 | else |
| 1233 | 1368 | nvalue(top-1) = - nvalue(top-1); |
| 1234 | 1369 | break; |
| 1235 | 1370 | |
| 1236 | 1371 | case NOTOP: |
| 1237 | − tag(top-1) = (tag(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; | |
| 1372 | + ttype(top-1) = (ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; | |
| 1238 | 1373 | nvalue(top-1) = 1; |
| 1239 | 1374 | break; |
| 1240 | 1375 | |
| @@ -1242,15 +1377,15 @@ static StkId lua_execute (Byte *pc, StkId base) · 1 unmodified line | ||
| 1242 | 1377 | { |
| 1243 | 1378 | Word w; |
| 1244 | 1379 | get_word(w,pc); |
| 1245 | − if (tag(top-1) != LUA_T_NIL) pc += w; | |
| 1380 | + if (ttype(top-1) != LUA_T_NIL) pc += w; | |
| 1246 | 1381 | } |
| 1247 | 1382 | break; |
| 1248 | 1383 | |
| 1249 | − case ONFJMP: | |
| 1384 | + case ONFJMP: | |
| 1250 | 1385 | { |
| 1251 | 1386 | Word w; |
| 1252 | 1387 | get_word(w,pc); |
| 1253 | − if (tag(top-1) == LUA_T_NIL) pc += w; | |
| 1388 | + if (ttype(top-1) == LUA_T_NIL) pc += w; | |
| 1254 | 1389 | } |
| 1255 | 1390 | break; |
| 1256 | 1391 | |
| @@ -1275,7 +1410,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 18 unmodified lines | ||
| 1275 | 1410 | Word w; |
| 1276 | 1411 | get_word(w,pc); |
| 1277 | 1412 | top--; |
| 1278 | − if (tag(top) == LUA_T_NIL) pc += w; | |
| 1413 | + if (ttype(top) == LUA_T_NIL) pc += w; | |
| 1279 | 1414 | } |
| 1280 | 1415 | break; |
| 1281 | 1416 | |
| @@ -1284,7 +1419,7 @@ static StkId lua_execute (Byte *pc, StkId base) · 2 unmodified lines | ||
| 1284 | 1419 | Word w; |
| 1285 | 1420 | get_word(w,pc); |
| 1286 | 1421 | top--; |
| 1287 | − if (tag(top) == LUA_T_NIL) pc -= w; | |
| 1422 | + if (ttype(top) == LUA_T_NIL) pc -= w; | |
| 1288 | 1423 | } |
| 1289 | 1424 | break; |
| 1290 | 1425 | |
| @@ -1309,12 +1444,12 @@ static StkId lua_execute (Byte *pc, StkId base) · 18 unmodified lines | ||
| 1309 | 1444 | { |
| 1310 | 1445 | Word line; |
| 1311 | 1446 | get_word(line,pc); |
| 1312 | − if ((stack+base-1)->tag != LUA_T_LINE) | |
| 1447 | + if ((stack+base-1)->ttype != LUA_T_LINE) | |
| 1313 | 1448 | { |
| 1314 | 1449 | /* open space for LINE value */ |
| 1315 | 1450 | open_stack((top-stack)-base); |
| 1316 | 1451 | base++; |
| 1317 | − (stack+base-1)->tag = LUA_T_LINE; | |
| 1452 | + (stack+base-1)->ttype = LUA_T_LINE; | |
| 1318 | 1453 | } |
| 1319 | 1454 | (stack+base-1)->value.i = line; |
| 1320 | 1455 | if (lua_linehook) |
| @@ -1328,3 +1463,16 @@ static StkId lua_execute (Byte *pc, StkId base) · 7 unmodified lines | ||
| 1328 | 1463 | } |
| 1329 | 1464 | } |
| 1330 | 1465 | |
| 1466 | + | |
| 1467 | +#if COMPAT2_5 | |
| 1468 | +/* | |
| 1469 | +** API: set a function as a fallback | |
| 1470 | +*/ | |
| 1471 | +lua_Object lua_setfallback (char *name, lua_CFunction fallback) | |
| 1472 | +{ | |
| 1473 | + lua_pushstring(name); | |
| 1474 | + lua_pushcfunction(fallback); | |
| 1475 | + do_unprotectedrun(luaI_setfallback, 2, 1); | |
| 1476 | + return put_luaObjectonTop(); | |
| 1477 | +} | |
| 1478 | +#endif | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** TeCGraf - PUC-Rio |
| 3 | −** $Id: opcode.h,v 3.24 1996/11/01 12:46:59 roberto Exp $ | |
| 3 | +** $Id: opcode.h,v 3.34 1997/06/16 16:50:22 roberto Exp $ | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | #ifndef opcode_h |
| @@ -14,6 +14,28 @@ · 7 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | #define FIELDS_PER_FLUSH 40 |
| 16 | 16 | |
| 17 | +/* | |
| 18 | +* WARNING: if you change the order of this enumeration, | |
| 19 | +* grep "ORDER LUA_T" | |
| 20 | +*/ | |
| 21 | +typedef enum | |
| 22 | +{ | |
| 23 | + LUA_T_NIL = -9, | |
| 24 | + LUA_T_NUMBER = -8, | |
| 25 | + LUA_T_STRING = -7, | |
| 26 | + LUA_T_ARRAY = -6, /* array==table */ | |
| 27 | + LUA_T_FUNCTION = -5, | |
| 28 | + LUA_T_CFUNCTION= -4, | |
| 29 | + LUA_T_MARK = -3, | |
| 30 | + LUA_T_CMARK = -2, | |
| 31 | + LUA_T_LINE = -1, | |
| 32 | + LUA_T_USERDATA = 0 | |
| 33 | +} lua_Type; | |
| 34 | + | |
| 35 | +#define NUM_TYPES 10 | |
| 36 | + | |
| 37 | + | |
| 38 | +extern char *luaI_typenames[]; | |
| 17 | 39 | |
| 18 | 40 | typedef enum { |
| 19 | 41 | /* name parm before after side effect |
| @@ -38,7 +60,7 @@ PUSHLOCAL6,/* - LOC[6] */ · 18 unmodified lines | ||
| 38 | 60 | PUSHLOCAL7,/* - LOC[7] */ |
| 39 | 61 | PUSHLOCAL8,/* - LOC[8] */ |
| 40 | 62 | PUSHLOCAL9,/* - LOC[9] */ |
| 41 | −PUSHLOCAL,/* w - LOC[w] */ | |
| 63 | +PUSHLOCAL,/* b - LOC[b] */ | |
| 42 | 64 | PUSHGLOBAL,/* w - VAR[w] */ |
| 43 | 65 | PUSHINDEXED,/* i t t[i] */ |
| 44 | 66 | PUSHSELF,/* w t t t[STR[w]] */ |
| @@ -52,14 +74,14 @@ STORELOCAL6,/* x - LOC[6]=x */ · 7 unmodified lines | ||
| 52 | 74 | STORELOCAL7,/* x - LOC[7]=x */ |
| 53 | 75 | STORELOCAL8,/* x - LOC[8]=x */ |
| 54 | 76 | STORELOCAL9,/* x - LOC[9]=x */ |
| 55 | −STORELOCAL,/* w x - LOC[w]=x */ | |
| 77 | +STORELOCAL,/* b x - LOC[b]=x */ | |
| 56 | 78 | STOREGLOBAL,/* w x - VAR[w]=x */ |
| 57 | 79 | STOREINDEXED0,/* v i t - t[i]=v */ |
| 58 | 80 | STOREINDEXED,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ |
| 59 | −STORELIST0,/* w v_w...v_1 t - t[i]=v_i */ | |
| 60 | −STORELIST,/* w n v_w...v_1 t - t[i+n*FPF]=v_i */ | |
| 61 | −STORERECORD,/* n | |
| 62 | − w_n...w_1 v_n...v_1 t - t[STR[w_i]]=v_i */ | |
| 81 | +STORELIST0,/* b v_b...v_1 t - t[i]=v_i */ | |
| 82 | +STORELIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */ | |
| 83 | +STORERECORD,/* b | |
| 84 | + w_b...w_1 v_b...v_1 t - t[STR[w_i]]=v_i */ | |
| 63 | 85 | ADJUST0,/* - - TOP=BASE */ |
| 64 | 86 | ADJUST,/* b - - TOP=BASE+b */ |
| 65 | 87 | CREATEARRAY,/* w - newarray(size = w) */ |
| @@ -76,19 +98,19 @@ POWOP,/* y x x^y */ · 10 unmodified lines | ||
| 76 | 98 | CONCOP,/* y x x..y */ |
| 77 | 99 | MINUSOP,/* x -x */ |
| 78 | 100 | NOTOP,/* x (x==nil)? 1 : nil */ |
| 79 | −ONTJMP,/* w x - (x!=nil)? PC+=w */ | |
| 80 | −ONFJMP,/* w x - (x==nil)? PC+=w */ | |
| 101 | +ONTJMP,/* w x - (x!=nil)? PC+=w */ | |
| 102 | +ONFJMP,/* w x - (x==nil)? PC+=w */ | |
| 81 | 103 | JMP,/* w - - PC+=w */ |
| 82 | −UPJMP,/* w - - PC-=w */ | |
| 83 | −IFFJMP,/* w x - (x==nil)? PC+=w */ | |
| 104 | +UPJMP,/* w - - PC-=w */ | |
| 105 | +IFFJMP,/* w x - (x==nil)? PC+=w */ | |
| 84 | 106 | IFFUPJMP,/* w x - (x==nil)? PC-=w */ |
| 85 | 107 | POP,/* x - */ |
| 86 | −CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */ | |
| 108 | +CALLFUNC,/* b c v_b...v_1 f r_c...r_1 f(v1,...,v_b) */ | |
| 87 | 109 | RETCODE0, |
| 88 | 110 | RETCODE,/* b - - */ |
| 89 | 111 | SETLINE,/* w - - LINE=w */ |
| 90 | −VARARGS/* b v_n...v_1 {v_1...v_n;n=n} */ | |
| 91 | − | |
| 112 | +VARARGS,/* b v_b...v_1 {v_1...v_b;n=b} */ | |
| 113 | +STOREMAP/* b v_b k_b ...v_1 k_1 t - t[k_i]=v_i */ | |
| 92 | 114 | } OpCode; |
| 93 | 115 | |
| 94 | 116 | |
| @@ -102,29 +124,27 @@ typedef union · 7 unmodified lines | ||
| 102 | 124 | TaggedString *ts; |
| 103 | 125 | TFunc *tf; |
| 104 | 126 | struct Hash *a; |
| 105 | − void *u; | |
| 106 | 127 | int i; |
| 107 | 128 | } Value; |
| 108 | 129 | |
| 109 | −typedef struct Object | |
| 130 | +typedef struct TObject | |
| 110 | 131 | { |
| 111 | − lua_Type tag; | |
| 132 | + lua_Type ttype; | |
| 112 | 133 | Value value; |
| 113 | −} Object; | |
| 134 | +} TObject; | |
| 114 | 135 | |
| 115 | 136 | |
| 116 | 137 | /* Macros to access structure members */ |
| 117 | −#define tag(o) ((o)->tag) | |
| 138 | +#define ttype(o) ((o)->ttype) | |
| 118 | 139 | #define nvalue(o) ((o)->value.n) |
| 119 | 140 | #define svalue(o) ((o)->value.ts->str) |
| 120 | 141 | #define tsvalue(o) ((o)->value.ts) |
| 121 | 142 | #define avalue(o) ((o)->value.a) |
| 122 | 143 | #define fvalue(o) ((o)->value.f) |
| 123 | −#define uvalue(o) ((o)->value.u) | |
| 124 | 144 | |
| 125 | 145 | /* Macros to access symbol table */ |
| 126 | 146 | #define s_object(i) (lua_table[i].object) |
| 127 | −#define s_tag(i) (tag(&s_object(i))) | |
| 147 | +#define s_ttype(i) (ttype(&s_object(i))) | |
| 128 | 148 | #define s_nvalue(i) (nvalue(&s_object(i))) |
| 129 | 149 | #define s_svalue(i) (svalue(&s_object(i))) |
| 130 | 150 | #define s_tsvalue(i) (tsvalue(&s_object(i))) |
| @@ -141,10 +161,11 @@ typedef struct Object · 10 unmodified lines | ||
| 141 | 161 | /* Exported functions */ |
| 142 | 162 | void lua_parse (TFunc *tf); /* from "lua.stx" module */ |
| 143 | 163 | void luaI_codedebugline (int line); /* from "lua.stx" module */ |
| 144 | −void lua_travstack (int (*fn)(Object *)); | |
| 145 | −Object *luaI_Address (lua_Object o); | |
| 146 | −void luaI_pushobject (Object *o); | |
| 147 | −void luaI_gcFB (Object *o); | |
| 164 | +void lua_travstack (int (*fn)(TObject *)); | |
| 165 | +TObject *luaI_Address (lua_Object o); | |
| 166 | +void luaI_pushobject (TObject *o); | |
| 167 | +void luaI_gcIM (TObject *o); | |
| 148 | 168 | int luaI_dorun (TFunc *tf); |
| 169 | +int lua_domain (void); | |
| 149 | 170 | |
| 150 | 171 | #endif |
| @@ -10,14 +10,14 @@ static char luaY_sccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; · 9 unmodified lines | ||
| 10 | 10 | #define YYPREFIX "luaY_" |
| 11 | 11 | #line 2 "lua.stx" |
| 12 | 12 | |
| 13 | −char *rcs_luastx = "$Id: parser.c,v 1.1 1996/11/21 16:11:40 lhf Exp $"; | |
| 13 | +char *rcs_luastx = "$Id: parser.c,v 1.1 1997/06/30 18:59:03 lhf Exp $"; | |
| 14 | 14 | |
| 15 | 15 | #include <stdio.h> |
| 16 | 16 | #include <stdlib.h> |
| 17 | 17 | #include <string.h> |
| 18 | 18 | |
| 19 | 19 | #include "luadebug.h" |
| 20 | −#include "mem.h" | |
| 20 | +#include "luamem.h" | |
| 21 | 21 | #include "lex.h" |
| 22 | 22 | #include "opcode.h" |
| 23 | 23 | #include "hash.h" |
| @@ -60,8 +60,6 @@ static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ · 36 unmodified lines | ||
| 60 | 60 | static int nlocalvar=0; /* number of local variables */ |
| 61 | 61 | |
| 62 | 62 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
| 63 | −static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ | |
| 64 | −static int nfields=0; | |
| 65 | 63 | |
| 66 | 64 | int lua_debug = 0; |
| 67 | 65 | |
| @@ -113,22 +111,11 @@ static void code_word_at (Byte *p, int n) · 45 unmodified lines | ||
| 113 | 111 | memcpy(p, &w, sizeof(Word)); |
| 114 | 112 | } |
| 115 | 113 | |
| 116 | −static void push_field (Word name) | |
| 117 | −{ | |
| 118 | − if (nfields < MAXFIELDS) | |
| 119 | − fields[nfields++] = name; | |
| 120 | − else | |
| 121 | − luaY_error ("too many fields in nested constructors"); | |
| 122 | −} | |
| 123 | − | |
| 124 | 114 | static void flush_record (int n) |
| 125 | 115 | { |
| 126 | − int i; | |
| 127 | 116 | if (n == 0) return; |
| 128 | − code_byte(STORERECORD); | |
| 117 | + code_byte(STOREMAP); | |
| 129 | 118 | code_byte(n); |
| 130 | − for (i=0; i<n; i++) | |
| 131 | − code_word(fields[--nfields]); | |
| 132 | 119 | } |
| 133 | 120 | |
| 134 | 121 | static void flush_list (int m, int n) |
| @@ -171,11 +158,22 @@ static void add_varbuffer (Long var) · 36 unmodified lines | ||
| 171 | 158 | luaY_error ("variable buffer overflow"); |
| 172 | 159 | } |
| 173 | 160 | |
| 161 | +static void code_string (Word w) | |
| 162 | +{ | |
| 163 | + code_byte(PUSHSTRING); | |
| 164 | + code_word(w); | |
| 165 | +} | |
| 166 | + | |
| 167 | +static void code_constant (TaggedString *s) | |
| 168 | +{ | |
| 169 | + code_string(luaI_findconstant(s)); | |
| 170 | +} | |
| 171 | + | |
| 174 | 172 | static void code_number (float f) |
| 175 | 173 | { |
| 176 | − Word i = (Word)f; | |
| 177 | − if (f == (float)i) /* f has an (short) integer value */ | |
| 178 | − { | |
| 174 | + Word i; | |
| 175 | + if (f >= 0 && f <= (float)MAX_WORD && (float)(i=(Word)f) == f) { | |
| 176 | + /* f has an (short) integer value */ | |
| 179 | 177 | if (i <= 2) code_byte(PUSH0 + i); |
| 180 | 178 | else if (i <= 255) |
| 181 | 179 | { |
| @@ -418,7 +416,7 @@ void lua_parse (TFunc *tf) · 236 unmodified lines | ||
| 418 | 416 | } |
| 419 | 417 | |
| 420 | 418 | |
| 421 | −#line 414 "lua.stx" | |
| 419 | +#line 412 "lua.stx" | |
| 422 | 420 | typedef union |
| 423 | 421 | { |
| 424 | 422 | int vInt; |
| @@ -429,7 +427,7 @@ typedef union · 4 unmodified lines | ||
| 429 | 427 | TFunc *pFunc; |
| 430 | 428 | TaggedString *pTStr; |
| 431 | 429 | } YYSTYPE; |
| 432 | −#line 433 "y.tab.c" | |
| 430 | +#line 431 "y.tab.c" | |
| 433 | 431 | #define WRONGTOKEN 257 |
| 434 | 432 | #define NIL 258 |
| 435 | 433 | #define IF 259 |
| @@ -467,8 +465,9 @@ short luaY_lhs[] = { -1, · 31 unmodified lines | ||
| 467 | 465 | 38, 5, 39, 5, 40, 37, 4, 8, 8, 7, |
| 468 | 466 | 7, 2, 2, 3, 41, 3, 17, 17, 18, 18, |
| 469 | 467 | 19, 19, 42, 9, 9, 14, 14, 43, 43, 12, |
| 470 | − 12, 13, 13, 44, 15, 15, 16, 16, 6, 6, | |
| 471 | − 20, 20, 20, 21, 29, 10, 10, 11, 11, | |
| 468 | + 12, 13, 13, 44, 45, 45, 15, 15, 16, 16, | |
| 469 | + 6, 6, 20, 20, 20, 21, 29, 10, 10, 11, | |
| 470 | + 11, | |
| 472 | 471 | }; |
| 473 | 472 | short luaY_len[] = { 2, |
| 474 | 473 | 2, 0, 3, 2, 3, 1, 3, 5, 0, 3, |
| @@ -479,113 +478,114 @@ short luaY_len[] = { 2, · 4 unmodified lines | ||
| 479 | 478 | 0, 5, 0, 5, 0, 4, 2, 1, 3, 3, |
| 480 | 479 | 1, 0, 1, 1, 0, 4, 0, 1, 1, 3, |
| 481 | 480 | 1, 1, 0, 3, 2, 0, 2, 0, 1, 0, |
| 482 | − 2, 1, 3, 3, 0, 2, 1, 3, 1, 3, | |
| 483 | − 1, 4, 3, 1, 1, 1, 3, 0, 2, | |
| 481 | + 2, 1, 3, 3, 3, 1, 0, 2, 1, 3, | |
| 482 | + 1, 3, 1, 4, 3, 1, 1, 1, 3, 0, | |
| 483 | + 2, | |
| 484 | 484 | }; |
| 485 | 485 | short luaY_defred[] = { 2, |
| 486 | − 0, 0, 0, 14, 16, 0, 0, 0, 94, 19, | |
| 487 | − 0, 0, 0, 91, 1, 0, 4, 0, 48, 46, | |
| 488 | − 47, 0, 0, 0, 49, 29, 95, 0, 0, 44, | |
| 489 | − 0, 0, 24, 0, 0, 0, 0, 96, 0, 0, | |
| 486 | + 0, 0, 0, 14, 16, 0, 0, 0, 96, 19, | |
| 487 | + 0, 0, 0, 93, 1, 0, 4, 0, 48, 46, | |
| 488 | + 47, 0, 0, 0, 49, 29, 97, 0, 0, 44, | |
| 489 | + 0, 0, 24, 0, 0, 0, 0, 98, 0, 0, | |
| 490 | 490 | 0, 0, 0, 0, 0, 57, 61, 12, 3, 0, |
| 491 | 491 | 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, |
| 492 | 492 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 493 | 493 | 0, 0, 0, 9, 27, 65, 0, 0, 20, 0, |
| 494 | − 5, 0, 0, 0, 0, 0, 59, 0, 93, 30, | |
| 494 | + 5, 0, 0, 0, 0, 0, 59, 0, 95, 30, | |
| 495 | 495 | 24, 51, 53, 0, 0, 0, 0, 0, 0, 0, |
| 496 | − 0, 0, 0, 0, 0, 0, 0, 0, 73, 0, | |
| 497 | − 0, 82, 28, 0, 0, 0, 0, 97, 72, 71, | |
| 498 | − 0, 0, 69, 7, 60, 92, 28, 0, 0, 0, | |
| 499 | − 56, 0, 75, 0, 0, 86, 24, 0, 25, 0, | |
| 500 | − 0, 24, 0, 0, 0, 0, 0, 0, 83, 0, | |
| 501 | − 74, 0, 28, 17, 10, 0, 70, 24, 0, 0, | |
| 502 | − 77, 0, 0, 8, 22, 0, 13, 81, 15, 28, | |
| 503 | − 24, 28, 0, 23, | |
| 496 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, | |
| 497 | + 0, 0, 82, 0, 28, 0, 0, 0, 0, 99, | |
| 498 | + 72, 71, 0, 0, 69, 7, 60, 94, 28, 0, | |
| 499 | + 0, 0, 56, 0, 75, 0, 0, 88, 0, 24, | |
| 500 | + 0, 25, 0, 0, 24, 0, 0, 0, 0, 85, | |
| 501 | + 86, 83, 0, 74, 0, 0, 28, 17, 10, 0, | |
| 502 | + 70, 24, 0, 0, 77, 0, 0, 8, 22, 0, | |
| 503 | + 13, 81, 15, 28, 24, 28, 0, 23, | |
| 504 | 504 | }; |
| 505 | 505 | short luaY_dgoto[] = { 1, |
| 506 | − 91, 34, 35, 25, 26, 11, 46, 12, 107, 39, | |
| 507 | − 79, 161, 108, 151, 109, 110, 121, 122, 123, 27, | |
| 506 | + 91, 34, 35, 25, 26, 11, 46, 12, 108, 39, | |
| 507 | + 79, 165, 109, 154, 110, 111, 123, 124, 125, 27, | |
| 508 | 508 | 14, 41, 81, 2, 15, 16, 49, 17, 28, 73, |
| 509 | − 115, 37, 160, 32, 33, 74, 30, 128, 129, 31, | |
| 510 | − 116, 134, 133, 112, | |
| 509 | + 117, 37, 164, 32, 33, 74, 30, 130, 131, 31, | |
| 510 | + 118, 136, 135, 113, 114, | |
| 511 | 511 | }; |
| 512 | 512 | short luaY_sindex[] = { 0, |
| 513 | − 0, 332, -38, 0, 0, -38, -239, -223, 0, 0, | |
| 514 | − -23, 17, 0, 0, 0, 3, 0, 137, 0, 0, | |
| 515 | − 0, -38, -38, -38, 0, 0, 0, 137, 547, 0, | |
| 516 | − -25, -38, 0, 3, 45, 0, 212, 0, -22, 0, | |
| 517 | − 52, 140, -38, -223, -38, 0, 0, 0, 0, -166, | |
| 518 | − -38, -154, 40, 40, 102, 0, 0, 0, -38, -38, | |
| 519 | − -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, | |
| 520 | − -34, 481, -130, 0, 0, 0, -38, -129, 0, -194, | |
| 521 | − 0, -123, 45, 0, -17, 103, 0, 753, 0, 0, | |
| 522 | − 0, 0, 0, -30, -30, -30, -30, -30, -30, 95, | |
| 523 | − 11, 11, 40, 40, 40, 97, 41, 123, 0, 124, | |
| 524 | − 212, 0, 0, -38, -59, -38, 45, 0, 0, 0, | |
| 525 | − 128, 131, 0, 0, 0, 0, 0, -38, -38, -38, | |
| 526 | − 0, -97, 0, 120, -38, 0, 0, 212, 0, 3, | |
| 527 | − 0, 0, -194, -183, 118, 118, 212, 97, 0, -97, | |
| 528 | − 0, 212, 0, 0, 0, -85, 0, 0, -38, -82, | |
| 529 | − 0, 123, -80, 0, 0, 1105, 0, 0, 0, 0, | |
| 530 | − 0, 0, -183, 0, | |
| 513 | + 0, 288, -34, 0, 0, -34, -238, -223, 0, 0, | |
| 514 | + -6, 22, 0, 0, 0, 14, 0, 150, 0, 0, | |
| 515 | + 0, -34, -34, -34, 0, 0, 0, 150, 547, 0, | |
| 516 | + -46, -34, 0, 14, 34, 0, 212, 0, -5, 0, | |
| 517 | + 39, 156, -34, -223, -34, 0, 0, 0, 0, -194, | |
| 518 | + -34, -193, -4, -4, 48, 0, 0, 0, -34, -34, | |
| 519 | + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, | |
| 520 | + -38, 481, -173, 0, 0, 0, -34, -146, 0, -234, | |
| 521 | + 0, -138, 34, 0, -15, 96, 0, 753, 0, 0, | |
| 522 | + 0, 0, 0, -30, -30, -30, -30, -30, -30, -20, | |
| 523 | + -12, -12, -4, -4, -4, 0, -34, 16, 95, 0, | |
| 524 | + 98, 212, 0, 82, 0, -34, 328, -34, 34, 0, | |
| 525 | + 0, 0, 103, 101, 0, 0, 0, 0, 0, -34, | |
| 526 | + -34, 1181, 0, -91, 0, 92, -34, 0, -34, 0, | |
| 527 | + 212, 0, 14, 0, 0, -234, -233, 118, 118, 0, | |
| 528 | + 0, 0, -91, 0, 212, 212, 0, 0, 0, -105, | |
| 529 | + 0, 0, -34, -103, 0, 95, -101, 0, 0, 1105, | |
| 530 | + 0, 0, 0, 0, 0, 0, -233, 0, | |
| 531 | 531 | }; |
| 532 | 532 | short luaY_rindex[] = { 0, |
| 533 | − 0, 191, 69, 0, 0, 173, 0, 0, 0, 0, | |
| 534 | − 0, 69, 150, 0, 0, 146, 0, -36, 0, 0, | |
| 535 | − 0, 69, 69, 69, 0, 0, 0, 1, 0, 0, | |
| 536 | − 0, 69, 0, 47, 461, 436, 0, 0, 197, 130, | |
| 537 | − 0, 0, 69, 0, -33, 0, 0, 0, 0, 0, | |
| 538 | − 69, 0, 24, 59, 1181, 0, 0, 0, 69, 69, | |
| 539 | − 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
| 540 | − -50, 0, 0, 0, 0, 0, 69, 0, 0, 152, | |
| 541 | − 0, 0, 311, -21, 0, 0, 0, 0, 0, 0, | |
| 533 | + 0, 169, 52, 0, 0, 173, 0, 0, 0, 0, | |
| 534 | + 0, 52, 508, 0, 0, 146, 0, -36, 0, 0, | |
| 535 | + 0, 52, 52, 52, 0, 0, 0, 1, 0, 0, | |
| 536 | + 0, 52, 0, 47, 461, 436, 0, 0, 197, 76, | |
| 537 | + 0, 0, 52, 0, -32, 0, 0, 0, 0, 0, | |
| 538 | + 52, 0, 24, 59, 1195, 0, 0, 0, 52, 52, | |
| 539 | + 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, | |
| 540 | + -27, 0, 0, 0, 0, 0, 52, 0, 0, 129, | |
| 541 | + 0, 0, 311, 142, 0, 0, 0, 0, 0, 0, | |
| 542 | 542 | 0, 0, 0, 746, 776, 799, 821, 844, 866, 505, |
| 543 | − 383, 410, 88, 112, 359, 1174, 0, 74, 0, -40, | |
| 544 | − -26, 0, 0, 69, -230, 69, 921, 0, 0, 0, | |
| 545 | − 0, 160, 0, 0, 0, 0, 0, 69, 69, 69, | |
| 546 | − 0, 77, 0, 78, -9, 0, 0, 939, 0, 289, | |
| 547 | − 474, 0, 0, -60, 894, 1137, -16, 0, 0, 89, | |
| 548 | − 0, -10, 0, 0, 0, 0, 0, 0, 69, 0, | |
| 549 | − 0, 74, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 550 | − 0, 0, -60, 0, | |
| 543 | + 383, 410, 88, 112, 359, 1174, 52, 0, 51, 0, | |
| 544 | + -40, -10, 0, 0, 0, 52, -153, 52, 921, 0, | |
| 545 | + 0, 0, 0, 144, 0, 0, 0, 0, 0, 52, | |
| 546 | + 52, 0, 0, 62, 0, 64, -26, 0, 52, 0, | |
| 547 | + 939, 0, 682, 474, 0, 0, -77, 894, 1137, 0, | |
| 548 | + 0, 0, 66, 0, 13, -18, 0, 0, 0, 0, | |
| 549 | + 0, 0, 52, 0, 0, 51, 0, 0, 0, 0, | |
| 550 | + 0, 0, 0, 0, 0, 0, -77, 0, | |
| 551 | 551 | }; |
| 552 | 552 | short luaY_gindex[] = { 0, |
| 553 | − -31, 171, 85, -2, 48, 0, 0, 0, 0, 0, | |
| 554 | − 0, 0, 67, 0, 0, 0, 0, 0, 75, 8, | |
| 555 | − 0, 0, 0, 0, 104, 107, -29, 0, 12, -61, | |
| 556 | − 0, 1260, 50, 0, 0, 0, 213, 0, 0, 0, | |
| 557 | − 0, 0, -107, 94, | |
| 553 | + 53, 147, -23, 3, 134, 0, 0, 0, 0, 0, | |
| 554 | + 0, 0, 40, 0, 0, 0, 0, 0, 49, 6, | |
| 555 | + 0, 0, 0, 0, 81, 83, -16, 0, 8, -70, | |
| 556 | + 0, 1445, 27, 0, 0, 0, 187, 0, 0, 0, | |
| 557 | + 0, 0, -108, 67, 0, | |
| 558 | 558 | }; |
| 559 | −#define YYTABLESIZE 1462 | |
| 560 | −short luaY_table[] = { 10, | |
| 561 | − 45, 24, 136, 58, 75, 24, 22, 62, 85, 13, | |
| 562 | − 22, 68, 66, 18, 67, 40, 69, 87, 78, 42, | |
| 563 | − 44, 78, 90, 43, 95, 92, 93, 84, 52, 127, | |
| 564 | − 26, 26, 87, 88, 38, 26, 26, 43, 77, 90, | |
| 565 | − 58, 45, 45, 45, 45, 45, 11, 45, 88, 79, | |
| 566 | − 9, 84, 68, 36, 168, 85, 45, 69, 50, 45, | |
| 567 | − 45, 48, 45, 70, 43, 43, 43, 43, 43, 95, | |
| 568 | − 43, 55, 55, 51, 85, 153, 119, 158, 159, 120, | |
| 569 | − 156, 137, 43, 43, 78, 43, 58, 39, 76, 55, | |
| 570 | − 36, 80, 36, 45, 45, 144, 165, 71, 87, 50, | |
| 571 | − 50, 50, 50, 50, 70, 50, 154, 87, 84, 172, | |
| 572 | − 155, 40, 10, 55, 88, 79, 43, 50, 50, 89, | |
| 573 | − 50, 163, 13, 58, 36, 45, 18, 83, 39, 39, | |
| 574 | − 39, 39, 39, 70, 39, 114, 68, 66, 171, 67, | |
| 575 | − 173, 69, 90, 125, 118, 11, 39, 39, 43, 39, | |
| 576 | − 124, 50, 40, 40, 40, 40, 40, 130, 40, 68, | |
| 577 | − 66, 117, 67, 141, 69, 131, 132, 135, 142, 6, | |
| 578 | − 40, 40, 62, 40, 143, 95, 148, 62, 150, 61, | |
| 579 | − 39, 164, 52, 50, 167, 52, 169, 95, 70, 95, | |
| 580 | − 26, 55, 67, 89, 50, 95, 98, 82, 78, 3, | |
| 581 | − 68, 79, 76, 4, 40, 5, 21, 95, 6, 7, | |
| 582 | − 89, 70, 39, 80, 9, 86, 162, 157, 139, 19, | |
| 583 | − 95, 140, 174, 19, 47, 149, 0, 51, 0, 0, | |
| 584 | − 51, 62, 0, 20, 21, 9, 40, 20, 21, 106, | |
| 585 | − 95, 0, 0, 0, 23, 0, 0, 0, 23, 0, | |
| 586 | − 65, 0, 0, 68, 66, 98, 67, 0, 69, 45, | |
| 559 | +#define YYTABLESIZE 1608 | |
| 560 | +short luaY_table[] = { 107, | |
| 561 | + 45, 24, 138, 58, 10, 24, 22, 13, 62, 18, | |
| 562 | + 22, 68, 66, 40, 67, 42, 69, 75, 78, 83, | |
| 563 | + 129, 68, 66, 43, 67, 84, 69, 162, 163, 68, | |
| 564 | + 52, 87, 79, 89, 69, 38, 121, 44, 78, 122, | |
| 565 | + 58, 45, 45, 45, 45, 45, 11, 45, 89, 84, | |
| 566 | + 9, 85, 107, 119, 43, 77, 90, 172, 50, 45, | |
| 567 | + 45, 45, 45, 70, 43, 43, 43, 43, 43, 157, | |
| 568 | + 43, 90, 48, 70, 160, 51, 71, 76, 80, 87, | |
| 569 | + 89, 70, 43, 43, 78, 43, 58, 39, 90, 70, | |
| 570 | + 55, 169, 116, 45, 45, 55, 55, 87, 79, 50, | |
| 571 | + 50, 50, 50, 50, 176, 50, 84, 26, 26, 92, | |
| 572 | + 93, 40, 26, 26, 89, 6, 43, 50, 50, 10, | |
| 573 | + 50, 97, 13, 58, 18, 45, 159, 120, 39, 39, | |
| 574 | + 39, 39, 39, 97, 39, 126, 127, 90, 134, 36, | |
| 575 | + 133, 137, 139, 145, 146, 11, 39, 39, 43, 39, | |
| 576 | + 153, 50, 40, 40, 40, 40, 40, 55, 40, 68, | |
| 577 | + 66, 168, 67, 171, 69, 173, 97, 140, 26, 67, | |
| 578 | + 40, 40, 62, 40, 55, 78, 36, 62, 36, 61, | |
| 579 | + 39, 147, 151, 50, 68, 92, 79, 97, 76, 21, | |
| 580 | + 80, 86, 166, 158, 161, 52, 100, 142, 47, 143, | |
| 581 | + 152, 52, 92, 178, 40, 0, 0, 50, 0, 167, | |
| 582 | + 36, 70, 39, 82, 0, 0, 0, 0, 0, 19, | |
| 583 | + 0, 0, 0, 19, 0, 0, 175, 0, 177, 0, | |
| 584 | + 0, 62, 97, 20, 21, 106, 40, 20, 21, 9, | |
| 585 | + 51, 0, 0, 0, 23, 0, 51, 0, 23, 0, | |
| 586 | + 65, 144, 0, 68, 66, 100, 67, 0, 69, 45, | |
| 587 | 587 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, |
| 588 | − 45, 62, 95, 61, 45, 45, 45, 45, 45, 45, | |
| 588 | + 45, 62, 0, 61, 45, 45, 45, 45, 45, 45, | |
| 589 | 589 | 45, 45, 43, 43, 43, 43, 43, 43, 43, 43, |
| 590 | 590 | 43, 43, 43, 43, 0, 55, 0, 43, 43, 43, |
| 591 | 591 | 43, 43, 43, 43, 43, 70, 0, 11, 11, 0, |
| @@ -603,25 +603,25 @@ short luaY_table[] = { 10, · 11 unmodified lines | ||
| 603 | 603 | 41, 0, 0, 37, 0, 37, 37, 37, 0, 0, |
| 604 | 604 | 0, 0, 0, 62, 62, 64, 0, 0, 62, 62, |
| 605 | 605 | 0, 37, 37, 0, 37, 0, 0, 0, 0, 0, |
| 606 | − 38, 41, 38, 38, 38, 98, 0, 98, 98, 98, | |
| 607 | − 63, 98, 98, 98, 98, 98, 98, 0, 38, 38, | |
| 608 | − 98, 38, 0, 66, 0, 37, 64, 29, 29, 64, | |
| 606 | + 38, 41, 38, 38, 38, 100, 0, 100, 100, 100, | |
| 607 | + 63, 100, 100, 100, 100, 100, 100, 0, 38, 38, | |
| 608 | + 100, 38, 0, 66, 0, 37, 64, 29, 29, 64, | |
| 609 | 609 | 29, 0, 29, 41, 0, 0, 57, 58, 59, 60, |
| 610 | 610 | 63, 64, 65, 0, 64, 29, 0, 29, 0, 0, |
| 611 | 611 | 0, 63, 38, 0, 42, 0, 0, 37, 0, 0, |
| 612 | 612 | 0, 0, 0, 0, 66, 29, 29, 66, 29, 63, |
| 613 | 613 | 29, 0, 68, 66, 0, 67, 0, 69, 0, 29, |
| 614 | 614 | 0, 0, 66, 29, 38, 29, 0, 0, 0, 0, |
| 615 | − 62, 0, 61, 0, 0, 42, 0, 11, 42, 11, | |
| 616 | − 11, 11, 0, 11, 11, 11, 11, 11, 0, 0, | |
| 617 | − 0, 0, 11, 42, 42, 0, 42, 29, 0, 18, | |
| 615 | + 62, 0, 61, 0, 0, 42, 3, 97, 42, 0, | |
| 616 | + 4, 91, 5, 97, 0, 6, 7, 8, 0, 0, | |
| 617 | + 0, 9, 0, 42, 42, 97, 42, 29, 91, 18, | |
| 618 | 618 | 0, 18, 18, 18, 70, 18, 18, 18, 18, 18, |
| 619 | − 18, 0, 0, 0, 18, 0, 0, 0, 68, 66, | |
| 620 | − 3, 67, 0, 69, 4, 0, 5, 42, 0, 6, | |
| 621 | − 7, 8, 0, 0, 0, 9, 62, 0, 61, 0, | |
| 619 | + 18, 0, 0, 0, 18, 0, 3, 0, 68, 66, | |
| 620 | + 4, 67, 5, 69, 0, 6, 7, 42, 97, 0, | |
| 621 | + 0, 9, 0, 0, 0, 0, 62, 0, 61, 0, | |
| 622 | 622 | 0, 0, 0, 0, 0, 0, 0, 41, 41, 41, |
| 623 | 623 | 41, 41, 41, 41, 41, 41, 41, 41, 41, 42, |
| 624 | − 0, 0, 41, 41, 41, 41, 41, 41, 41, 41, | |
| 624 | + 97, 0, 41, 41, 41, 41, 41, 41, 41, 41, | |
| 625 | 625 | 70, 37, 37, 37, 37, 37, 37, 37, 37, 37, |
| 626 | 626 | 37, 37, 37, 0, 0, 0, 37, 37, 37, 37, |
| 627 | 627 | 37, 37, 37, 37, 0, 0, 0, 0, 38, 38, |
| @@ -632,7 +632,7 @@ short luaY_table[] = { 10, · 4 unmodified lines | ||
| 632 | 632 | 29, 29, 29, 29, 29, 29, 29, 0, 0, 0, |
| 633 | 633 | 0, 63, 63, 0, 0, 0, 63, 63, 0, 0, |
| 634 | 634 | 0, 0, 66, 0, 66, 66, 66, 0, 66, 66, |
| 635 | − 66, 66, 66, 66, 113, 31, 0, 66, 29, 29, | |
| 635 | + 66, 66, 66, 66, 115, 31, 0, 66, 29, 29, | |
| 636 | 636 | 29, 29, 29, 29, 29, 57, 58, 59, 60, 63, |
| 637 | 637 | 64, 65, 0, 42, 42, 42, 42, 42, 42, 42, |
| 638 | 638 | 42, 42, 42, 42, 42, 34, 0, 0, 42, 42, |
| @@ -642,7 +642,7 @@ short luaY_table[] = { 10, · 3 unmodified lines | ||
| 642 | 642 | 0, 0, 62, 0, 61, 0, 34, 0, 0, 34, |
| 643 | 643 | 32, 57, 58, 59, 60, 63, 64, 65, 0, 0, |
| 644 | 644 | 0, 0, 0, 0, 34, 34, 0, 34, 31, 33, |
| 645 | − 0, 0, 33, 35, 0, 126, 70, 0, 0, 0, | |
| 645 | + 0, 0, 33, 35, 0, 128, 70, 0, 0, 0, | |
| 646 | 646 | 0, 0, 0, 0, 0, 0, 0, 33, 33, 0, |
| 647 | 647 | 33, 32, 0, 0, 32, 36, 0, 0, 34, 0, |
| 648 | 648 | 31, 0, 0, 0, 0, 0, 0, 0, 0, 32, |
| @@ -650,12 +650,12 @@ short luaY_table[] = { 10, · 1 unmodified line | ||
| 650 | 650 | 0, 33, 0, 52, 0, 0, 0, 0, 0, 0, |
| 651 | 651 | 34, 0, 35, 35, 0, 35, 36, 0, 0, 36, |
| 652 | 652 | 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, |
| 653 | − 99, 0, 0, 33, 36, 36, 0, 36, 0, 0, | |
| 653 | + 101, 0, 0, 33, 36, 36, 0, 36, 0, 0, | |
| 654 | 654 | 0, 0, 0, 0, 52, 0, 35, 52, 28, 0, |
| 655 | − 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, | |
| 656 | − 0, 0, 52, 0, 0, 0, 0, 0, 36, 0, | |
| 655 | + 11, 0, 11, 11, 11, 32, 11, 11, 11, 11, | |
| 656 | + 11, 0, 52, 0, 0, 11, 0, 0, 36, 0, | |
| 657 | 657 | 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, |
| 658 | − 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, | |
| 658 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, | |
| 659 | 659 | 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, |
| 660 | 660 | 36, 0, 0, 0, 0, 0, 0, 28, 0, 0, |
| 661 | 661 | 0, 0, 0, 0, 31, 31, 31, 31, 31, 31, |
| @@ -675,66 +675,80 @@ short luaY_table[] = { 10, · 13 unmodified lines | ||
| 675 | 675 | 36, 36, 36, 36, 36, 36, 68, 66, 0, 67, |
| 676 | 676 | 0, 69, 52, 52, 52, 52, 52, 52, 52, 52, |
| 677 | 677 | 52, 52, 52, 52, 62, 0, 61, 52, 52, 52, |
| 678 | − 0, 0, 0, 0, 0, 0, 0, 54, 0, 99, | |
| 679 | − 54, 99, 99, 99, 0, 99, 99, 99, 99, 99, | |
| 680 | − 99, 0, 0, 0, 99, 54, 0, 28, 70, 28, | |
| 678 | + 0, 0, 0, 0, 0, 0, 0, 54, 0, 101, | |
| 679 | + 54, 101, 101, 101, 0, 101, 101, 101, 101, 101, | |
| 680 | + 101, 0, 0, 0, 101, 54, 0, 28, 70, 28, | |
| 681 | 681 | 28, 28, 0, 28, 28, 28, 28, 28, 28, 0, |
| 682 | − 0, 0, 28, 94, 0, 94, 94, 94, 94, 94, | |
| 683 | − 94, 0, 29, 29, 0, 29, 0, 29, 0, 54, | |
| 684 | − 0, 94, 94, 94, 0, 94, 0, 0, 0, 0, | |
| 685 | − 29, 0, 29, 0, 0, 0, 0, 0, 0, 0, | |
| 682 | + 0, 0, 28, 96, 0, 96, 96, 96, 96, 96, | |
| 683 | + 96, 0, 68, 66, 0, 67, 0, 69, 0, 54, | |
| 684 | + 0, 96, 96, 96, 86, 96, 29, 29, 0, 29, | |
| 685 | + 62, 29, 61, 0, 0, 0, 0, 0, 0, 0, | |
| 686 | + 0, 0, 0, 0, 29, 0, 29, 0, 0, 0, | |
| 687 | + 0, 54, 0, 0, 96, 0, 0, 96, 0, 0, | |
| 688 | + 0, 0, 0, 150, 70, 0, 0, 0, 0, 0, | |
| 689 | + 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, | |
| 690 | + 0, 0, 0, 0, 0, 0, 96, 0, 96, 0, | |
| 691 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 686 | 692 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 687 | − 0, 54, 29, 0, 94, 0, 0, 94, 0, 0, | |
| 688 | − 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, | |
| 689 | − 0, 53, 54, 0, 0, 0, 0, 0, 0, 0, | |
| 690 | − 0, 72, 0, 0, 0, 0, 94, 0, 94, 0, | |
| 691 | 693 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 692 | − 88, 0, 0, 0, 0, 0, 0, 0, 94, 95, | |
| 693 | − 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, | |
| 694 | − 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 695 | 694 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 696 | 695 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 697 | − 0, 0, 0, 0, 170, 0, 0, 0, 0, 0, | |
| 698 | − 0, 0, 0, 138, 0, 0, 0, 0, 0, 57, | |
| 699 | − 58, 59, 60, 63, 64, 65, 0, 145, 146, 147, | |
| 700 | − 0, 0, 0, 0, 152, 54, 54, 54, 54, 54, | |
| 696 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 697 | + 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, | |
| 698 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, | |
| 699 | + 58, 59, 60, 63, 64, 65, 0, 0, 0, 0, | |
| 700 | + 0, 0, 0, 0, 0, 54, 54, 54, 54, 54, | |
| 701 | 701 | 54, 54, 54, 54, 54, 54, 54, 0, 0, 0, |
| 702 | − 54, 54, 54, 0, 0, 0, 0, 0, 166, 0, | |
| 702 | + 54, 54, 54, 0, 0, 0, 0, 0, 0, 0, | |
| 703 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 704 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 705 | + 0, 0, 0, 0, 0, 0, 0, 29, 96, 96, | |
| 706 | + 96, 96, 96, 96, 96, 57, 58, 59, 60, 63, | |
| 707 | + 64, 65, 0, 0, 0, 0, 53, 54, 0, 29, | |
| 708 | + 29, 29, 29, 29, 29, 29, 72, 0, 0, 0, | |
| 703 | 709 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 710 | + 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, | |
| 711 | + 0, 0, 0, 94, 95, 96, 97, 98, 99, 100, | |
| 712 | + 101, 102, 103, 104, 105, 112, 0, 0, 0, 0, | |
| 704 | 713 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 705 | − 0, 0, 0, 0, 0, 0, 0, 0, 94, 94, | |
| 706 | − 94, 94, 94, 94, 94, 29, 29, 29, 29, 29, | |
| 707 | − 29, 29, | |
| 714 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 715 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 716 | + 0, 132, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 717 | + 141, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 718 | + 0, 0, 0, 0, 148, 149, 0, 0, 0, 0, | |
| 719 | + 0, 155, 0, 156, 0, 0, 0, 0, 0, 0, | |
| 720 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 721 | + 0, 0, 0, 0, 0, 0, 0, 170, | |
| 708 | 722 | }; |
| 709 | −short luaY_check[] = { 2, | |
| 710 | − 0, 40, 110, 40, 34, 40, 45, 41, 59, 2, | |
| 711 | − 45, 42, 43, 2, 45, 8, 47, 44, 59, 8, | |
| 712 | − 44, 44, 44, 0, 46, 57, 58, 44, 46, 91, | |
| 713 | − 261, 262, 59, 44, 274, 266, 267, 61, 61, 61, | |
| 714 | − 40, 41, 42, 43, 44, 45, 0, 47, 59, 59, | |
| 715 | − 274, 44, 42, 6, 162, 44, 40, 47, 0, 59, | |
| 716 | − 60, 59, 62, 94, 41, 42, 43, 44, 45, 91, | |
| 717 | − 47, 24, 123, 91, 125, 137, 271, 261, 262, 274, | |
| 718 | − 142, 113, 59, 60, 125, 62, 123, 0, 44, 123, | |
| 719 | − 43, 40, 45, 93, 94, 127, 158, 123, 125, 41, | |
| 720 | − 42, 43, 44, 45, 94, 47, 138, 274, 125, 171, | |
| 721 | − 140, 0, 115, 123, 125, 125, 93, 59, 60, 274, | |
| 722 | − 62, 153, 115, 123, 77, 125, 115, 43, 41, 42, | |
| 723 | − 43, 44, 45, 94, 47, 266, 42, 43, 170, 45, | |
| 724 | − 172, 47, 41, 41, 274, 0, 59, 60, 125, 62, | |
| 725 | − 274, 93, 41, 42, 43, 44, 45, 61, 47, 42, | |
| 726 | − 43, 77, 45, 116, 47, 125, 44, 44, 41, 40, | |
| 727 | − 59, 60, 0, 62, 44, 46, 274, 60, 59, 62, | |
| 728 | − 93, 267, 46, 125, 267, 46, 267, 58, 94, 40, | |
| 729 | − 0, 123, 41, 44, 58, 46, 0, 58, 125, 259, | |
| 730 | − 41, 125, 125, 263, 93, 265, 267, 58, 268, 269, | |
| 731 | − 61, 94, 125, 125, 274, 45, 150, 143, 115, 258, | |
| 732 | − 91, 115, 173, 258, 12, 132, -1, 91, -1, -1, | |
| 733 | − 91, 59, -1, 272, 273, 274, 125, 272, 273, 274, | |
| 734 | − 91, -1, -1, -1, 283, -1, -1, -1, 283, -1, | |
| 735 | − 281, -1, -1, 42, 43, 59, 45, -1, 47, 259, | |
| 723 | +short luaY_check[] = { 91, | |
| 724 | + 0, 40, 111, 40, 2, 40, 45, 2, 41, 2, | |
| 725 | + 45, 42, 43, 8, 45, 8, 47, 34, 59, 43, | |
| 726 | + 91, 42, 43, 0, 45, 44, 47, 261, 262, 42, | |
| 727 | + 46, 59, 59, 44, 47, 274, 271, 44, 44, 274, | |
| 728 | + 40, 41, 42, 43, 44, 45, 0, 47, 59, 44, | |
| 729 | + 274, 44, 91, 77, 61, 61, 44, 166, 0, 59, | |
| 730 | + 60, 40, 62, 94, 41, 42, 43, 44, 45, 140, | |
| 731 | + 47, 59, 59, 94, 145, 91, 123, 44, 40, 274, | |
| 732 | + 274, 94, 59, 60, 125, 62, 123, 0, 41, 94, | |
| 733 | + 123, 162, 266, 93, 94, 123, 123, 125, 125, 41, | |
| 734 | + 42, 43, 44, 45, 175, 47, 125, 261, 262, 57, | |
| 735 | + 58, 0, 266, 267, 125, 40, 93, 59, 60, 117, | |
| 736 | + 62, 46, 117, 123, 117, 125, 143, 274, 41, 42, | |
| 737 | + 43, 44, 45, 58, 47, 274, 41, 125, 44, 6, | |
| 738 | + 125, 44, 61, 41, 44, 0, 59, 60, 125, 62, | |
| 739 | + 59, 93, 41, 42, 43, 44, 45, 24, 47, 42, | |
| 740 | + 43, 267, 45, 267, 47, 267, 91, 115, 0, 41, | |
| 741 | + 59, 60, 0, 62, 123, 125, 43, 60, 45, 62, | |
| 742 | + 93, 129, 274, 125, 41, 44, 125, 46, 125, 267, | |
| 743 | + 125, 45, 153, 141, 146, 46, 0, 117, 12, 117, | |
| 744 | + 134, 46, 61, 177, 93, -1, -1, 58, -1, 157, | |
| 745 | + 77, 94, 125, 58, -1, -1, -1, -1, -1, 258, | |
| 746 | + -1, -1, -1, 258, -1, -1, 174, -1, 176, -1, | |
| 747 | + -1, 59, 91, 272, 273, 274, 125, 272, 273, 274, | |
| 748 | + 91, -1, -1, -1, 283, -1, 91, -1, 283, -1, | |
| 749 | + 281, 118, -1, 42, 43, 59, 45, -1, 47, 259, | |
| 736 | 750 | 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, |
| 737 | − 270, 60, 123, 62, 274, 275, 276, 277, 278, 279, | |
| 751 | + 270, 60, -1, 62, 274, 275, 276, 277, 278, 279, | |
| 738 | 752 | 280, 281, 259, 260, 261, 262, 263, 264, 265, 266, |
| 739 | 753 | 267, 268, 269, 270, -1, 123, -1, 274, 275, 276, |
| 740 | 754 | 277, 278, 279, 280, 281, 94, -1, 261, 262, -1, |
| @@ -761,16 +775,16 @@ short luaY_check[] = { 2, · 20 unmodified lines | ||
| 761 | 775 | -1, -1, -1, -1, 41, 42, 43, 44, 45, 59, |
| 762 | 776 | 47, -1, 42, 43, -1, 45, -1, 47, -1, 94, |
| 763 | 777 | -1, -1, 59, 60, 125, 62, -1, -1, -1, -1, |
| 764 | − 60, -1, 62, -1, -1, 41, -1, 259, 44, 261, | |
| 765 | − 262, 263, -1, 265, 266, 267, 268, 269, -1, -1, | |
| 766 | − -1, -1, 274, 59, 60, -1, 62, 94, -1, 259, | |
| 778 | + 60, -1, 62, -1, -1, 41, 259, 40, 44, -1, | |
| 779 | + 263, 44, 265, 46, -1, 268, 269, 270, -1, -1, | |
| 780 | + -1, 274, -1, 59, 60, 58, 62, 94, 61, 259, | |
| 767 | 781 | -1, 261, 262, 263, 94, 265, 266, 267, 268, 269, |
| 768 | − 270, -1, -1, -1, 274, -1, -1, -1, 42, 43, | |
| 769 | − 259, 45, -1, 47, 263, -1, 265, 93, -1, 268, | |
| 770 | − 269, 270, -1, -1, -1, 274, 60, -1, 62, -1, | |
| 782 | + 270, -1, -1, -1, 274, -1, 259, -1, 42, 43, | |
| 783 | + 263, 45, 265, 47, -1, 268, 269, 93, 91, -1, | |
| 784 | + -1, 274, -1, -1, -1, -1, 60, -1, 62, -1, | |
| 771 | 785 | -1, -1, -1, -1, -1, -1, -1, 259, 260, 261, |
| 772 | 786 | 262, 263, 264, 265, 266, 267, 268, 269, 270, 125, |
| 773 | − -1, -1, 274, 275, 276, 277, 278, 279, 280, 281, | |
| 787 | + 123, -1, 274, 275, 276, 277, 278, 279, 280, 281, | |
| 774 | 788 | 94, 259, 260, 261, 262, 263, 264, 265, 266, 267, |
| 775 | 789 | 268, 269, 270, -1, -1, -1, 274, 275, 276, 277, |
| 776 | 790 | 278, 279, 280, 281, -1, -1, -1, -1, 259, 260, |
| @@ -801,8 +815,8 @@ short luaY_check[] = { 2, · 24 unmodified lines | ||
| 801 | 815 | -1, -1, -1, 93, -1, -1, -1, -1, -1, -1, |
| 802 | 816 | 0, -1, -1, 125, 59, 60, -1, 62, -1, -1, |
| 803 | 817 | -1, -1, -1, -1, 41, -1, 93, 44, 0, -1, |
| 804 | − -1, -1, -1, -1, -1, 125, -1, -1, -1, -1, | |
| 805 | − -1, -1, 59, -1, -1, -1, -1, -1, 93, -1, | |
| 818 | + 259, -1, 261, 262, 263, 125, 265, 266, 267, 268, | |
| 819 | + 269, -1, 59, -1, -1, 274, -1, -1, 93, -1, | |
| 806 | 820 | -1, -1, -1, -1, -1, -1, -1, -1, 125, -1, |
| 807 | 821 | -1, -1, -1, -1, -1, -1, -1, -1, -1, 59, |
| 808 | 822 | -1, -1, -1, -1, -1, -1, 93, -1, -1, -1, |
| @@ -830,30 +844,44 @@ short luaY_check[] = { 2, · 21 unmodified lines | ||
| 830 | 844 | 262, 263, -1, 265, 266, 267, 268, 269, 270, -1, |
| 831 | 845 | -1, -1, 274, 40, -1, 42, 43, 44, 45, 46, |
| 832 | 846 | 47, -1, 42, 43, -1, 45, -1, 47, -1, 93, |
| 833 | − -1, 58, 59, 60, -1, 62, -1, -1, -1, -1, | |
| 834 | − 60, -1, 62, -1, -1, -1, -1, -1, -1, -1, | |
| 847 | + -1, 58, 59, 60, 61, 62, 42, 43, -1, 45, | |
| 848 | + 60, 47, 62, -1, -1, -1, -1, -1, -1, -1, | |
| 849 | + -1, -1, -1, -1, 60, -1, 62, -1, -1, -1, | |
| 850 | + -1, 125, -1, -1, 91, -1, -1, 94, -1, -1, | |
| 851 | + -1, -1, -1, 93, 94, -1, -1, -1, -1, -1, | |
| 852 | + -1, -1, -1, -1, -1, -1, -1, -1, 94, -1, | |
| 853 | + -1, -1, -1, -1, -1, -1, 123, -1, 125, -1, | |
| 854 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 855 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 835 | 856 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 836 | − -1, 125, 3, -1, 91, -1, -1, 94, -1, -1, | |
| 837 | − -1, -1, -1, -1, 94, -1, -1, -1, -1, -1, | |
| 838 | − -1, 22, 23, -1, -1, -1, -1, -1, -1, -1, | |
| 839 | − -1, 32, -1, -1, -1, -1, 123, -1, 125, -1, | |
| 840 | 857 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 841 | − 51, -1, -1, -1, -1, -1, -1, -1, 59, 60, | |
| 842 | − 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, | |
| 843 | − 71, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 844 | 858 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 845 | 859 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 846 | 860 | -1, -1, -1, -1, 260, -1, -1, -1, -1, -1, |
| 847 | − -1, -1, -1, 114, -1, -1, -1, -1, -1, 275, | |
| 848 | − 276, 277, 278, 279, 280, 281, -1, 128, 129, 130, | |
| 849 | − -1, -1, -1, -1, 135, 259, 260, 261, 262, 263, | |
| 861 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, 275, | |
| 862 | + 276, 277, 278, 279, 280, 281, -1, -1, -1, -1, | |
| 863 | + -1, -1, -1, -1, -1, 259, 260, 261, 262, 263, | |
| 850 | 864 | 264, 265, 266, 267, 268, 269, 270, -1, -1, -1, |
| 851 | − 274, 275, 276, -1, -1, -1, -1, -1, 159, -1, | |
| 865 | + 274, 275, 276, -1, -1, -1, -1, -1, -1, -1, | |
| 852 | 866 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 853 | 867 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 854 | − -1, -1, -1, -1, -1, -1, -1, -1, 275, 276, | |
| 868 | + -1, -1, -1, -1, -1, -1, -1, 3, 275, 276, | |
| 855 | 869 | 277, 278, 279, 280, 281, 275, 276, 277, 278, 279, |
| 856 | − 280, 281, | |
| 870 | + 280, 281, -1, -1, -1, -1, 22, 23, -1, 275, | |
| 871 | + 276, 277, 278, 279, 280, 281, 32, -1, -1, -1, | |
| 872 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 873 | + -1, -1, -1, -1, -1, 51, -1, -1, -1, -1, | |
| 874 | + -1, -1, -1, 59, 60, 61, 62, 63, 64, 65, | |
| 875 | + 66, 67, 68, 69, 70, 71, -1, -1, -1, -1, | |
| 876 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 877 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 878 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 879 | + -1, 107, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 880 | + 116, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 881 | + -1, -1, -1, -1, 130, 131, -1, -1, -1, -1, | |
| 882 | + -1, 137, -1, 139, -1, -1, -1, -1, -1, -1, | |
| 883 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 884 | + -1, -1, -1, -1, -1, -1, -1, 163, | |
| 857 | 885 | }; |
| 858 | 886 | #define YYFINAL 1 |
| 859 | 887 | #ifndef YYDEBUG |
| @@ -958,7 +986,9 @@ char *luaY_rule[] = { · 98 unmodified lines | ||
| 958 | 986 | "ffieldlist : ffieldlist1 lastcomma", |
| 959 | 987 | "ffieldlist1 : ffield", |
| 960 | 988 | "ffieldlist1 : ffieldlist1 ',' ffield", |
| 961 | −"ffield : NAME '=' expr1", | |
| 989 | +"ffield : ffieldkey '=' expr1", | |
| 990 | +"ffieldkey : '[' expr1 ']'", | |
| 991 | +"ffieldkey : NAME", | |
| 962 | 992 | "lfieldlist :", |
| 963 | 993 | "lfieldlist : lfieldlist1 lastcomma", |
| 964 | 994 | "lfieldlist1 : expr1", |
| @@ -1139,7 +1169,7 @@ luaY_reduce: · 174 unmodified lines | ||
| 1139 | 1169 | switch (luaY_n) |
| 1140 | 1170 | { |
| 1141 | 1171 | case 5: |
| 1142 | −#line 470 "lua.stx" | |
| 1172 | +#line 468 "lua.stx" | |
| 1143 | 1173 | { |
| 1144 | 1174 | code_byte(PUSHFUNCTION); |
| 1145 | 1175 | code_code(luaY_vsp[0].pFunc); |
| @@ -1147,28 +1177,26 @@ case 5: · 1 unmodified line | ||
| 1147 | 1177 | } |
| 1148 | 1178 | break; |
| 1149 | 1179 | case 6: |
| 1150 | −#line 477 "lua.stx" | |
| 1180 | +#line 475 "lua.stx" | |
| 1151 | 1181 | { luaY_val.vLong =luaY_vsp[0].vLong; init_func(); } |
| 1152 | 1182 | break; |
| 1153 | 1183 | case 7: |
| 1154 | −#line 479 "lua.stx" | |
| 1184 | +#line 477 "lua.stx" | |
| 1155 | 1185 | { |
| 1156 | − code_byte(PUSHSTRING); | |
| 1157 | − code_word(luaI_findconstant(luaY_vsp[0].pTStr)); | |
| 1186 | + code_constant(luaY_vsp[0].pTStr); | |
| 1158 | 1187 | luaY_val.vLong = 0; /* indexed variable */ |
| 1159 | 1188 | init_func(); |
| 1160 | 1189 | add_localvar(luaI_createfixedstring("self")); |
| 1161 | 1190 | } |
| 1162 | 1191 | break; |
| 1163 | 1192 | case 8: |
| 1164 | −#line 489 "lua.stx" | |
| 1193 | +#line 486 "lua.stx" | |
| 1165 | 1194 | { |
| 1166 | 1195 | codereturn(); |
| 1167 | 1196 | luaY_val.pFunc = new(TFunc); |
| 1168 | 1197 | luaI_initTFunc(luaY_val.pFunc); |
| 1169 | 1198 | luaY_val.pFunc->size = pc; |
| 1170 | 1199 | luaY_val.pFunc->code = newvector(pc, Byte); |
| 1171 | − luaY_val.pFunc->fileName = lua_parsedfile; | |
| 1172 | 1200 | luaY_val.pFunc->lineDefined = luaY_vsp[-3].vInt; |
| 1173 | 1201 | memcpy(luaY_val.pFunc->code, basepc, pc*sizeof(Byte)); |
| 1174 | 1202 | if (lua_debug) |
| @@ -1182,15 +1210,15 @@ case 8: · 7 unmodified lines | ||
| 1182 | 1210 | } |
| 1183 | 1211 | break; |
| 1184 | 1212 | case 13: |
| 1185 | −#line 516 "lua.stx" | |
| 1213 | +#line 512 "lua.stx" | |
| 1186 | 1214 | { codeIf(luaY_vsp[-4].vLong, luaY_vsp[-2].vLong); } |
| 1187 | 1215 | break; |
| 1188 | 1216 | case 14: |
| 1189 | −#line 518 "lua.stx" | |
| 1217 | +#line 514 "lua.stx" | |
| 1190 | 1218 | {luaY_val.vLong=pc;} |
| 1191 | 1219 | break; |
| 1192 | 1220 | case 15: |
| 1193 | −#line 519 "lua.stx" | |
| 1221 | +#line 515 "lua.stx" | |
| 1194 | 1222 | { |
| 1195 | 1223 | basepc[luaY_vsp[-3].vLong] = IFFJMP; |
| 1196 | 1224 | code_word_at(basepc+luaY_vsp[-3].vLong+1, pc - (luaY_vsp[-3].vLong + sizeof(Word)+1)); |
| @@ -1199,18 +1227,18 @@ case 15: · 2 unmodified lines | ||
| 1199 | 1227 | } |
| 1200 | 1228 | break; |
| 1201 | 1229 | case 16: |
| 1202 | −#line 526 "lua.stx" | |
| 1230 | +#line 522 "lua.stx" | |
| 1203 | 1231 | {luaY_val.vLong=pc;} |
| 1204 | 1232 | break; |
| 1205 | 1233 | case 17: |
| 1206 | −#line 527 "lua.stx" | |
| 1234 | +#line 523 "lua.stx" | |
| 1207 | 1235 | { |
| 1208 | 1236 | basepc[luaY_vsp[0].vLong] = IFFUPJMP; |
| 1209 | 1237 | code_word_at(basepc+luaY_vsp[0].vLong+1, pc - (luaY_vsp[-4].vLong)); |
| 1210 | 1238 | } |
| 1211 | 1239 | break; |
| 1212 | 1240 | case 18: |
| 1213 | −#line 533 "lua.stx" | |
| 1241 | +#line 529 "lua.stx" | |
| 1214 | 1242 | { |
| 1215 | 1243 | { |
| 1216 | 1244 | int i; |
| @@ -1222,22 +1250,26 @@ case 18: · 5 unmodified lines | ||
| 1222 | 1250 | } |
| 1223 | 1251 | } |
| 1224 | 1252 | break; |
| 1253 | +case 19: | |
| 1254 | +#line 539 "lua.stx" | |
| 1255 | +{;} | |
| 1256 | +break; | |
| 1225 | 1257 | case 20: |
| 1226 | −#line 545 "lua.stx" | |
| 1258 | +#line 541 "lua.stx" | |
| 1227 | 1259 | { nlocalvar += luaY_vsp[-1].vInt; |
| 1228 | 1260 | adjust_mult_assign(luaY_vsp[-1].vInt, luaY_vsp[0].vInt, 0); |
| 1229 | 1261 | } |
| 1230 | 1262 | break; |
| 1231 | 1263 | case 23: |
| 1232 | −#line 553 "lua.stx" | |
| 1264 | +#line 549 "lua.stx" | |
| 1233 | 1265 | { codeIf(luaY_vsp[-3].vLong, luaY_vsp[-1].vLong); } |
| 1234 | 1266 | break; |
| 1235 | 1267 | case 24: |
| 1236 | −#line 556 "lua.stx" | |
| 1268 | +#line 552 "lua.stx" | |
| 1237 | 1269 | {luaY_val.vInt = nlocalvar;} |
| 1238 | 1270 | break; |
| 1239 | 1271 | case 25: |
| 1240 | −#line 557 "lua.stx" | |
| 1272 | +#line 553 "lua.stx" | |
| 1241 | 1273 | { |
| 1242 | 1274 | if (nlocalvar != luaY_vsp[-2].vInt) |
| 1243 | 1275 | { |
| @@ -1251,14 +1283,14 @@ case 25: · 7 unmodified lines | ||
| 1251 | 1283 | } |
| 1252 | 1284 | break; |
| 1253 | 1285 | case 27: |
| 1254 | −#line 572 "lua.stx" | |
| 1286 | +#line 568 "lua.stx" | |
| 1255 | 1287 | { |
| 1256 | 1288 | adjust_functioncall(luaY_vsp[-1].vLong, MULT_RET); |
| 1257 | 1289 | codereturn(); |
| 1258 | 1290 | } |
| 1259 | 1291 | break; |
| 1260 | 1292 | case 28: |
| 1261 | −#line 579 "lua.stx" | |
| 1293 | +#line 575 "lua.stx" | |
| 1262 | 1294 | { |
| 1263 | 1295 | luaY_val.vLong = pc; |
| 1264 | 1296 | code_byte(0); /* open space */ |
| @@ -1266,103 +1298,102 @@ case 28: · 1 unmodified line | ||
| 1266 | 1298 | } |
| 1267 | 1299 | break; |
| 1268 | 1300 | case 29: |
| 1269 | −#line 586 "lua.stx" | |
| 1301 | +#line 582 "lua.stx" | |
| 1270 | 1302 | { adjust_functioncall(luaY_vsp[0].vLong, 1); } |
| 1271 | 1303 | break; |
| 1272 | 1304 | case 30: |
| 1273 | −#line 589 "lua.stx" | |
| 1305 | +#line 585 "lua.stx" | |
| 1274 | 1306 | { luaY_val.vLong = luaY_vsp[-1].vLong; } |
| 1275 | 1307 | break; |
| 1276 | 1308 | case 31: |
| 1277 | −#line 590 "lua.stx" | |
| 1309 | +#line 586 "lua.stx" | |
| 1278 | 1310 | { code_byte(EQOP); luaY_val.vLong = 0; } |
| 1279 | 1311 | break; |
| 1280 | 1312 | case 32: |
| 1281 | −#line 591 "lua.stx" | |
| 1313 | +#line 587 "lua.stx" | |
| 1282 | 1314 | { code_byte(LTOP); luaY_val.vLong = 0; } |
| 1283 | 1315 | break; |
| 1284 | 1316 | case 33: |
| 1285 | −#line 592 "lua.stx" | |
| 1317 | +#line 588 "lua.stx" | |
| 1286 | 1318 | { code_byte(GTOP); luaY_val.vLong = 0; } |
| 1287 | 1319 | break; |
| 1288 | 1320 | case 34: |
| 1289 | −#line 593 "lua.stx" | |
| 1321 | +#line 589 "lua.stx" | |
| 1290 | 1322 | { code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; } |
| 1291 | 1323 | break; |
| 1292 | 1324 | case 35: |
| 1293 | −#line 594 "lua.stx" | |
| 1325 | +#line 590 "lua.stx" | |
| 1294 | 1326 | { code_byte(LEOP); luaY_val.vLong = 0; } |
| 1295 | 1327 | break; |
| 1296 | 1328 | case 36: |
| 1297 | −#line 595 "lua.stx" | |
| 1329 | +#line 591 "lua.stx" | |
| 1298 | 1330 | { code_byte(GEOP); luaY_val.vLong = 0; } |
| 1299 | 1331 | break; |
| 1300 | 1332 | case 37: |
| 1301 | −#line 596 "lua.stx" | |
| 1333 | +#line 592 "lua.stx" | |
| 1302 | 1334 | { code_byte(ADDOP); luaY_val.vLong = 0; } |
| 1303 | 1335 | break; |
| 1304 | 1336 | case 38: |
| 1305 | −#line 597 "lua.stx" | |
| 1337 | +#line 593 "lua.stx" | |
| 1306 | 1338 | { code_byte(SUBOP); luaY_val.vLong = 0; } |
| 1307 | 1339 | break; |
| 1308 | 1340 | case 39: |
| 1309 | −#line 598 "lua.stx" | |
| 1341 | +#line 594 "lua.stx" | |
| 1310 | 1342 | { code_byte(MULTOP); luaY_val.vLong = 0; } |
| 1311 | 1343 | break; |
| 1312 | 1344 | case 40: |
| 1313 | −#line 599 "lua.stx" | |
| 1345 | +#line 595 "lua.stx" | |
| 1314 | 1346 | { code_byte(DIVOP); luaY_val.vLong = 0; } |
| 1315 | 1347 | break; |
| 1316 | 1348 | case 41: |
| 1317 | −#line 600 "lua.stx" | |
| 1349 | +#line 596 "lua.stx" | |
| 1318 | 1350 | { code_byte(POWOP); luaY_val.vLong = 0; } |
| 1319 | 1351 | break; |
| 1320 | 1352 | case 42: |
| 1321 | −#line 601 "lua.stx" | |
| 1353 | +#line 597 "lua.stx" | |
| 1322 | 1354 | { code_byte(CONCOP); luaY_val.vLong = 0; } |
| 1323 | 1355 | break; |
| 1324 | 1356 | case 43: |
| 1325 | −#line 602 "lua.stx" | |
| 1357 | +#line 598 "lua.stx" | |
| 1326 | 1358 | { code_byte(MINUSOP); luaY_val.vLong = 0;} |
| 1327 | 1359 | break; |
| 1328 | 1360 | case 44: |
| 1329 | −#line 603 "lua.stx" | |
| 1361 | +#line 599 "lua.stx" | |
| 1330 | 1362 | { luaY_val.vLong = 0; } |
| 1331 | 1363 | break; |
| 1332 | 1364 | case 45: |
| 1333 | −#line 604 "lua.stx" | |
| 1365 | +#line 600 "lua.stx" | |
| 1334 | 1366 | { luaY_val.vLong = 0;} |
| 1335 | 1367 | break; |
| 1336 | 1368 | case 46: |
| 1337 | −#line 605 "lua.stx" | |
| 1369 | +#line 601 "lua.stx" | |
| 1338 | 1370 | { code_number(luaY_vsp[0].vFloat); luaY_val.vLong = 0; } |
| 1339 | 1371 | break; |
| 1340 | 1372 | case 47: |
| 1341 | −#line 607 "lua.stx" | |
| 1373 | +#line 603 "lua.stx" | |
| 1342 | 1374 | { |
| 1343 | − code_byte(PUSHSTRING); | |
| 1344 | − code_word(luaY_vsp[0].vWord); | |
| 1345 | − luaY_val.vLong = 0; | |
| 1375 | + code_string(luaY_vsp[0].vWord); | |
| 1376 | + luaY_val.vLong = 0; | |
| 1346 | 1377 | } |
| 1347 | 1378 | break; |
| 1348 | 1379 | case 48: |
| 1349 | −#line 612 "lua.stx" | |
| 1380 | +#line 607 "lua.stx" | |
| 1350 | 1381 | {code_byte(PUSHNIL); luaY_val.vLong = 0; } |
| 1351 | 1382 | break; |
| 1352 | 1383 | case 49: |
| 1353 | −#line 613 "lua.stx" | |
| 1384 | +#line 608 "lua.stx" | |
| 1354 | 1385 | { luaY_val.vLong = luaY_vsp[0].vLong; } |
| 1355 | 1386 | break; |
| 1356 | 1387 | case 50: |
| 1357 | −#line 614 "lua.stx" | |
| 1388 | +#line 609 "lua.stx" | |
| 1358 | 1389 | { code_byte(NOTOP); luaY_val.vLong = 0;} |
| 1359 | 1390 | break; |
| 1360 | 1391 | case 51: |
| 1361 | −#line 615 "lua.stx" | |
| 1392 | +#line 610 "lua.stx" | |
| 1362 | 1393 | {code_byte(POP); } |
| 1363 | 1394 | break; |
| 1364 | 1395 | case 52: |
| 1365 | −#line 616 "lua.stx" | |
| 1396 | +#line 611 "lua.stx" | |
| 1366 | 1397 | { |
| 1367 | 1398 | basepc[luaY_vsp[-2].vLong] = ONFJMP; |
| 1368 | 1399 | code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1)); |
| @@ -1370,11 +1401,11 @@ case 52: · 1 unmodified line | ||
| 1370 | 1401 | } |
| 1371 | 1402 | break; |
| 1372 | 1403 | case 53: |
| 1373 | −#line 621 "lua.stx" | |
| 1404 | +#line 616 "lua.stx" | |
| 1374 | 1405 | {code_byte(POP); } |
| 1375 | 1406 | break; |
| 1376 | 1407 | case 54: |
| 1377 | −#line 622 "lua.stx" | |
| 1408 | +#line 617 "lua.stx" | |
| 1378 | 1409 | { |
| 1379 | 1410 | basepc[luaY_vsp[-2].vLong] = ONTJMP; |
| 1380 | 1411 | code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1)); |
| @@ -1382,20 +1413,20 @@ case 54: · 1 unmodified line | ||
| 1382 | 1413 | } |
| 1383 | 1414 | break; |
| 1384 | 1415 | case 55: |
| 1385 | −#line 630 "lua.stx" | |
| 1416 | +#line 625 "lua.stx" | |
| 1386 | 1417 | { |
| 1387 | 1418 | code_byte(CREATEARRAY); |
| 1388 | 1419 | luaY_val.vLong = pc; code_word(0); |
| 1389 | 1420 | } |
| 1390 | 1421 | break; |
| 1391 | 1422 | case 56: |
| 1392 | −#line 635 "lua.stx" | |
| 1423 | +#line 630 "lua.stx" | |
| 1393 | 1424 | { |
| 1394 | 1425 | code_word_at(basepc+luaY_vsp[-3].vLong, luaY_vsp[-1].vInt); |
| 1395 | 1426 | } |
| 1396 | 1427 | break; |
| 1397 | 1428 | case 57: |
| 1398 | −#line 641 "lua.stx" | |
| 1429 | +#line 636 "lua.stx" | |
| 1399 | 1430 | { |
| 1400 | 1431 | code_byte(CALLFUNC); |
| 1401 | 1432 | code_byte(luaY_vsp[-1].vInt+luaY_vsp[0].vInt); |
| @@ -1404,11 +1435,11 @@ case 57: · 2 unmodified lines | ||
| 1404 | 1435 | } |
| 1405 | 1436 | break; |
| 1406 | 1437 | case 58: |
| 1407 | −#line 649 "lua.stx" | |
| 1438 | +#line 644 "lua.stx" | |
| 1408 | 1439 | { luaY_val.vInt = 0; } |
| 1409 | 1440 | break; |
| 1410 | 1441 | case 59: |
| 1411 | −#line 651 "lua.stx" | |
| 1442 | +#line 646 "lua.stx" | |
| 1412 | 1443 | { |
| 1413 | 1444 | code_byte(PUSHSELF); |
| 1414 | 1445 | code_word(luaI_findconstant(luaY_vsp[0].pTStr)); |
| @@ -1416,31 +1447,31 @@ case 59: · 1 unmodified line | ||
| 1416 | 1447 | } |
| 1417 | 1448 | break; |
| 1418 | 1449 | case 60: |
| 1419 | −#line 659 "lua.stx" | |
| 1450 | +#line 654 "lua.stx" | |
| 1420 | 1451 | { luaY_val.vInt = adjust_functioncall(luaY_vsp[-1].vLong, 1); } |
| 1421 | 1452 | break; |
| 1422 | 1453 | case 61: |
| 1423 | −#line 660 "lua.stx" | |
| 1454 | +#line 655 "lua.stx" | |
| 1424 | 1455 | { luaY_val.vInt = 1; } |
| 1425 | 1456 | break; |
| 1426 | 1457 | case 62: |
| 1427 | −#line 663 "lua.stx" | |
| 1458 | +#line 658 "lua.stx" | |
| 1428 | 1459 | { luaY_val.vLong = 0; } |
| 1429 | 1460 | break; |
| 1430 | 1461 | case 63: |
| 1431 | −#line 664 "lua.stx" | |
| 1462 | +#line 659 "lua.stx" | |
| 1432 | 1463 | { luaY_val.vLong = luaY_vsp[0].vLong; } |
| 1433 | 1464 | break; |
| 1434 | 1465 | case 64: |
| 1435 | −#line 667 "lua.stx" | |
| 1466 | +#line 662 "lua.stx" | |
| 1436 | 1467 | { if (luaY_vsp[0].vLong != 0) luaY_val.vLong = luaY_vsp[0].vLong; else luaY_val.vLong = -1; } |
| 1437 | 1468 | break; |
| 1438 | 1469 | case 65: |
| 1439 | −#line 668 "lua.stx" | |
| 1470 | +#line 663 "lua.stx" | |
| 1440 | 1471 | { luaY_val.vLong = adjust_functioncall(luaY_vsp[-1].vLong, 1); } |
| 1441 | 1472 | break; |
| 1442 | 1473 | case 66: |
| 1443 | −#line 669 "lua.stx" | |
| 1474 | +#line 664 "lua.stx" | |
| 1444 | 1475 | { |
| 1445 | 1476 | if (luaY_vsp[0].vLong == 0) luaY_val.vLong = -(luaY_vsp[-1].vLong + 1); /* -length */ |
| 1446 | 1477 | else |
| @@ -1451,19 +1482,19 @@ case 66: · 4 unmodified lines | ||
| 1451 | 1482 | } |
| 1452 | 1483 | break; |
| 1453 | 1484 | case 67: |
| 1454 | −#line 679 "lua.stx" | |
| 1485 | +#line 674 "lua.stx" | |
| 1455 | 1486 | { luaY_val.vInt = close_parlist(0); } |
| 1456 | 1487 | break; |
| 1457 | 1488 | case 68: |
| 1458 | −#line 680 "lua.stx" | |
| 1489 | +#line 675 "lua.stx" | |
| 1459 | 1490 | { luaY_val.vInt = close_parlist(luaY_vsp[0].vInt); } |
| 1460 | 1491 | break; |
| 1461 | 1492 | case 69: |
| 1462 | −#line 683 "lua.stx" | |
| 1493 | +#line 678 "lua.stx" | |
| 1463 | 1494 | { luaY_val.vInt = luaY_vsp[0].vInt; } |
| 1464 | 1495 | break; |
| 1465 | 1496 | case 70: |
| 1466 | −#line 685 "lua.stx" | |
| 1497 | +#line 680 "lua.stx" | |
| 1467 | 1498 | { |
| 1468 | 1499 | if (luaY_vsp[-2].vInt) |
| 1469 | 1500 | lua_error("invalid parameter list"); |
| @@ -1471,113 +1502,110 @@ case 70: · 1 unmodified line | ||
| 1471 | 1502 | } |
| 1472 | 1503 | break; |
| 1473 | 1504 | case 71: |
| 1474 | −#line 692 "lua.stx" | |
| 1505 | +#line 687 "lua.stx" | |
| 1475 | 1506 | { add_localvar(luaY_vsp[0].pTStr); luaY_val.vInt = 0; } |
| 1476 | 1507 | break; |
| 1477 | 1508 | case 72: |
| 1478 | −#line 693 "lua.stx" | |
| 1509 | +#line 688 "lua.stx" | |
| 1479 | 1510 | { luaY_val.vInt = 1; } |
| 1480 | 1511 | break; |
| 1481 | 1512 | case 73: |
| 1482 | −#line 697 "lua.stx" | |
| 1513 | +#line 692 "lua.stx" | |
| 1483 | 1514 | { flush_list(luaY_vsp[0].vInt/FIELDS_PER_FLUSH, luaY_vsp[0].vInt%FIELDS_PER_FLUSH); } |
| 1484 | 1515 | break; |
| 1485 | 1516 | case 74: |
| 1486 | −#line 699 "lua.stx" | |
| 1517 | +#line 694 "lua.stx" | |
| 1487 | 1518 | { luaY_val.vInt = luaY_vsp[-2].vInt+luaY_vsp[0].vInt; } |
| 1488 | 1519 | break; |
| 1489 | 1520 | case 75: |
| 1490 | −#line 701 "lua.stx" | |
| 1521 | +#line 696 "lua.stx" | |
| 1491 | 1522 | { luaY_val.vInt = luaY_vsp[-1].vInt; flush_record(luaY_vsp[-1].vInt%FIELDS_PER_FLUSH); } |
| 1492 | 1523 | break; |
| 1493 | 1524 | case 76: |
| 1494 | −#line 705 "lua.stx" | |
| 1525 | +#line 700 "lua.stx" | |
| 1495 | 1526 | { luaY_val.vInt = 0; } |
| 1496 | 1527 | break; |
| 1497 | 1528 | case 77: |
| 1498 | −#line 707 "lua.stx" | |
| 1529 | +#line 702 "lua.stx" | |
| 1499 | 1530 | { luaY_val.vInt = luaY_vsp[0].vInt; flush_record(luaY_vsp[0].vInt%FIELDS_PER_FLUSH); } |
| 1500 | 1531 | break; |
| 1501 | 1532 | case 80: |
| 1502 | −#line 714 "lua.stx" | |
| 1533 | +#line 709 "lua.stx" | |
| 1503 | 1534 | { luaY_val.vInt = 0; } |
| 1504 | 1535 | break; |
| 1505 | 1536 | case 81: |
| 1506 | −#line 715 "lua.stx" | |
| 1537 | +#line 710 "lua.stx" | |
| 1507 | 1538 | { luaY_val.vInt = luaY_vsp[-1].vInt; } |
| 1508 | 1539 | break; |
| 1509 | 1540 | case 82: |
| 1510 | −#line 718 "lua.stx" | |
| 1541 | +#line 713 "lua.stx" | |
| 1511 | 1542 | {luaY_val.vInt=1;} |
| 1512 | 1543 | break; |
| 1513 | 1544 | case 83: |
| 1514 | −#line 720 "lua.stx" | |
| 1545 | +#line 715 "lua.stx" | |
| 1515 | 1546 | { |
| 1516 | 1547 | luaY_val.vInt=luaY_vsp[-2].vInt+1; |
| 1517 | 1548 | if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH); |
| 1518 | 1549 | } |
| 1519 | 1550 | break; |
| 1520 | −case 84: | |
| 1521 | −#line 727 "lua.stx" | |
| 1522 | −{ | |
| 1523 | − push_field(luaI_findconstant(luaY_vsp[-2].pTStr)); | |
| 1524 | − } | |
| 1551 | +case 86: | |
| 1552 | +#line 725 "lua.stx" | |
| 1553 | +{ code_constant(luaY_vsp[0].pTStr); } | |
| 1525 | 1554 | break; |
| 1526 | −case 85: | |
| 1527 | −#line 732 "lua.stx" | |
| 1555 | +case 87: | |
| 1556 | +#line 728 "lua.stx" | |
| 1528 | 1557 | { luaY_val.vInt = 0; } |
| 1529 | 1558 | break; |
| 1530 | −case 86: | |
| 1531 | −#line 733 "lua.stx" | |
| 1559 | +case 88: | |
| 1560 | +#line 729 "lua.stx" | |
| 1532 | 1561 | { luaY_val.vInt = luaY_vsp[-1].vInt; } |
| 1533 | 1562 | break; |
| 1534 | −case 87: | |
| 1535 | −#line 736 "lua.stx" | |
| 1563 | +case 89: | |
| 1564 | +#line 732 "lua.stx" | |
| 1536 | 1565 | {luaY_val.vInt=1;} |
| 1537 | 1566 | break; |
| 1538 | −case 88: | |
| 1539 | −#line 738 "lua.stx" | |
| 1567 | +case 90: | |
| 1568 | +#line 734 "lua.stx" | |
| 1540 | 1569 | { |
| 1541 | 1570 | luaY_val.vInt=luaY_vsp[-2].vInt+1; |
| 1542 | 1571 | if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) |
| 1543 | 1572 | flush_list(luaY_val.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH); |
| 1544 | 1573 | } |
| 1545 | 1574 | break; |
| 1546 | −case 89: | |
| 1547 | −#line 746 "lua.stx" | |
| 1575 | +case 91: | |
| 1576 | +#line 742 "lua.stx" | |
| 1548 | 1577 | { |
| 1549 | 1578 | nvarbuffer = 0; |
| 1550 | 1579 | add_varbuffer(luaY_vsp[0].vLong); |
| 1551 | 1580 | luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? 1 : 0; |
| 1552 | 1581 | } |
| 1553 | 1582 | break; |
| 1554 | −case 90: | |
| 1555 | −#line 752 "lua.stx" | |
| 1583 | +case 92: | |
| 1584 | +#line 748 "lua.stx" | |
| 1556 | 1585 | { |
| 1557 | 1586 | add_varbuffer(luaY_vsp[0].vLong); |
| 1558 | 1587 | luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? luaY_vsp[-2].vInt + 1 : luaY_vsp[-2].vInt; |
| 1559 | 1588 | } |
| 1560 | 1589 | break; |
| 1561 | −case 91: | |
| 1562 | −#line 758 "lua.stx" | |
| 1590 | +case 93: | |
| 1591 | +#line 754 "lua.stx" | |
| 1563 | 1592 | { luaY_val.vLong = luaY_vsp[0].vLong; } |
| 1564 | 1593 | break; |
| 1565 | −case 92: | |
| 1566 | −#line 760 "lua.stx" | |
| 1594 | +case 94: | |
| 1595 | +#line 756 "lua.stx" | |
| 1567 | 1596 | { |
| 1568 | 1597 | luaY_val.vLong = 0; /* indexed variable */ |
| 1569 | 1598 | } |
| 1570 | 1599 | break; |
| 1571 | −case 93: | |
| 1572 | −#line 764 "lua.stx" | |
| 1600 | +case 95: | |
| 1601 | +#line 760 "lua.stx" | |
| 1573 | 1602 | { |
| 1574 | − code_byte(PUSHSTRING); | |
| 1575 | − code_word(luaI_findconstant(luaY_vsp[0].pTStr)); | |
| 1576 | − luaY_val.vLong = 0; /* indexed variable */ | |
| 1603 | + code_constant(luaY_vsp[0].pTStr); | |
| 1604 | + luaY_val.vLong = 0; /* indexed variable */ | |
| 1577 | 1605 | } |
| 1578 | 1606 | break; |
| 1579 | −case 94: | |
| 1580 | −#line 772 "lua.stx" | |
| 1607 | +case 96: | |
| 1608 | +#line 767 "lua.stx" | |
| 1581 | 1609 | { |
| 1582 | 1610 | int local = lua_localname(luaY_vsp[0].pTStr); |
| 1583 | 1611 | if (local == -1) /* global var */ |
| @@ -1586,30 +1614,30 @@ case 94: · 2 unmodified lines | ||
| 1586 | 1614 | luaY_val.vLong = -(local+1); /* return negative value */ |
| 1587 | 1615 | } |
| 1588 | 1616 | break; |
| 1589 | −case 95: | |
| 1590 | −#line 781 "lua.stx" | |
| 1617 | +case 97: | |
| 1618 | +#line 776 "lua.stx" | |
| 1591 | 1619 | { lua_pushvar(luaY_vsp[0].vLong); } |
| 1592 | 1620 | break; |
| 1593 | −case 96: | |
| 1594 | −#line 784 "lua.stx" | |
| 1621 | +case 98: | |
| 1622 | +#line 779 "lua.stx" | |
| 1595 | 1623 | {store_localvar(luaY_vsp[0].pTStr, 0); luaY_val.vInt = 1;} |
| 1596 | 1624 | break; |
| 1597 | −case 97: | |
| 1598 | −#line 786 "lua.stx" | |
| 1625 | +case 99: | |
| 1626 | +#line 781 "lua.stx" | |
| 1599 | 1627 | { |
| 1600 | 1628 | store_localvar(luaY_vsp[0].pTStr, luaY_vsp[-2].vInt); |
| 1601 | 1629 | luaY_val.vInt = luaY_vsp[-2].vInt+1; |
| 1602 | 1630 | } |
| 1603 | 1631 | break; |
| 1604 | −case 98: | |
| 1605 | −#line 792 "lua.stx" | |
| 1632 | +case 100: | |
| 1633 | +#line 787 "lua.stx" | |
| 1606 | 1634 | { luaY_val.vInt = 0; } |
| 1607 | 1635 | break; |
| 1608 | −case 99: | |
| 1609 | −#line 793 "lua.stx" | |
| 1636 | +case 101: | |
| 1637 | +#line 788 "lua.stx" | |
| 1610 | 1638 | { luaY_val.vInt = luaY_vsp[0].vLong; } |
| 1611 | 1639 | break; |
| 1612 | −#line 1613 "y.tab.c" | |
| 1640 | +#line 1641 "y.tab.c" | |
| 1613 | 1641 | } |
| 1614 | 1642 | luaY_ssp -= luaY_m; |
| 1615 | 1643 | luaY_state = *luaY_ssp; |
| @@ -3,9 +3,11 @@ · 2 unmodified lines | ||
| 3 | 3 | ** Module to control static tables |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_table="$Id: table.c,v 2.58 1996/11/01 12:47:45 roberto Exp $"; | |
| 6 | +char *rcs_table="$Id: table.c,v 2.72 1997/06/17 18:09:31 roberto Exp $"; | |
| 7 | 7 | |
| 8 | −#include "mem.h" | |
| 8 | +#include "luamem.h" | |
| 9 | +#include "auxlib.h" | |
| 10 | +#include "func.h" | |
| 9 | 11 | #include "opcode.h" |
| 10 | 12 | #include "tree.h" |
| 11 | 13 | #include "hash.h" |
| @@ -27,49 +29,14 @@ Word lua_nconstant = 0; · 15 unmodified lines | ||
| 27 | 29 | static Long lua_maxconstant = 0; |
| 28 | 30 | |
| 29 | 31 | |
| 30 | −#define GARBAGE_BLOCK 50 | |
| 31 | − | |
| 32 | −static void lua_nextvar (void); | |
| 33 | − | |
| 34 | −/* | |
| 35 | −** Internal functions | |
| 36 | −*/ | |
| 37 | −static struct { | |
| 38 | − char *name; | |
| 39 | − lua_CFunction func; | |
| 40 | −} int_funcs[] = { | |
| 41 | − {"assert", luaI_assert}, | |
| 42 | − {"call", luaI_call}, | |
| 43 | − {"dofile", lua_internaldofile}, | |
| 44 | − {"dostring", lua_internaldostring}, | |
| 45 | − {"error", luaI_error}, | |
| 46 | − {"getglobal", luaI_getglobal}, | |
| 47 | − {"next", lua_next}, | |
| 48 | − {"nextvar", lua_nextvar}, | |
| 49 | − {"print", luaI_print}, | |
| 50 | − {"setfallback", luaI_setfallback}, | |
| 51 | − {"setglobal", luaI_setglobal}, | |
| 52 | − {"tonumber", lua_obj2number}, | |
| 53 | − {"tostring", luaI_tostring}, | |
| 54 | − {"type", luaI_type} | |
| 55 | −}; | |
| 56 | − | |
| 57 | −#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0])) | |
| 32 | +#define GARBAGE_BLOCK 100 | |
| 58 | 33 | |
| 59 | 34 | |
| 60 | 35 | void luaI_initsymbol (void) |
| 61 | 36 | { |
| 62 | − int i; | |
| 63 | − Word n; | |
| 64 | 37 | lua_maxsymbol = BUFFER_BLOCK; |
| 65 | 38 | lua_table = newvector(lua_maxsymbol, Symbol); |
| 66 | − for (i=0; i<INTFUNCSIZE; i++) | |
| 67 | − { | |
| 68 | − n = luaI_findsymbolbyname(int_funcs[i].name); | |
| 69 | − s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = int_funcs[i].func; | |
| 70 | − } | |
| 71 | − n = luaI_findsymbolbyname("_VERSION_"); | |
| 72 | − s_tag(n) = LUA_T_STRING; s_tsvalue(n) = lua_createstring(LUA_VERSION); | |
| 39 | + luaI_predefine(); | |
| 73 | 40 | } |
| 74 | 41 | |
| 75 | 42 | |
| @@ -92,17 +59,17 @@ void luaI_initconstant (void) · 16 unmodified lines | ||
| 92 | 59 | */ |
| 93 | 60 | Word luaI_findsymbol (TaggedString *t) |
| 94 | 61 | { |
| 95 | − if (t->varindex == NOT_USED) | |
| 62 | + if (t->u.s.varindex == NOT_USED) | |
| 96 | 63 | { |
| 97 | 64 | if (lua_ntable == lua_maxsymbol) |
| 98 | 65 | lua_maxsymbol = growvector(&lua_table, lua_maxsymbol, Symbol, |
| 99 | 66 | symbolEM, MAX_WORD); |
| 100 | − t->varindex = lua_ntable; | |
| 67 | + t->u.s.varindex = lua_ntable; | |
| 101 | 68 | lua_table[lua_ntable].varname = t; |
| 102 | − s_tag(lua_ntable) = LUA_T_NIL; | |
| 69 | + s_ttype(lua_ntable) = LUA_T_NIL; | |
| 103 | 70 | lua_ntable++; |
| 104 | 71 | } |
| 105 | − return t->varindex; | |
| 72 | + return t->u.s.varindex; | |
| 106 | 73 | } |
| 107 | 74 | |
| 108 | 75 | |
| @@ -118,16 +85,16 @@ Word luaI_findsymbolbyname (char *name) · 9 unmodified lines | ||
| 118 | 85 | */ |
| 119 | 86 | Word luaI_findconstant (TaggedString *t) |
| 120 | 87 | { |
| 121 | − if (t->constindex == NOT_USED) | |
| 88 | + if (t->u.s.constindex == NOT_USED) | |
| 122 | 89 | { |
| 123 | 90 | if (lua_nconstant == lua_maxconstant) |
| 124 | 91 | lua_maxconstant = growvector(&lua_constant, lua_maxconstant, TaggedString *, |
| 125 | 92 | constantEM, MAX_WORD); |
| 126 | − t->constindex = lua_nconstant; | |
| 93 | + t->u.s.constindex = lua_nconstant; | |
| 127 | 94 | lua_constant[lua_nconstant] = t; |
| 128 | 95 | lua_nconstant++; |
| 129 | 96 | } |
| 130 | − return t->constindex; | |
| 97 | + return t->u.s.constindex; | |
| 131 | 98 | } |
| 132 | 99 | |
| 133 | 100 | |
| @@ -145,10 +112,16 @@ TaggedString *luaI_createfixedstring (char *name) · 11 unmodified lines | ||
| 145 | 112 | } |
| 146 | 113 | |
| 147 | 114 | |
| 115 | +int luaI_globaldefined (char *name) | |
| 116 | +{ | |
| 117 | + return ttype(&lua_table[luaI_findsymbolbyname(name)].object) != LUA_T_NIL; | |
| 118 | +} | |
| 119 | + | |
| 120 | + | |
| 148 | 121 | /* |
| 149 | 122 | ** Traverse symbol table objects |
| 150 | 123 | */ |
| 151 | −static char *lua_travsymbol (int (*fn)(Object *)) | |
| 124 | +static char *lua_travsymbol (int (*fn)(TObject *)) | |
| 152 | 125 | { |
| 153 | 126 | Word i; |
| 154 | 127 | for (i=0; i<lua_ntable; i++) |
| @@ -161,13 +134,14 @@ static char *lua_travsymbol (int (*fn)(Object *)) · 6 unmodified lines | ||
| 161 | 134 | /* |
| 162 | 135 | ** Mark an object if it is a string or a unmarked array. |
| 163 | 136 | */ |
| 164 | −int lua_markobject (Object *o) | |
| 137 | +int lua_markobject (TObject *o) | |
| 165 | 138 | {/* if already marked, does not change mark value */ |
| 166 | − if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked) | |
| 139 | + if (ttype(o) == LUA_T_USERDATA || | |
| 140 | + (ttype(o) == LUA_T_STRING && !tsvalue(o)->marked)) | |
| 167 | 141 | tsvalue(o)->marked = 1; |
| 168 | − else if (tag(o) == LUA_T_ARRAY) | |
| 142 | + else if (ttype(o) == LUA_T_ARRAY) | |
| 169 | 143 | lua_hashmark (avalue(o)); |
| 170 | − else if ((o->tag == LUA_T_FUNCTION || o->tag == LUA_T_MARK) | |
| 144 | + else if ((o->ttype == LUA_T_FUNCTION || o->ttype == LUA_T_MARK) | |
| 171 | 145 | && !o->value.tf->marked) |
| 172 | 146 | o->value.tf->marked = 1; |
| 173 | 147 | return 0; |
| @@ -176,11 +150,11 @@ int lua_markobject (Object *o) · 2 unmodified lines | ||
| 176 | 150 | /* |
| 177 | 151 | * returns 0 if the object is going to be (garbage) collected |
| 178 | 152 | */ |
| 179 | −int luaI_ismarked (Object *o) | |
| 153 | +int luaI_ismarked (TObject *o) | |
| 180 | 154 | { |
| 181 | − switch (o->tag) | |
| 155 | + switch (o->ttype) | |
| 182 | 156 | { |
| 183 | − case LUA_T_STRING: | |
| 157 | + case LUA_T_STRING: case LUA_T_USERDATA: | |
| 184 | 158 | return o->value.ts->marked; |
| 185 | 159 | case LUA_T_FUNCTION: |
| 186 | 160 | return o->value.tf->marked; |
| @@ -192,76 +166,90 @@ int luaI_ismarked (Object *o) · 5 unmodified lines | ||
| 192 | 166 | } |
| 193 | 167 | |
| 194 | 168 | |
| 169 | +static void call_nilIM (void) | |
| 170 | +{ /* signals end of garbage collection */ | |
| 171 | + TObject t; | |
| 172 | + ttype(&t) = LUA_T_NIL; | |
| 173 | + luaI_gcIM(&t); /* end of list */ | |
| 174 | +} | |
| 175 | + | |
| 195 | 176 | /* |
| 196 | 177 | ** Garbage collection. |
| 197 | 178 | ** Delete all unused strings and arrays. |
| 198 | 179 | */ |
| 199 | −Long luaI_collectgarbage (void) | |
| 180 | +static long gc_block = GARBAGE_BLOCK; | |
| 181 | +static long gc_nentity = 0; /* total of strings, arrays, etc */ | |
| 182 | + | |
| 183 | +static void markall (void) | |
| 200 | 184 | { |
| 201 | − Long recovered = 0; | |
| 202 | 185 | lua_travstack(lua_markobject); /* mark stack objects */ |
| 203 | 186 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
| 204 | 187 | luaI_travlock(lua_markobject); /* mark locked objects */ |
| 205 | 188 | luaI_travfallbacks(lua_markobject); /* mark fallbacks */ |
| 189 | +} | |
| 190 | + | |
| 191 | + | |
| 192 | +long lua_collectgarbage (long limit) | |
| 193 | +{ | |
| 194 | + long recovered = 0; | |
| 195 | + Hash *freetable; | |
| 196 | + TaggedString *freestr; | |
| 197 | + TFunc *freefunc; | |
| 198 | + markall(); | |
| 206 | 199 | luaI_invalidaterefs(); |
| 207 | − recovered += lua_strcollector(); | |
| 208 | − recovered += lua_hashcollector(); | |
| 209 | − recovered += luaI_funccollector(); | |
| 200 | + freetable = luaI_hashcollector(&recovered); | |
| 201 | + freestr = luaI_strcollector(&recovered); | |
| 202 | + freefunc = luaI_funccollector(&recovered); | |
| 203 | + gc_nentity -= recovered; | |
| 204 | + gc_block = (limit == 0) ? 2*(gc_block-recovered) : gc_nentity+limit; | |
| 205 | + luaI_hashcallIM(freetable); | |
| 206 | + luaI_strcallIM(freestr); | |
| 207 | + call_nilIM(); | |
| 208 | + luaI_hashfree(freetable); | |
| 209 | + luaI_strfree(freestr); | |
| 210 | + luaI_funcfree(freefunc); | |
| 210 | 211 | return recovered; |
| 211 | 212 | } |
| 212 | 213 | |
| 214 | + | |
| 213 | 215 | void lua_pack (void) |
| 214 | 216 | { |
| 215 | − static unsigned long block = GARBAGE_BLOCK; | |
| 216 | − static unsigned long nentity = 0; /* total of strings, arrays, etc */ | |
| 217 | − unsigned long recovered = 0; | |
| 218 | − if (nentity++ < block) return; | |
| 219 | − recovered = luaI_collectgarbage(); | |
| 220 | − block = 2*(block-recovered); | |
| 221 | − nentity -= recovered; | |
| 217 | + if (++gc_nentity >= gc_block) | |
| 218 | + lua_collectgarbage(0); | |
| 222 | 219 | } |
| 223 | 220 | |
| 224 | 221 | |
| 225 | 222 | /* |
| 226 | 223 | ** Internal function: return next global variable |
| 227 | 224 | */ |
| 228 | −static void lua_nextvar (void) | |
| 225 | +void luaI_nextvar (void) | |
| 229 | 226 | { |
| 230 | − Word next; | |
| 231 | − lua_Object o = lua_getparam(1); | |
| 232 | − if (o == LUA_NOOBJECT) | |
| 233 | − lua_error("too few arguments to function `nextvar'"); | |
| 234 | − if (lua_getparam(2) != LUA_NOOBJECT) | |
| 235 | − lua_error("too many arguments to function `nextvar'"); | |
| 236 | − if (lua_isnil(o)) | |
| 237 | − next = 0; | |
| 238 | − else if (!lua_isstring(o)) | |
| 239 | − { | |
| 240 | − lua_error("incorrect argument to function `nextvar'"); | |
| 241 | − return; /* to avoid warnings */ | |
| 242 | − } | |
| 243 | − else | |
| 244 | − next = luaI_findsymbolbyname(lua_getstring(o)) + 1; | |
| 245 | − while (next < lua_ntable && s_tag(next) == LUA_T_NIL) next++; | |
| 246 | − if (next < lua_ntable) | |
| 247 | − { | |
| 248 | − lua_pushstring(lua_table[next].varname->str); | |
| 249 | − luaI_pushobject(&s_object(next)); | |
| 250 | − } | |
| 227 | + Word next; | |
| 228 | + if (lua_isnil(lua_getparam(1))) | |
| 229 | + next = 0; | |
| 230 | + else | |
| 231 | + next = luaI_findsymbolbyname(luaL_check_string(1)) + 1; | |
| 232 | + while (next < lua_ntable && s_ttype(next) == LUA_T_NIL) | |
| 233 | + next++; | |
| 234 | + if (next < lua_ntable) { | |
| 235 | + lua_pushstring(lua_table[next].varname->str); | |
| 236 | + luaI_pushobject(&s_object(next)); | |
| 237 | + } | |
| 251 | 238 | } |
| 252 | 239 | |
| 253 | 240 | |
| 254 | −static Object *functofind; | |
| 255 | −static int checkfunc (Object *o) | |
| 241 | +static TObject *functofind; | |
| 242 | +static int checkfunc (TObject *o) | |
| 256 | 243 | { |
| 257 | − if (o->tag == LUA_T_FUNCTION) | |
| 244 | + if (o->ttype == LUA_T_FUNCTION) | |
| 258 | 245 | return |
| 259 | − ((functofind->tag == LUA_T_FUNCTION || functofind->tag == LUA_T_MARK) | |
| 246 | + ((functofind->ttype == LUA_T_FUNCTION || functofind->ttype == LUA_T_MARK) | |
| 260 | 247 | && (functofind->value.tf == o->value.tf)); |
| 261 | − if (o->tag == LUA_T_CFUNCTION) | |
| 248 | + if (o->ttype == LUA_T_CFUNCTION) | |
| 262 | 249 | return |
| 263 | − ((functofind->tag == LUA_T_CFUNCTION || functofind->tag == LUA_T_CMARK) | |
| 264 | − && (functofind->value.f == o->value.f)); | |
| 250 | + ((functofind->ttype == LUA_T_CFUNCTION || | |
| 251 | + functofind->ttype == LUA_T_CMARK) && | |
| 252 | + (functofind->value.f == o->value.f)); | |
| 265 | 253 | return 0; |
| 266 | 254 | } |
| 267 | 255 | |
| @@ -270,7 +258,7 @@ char *lua_getobjname (lua_Object o, char **name) · 2 unmodified lines | ||
| 270 | 258 | { /* try to find a name for given function */ |
| 271 | 259 | functofind = luaI_Address(o); |
| 272 | 260 | if ((*name = luaI_travfallbacks(checkfunc)) != NULL) |
| 273 | − return "fallback"; | |
| 261 | + return "tag-method"; | |
| 274 | 262 | else if ((*name = lua_travsymbol(checkfunc)) != NULL) |
| 275 | 263 | return "global"; |
| 276 | 264 | else return ""; |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** Module to control static tables |
| 3 | 3 | ** TeCGraf - PUC-Rio |
| 4 | −** $Id: table.h,v 2.21 1996/04/22 18:00:37 roberto Exp $ | |
| 4 | +** $Id: table.h,v 2.25 1997/05/26 14:42:36 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef table_h |
| @@ -12,7 +12,7 @@ · 4 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | typedef struct |
| 14 | 14 | { |
| 15 | − Object object; | |
| 15 | + TObject object; | |
| 16 | 16 | TaggedString *varname; |
| 17 | 17 | } Symbol; |
| 18 | 18 | |
| @@ -28,10 +28,11 @@ Word luaI_findsymbolbyname (char *name); · 9 unmodified lines | ||
| 28 | 28 | Word luaI_findsymbol (TaggedString *t); |
| 29 | 29 | Word luaI_findconstant (TaggedString *t); |
| 30 | 30 | Word luaI_findconstantbyname (char *name); |
| 31 | +int luaI_globaldefined (char *name); | |
| 32 | +void luaI_nextvar (void); | |
| 31 | 33 | TaggedString *luaI_createfixedstring (char *str); |
| 32 | −int lua_markobject (Object *o); | |
| 33 | −int luaI_ismarked (Object *o); | |
| 34 | −Long luaI_collectgarbage (void); | |
| 34 | +int lua_markobject (TObject *o); | |
| 35 | +int luaI_ismarked (TObject *o); | |
| 35 | 36 | void lua_pack (void); |
| 36 | 37 | |
| 37 | 38 | |
| @@ -3,17 +3,18 @@ · 2 unmodified lines | ||
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char *rcs_tree="$Id: tree.c,v 1.20 1996/03/14 15:56:26 roberto Exp $"; | |
| 6 | +char *rcs_tree="$Id: tree.c,v 1.28 1997/06/11 14:24:40 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | #include <string.h> |
| 10 | 10 | |
| 11 | −#include "mem.h" | |
| 11 | +#include "luamem.h" | |
| 12 | 12 | #include "lua.h" |
| 13 | 13 | #include "tree.h" |
| 14 | 14 | #include "lex.h" |
| 15 | 15 | #include "hash.h" |
| 16 | 16 | #include "table.h" |
| 17 | +#include "fallback.h" | |
| 17 | 18 | |
| 18 | 19 | |
| 19 | 20 | #define NUM_HASHS 64 |
| @@ -28,23 +29,43 @@ static int initialized = 0; · 8 unmodified lines | ||
| 28 | 29 | |
| 29 | 30 | static stringtable string_root[NUM_HASHS]; |
| 30 | 31 | |
| 31 | −static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 2, {0}}; | |
| 32 | +static TaggedString EMPTY = {LUA_T_STRING, NULL, {{NOT_USED, NOT_USED}}, | |
| 33 | + 0, 2, {0}}; | |
| 32 | 34 | |
| 33 | 35 | |
| 34 | −static unsigned long hash (char *str) | |
| 36 | +static unsigned long hash (char *s, int tag) | |
| 35 | 37 | { |
| 36 | − unsigned long h = 0; | |
| 37 | − while (*str) | |
| 38 | − h = ((h<<5)-h)^(unsigned char)*(str++); | |
| 38 | + unsigned long h; | |
| 39 | + if (tag != LUA_T_STRING) | |
| 40 | + h = (unsigned long)s; | |
| 41 | + else { | |
| 42 | + h = 0; | |
| 43 | + while (*s) | |
| 44 | + h = ((h<<5)-h)^(unsigned char)*(s++); | |
| 45 | + } | |
| 39 | 46 | return h; |
| 40 | 47 | } |
| 41 | 48 | |
| 49 | + | |
| 50 | +static void luaI_inittree (void) | |
| 51 | +{ | |
| 52 | + int i; | |
| 53 | + for (i=0; i<NUM_HASHS; i++) { | |
| 54 | + string_root[i].size = 0; | |
| 55 | + string_root[i].nuse = 0; | |
| 56 | + string_root[i].hash = NULL; | |
| 57 | + } | |
| 58 | +} | |
| 59 | + | |
| 60 | + | |
| 42 | 61 | static void initialize (void) |
| 43 | 62 | { |
| 44 | 63 | initialized = 1; |
| 64 | + luaI_inittree(); | |
| 45 | 65 | luaI_addReserved(); |
| 46 | 66 | luaI_initsymbol(); |
| 47 | 67 | luaI_initconstant(); |
| 68 | + luaI_initfallbacks(); | |
| 48 | 69 | } |
| 49 | 70 | |
| 50 | 71 | |
| @@ -58,8 +79,7 @@ static void grow (stringtable *tb) · 7 unmodified lines | ||
| 58 | 79 | /* rehash */ |
| 59 | 80 | tb->nuse = 0; |
| 60 | 81 | for (i=0; i<tb->size; i++) |
| 61 | − if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) | |
| 62 | − { | |
| 82 | + if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) { | |
| 63 | 83 | int h = tb->hash[i]->hash%newsize; |
| 64 | 84 | while (newhash[h]) |
| 65 | 85 | h = (h+1)%newsize; |
| @@ -71,10 +91,30 @@ static void grow (stringtable *tb) · 5 unmodified lines | ||
| 71 | 91 | tb->hash = newhash; |
| 72 | 92 | } |
| 73 | 93 | |
| 74 | −static TaggedString *insert (char *str, stringtable *tb) | |
| 94 | + | |
| 95 | +static TaggedString *newone(char *buff, int tag, unsigned long h) | |
| 96 | +{ | |
| 97 | + TaggedString *ts; | |
| 98 | + if (tag == LUA_T_STRING) { | |
| 99 | + ts = (TaggedString *)luaI_malloc(sizeof(TaggedString)+strlen(buff)); | |
| 100 | + strcpy(ts->str, buff); | |
| 101 | + ts->u.s.varindex = ts->u.s.constindex = NOT_USED; | |
| 102 | + ts->tag = LUA_T_STRING; | |
| 103 | + } | |
| 104 | + else { | |
| 105 | + ts = (TaggedString *)luaI_malloc(sizeof(TaggedString)); | |
| 106 | + ts->u.v = buff; | |
| 107 | + ts->tag = tag == LUA_ANYTAG ? 0 : tag; | |
| 108 | + } | |
| 109 | + ts->marked = 0; | |
| 110 | + ts->hash = h; | |
| 111 | + return ts; | |
| 112 | +} | |
| 113 | + | |
| 114 | +static TaggedString *insert (char *buff, int tag, stringtable *tb) | |
| 75 | 115 | { |
| 76 | 116 | TaggedString *ts; |
| 77 | − unsigned long h = hash(str); | |
| 117 | + unsigned long h = hash(buff, tag); | |
| 78 | 118 | int i; |
| 79 | 119 | int j = -1; |
| 80 | 120 | if ((Long)tb->nuse*3 >= (Long)tb->size*2) |
| @@ -84,12 +124,14 @@ static TaggedString *insert (char *str, stringtable *tb) · 3 unmodified lines | ||
| 84 | 124 | grow(tb); |
| 85 | 125 | } |
| 86 | 126 | i = h%tb->size; |
| 87 | − while (tb->hash[i]) | |
| 127 | + while ((ts = tb->hash[i]) != NULL) | |
| 88 | 128 | { |
| 89 | − if (tb->hash[i] == &EMPTY) | |
| 129 | + if (ts == &EMPTY) | |
| 90 | 130 | j = i; |
| 91 | − else if (strcmp(str, tb->hash[i]->str) == 0) | |
| 92 | − return tb->hash[i]; | |
| 131 | + else if ((ts->tag == LUA_T_STRING) ? | |
| 132 | + (tag == LUA_T_STRING && (strcmp(buff, ts->str) == 0)) : | |
| 133 | + ((tag == ts->tag || tag == LUA_ANYTAG) && buff == ts->u.v)) | |
| 134 | + return ts; | |
| 93 | 135 | i = (i+1)%tb->size; |
| 94 | 136 | } |
| 95 | 137 | /* not found */ |
| @@ -98,27 +140,49 @@ static TaggedString *insert (char *str, stringtable *tb) · 2 unmodified lines | ||
| 98 | 140 | i = j; |
| 99 | 141 | else |
| 100 | 142 | 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; | |
| 143 | + ts = tb->hash[i] = newone(buff, tag, h); | |
| 106 | 144 | return ts; |
| 107 | 145 | } |
| 108 | 146 | |
| 109 | −TaggedString *lua_createstring (char *str) | |
| 147 | +TaggedString *luaI_createudata (void *udata, int tag) | |
| 110 | 148 | { |
| 111 | − return insert(str, &string_root[(unsigned)str[0]%NUM_HASHS]); | |
| 149 | + return insert(udata, tag, &string_root[(unsigned)udata%NUM_HASHS]); | |
| 150 | +} | |
| 151 | + | |
| 152 | +TaggedString *lua_createstring (char *str) | |
| 153 | +{ | |
| 154 | + return insert(str, LUA_T_STRING, &string_root[(unsigned)str[0]%NUM_HASHS]); | |
| 155 | +} | |
| 156 | + | |
| 157 | + | |
| 158 | +void luaI_strcallIM (TaggedString *l) | |
| 159 | +{ | |
| 160 | + TObject o; | |
| 161 | + ttype(&o) = LUA_T_USERDATA; | |
| 162 | + for (; l; l=l->next) { | |
| 163 | + tsvalue(&o) = l; | |
| 164 | + luaI_gcIM(&o); | |
| 165 | + } | |
| 166 | +} | |
| 167 | + | |
| 168 | + | |
| 169 | +void luaI_strfree (TaggedString *l) | |
| 170 | +{ | |
| 171 | + while (l) { | |
| 172 | + TaggedString *next = l->next; | |
| 173 | + luaI_free(l); | |
| 174 | + l = next; | |
| 175 | + } | |
| 112 | 176 | } |
| 113 | 177 | |
| 114 | 178 | |
| 115 | 179 | /* |
| 116 | 180 | ** Garbage collection function. |
| 117 | −** This function traverse the string list freeing unindexed strings | |
| 118 | 181 | */ |
| 119 | −Long lua_strcollector (void) | |
| 182 | +TaggedString *luaI_strcollector (long *acum) | |
| 120 | 183 | { |
| 121 | 184 | Long counter = 0; |
| 185 | + TaggedString *frees = NULL; | |
| 122 | 186 | int i; |
| 123 | 187 | for (i=0; i<NUM_HASHS; i++) |
| 124 | 188 | { |
| @@ -133,13 +197,15 @@ Long lua_strcollector (void) · 8 unmodified lines | ||
| 133 | 197 | t->marked = 0; |
| 134 | 198 | else |
| 135 | 199 | { |
| 136 | − luaI_free(t); | |
| 200 | + t->next = frees; | |
| 201 | + frees = t; | |
| 137 | 202 | tb->hash[j] = &EMPTY; |
| 138 | 203 | counter++; |
| 139 | 204 | } |
| 140 | 205 | } |
| 141 | 206 | } |
| 142 | 207 | } |
| 143 | − return counter; | |
| 208 | + *acum += counter; | |
| 209 | + return frees; | |
| 144 | 210 | } |
| 145 | 211 | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** tree.h |
| 3 | 3 | ** TecCGraf - PUC-Rio |
| 4 | −** $Id: tree.h,v 1.14 1996/02/26 17:07:49 roberto Exp $ | |
| 4 | +** $Id: tree.h,v 1.18 1997/06/09 17:28:14 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef tree_h |
| @@ -14,8 +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 | + int tag; /* if != LUA_T_STRING, this is a userdata */ | |
| 18 | + struct TaggedString *next; | |
| 19 | + union { | |
| 20 | + struct { | |
| 21 | + Word varindex; /* != NOT_USED if this is a symbol */ | |
| 22 | + Word constindex; /* != NOT_USED if this is a constant */ | |
| 23 | + } s; | |
| 24 | + void *v; /* if this is a userdata, here is its value */ | |
| 25 | + } u; | |
| 19 | 26 | unsigned long hash; /* 0 if not initialized */ |
| 20 | 27 | int marked; /* for garbage collection; never collect (nor change) if > 1 */ |
| 21 | 28 | char str[1]; /* \0 byte already reserved */ |
| @@ -23,6 +30,9 @@ typedef struct TaggedString · 1 unmodified line | ||
| 23 | 30 | |
| 24 | 31 | |
| 25 | 32 | TaggedString *lua_createstring (char *str); |
| 26 | −Long lua_strcollector (void); | |
| 33 | +TaggedString *luaI_createudata (void *udata, int tag); | |
| 34 | +TaggedString *luaI_strcollector (long *cont); | |
| 35 | +void luaI_strfree (TaggedString *l); | |
| 36 | +void luaI_strcallIM (TaggedString *l); | |
| 27 | 37 | |
| 28 | 38 | #endif |
| @@ -3,33 +3,28 @@ · 2 unmodified lines | ||
| 3 | 3 | ** load bytecodes from files |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −char* rcs_undump="$Id: undump.c,v 1.21 1996/11/18 11:18:29 lhf Exp $"; | |
| 6 | +char* rcs_undump="$Id: undump.c,v 1.24 1997/06/17 18:19:17 roberto Exp $"; | |
| 7 | 7 | |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <string.h> |
| 10 | +#include "auxlib.h" | |
| 10 | 11 | #include "opcode.h" |
| 11 | −#include "mem.h" | |
| 12 | +#include "luamem.h" | |
| 12 | 13 | #include "table.h" |
| 13 | 14 | #include "undump.h" |
| 15 | +#include "zio.h" | |
| 14 | 16 | |
| 15 | 17 | static int swapword=0; |
| 16 | 18 | static int swapfloat=0; |
| 17 | 19 | static TFunc* Main=NULL; /* functions in a chunk */ |
| 18 | 20 | static TFunc* lastF=NULL; |
| 19 | 21 | |
| 20 | −static void warn(char* s) /* TODO: remove */ | |
| 21 | −{ | |
| 22 | −#if 0 | |
| 23 | − fprintf(stderr,"undump: %s\n",s); | |
| 24 | −#endif | |
| 25 | −} | |
| 26 | − | |
| 27 | 22 | static void FixCode(Byte* code, Byte* end) /* swap words */ |
| 28 | 23 | { |
| 29 | 24 | Byte* p; |
| 30 | 25 | for (p=code; p!=end;) |
| 31 | 26 | { |
| 32 | − OpCode op=(OpCode)*p; | |
| 27 | + int op=*p; | |
| 33 | 28 | switch (op) |
| 34 | 29 | { |
| 35 | 30 | case PUSHNIL: |
| @@ -83,6 +78,8 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ · 47 unmodified lines | ||
| 83 | 78 | case STORELIST0: |
| 84 | 79 | case ADJUST: |
| 85 | 80 | case RETCODE: |
| 81 | + case VARARGS: | |
| 82 | + case STOREMAP: | |
| 86 | 83 | p+=2; |
| 87 | 84 | break; |
| 88 | 85 | case STORELIST: |
| @@ -132,7 +129,8 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ · 43 unmodified lines | ||
| 132 | 129 | break; |
| 133 | 130 | } |
| 134 | 131 | default: |
| 135 | − lua_error("corrupt binary file"); | |
| 132 | + luaL_verror("corrupt binary file: bad opcode %d at %d\n", | |
| 133 | + op,(int)(p-code)); | |
| 136 | 134 | break; |
| 137 | 135 | } |
| 138 | 136 | } |
| @@ -150,149 +148,152 @@ static void Unthread(Byte* code, int i, int v) · 11 unmodified lines | ||
| 150 | 148 | } |
| 151 | 149 | } |
| 152 | 150 | |
| 153 | −static int LoadWord(FILE* D) | |
| 151 | +static int LoadWord(ZIO* Z) | |
| 154 | 152 | { |
| 155 | 153 | Word w; |
| 156 | − fread(&w,sizeof(w),1,D); | |
| 154 | + zread(Z,&w,sizeof(w)); | |
| 157 | 155 | if (swapword) |
| 158 | 156 | { |
| 159 | − Byte* p=(Byte*)&w; /* TODO: need union? */ | |
| 157 | + Byte* p=(Byte*)&w; | |
| 160 | 158 | Byte t; |
| 161 | 159 | t=p[0]; p[0]=p[1]; p[1]=t; |
| 162 | 160 | } |
| 163 | 161 | return w; |
| 164 | 162 | } |
| 165 | 163 | |
| 166 | −static int LoadSize(FILE* D) | |
| 164 | +static int LoadSize(ZIO* Z) | |
| 167 | 165 | { |
| 168 | − Word hi=LoadWord(D); | |
| 169 | − Word lo=LoadWord(D); | |
| 166 | + Word hi=LoadWord(Z); | |
| 167 | + Word lo=LoadWord(Z); | |
| 170 | 168 | int s=(hi<<16)|lo; |
| 171 | 169 | if ((Word)s != s) lua_error("code too long"); |
| 172 | 170 | return s; |
| 173 | 171 | } |
| 174 | 172 | |
| 175 | −static void* LoadBlock(int size, FILE* D) | |
| 173 | +static void* LoadBlock(int size, ZIO* Z) | |
| 176 | 174 | { |
| 177 | 175 | void* b=luaI_malloc(size); |
| 178 | − fread(b,size,1,D); | |
| 176 | + zread(Z,b,size); | |
| 179 | 177 | return b; |
| 180 | 178 | } |
| 181 | 179 | |
| 182 | −static char* LoadString(FILE* D) | |
| 180 | +static char* LoadString(ZIO* Z) | |
| 183 | 181 | { |
| 184 | − int size=LoadWord(D); | |
| 182 | + int size=LoadWord(Z); | |
| 185 | 183 | char *b=luaI_buffer(size); |
| 186 | − fread(b,size,1,D); | |
| 184 | + zread(Z,b,size); | |
| 187 | 185 | return b; |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | −static char* LoadNewString(FILE* D) | |
| 188 | +static char* LoadNewString(ZIO* Z) | |
| 191 | 189 | { |
| 192 | − return LoadBlock(LoadWord(D),D); | |
| 190 | + return LoadBlock(LoadWord(Z),Z); | |
| 193 | 191 | } |
| 194 | 192 | |
| 195 | −static void LoadFunction(FILE* D) | |
| 193 | +static void LoadFunction(ZIO* Z) | |
| 196 | 194 | { |
| 197 | 195 | TFunc* tf=new(TFunc); |
| 198 | 196 | tf->next=NULL; |
| 199 | 197 | tf->locvars=NULL; |
| 200 | − tf->size=LoadSize(D); | |
| 201 | − tf->lineDefined=LoadWord(D); | |
| 198 | + tf->size=LoadSize(Z); | |
| 199 | + tf->lineDefined=LoadWord(Z); | |
| 202 | 200 | if (IsMain(tf)) /* new main */ |
| 203 | 201 | { |
| 204 | − tf->fileName=LoadNewString(D); | |
| 202 | + tf->fileName=LoadNewString(Z); | |
| 205 | 203 | Main=lastF=tf; |
| 206 | 204 | } |
| 207 | 205 | else /* fix PUSHFUNCTION */ |
| 208 | 206 | { |
| 209 | − tf->marked=LoadWord(D); | |
| 207 | + tf->marked=LoadWord(Z); | |
| 210 | 208 | tf->fileName=Main->fileName; |
| 211 | 209 | memcpy(Main->code+tf->marked,&tf,sizeof(tf)); |
| 212 | 210 | lastF=lastF->next=tf; |
| 213 | 211 | } |
| 214 | − tf->code=LoadBlock(tf->size,D); | |
| 212 | + tf->code=LoadBlock(tf->size,Z); | |
| 215 | 213 | if (swapword || swapfloat) FixCode(tf->code,tf->code+tf->size); |
| 216 | 214 | while (1) /* unthread */ |
| 217 | 215 | { |
| 218 | − int c=getc(D); | |
| 216 | + int c=zgetc(Z); | |
| 219 | 217 | if (c==ID_VAR) /* global var */ |
| 220 | 218 | { |
| 221 | − int i=LoadWord(D); | |
| 222 | − char* s=LoadString(D); | |
| 219 | + int i=LoadWord(Z); | |
| 220 | + char* s=LoadString(Z); | |
| 223 | 221 | int v=luaI_findsymbolbyname(s); |
| 224 | 222 | Unthread(tf->code,i,v); |
| 225 | 223 | } |
| 226 | 224 | else if (c==ID_STR) /* constant string */ |
| 227 | 225 | { |
| 228 | − int i=LoadWord(D); | |
| 229 | − char* s=LoadString(D); | |
| 226 | + int i=LoadWord(Z); | |
| 227 | + char* s=LoadString(Z); | |
| 230 | 228 | int v=luaI_findconstantbyname(s); |
| 231 | 229 | Unthread(tf->code,i,v); |
| 232 | 230 | } |
| 233 | 231 | else |
| 234 | 232 | { |
| 235 | − ungetc(c,D); | |
| 233 | + zungetc(Z); | |
| 236 | 234 | break; |
| 237 | 235 | } |
| 238 | 236 | } |
| 239 | 237 | } |
| 240 | 238 | |
| 241 | −static void LoadSignature(FILE* D) | |
| 239 | +static void LoadSignature(ZIO* Z) | |
| 242 | 240 | { |
| 243 | 241 | char* s=SIGNATURE; |
| 244 | − while (*s!=0 && getc(D)==*s) | |
| 242 | + while (*s!=0 && zgetc(Z)==*s) | |
| 245 | 243 | ++s; |
| 246 | − if (*s!=0) lua_error("bad signature"); | |
| 244 | + if (*s!=0) lua_error("cannot load binary file: bad signature"); | |
| 247 | 245 | } |
| 248 | 246 | |
| 249 | −static void LoadHeader(FILE* D) /* TODO: error handling */ | |
| 247 | +static void LoadHeader(ZIO* Z) | |
| 250 | 248 | { |
| 251 | 249 | Word w,tw=TEST_WORD; |
| 252 | 250 | float f,tf=TEST_FLOAT; |
| 253 | 251 | int version; |
| 254 | − LoadSignature(D); | |
| 255 | − version=getc(D); | |
| 252 | + LoadSignature(Z); | |
| 253 | + version=zgetc(Z); | |
| 256 | 254 | if (version>0x23) /* after 2.5 */ |
| 257 | 255 | { |
| 258 | − int oldsizeofW=getc(D); | |
| 259 | − int oldsizeofF=getc(D); | |
| 260 | − int oldsizeofP=getc(D); | |
| 256 | + int oldsizeofW=zgetc(Z); | |
| 257 | + int oldsizeofF=zgetc(Z); | |
| 258 | + int oldsizeofP=zgetc(Z); | |
| 261 | 259 | if (oldsizeofW!=2) |
| 262 | − lua_error("cannot load binary file created on machine with sizeof(Word)!=2"); | |
| 260 | + luaL_verror( | |
| 261 | + "cannot load binary file created on machine with sizeof(Word)=%d; " | |
| 262 | + "expected 2",oldsizeofW); | |
| 263 | 263 | if (oldsizeofF!=4) |
| 264 | − lua_error("cannot load binary file created on machine with sizeof(float)!=4. not an IEEE machine?"); | |
| 265 | − if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack */ | |
| 266 | − lua_error("cannot load binary file: different pointer sizes"); | |
| 264 | + luaL_verror( | |
| 265 | + "cannot load binary file created on machine with sizeof(float)=%d; " | |
| 266 | + "expected 4\nnot an IEEE machine?",oldsizeofF); | |
| 267 | + if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack? */ | |
| 268 | + luaL_verror( | |
| 269 | + "cannot load binary file created on machine with sizeof(TFunc*)=%d; " | |
| 270 | + "expected %d",oldsizeofP,(int)sizeof(TFunc*)); | |
| 267 | 271 | } |
| 268 | − fread(&w,sizeof(w),1,D); /* test word */ | |
| 272 | + zread(Z,&w,sizeof(w)); /* test word */ | |
| 269 | 273 | if (w!=tw) |
| 270 | 274 | { |
| 271 | 275 | swapword=1; |
| 272 | − warn("different byte order"); | |
| 273 | 276 | } |
| 274 | − fread(&f,sizeof(f),1,D); /* test float */ | |
| 277 | + zread(Z,&f,sizeof(f)); /* test float */ | |
| 275 | 278 | if (f!=tf) |
| 276 | 279 | { |
| 277 | − Byte* p=(Byte*)&f; /* TODO: need union? */ | |
| 280 | + Byte* p=(Byte*)&f; | |
| 278 | 281 | Byte t; |
| 279 | 282 | swapfloat=1; |
| 280 | 283 | t=p[0]; p[0]=p[3]; p[3]=t; |
| 281 | 284 | t=p[1]; p[1]=p[2]; p[2]=t; |
| 282 | 285 | if (f!=tf) /* TODO: try another perm? */ |
| 283 | − lua_error("different float representation"); | |
| 284 | − else | |
| 285 | − warn("different byte order in floats"); | |
| 286 | + lua_error("cannot load binary file: unknown float representation"); | |
| 286 | 287 | } |
| 287 | 288 | } |
| 288 | 289 | |
| 289 | −static void LoadChunk(FILE* D) | |
| 290 | +static void LoadChunk(ZIO* Z) | |
| 290 | 291 | { |
| 291 | − LoadHeader(D); | |
| 292 | + LoadHeader(Z); | |
| 292 | 293 | while (1) |
| 293 | 294 | { |
| 294 | − int c=getc(D); | |
| 295 | − if (c==ID_FUN) LoadFunction(D); else { ungetc(c,D); break; } | |
| 295 | + int c=zgetc(Z); | |
| 296 | + if (c==ID_FUN) LoadFunction(Z); else { zungetc(Z); break; } | |
| 296 | 297 | } |
| 297 | 298 | } |
| 298 | 299 | |
| @@ -300,30 +301,26 @@ static void LoadChunk(FILE* D) · 1 unmodified line | ||
| 300 | 301 | ** load one chunk from a file. |
| 301 | 302 | ** return list of functions found, headed by main, or NULL at EOF. |
| 302 | 303 | */ |
| 303 | −TFunc* luaI_undump1(FILE* D) | |
| 304 | +TFunc* luaI_undump1(ZIO* Z) | |
| 304 | 305 | { |
| 305 | − while (1) | |
| 306 | + int c=zgetc(Z); | |
| 307 | + if (c==ID_CHUNK) | |
| 306 | 308 | { |
| 307 | − int c=getc(D); | |
| 308 | − if (c==ID_CHUNK) | |
| 309 | − { | |
| 310 | − LoadChunk(D); | |
| 311 | − return Main; | |
| 312 | − } | |
| 313 | − else if (c==EOF) | |
| 314 | − return NULL; | |
| 315 | − else | |
| 316 | − lua_error("not a lua binary file"); | |
| 309 | + LoadChunk(Z); | |
| 310 | + return Main; | |
| 317 | 311 | } |
| 312 | + else if (c!=EOZ) | |
| 313 | + lua_error("not a lua binary file"); | |
| 314 | + return NULL; | |
| 318 | 315 | } |
| 319 | 316 | |
| 320 | 317 | /* |
| 321 | 318 | ** load and run all chunks in a file |
| 322 | 319 | */ |
| 323 | −int luaI_undump(FILE* D) | |
| 320 | +int luaI_undump(ZIO* Z) | |
| 324 | 321 | { |
| 325 | 322 | TFunc* m; |
| 326 | − while ((m=luaI_undump1(D))) | |
| 323 | + while ((m=luaI_undump1(Z))) | |
| 327 | 324 | { |
| 328 | 325 | int status=luaI_dorun(m); |
| 329 | 326 | luaI_freefunc(m); |
| @@ -1,10 +1,14 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ** undump.h |
| 3 | 3 | ** definitions for lua decompiler |
| 4 | −** $Id: undump.h,v 1.3 1996/11/14 11:44:34 lhf Exp $ | |
| 4 | +** $Id: undump.h,v 1.6 1997/06/17 18:19:17 roberto Exp $ | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | +#ifndef undump_h | |
| 8 | +#define undump_h | |
| 9 | + | |
| 7 | 10 | #include "func.h" |
| 11 | +#include "zio.h" | |
| 8 | 12 | |
| 9 | 13 | #define IsMain(f) (f->lineDefined==0) |
| 10 | 14 | |
| @@ -15,9 +19,12 @@ · 4 unmodified lines | ||
| 15 | 19 | #define ID_VAR 'V' |
| 16 | 20 | #define ID_STR 'S' |
| 17 | 21 | #define SIGNATURE "Lua" |
| 18 | −#define VERSION 0x25 /* 2.5 */ | |
| 22 | +#define VERSION 0x25 /* last format change was in 2.5 */ | |
| 19 | 23 | #define TEST_WORD 0x1234 /* a word for testing byte ordering */ |
| 20 | 24 | #define TEST_FLOAT 0.123456789e-23 /* a float for testing representation */ |
| 21 | 25 | |
| 22 | −TFunc* luaI_undump1(FILE* D); /* load one chunk */ | |
| 23 | −int luaI_undump(FILE* D); /* load all chunks */ | |
| 26 | + | |
| 27 | +TFunc* luaI_undump1(ZIO* Z); | |
| 28 | +int luaI_undump(ZIO* Z); /* load all chunks */ | |
| 29 | + | |
| 30 | +#endif | |
| @@ -0,0 +1,79 @@ | ||
| 1 | +/* | |
| 2 | +* zio.c | |
| 3 | +* a generic input stream interface | |
| 4 | +* $Id: zio.c,v 1.2 1997/06/20 19:25:54 roberto Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#include <stdio.h> | |
| 8 | +#include <stdlib.h> | |
| 9 | +#include <string.h> | |
| 10 | +#include "zio.h" | |
| 11 | + | |
| 12 | + | |
| 13 | +/* ----------------------------------------------------- memory buffers --- */ | |
| 14 | + | |
| 15 | +static int zmfilbuf(ZIO* z) | |
| 16 | +{ | |
| 17 | + return EOZ; | |
| 18 | +} | |
| 19 | + | |
| 20 | +ZIO* zmopen(ZIO* z, char* b, int size) | |
| 21 | +{ | |
| 22 | + if (b==NULL) return NULL; | |
| 23 | + z->n=size; | |
| 24 | + z->p= (unsigned char *)b; | |
| 25 | + z->filbuf=zmfilbuf; | |
| 26 | + z->u=NULL; | |
| 27 | + return z; | |
| 28 | +} | |
| 29 | + | |
| 30 | +/* ------------------------------------------------------------ strings --- */ | |
| 31 | + | |
| 32 | +ZIO* zsopen(ZIO* z, char* s) | |
| 33 | +{ | |
| 34 | + if (s==NULL) return NULL; | |
| 35 | + return zmopen(z,s,strlen(s)); | |
| 36 | +} | |
| 37 | + | |
| 38 | +/* -------------------------------------------------------------- FILEs --- */ | |
| 39 | + | |
| 40 | +static int zffilbuf(ZIO* z) | |
| 41 | +{ | |
| 42 | + int n=fread(z->buffer,1,ZBSIZE,z->u); | |
| 43 | + if (n==0) return EOZ; | |
| 44 | + z->n=n-1; | |
| 45 | + z->p=z->buffer; | |
| 46 | + return *(z->p++); | |
| 47 | +} | |
| 48 | + | |
| 49 | + | |
| 50 | +ZIO* zFopen(ZIO* z, FILE* f) | |
| 51 | +{ | |
| 52 | + if (f==NULL) return NULL; | |
| 53 | + z->n=0; | |
| 54 | + z->p=z->buffer; | |
| 55 | + z->filbuf=zffilbuf; | |
| 56 | + z->u=f; | |
| 57 | + return z; | |
| 58 | +} | |
| 59 | + | |
| 60 | + | |
| 61 | +/* --------------------------------------------------------------- read --- */ | |
| 62 | +int zread(ZIO *z, void *b, int n) | |
| 63 | +{ | |
| 64 | + while (n) { | |
| 65 | + int m; | |
| 66 | + if (z->n == 0) { | |
| 67 | + if (z->filbuf(z) == EOZ) | |
| 68 | + return n; /* retorna quantos faltaram ler */ | |
| 69 | + zungetc(z); /* poe o resultado de filbuf no buffer */ | |
| 70 | + } | |
| 71 | + m = (n <= z->n) ? n : z->n; /* minimo de n e z->n */ | |
| 72 | + memcpy(b, z->p, m); | |
| 73 | + z->n -= m; | |
| 74 | + z->p += m; | |
| 75 | + b = (char *)b + m; | |
| 76 | + n -= m; | |
| 77 | + } | |
| 78 | + return 0; | |
| 79 | +} | |
| @@ -0,0 +1,48 @@ | ||
| 1 | +/* | |
| 2 | +* zio.h | |
| 3 | +* a generic input stream interface | |
| 4 | +* $Id: zio.h,v 1.5 1997/06/20 19:25:54 roberto Exp $ | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#ifndef zio_h | |
| 8 | +#define zio_h | |
| 9 | + | |
| 10 | +#include <stdio.h> | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | +/* For Lua only */ | |
| 15 | +#define zFopen luaZ_Fopen | |
| 16 | +#define zsopen luaZ_sopen | |
| 17 | +#define zmopen luaZ_mopen | |
| 18 | +#define zread luaZ_read | |
| 19 | + | |
| 20 | +#define EOZ (-1) /* end of stream */ | |
| 21 | + | |
| 22 | +typedef struct zio ZIO; | |
| 23 | + | |
| 24 | +ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */ | |
| 25 | +ZIO* zsopen(ZIO* z, char* s); /* string */ | |
| 26 | +ZIO* zmopen(ZIO* z, char* b, int size); /* memory */ | |
| 27 | + | |
| 28 | +int zread(ZIO* z, void* b, int n); /* read next n bytes */ | |
| 29 | + | |
| 30 | +#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) | |
| 31 | +#define zungetc(z) (++(z)->n,--(z)->p) | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | +/* --------- Private Part ------------------ */ | |
| 36 | + | |
| 37 | +#define ZBSIZE 256 /* buffer size */ | |
| 38 | + | |
| 39 | +struct zio { | |
| 40 | + int n; /* bytes still unread */ | |
| 41 | + unsigned char* p; /* current position in buffer */ | |
| 42 | + int (*filbuf)(ZIO* z); | |
| 43 | + void* u; /* additional data */ | |
| 44 | + unsigned char buffer[ZBSIZE]; /* buffer */ | |
| 45 | +}; | |
| 46 | + | |
| 47 | + | |
| 48 | +#endif | |