1993-07-28 17:18:00 +04:00
|
|
|
/*
|
|
|
|
** TeCGraf - PUC-Rio
|
1997-02-20 18:51:14 +03:00
|
|
|
** $Id: opcode.h,v 3.25 1997/02/11 11:35:05 roberto Exp roberto $
|
1993-07-28 17:18:00 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef opcode_h
|
|
|
|
#define opcode_h
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
#include "lua.h"
|
1994-12-21 00:20:36 +03:00
|
|
|
#include "types.h"
|
1994-11-23 17:32:00 +03:00
|
|
|
#include "tree.h"
|
1995-10-04 20:13:02 +03:00
|
|
|
#include "func.h"
|
1994-11-02 23:30:53 +03:00
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
|
1994-02-13 23:35:53 +03:00
|
|
|
#define FIELDS_PER_FLUSH 40
|
|
|
|
|
1997-02-20 18:51:14 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LUA_T_NIL = -1,
|
|
|
|
LUA_T_NUMBER = -2,
|
|
|
|
LUA_T_STRING = -3,
|
|
|
|
LUA_T_ARRAY = -4, /* array==table */
|
|
|
|
LUA_T_FUNCTION = -5,
|
|
|
|
LUA_T_CFUNCTION= -6,
|
|
|
|
LUA_T_MARK = -7,
|
|
|
|
LUA_T_CMARK = -8,
|
|
|
|
LUA_T_LINE = -9,
|
|
|
|
LUA_T_USERDATA = 0
|
|
|
|
} lua_Type;
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
|
1996-09-27 01:08:41 +04:00
|
|
|
typedef enum {
|
|
|
|
/* name parm before after side effect
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
PUSHNIL,/* - nil */
|
|
|
|
PUSH0,/* - 0.0 */
|
|
|
|
PUSH1,/* - 1.0 */
|
|
|
|
PUSH2,/* - 2.0 */
|
|
|
|
PUSHBYTE,/* b - (float)b */
|
|
|
|
PUSHWORD,/* w - (float)w */
|
|
|
|
PUSHFLOAT,/* f - f */
|
|
|
|
PUSHSTRING,/* w - STR[w] */
|
|
|
|
PUSHFUNCTION,/* p - FUN(p) */
|
|
|
|
PUSHLOCAL0,/* - LOC[0] */
|
|
|
|
PUSHLOCAL1,/* - LOC[1] */
|
|
|
|
PUSHLOCAL2,/* - LOC[2] */
|
|
|
|
PUSHLOCAL3,/* - LOC[3] */
|
|
|
|
PUSHLOCAL4,/* - LOC[4] */
|
|
|
|
PUSHLOCAL5,/* - LOC[5] */
|
|
|
|
PUSHLOCAL6,/* - LOC[6] */
|
|
|
|
PUSHLOCAL7,/* - LOC[7] */
|
|
|
|
PUSHLOCAL8,/* - LOC[8] */
|
|
|
|
PUSHLOCAL9,/* - LOC[9] */
|
|
|
|
PUSHLOCAL,/* w - LOC[w] */
|
|
|
|
PUSHGLOBAL,/* w - VAR[w] */
|
|
|
|
PUSHINDEXED,/* i t t[i] */
|
|
|
|
PUSHSELF,/* w t t t[STR[w]] */
|
|
|
|
STORELOCAL0,/* x - LOC[0]=x */
|
|
|
|
STORELOCAL1,/* x - LOC[1]=x */
|
|
|
|
STORELOCAL2,/* x - LOC[2]=x */
|
|
|
|
STORELOCAL3,/* x - LOC[3]=x */
|
|
|
|
STORELOCAL4,/* x - LOC[4]=x */
|
|
|
|
STORELOCAL5,/* x - LOC[5]=x */
|
|
|
|
STORELOCAL6,/* x - LOC[6]=x */
|
|
|
|
STORELOCAL7,/* x - LOC[7]=x */
|
|
|
|
STORELOCAL8,/* x - LOC[8]=x */
|
|
|
|
STORELOCAL9,/* x - LOC[9]=x */
|
|
|
|
STORELOCAL,/* w x - LOC[w]=x */
|
|
|
|
STOREGLOBAL,/* w x - VAR[w]=x */
|
|
|
|
STOREINDEXED0,/* v i t - t[i]=v */
|
|
|
|
STOREINDEXED,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */
|
|
|
|
STORELIST0,/* w v_w...v_1 t - t[i]=v_i */
|
|
|
|
STORELIST,/* w n v_w...v_1 t - t[i+n*FPF]=v_i */
|
|
|
|
STORERECORD,/* n
|
|
|
|
w_n...w_1 v_n...v_1 t - t[STR[w_i]]=v_i */
|
|
|
|
ADJUST0,/* - - TOP=BASE */
|
|
|
|
ADJUST,/* b - - TOP=BASE+b */
|
|
|
|
CREATEARRAY,/* w - newarray(size = w) */
|
|
|
|
EQOP,/* y x (x==y)? 1 : nil */
|
|
|
|
LTOP,/* y x (x<y)? 1 : nil */
|
|
|
|
LEOP,/* y x (x<y)? 1 : nil */
|
|
|
|
GTOP,/* y x (x>y)? 1 : nil */
|
|
|
|
GEOP,/* y x (x>=y)? 1 : nil */
|
|
|
|
ADDOP,/* y x x+y */
|
|
|
|
SUBOP,/* y x x-y */
|
|
|
|
MULTOP,/* y x x*y */
|
|
|
|
DIVOP,/* y x x/y */
|
|
|
|
POWOP,/* y x x^y */
|
|
|
|
CONCOP,/* y x x..y */
|
|
|
|
MINUSOP,/* x -x */
|
|
|
|
NOTOP,/* x (x==nil)? 1 : nil */
|
|
|
|
ONTJMP,/* w x - (x!=nil)? PC+=w */
|
|
|
|
ONFJMP,/* w x - (x==nil)? PC+=w */
|
|
|
|
JMP,/* w - - PC+=w */
|
|
|
|
UPJMP,/* w - - PC-=w */
|
|
|
|
IFFJMP,/* w x - (x==nil)? PC+=w */
|
|
|
|
IFFUPJMP,/* w x - (x==nil)? PC-=w */
|
|
|
|
POP,/* x - */
|
|
|
|
CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */
|
|
|
|
RETCODE0,
|
|
|
|
RETCODE,/* b - - */
|
|
|
|
SETLINE,/* w - - LINE=w */
|
|
|
|
VARARGS/* b v_n...v_1 {v_1...v_n;n=n} */
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
} OpCode;
|
|
|
|
|
1996-09-27 01:08:41 +04:00
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
#define MULT_RET 255
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
1996-02-13 20:30:39 +03:00
|
|
|
lua_CFunction f;
|
1994-11-02 23:30:53 +03:00
|
|
|
real n;
|
1994-11-23 17:32:00 +03:00
|
|
|
TaggedString *ts;
|
1995-10-04 20:13:02 +03:00
|
|
|
TFunc *tf;
|
1993-07-28 17:18:00 +04:00
|
|
|
struct Hash *a;
|
1995-10-25 16:05:51 +03:00
|
|
|
int i;
|
1993-07-28 17:18:00 +04:00
|
|
|
} Value;
|
|
|
|
|
|
|
|
typedef struct Object
|
|
|
|
{
|
1994-11-07 18:20:56 +03:00
|
|
|
lua_Type tag;
|
1993-07-28 17:18:00 +04:00
|
|
|
Value value;
|
|
|
|
} Object;
|
|
|
|
|
|
|
|
|
|
|
|
/* Macros to access structure members */
|
|
|
|
#define tag(o) ((o)->tag)
|
|
|
|
#define nvalue(o) ((o)->value.n)
|
1994-11-23 17:32:00 +03:00
|
|
|
#define svalue(o) ((o)->value.ts->str)
|
|
|
|
#define tsvalue(o) ((o)->value.ts)
|
1993-07-28 17:18:00 +04:00
|
|
|
#define avalue(o) ((o)->value.a)
|
|
|
|
#define fvalue(o) ((o)->value.f)
|
|
|
|
|
|
|
|
/* Macros to access symbol table */
|
|
|
|
#define s_object(i) (lua_table[i].object)
|
|
|
|
#define s_tag(i) (tag(&s_object(i)))
|
|
|
|
#define s_nvalue(i) (nvalue(&s_object(i)))
|
|
|
|
#define s_svalue(i) (svalue(&s_object(i)))
|
1996-11-01 15:46:59 +03:00
|
|
|
#define s_tsvalue(i) (tsvalue(&s_object(i)))
|
1993-07-28 17:18:00 +04:00
|
|
|
#define s_avalue(i) (avalue(&s_object(i)))
|
|
|
|
#define s_fvalue(i) (fvalue(&s_object(i)))
|
|
|
|
#define s_uvalue(i) (uvalue(&s_object(i)))
|
|
|
|
|
1996-05-29 01:07:32 +04:00
|
|
|
#define get_word(code,pc) {memcpy(&code, pc, sizeof(Word)); pc+=sizeof(Word);}
|
|
|
|
#define get_float(code,pc){memcpy(&code, pc, sizeof(real)); pc+=sizeof(real);}
|
|
|
|
#define get_code(code,pc) {memcpy(&code, pc, sizeof(TFunc *)); \
|
|
|
|
pc+=sizeof(TFunc *);}
|
1994-12-21 00:20:36 +03:00
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
/* Exported functions */
|
1995-10-04 20:13:02 +03:00
|
|
|
void lua_parse (TFunc *tf); /* from "lua.stx" module */
|
1995-10-25 16:05:51 +03:00
|
|
|
void luaI_codedebugline (int line); /* from "lua.stx" module */
|
1995-10-17 14:58:41 +03:00
|
|
|
void lua_travstack (int (*fn)(Object *));
|
1994-11-07 19:34:44 +03:00
|
|
|
Object *luaI_Address (lua_Object o);
|
|
|
|
void luaI_pushobject (Object *o);
|
1994-11-10 20:36:54 +03:00
|
|
|
void luaI_gcFB (Object *o);
|
1996-03-15 16:13:13 +03:00
|
|
|
int luaI_dorun (TFunc *tf);
|
1993-07-28 17:18:00 +04:00
|
|
|
|
|
|
|
#endif
|