1993-07-28 17:18:00 +04:00
|
|
|
/*
|
|
|
|
** TeCGraf - PUC-Rio
|
1994-11-02 23:30:53 +03:00
|
|
|
** $Id: opcode.h,v 2.4 1994/10/17 19:00:40 celes 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"
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
#ifndef STACKGAP
|
|
|
|
#define STACKGAP 128
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef real
|
|
|
|
#define real float
|
|
|
|
#endif
|
|
|
|
|
1994-02-13 23:35:53 +03:00
|
|
|
#define FIELDS_PER_FLUSH 40
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
#define MAX_TEMPS 20
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
typedef unsigned char Byte;
|
|
|
|
|
|
|
|
typedef unsigned short Word;
|
|
|
|
|
1994-07-20 01:27:18 +04:00
|
|
|
typedef signed long Long;
|
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
struct {char c1; char c2;} m;
|
|
|
|
Word w;
|
|
|
|
} CodeWord;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
struct {char c1; char c2; char c3; char c4;} m;
|
|
|
|
float f;
|
|
|
|
} CodeFloat;
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
struct {char c1; char c2; char c3; char c4;} m;
|
|
|
|
Byte *b;
|
|
|
|
} CodeCode;
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PUSHNIL,
|
|
|
|
PUSH0, PUSH1, PUSH2,
|
|
|
|
PUSHBYTE,
|
|
|
|
PUSHWORD,
|
|
|
|
PUSHFLOAT,
|
|
|
|
PUSHSTRING,
|
1994-08-05 23:31:09 +04:00
|
|
|
PUSHFUNCTION,
|
1993-07-28 17:18:00 +04:00
|
|
|
PUSHLOCAL0, PUSHLOCAL1, PUSHLOCAL2, PUSHLOCAL3, PUSHLOCAL4,
|
|
|
|
PUSHLOCAL5, PUSHLOCAL6, PUSHLOCAL7, PUSHLOCAL8, PUSHLOCAL9,
|
|
|
|
PUSHLOCAL,
|
|
|
|
PUSHGLOBAL,
|
|
|
|
PUSHINDEXED,
|
1994-11-02 23:30:53 +03:00
|
|
|
PUSHSELF,
|
1993-07-28 17:18:00 +04:00
|
|
|
STORELOCAL0, STORELOCAL1, STORELOCAL2, STORELOCAL3, STORELOCAL4,
|
|
|
|
STORELOCAL5, STORELOCAL6, STORELOCAL7, STORELOCAL8, STORELOCAL9,
|
|
|
|
STORELOCAL,
|
|
|
|
STOREGLOBAL,
|
|
|
|
STOREINDEXED0,
|
|
|
|
STOREINDEXED,
|
1994-02-13 23:35:53 +03:00
|
|
|
STORELIST0,
|
|
|
|
STORELIST,
|
|
|
|
STORERECORD,
|
1994-11-02 23:30:53 +03:00
|
|
|
ADJUST0,
|
1993-07-28 17:18:00 +04:00
|
|
|
ADJUST,
|
|
|
|
CREATEARRAY,
|
|
|
|
EQOP,
|
|
|
|
LTOP,
|
|
|
|
LEOP,
|
|
|
|
ADDOP,
|
|
|
|
SUBOP,
|
|
|
|
MULTOP,
|
|
|
|
DIVOP,
|
1994-10-17 22:00:40 +03:00
|
|
|
POWOP,
|
1993-07-28 17:18:00 +04:00
|
|
|
CONCOP,
|
|
|
|
MINUSOP,
|
|
|
|
NOTOP,
|
|
|
|
ONTJMP,
|
|
|
|
ONFJMP,
|
|
|
|
JMP,
|
|
|
|
UPJMP,
|
|
|
|
IFFJMP,
|
|
|
|
IFFUPJMP,
|
|
|
|
POP,
|
|
|
|
CALLFUNC,
|
1994-11-02 23:30:53 +03:00
|
|
|
RETCODE0,
|
1993-07-28 17:18:00 +04:00
|
|
|
RETCODE,
|
|
|
|
SETFUNCTION,
|
|
|
|
SETLINE,
|
|
|
|
RESET
|
|
|
|
} OpCode;
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
#define MULT_RET 255
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
|
|
|
|
typedef void (*Cfunction) (void);
|
|
|
|
typedef int (*Input) (void);
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
1994-11-02 23:30:53 +03:00
|
|
|
Cfunction f;
|
|
|
|
real n;
|
|
|
|
char *s;
|
|
|
|
Byte *b;
|
1993-07-28 17:18:00 +04:00
|
|
|
struct Hash *a;
|
|
|
|
void *u;
|
|
|
|
} Value;
|
|
|
|
|
|
|
|
typedef struct Object
|
|
|
|
{
|
|
|
|
Type tag;
|
|
|
|
Value value;
|
|
|
|
} Object;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Object object;
|
|
|
|
} Symbol;
|
|
|
|
|
|
|
|
/* Macros to access structure members */
|
|
|
|
#define tag(o) ((o)->tag)
|
|
|
|
#define nvalue(o) ((o)->value.n)
|
|
|
|
#define svalue(o) ((o)->value.s)
|
|
|
|
#define bvalue(o) ((o)->value.b)
|
|
|
|
#define avalue(o) ((o)->value.a)
|
|
|
|
#define fvalue(o) ((o)->value.f)
|
|
|
|
#define uvalue(o) ((o)->value.u)
|
|
|
|
|
|
|
|
/* 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)))
|
|
|
|
#define s_bvalue(i) (bvalue(&s_object(i)))
|
|
|
|
#define s_avalue(i) (avalue(&s_object(i)))
|
|
|
|
#define s_fvalue(i) (fvalue(&s_object(i)))
|
|
|
|
#define s_uvalue(i) (uvalue(&s_object(i)))
|
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
#define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;}
|
|
|
|
#define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
|
|
|
|
code.m.c3 = *pc++; code.m.c4 = *pc++;}
|
1994-08-05 23:31:09 +04:00
|
|
|
#define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
|
|
|
|
code.m.c3 = *pc++; code.m.c4 = *pc++;}
|
1994-04-14 01:37:20 +04:00
|
|
|
|
|
|
|
|
1993-07-28 17:18:00 +04:00
|
|
|
|
|
|
|
/* Exported functions */
|
|
|
|
char *lua_strdup (char *l);
|
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
void lua_setinput (Input fn); /* from "lex.c" module */
|
|
|
|
char *lua_lasttext (void); /* from "lex.c" module */
|
1994-11-02 23:30:53 +03:00
|
|
|
Byte *lua_parse (void); /* from "lua.stx" module */
|
1993-07-28 17:18:00 +04:00
|
|
|
void lua_obj2number (void);
|
1994-04-21 02:07:57 +04:00
|
|
|
void lua_travstack (void (*fn)(Object *));
|
1993-07-28 17:18:00 +04:00
|
|
|
|
|
|
|
#endif
|