From 64097041c48070deb2e9d88c55efb41ba77cdd9b Mon Sep 17 00:00:00 2001 From: Waldemar Celes Date: Fri, 17 Dec 1993 16:41:19 -0200 Subject: LUA intermediate code interpreter --- opcode.c | 41 +++++++++++++++++++++++++++++++++++++++-- opcode.h | 5 +++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/opcode.c b/opcode.c index 97975ba1..ab470fb8 100644 --- a/opcode.c +++ b/opcode.c @@ -1,9 +1,10 @@ /* ** opcode.c ** TecCGraf - PUC-Rio -** 26 Apr 93 */ +char *rcs_opcode="$Id: $"; + #include #include #include @@ -137,6 +138,8 @@ static int lua_tostring (Object *obj) */ int lua_execute (Byte *pc) { + Object *oldbase = base; + base = top; while (1) { switch ((OpCode)*pc++) @@ -252,7 +255,7 @@ int lua_execute (Byte *pc) case STOREFIELD: if (tag(top-3) != T_ARRAY) { - lua_error ("internal error - table expected"); + lua_reportbug ("internal error - table expected"); return 1; } *(lua_hashdefine (avalue(top-3), top-2)) = *(top-1); @@ -516,6 +519,7 @@ int lua_execute (Byte *pc) break; case HALT: + base = oldbase; return 0; /* success */ case SETFUNCTION: @@ -577,6 +581,7 @@ int lua_dostring (char *string) { if (lua_openstring (string)) return 1; if (lua_parse ()) return 1; + lua_closestring(); return 0; } @@ -612,6 +617,7 @@ Object *lua_getparam (int number) */ real lua_getnumber (Object *object) { + if (object == NULL || tag(object) == T_NIL) return 0.0; if (tonumber (object)) return 0.0; else return (nvalue(object)); } @@ -621,6 +627,7 @@ real lua_getnumber (Object *object) */ char *lua_getstring (Object *object) { + if (object == NULL || tag(object) == T_NIL) return NULL; if (tostring (object)) return NULL; else return (svalue(object)); } @@ -630,6 +637,7 @@ char *lua_getstring (Object *object) */ char *lua_copystring (Object *object) { + if (object == NULL || tag(object) == T_NIL) return NULL; if (tostring (object)) return NULL; else return (strdup(svalue(object))); } @@ -639,6 +647,7 @@ char *lua_copystring (Object *object) */ lua_CFunction lua_getcfunction (Object *object) { + if (object == NULL) return NULL; if (tag(object) != T_CFUNCTION) return NULL; else return (fvalue(object)); } @@ -648,6 +657,7 @@ lua_CFunction lua_getcfunction (Object *object) */ void *lua_getuserdata (Object *object) { + if (object == NULL) return NULL; if (tag(object) != T_USERDATA) return NULL; else return (uvalue(object)); } @@ -658,6 +668,7 @@ void *lua_getuserdata (Object *object) */ Object *lua_getfield (Object *object, char *field) { + if (object == NULL) return NULL; if (tag(object) != T_ARRAY) return NULL; else @@ -675,6 +686,7 @@ Object *lua_getfield (Object *object, char *field) */ Object *lua_getindexed (Object *object, float index) { + if (object == NULL) return NULL; if (tag(object) != T_ARRAY) return NULL; else @@ -931,3 +943,28 @@ void lua_print (void) } } +/* +** Internal function: do a file +*/ +void lua_internaldofile (void) +{ + lua_Object obj = lua_getparam (1); + if (lua_isstring(obj) && !lua_dofile(lua_getstring(obj))) + lua_pushnumber(1); + else + lua_pushnil(); +} + +/* +** Internal function: do a string +*/ +void lua_internaldostring (void) +{ + lua_Object obj = lua_getparam (1); + if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj))) + lua_pushnumber(1); + else + lua_pushnil(); +} + + diff --git a/opcode.h b/opcode.h index b32969d5..e7d505f3 100644 --- a/opcode.h +++ b/opcode.h @@ -1,7 +1,6 @@ /* -** opcode.h ** TeCGraf - PUC-Rio -** 16 Apr 92 +** $Id: $ */ #ifndef opcode_h @@ -140,5 +139,7 @@ int lua_parse (void); /* from "lua.stx" module */ void lua_type (void); void lua_obj2number (void); void lua_print (void); +void lua_internaldofile (void); +void lua_internaldostring (void); #endif -- cgit v1.2.3-55-g6feb