1993-12-17 21:53:07 +03:00
|
|
|
%{
|
|
|
|
|
1994-12-27 23:41:11 +03:00
|
|
|
char *rcs_luastx = "$Id: lua.stx,v 3.15 1994/12/27 20:04:29 celes Exp celes $";
|
1993-12-17 21:53:07 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1994-11-17 21:59:06 +03:00
|
|
|
#include "mem.h"
|
1993-12-17 21:53:07 +03:00
|
|
|
#include "opcode.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "inout.h"
|
1994-11-15 00:40:14 +03:00
|
|
|
#include "tree.h"
|
1993-12-17 21:53:07 +03:00
|
|
|
#include "table.h"
|
|
|
|
#include "lua.h"
|
|
|
|
|
1994-11-23 17:39:52 +03:00
|
|
|
/* to avoid warnings generated by yacc */
|
|
|
|
int yyparse (void);
|
|
|
|
#define malloc luaI_malloc
|
|
|
|
#define realloc luaI_realloc
|
|
|
|
#define free luaI_free
|
|
|
|
|
1994-11-09 21:07:38 +03:00
|
|
|
#ifndef LISTING
|
1994-11-17 22:09:46 +03:00
|
|
|
#define LISTING 0
|
1994-11-09 21:07:38 +03:00
|
|
|
#endif
|
1994-02-13 23:38:20 +03:00
|
|
|
|
1994-07-20 01:27:18 +04:00
|
|
|
#ifndef CODE_BLOCK
|
|
|
|
#define CODE_BLOCK 256
|
1993-12-17 21:53:07 +03:00
|
|
|
#endif
|
1994-12-27 23:41:11 +03:00
|
|
|
static int maxcode;
|
|
|
|
static int maxmain;
|
1994-12-21 00:20:36 +03:00
|
|
|
static Long maxcurr; /* to allow maxcurr *= 2 without overflow */
|
1994-11-13 17:54:18 +03:00
|
|
|
static Byte *funcCode = NULL;
|
1994-11-09 21:07:38 +03:00
|
|
|
static Byte **initcode;
|
1993-12-17 21:53:07 +03:00
|
|
|
static Byte *basepc;
|
1994-12-27 23:41:11 +03:00
|
|
|
static int maincode;
|
|
|
|
static int pc;
|
1993-12-17 21:53:07 +03:00
|
|
|
|
|
|
|
#define MAXVAR 32
|
1994-12-21 00:20:36 +03:00
|
|
|
static Long varbuffer[MAXVAR]; /* variables in an assignment list;
|
1994-02-13 23:38:20 +03:00
|
|
|
it's long to store negative Word values */
|
|
|
|
static int nvarbuffer=0; /* number of variables at a list */
|
|
|
|
|
|
|
|
static Word localvar[STACKGAP]; /* store local variable names */
|
|
|
|
static int nlocalvar=0; /* number of local variables */
|
1993-12-17 21:53:07 +03:00
|
|
|
|
1994-02-13 23:38:20 +03:00
|
|
|
#define MAXFIELDS FIELDS_PER_FLUSH*2
|
|
|
|
static Word fields[MAXFIELDS]; /* fieldnames to be flushed */
|
|
|
|
static int nfields=0;
|
1993-12-17 21:53:07 +03:00
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
|
1993-12-17 21:53:07 +03:00
|
|
|
/* Internal functions */
|
|
|
|
|
|
|
|
static void code_byte (Byte c)
|
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-12-27 23:41:11 +03:00
|
|
|
if (maxcurr >= MAX_INT)
|
1994-12-21 00:20:36 +03:00
|
|
|
lua_error("code size overflow");
|
1994-07-20 01:27:18 +04:00
|
|
|
maxcurr *= 2;
|
1994-12-27 23:41:11 +03:00
|
|
|
if (maxcurr >= MAX_INT)
|
|
|
|
maxcurr = MAX_INT;
|
1994-11-17 21:59:06 +03:00
|
|
|
basepc = growvector(basepc, maxcurr, Byte);
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
1994-04-20 20:22:21 +04:00
|
|
|
basepc[pc++] = c;
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
static void code_word (Word n)
|
1994-02-13 23:38:20 +03:00
|
|
|
{
|
1994-04-14 01:37:20 +04:00
|
|
|
CodeWord code;
|
|
|
|
code.w = n;
|
|
|
|
code_byte(code.m.c1);
|
|
|
|
code_byte(code.m.c2);
|
1994-02-13 23:38:20 +03:00
|
|
|
}
|
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
static void code_float (float n)
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-14 01:37:20 +04:00
|
|
|
CodeFloat code;
|
|
|
|
code.f = n;
|
|
|
|
code_byte(code.m.c1);
|
|
|
|
code_byte(code.m.c2);
|
|
|
|
code_byte(code.m.c3);
|
|
|
|
code_byte(code.m.c4);
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
static void code_code (Byte *b)
|
|
|
|
{
|
|
|
|
CodeCode code;
|
|
|
|
code.b = b;
|
|
|
|
code_byte(code.m.c1);
|
|
|
|
code_byte(code.m.c2);
|
|
|
|
code_byte(code.m.c3);
|
|
|
|
code_byte(code.m.c4);
|
|
|
|
}
|
|
|
|
|
1994-04-14 01:37:20 +04:00
|
|
|
static void code_word_at (Byte *p, Word n)
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-14 01:37:20 +04:00
|
|
|
CodeWord code;
|
|
|
|
code.w = n;
|
|
|
|
*p++ = code.m.c1;
|
|
|
|
*p++ = code.m.c2;
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
1994-02-13 23:38:20 +03:00
|
|
|
static void push_field (Word name)
|
|
|
|
{
|
|
|
|
if (nfields < STACKGAP-1)
|
|
|
|
fields[nfields++] = name;
|
|
|
|
else
|
|
|
|
lua_error ("too many fields in a constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_record (int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (n == 0) return;
|
|
|
|
code_byte(STORERECORD);
|
|
|
|
code_byte(n);
|
|
|
|
for (i=0; i<n; i++)
|
1994-04-15 23:02:04 +04:00
|
|
|
code_word(fields[--nfields]);
|
1994-02-13 23:38:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_list (int m, int n)
|
|
|
|
{
|
|
|
|
if (n == 0) return;
|
|
|
|
if (m == 0)
|
|
|
|
code_byte(STORELIST0);
|
|
|
|
else
|
1994-08-03 18:15:46 +04:00
|
|
|
if (m < 255)
|
1994-02-13 23:38:20 +03:00
|
|
|
{
|
|
|
|
code_byte(STORELIST);
|
|
|
|
code_byte(m);
|
|
|
|
}
|
1994-08-03 18:15:46 +04:00
|
|
|
else
|
|
|
|
lua_error ("list constructor too long");
|
1994-02-13 23:38:20 +03:00
|
|
|
code_byte(n);
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_nlocalvar (int n)
|
|
|
|
{
|
1994-11-02 23:30:53 +03:00
|
|
|
if (MAX_TEMPS+nlocalvar+MAXVAR+n < STACKGAP)
|
1993-12-17 21:53:07 +03:00
|
|
|
nlocalvar += n;
|
|
|
|
else
|
1994-11-02 23:30:53 +03:00
|
|
|
lua_error ("too many local variables");
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void incr_nvarbuffer (void)
|
|
|
|
{
|
|
|
|
if (nvarbuffer < MAXVAR-1)
|
|
|
|
nvarbuffer++;
|
|
|
|
else
|
|
|
|
lua_error ("variable buffer overflow");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void code_number (float f)
|
1994-07-20 01:27:18 +04:00
|
|
|
{
|
|
|
|
Word i = (Word)f;
|
1993-12-28 19:42:29 +03:00
|
|
|
if (f == (float)i) /* f has an (short) integer value */
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
if (i <= 2) code_byte(PUSH0 + i);
|
|
|
|
else if (i <= 255)
|
|
|
|
{
|
|
|
|
code_byte(PUSHBYTE);
|
|
|
|
code_byte(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(PUSHWORD);
|
|
|
|
code_word(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(PUSHFLOAT);
|
|
|
|
code_float(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-12-27 23:04:29 +03:00
|
|
|
/*
|
|
|
|
** Search a local name and if find return its index. If do not find return -1
|
|
|
|
*/
|
|
|
|
static int lua_localname (Word n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=nlocalvar-1; i >= 0; i--)
|
|
|
|
if (n == localvar[i]) return i; /* local var */
|
|
|
|
return -1; /* global var */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Push a variable given a number. If number is positive, push global variable
|
|
|
|
** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
|
|
|
|
** Otherwise, if zero, push indexed variable (record).
|
|
|
|
*/
|
|
|
|
static void lua_pushvar (Long number)
|
|
|
|
{
|
|
|
|
if (number > 0) /* global var */
|
|
|
|
{
|
|
|
|
code_byte(PUSHGLOBAL);
|
|
|
|
code_word(number-1);
|
|
|
|
}
|
|
|
|
else if (number < 0) /* local var */
|
|
|
|
{
|
|
|
|
number = (-number) - 1;
|
|
|
|
if (number < 10) code_byte(PUSHLOCAL0 + number);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(PUSHLOCAL);
|
|
|
|
code_byte(number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(PUSHINDEXED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lua_codeadjust (int n)
|
|
|
|
{
|
|
|
|
if (n+nlocalvar == 0)
|
|
|
|
code_byte(ADJUST0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(ADJUST);
|
|
|
|
code_byte(n+nlocalvar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_function (TreeNode *func)
|
|
|
|
{
|
|
|
|
if (funcCode == NULL) /* first function */
|
|
|
|
{
|
|
|
|
funcCode = newvector(CODE_BLOCK, Byte);
|
|
|
|
maxcode = CODE_BLOCK;
|
|
|
|
}
|
|
|
|
pc=0; basepc=funcCode; maxcurr=maxcode;
|
|
|
|
nlocalvar=0;
|
|
|
|
if (lua_debug)
|
|
|
|
{
|
|
|
|
code_byte(SETFUNCTION);
|
|
|
|
code_code((Byte *)strdup(lua_file[lua_nfile-1]));
|
|
|
|
code_word(luaI_findconstant(func));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void codereturn (void)
|
|
|
|
{
|
|
|
|
if (lua_debug) code_byte(RESET);
|
|
|
|
if (nlocalvar == 0)
|
|
|
|
code_byte(RETCODE0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(RETCODE);
|
|
|
|
code_byte(nlocalvar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void codedebugline (void)
|
|
|
|
{
|
|
|
|
if (lua_debug)
|
|
|
|
{
|
|
|
|
code_byte(SETLINE);
|
|
|
|
code_word(lua_linenumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adjust_mult_assign (int vars, int exps, int temps)
|
|
|
|
{
|
|
|
|
if (exps < 0)
|
|
|
|
{
|
|
|
|
int r = vars - (-exps-1);
|
|
|
|
if (r >= 0)
|
|
|
|
code_byte(r);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(0);
|
|
|
|
lua_codeadjust(temps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vars != exps)
|
|
|
|
lua_codeadjust(temps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lua_codestore (int i)
|
|
|
|
{
|
|
|
|
if (varbuffer[i] > 0) /* global var */
|
|
|
|
{
|
|
|
|
code_byte(STOREGLOBAL);
|
|
|
|
code_word(varbuffer[i]-1);
|
|
|
|
}
|
|
|
|
else if (varbuffer[i] < 0) /* local var */
|
|
|
|
{
|
|
|
|
int number = (-varbuffer[i]) - 1;
|
|
|
|
if (number < 10) code_byte(STORELOCAL0 + number);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(STORELOCAL);
|
|
|
|
code_byte(number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* indexed var */
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int upper=0; /* number of indexed variables upper */
|
|
|
|
int param; /* number of itens until indexed expression */
|
|
|
|
for (j=i+1; j <nvarbuffer; j++)
|
|
|
|
if (varbuffer[j] == 0) upper++;
|
|
|
|
param = upper*2 + i;
|
|
|
|
if (param == 0)
|
|
|
|
code_byte(STOREINDEXED0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
code_byte(STOREINDEXED);
|
|
|
|
code_byte(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void codeIf (Long thenAdd, Long elseAdd)
|
|
|
|
{
|
|
|
|
Long elseinit = elseAdd+sizeof(Word)+1;
|
|
|
|
if (pc == elseinit) /* no else */
|
|
|
|
{
|
|
|
|
pc -= sizeof(Word)+1;
|
|
|
|
elseinit = pc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
basepc[elseAdd] = JMP;
|
|
|
|
code_word_at(basepc+elseAdd+1, pc-elseinit);
|
|
|
|
}
|
|
|
|
basepc[thenAdd] = IFFJMP;
|
|
|
|
code_word_at(basepc+thenAdd+1,elseinit-(thenAdd+sizeof(Word)+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void yyerror (char *s)
|
|
|
|
{
|
|
|
|
static char msg[256];
|
|
|
|
sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"",
|
|
|
|
s, lua_lasttext (), lua_linenumber, lua_filename());
|
|
|
|
lua_error (msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Parse LUA code.
|
|
|
|
*/
|
|
|
|
void lua_parse (Byte **code)
|
|
|
|
{
|
|
|
|
initcode = code;
|
|
|
|
*initcode = newvector(CODE_BLOCK, Byte);
|
|
|
|
maincode = 0;
|
|
|
|
maxmain = CODE_BLOCK;
|
|
|
|
if (yyparse ()) lua_error("parse error");
|
|
|
|
(*initcode)[maincode++] = RETCODE0;
|
|
|
|
#if LISTING
|
|
|
|
{ static void PrintCode (Byte *c, Byte *end);
|
|
|
|
PrintCode(*initcode,*initcode+maincode); }
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
|
1993-12-17 21:53:07 +03:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
|
|
|
int vInt;
|
|
|
|
float vFloat;
|
1994-04-15 23:02:04 +04:00
|
|
|
char *pChar;
|
1993-12-17 21:53:07 +03:00
|
|
|
Word vWord;
|
1994-07-20 01:27:18 +04:00
|
|
|
Long vLong;
|
1993-12-17 21:53:07 +03:00
|
|
|
Byte *pByte;
|
1994-11-15 00:40:14 +03:00
|
|
|
TreeNode *pNode;
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
%start functionlist
|
|
|
|
|
1993-12-23 00:19:23 +03:00
|
|
|
%token WRONGTOKEN
|
1993-12-17 21:53:07 +03:00
|
|
|
%token NIL
|
|
|
|
%token IF THEN ELSE ELSEIF WHILE DO REPEAT UNTIL END
|
|
|
|
%token RETURN
|
|
|
|
%token LOCAL
|
1994-08-05 23:31:09 +04:00
|
|
|
%token FUNCTION
|
1993-12-17 21:53:07 +03:00
|
|
|
%token <vFloat> NUMBER
|
1994-11-15 00:40:14 +03:00
|
|
|
%token <vWord> STRING
|
|
|
|
%token <pNode> NAME
|
1993-12-17 21:53:07 +03:00
|
|
|
%token <vInt> DEBUG
|
|
|
|
|
1994-07-20 01:27:18 +04:00
|
|
|
%type <vLong> PrepJump
|
1994-11-02 23:30:53 +03:00
|
|
|
%type <vInt> expr, exprlist, exprlist1, varlist1, funcParams, funcvalue
|
|
|
|
%type <vInt> fieldlist, localdeclist, decinit
|
1994-10-11 16:02:39 +03:00
|
|
|
%type <vInt> ffieldlist1
|
|
|
|
%type <vInt> lfieldlist1
|
|
|
|
%type <vLong> var, singlevar
|
1994-11-15 00:40:14 +03:00
|
|
|
%type <pByte> body
|
1993-12-17 21:53:07 +03:00
|
|
|
|
|
|
|
%left AND OR
|
1994-10-11 16:02:39 +03:00
|
|
|
%left EQ NE '>' '<' LE GE
|
1993-12-17 21:53:07 +03:00
|
|
|
%left CONC
|
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/'
|
|
|
|
%left UNARY NOT
|
1994-10-17 22:05:32 +03:00
|
|
|
%right '^'
|
1993-12-17 21:53:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
%% /* beginning of rules section */
|
|
|
|
|
|
|
|
|
|
|
|
functionlist : /* empty */
|
1994-04-19 23:06:15 +04:00
|
|
|
| functionlist
|
|
|
|
{
|
1994-11-09 21:07:38 +03:00
|
|
|
pc=maincode; basepc=*initcode; maxcurr=maxmain;
|
1994-04-19 23:06:15 +04:00
|
|
|
nlocalvar=0;
|
|
|
|
}
|
|
|
|
stat sc
|
1994-02-13 23:38:20 +03:00
|
|
|
{
|
1994-11-09 21:07:38 +03:00
|
|
|
maincode=pc; *initcode=basepc; maxmain=maxcurr;
|
1994-02-13 23:38:20 +03:00
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
| functionlist function
|
1994-08-05 23:31:09 +04:00
|
|
|
| functionlist method
|
1993-12-17 21:53:07 +03:00
|
|
|
| functionlist setdebug
|
|
|
|
;
|
1994-08-05 23:31:09 +04:00
|
|
|
|
1994-04-15 23:02:04 +04:00
|
|
|
function : FUNCTION NAME
|
1994-08-05 23:31:09 +04:00
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
init_function($2);
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
1994-11-15 00:40:14 +03:00
|
|
|
body
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
Word func = luaI_findsymbol($2);
|
|
|
|
s_tag(func) = LUA_T_FUNCTION;
|
|
|
|
s_bvalue(func) = $4;
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
method : FUNCTION NAME ':' NAME
|
1994-08-05 23:31:09 +04:00
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
init_function($4);
|
|
|
|
localvar[nlocalvar]=luaI_findsymbolbyname("self");
|
1994-08-05 23:31:09 +04:00
|
|
|
add_nlocalvar(1);
|
|
|
|
}
|
1994-11-15 00:40:14 +03:00
|
|
|
body
|
1994-08-05 23:31:09 +04:00
|
|
|
{
|
|
|
|
/* assign function to table field */
|
1994-11-09 21:07:38 +03:00
|
|
|
pc=maincode; basepc=*initcode; maxcurr=maxmain;
|
1994-08-05 23:31:09 +04:00
|
|
|
nlocalvar=0;
|
1994-11-15 00:40:14 +03:00
|
|
|
lua_pushvar(luaI_findsymbol($2)+1);
|
1994-08-05 23:31:09 +04:00
|
|
|
code_byte(PUSHSTRING);
|
1994-11-15 00:40:14 +03:00
|
|
|
code_word(luaI_findconstant($4));
|
1994-08-05 23:31:09 +04:00
|
|
|
code_byte(PUSHFUNCTION);
|
1994-11-15 00:40:14 +03:00
|
|
|
code_code($6);
|
1994-08-05 23:31:09 +04:00
|
|
|
code_byte(STOREINDEXED0);
|
1994-11-09 21:07:38 +03:00
|
|
|
maincode=pc; *initcode=basepc; maxmain=maxcurr;
|
1994-08-05 23:31:09 +04:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
body : '(' parlist ')' block END
|
|
|
|
{
|
|
|
|
codereturn();
|
1994-11-17 21:59:06 +03:00
|
|
|
$$ = newvector(pc, Byte);
|
|
|
|
memcpy($$, basepc, pc*sizeof(Byte));
|
1994-11-15 00:40:14 +03:00
|
|
|
funcCode = basepc; maxcode=maxcurr;
|
1994-11-18 00:11:37 +03:00
|
|
|
#if LISTING
|
|
|
|
PrintCode(funcCode,funcCode+pc);
|
|
|
|
#endif
|
1994-11-15 00:40:14 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1993-12-17 21:53:07 +03:00
|
|
|
statlist : /* empty */
|
|
|
|
| statlist stat sc
|
|
|
|
;
|
|
|
|
|
|
|
|
sc : /* empty */ | ';' ;
|
|
|
|
|
1994-11-17 21:59:06 +03:00
|
|
|
stat : { codedebugline(); } stat1 ;
|
1993-12-17 21:53:07 +03:00
|
|
|
|
1994-11-17 21:59:06 +03:00
|
|
|
cond : { codedebugline(); } expr1 ;
|
|
|
|
|
|
|
|
stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
|
|
|
|
{ codeIf($4, $6); }
|
|
|
|
|
|
|
|
| WHILE {$<vLong>$=pc;} expr1 DO PrepJump block PrepJump END
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
basepc[$5] = IFFJMP;
|
|
|
|
code_word_at(basepc+$5+1, pc - ($5 + sizeof(Word)+1));
|
|
|
|
basepc[$7] = UPJMP;
|
1994-07-20 01:27:18 +04:00
|
|
|
code_word_at(basepc+$7+1, pc - ($<vLong>2));
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
1994-11-17 21:59:06 +03:00
|
|
|
| REPEAT {$<vLong>$=pc;} block UNTIL cond PrepJump
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
basepc[$6] = IFFUPJMP;
|
1994-07-20 01:27:18 +04:00
|
|
|
code_word_at(basepc+$6+1, pc - ($<vLong>2));
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
| varlist1 '=' exprlist1
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
1994-11-02 23:30:53 +03:00
|
|
|
adjust_mult_assign(nvarbuffer, $3, $1 * 2 + nvarbuffer);
|
1993-12-17 21:53:07 +03:00
|
|
|
for (i=nvarbuffer-1; i>=0; i--)
|
|
|
|
lua_codestore (i);
|
|
|
|
if ($1 > 1 || ($1 == 1 && varbuffer[0] != 0))
|
|
|
|
lua_codeadjust (0);
|
|
|
|
}
|
|
|
|
}
|
1994-11-09 21:07:38 +03:00
|
|
|
| functioncall { code_byte(0); }
|
1994-11-17 21:59:06 +03:00
|
|
|
| LOCAL localdeclist decinit
|
1994-11-02 23:30:53 +03:00
|
|
|
{ add_nlocalvar($2);
|
|
|
|
adjust_mult_assign($2, $3, 0);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
elsepart : /* empty */
|
|
|
|
| ELSE block
|
1994-11-17 21:59:06 +03:00
|
|
|
| ELSEIF cond THEN PrepJump block PrepJump elsepart
|
|
|
|
{ codeIf($4, $6); }
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
block : {$<vInt>$ = nlocalvar;} statlist ret
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
if (nlocalvar != $<vInt>1)
|
|
|
|
{
|
|
|
|
nlocalvar = $<vInt>1;
|
|
|
|
lua_codeadjust (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
ret : /* empty */
|
1994-11-17 21:59:06 +03:00
|
|
|
| RETURN { codedebugline(); } exprlist sc
|
|
|
|
{
|
1994-11-02 23:30:53 +03:00
|
|
|
if ($3 < 0) code_byte(MULT_RET);
|
|
|
|
codereturn();
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
PrepJump : /* empty */
|
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
$$ = pc;
|
1993-12-17 21:53:07 +03:00
|
|
|
code_byte(0); /* open space */
|
|
|
|
code_word (0);
|
|
|
|
}
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
expr1 : expr { if ($1 == 0) code_byte(1); }
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-10-17 22:05:32 +03:00
|
|
|
expr : '(' expr ')' { $$ = $2; }
|
1994-11-02 23:30:53 +03:00
|
|
|
| expr1 EQ expr1 { code_byte(EQOP); $$ = 1; }
|
|
|
|
| expr1 '<' expr1 { code_byte(LTOP); $$ = 1; }
|
1994-11-06 18:35:04 +03:00
|
|
|
| expr1 '>' expr1 { code_byte(GTOP); $$ = 1; }
|
1994-11-02 23:30:53 +03:00
|
|
|
| expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; }
|
|
|
|
| expr1 LE expr1 { code_byte(LEOP); $$ = 1; }
|
1994-11-06 18:35:04 +03:00
|
|
|
| expr1 GE expr1 { code_byte(GEOP); $$ = 1; }
|
1994-11-02 23:30:53 +03:00
|
|
|
| expr1 '+' expr1 { code_byte(ADDOP); $$ = 1; }
|
|
|
|
| expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; }
|
|
|
|
| expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; }
|
|
|
|
| expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; }
|
|
|
|
| expr1 '^' expr1 { code_byte(POWOP); $$ = 1; }
|
|
|
|
| expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; }
|
1993-12-17 21:53:07 +03:00
|
|
|
| '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
|
1994-10-11 16:02:39 +03:00
|
|
|
| table { $$ = 1; }
|
1994-10-17 22:05:32 +03:00
|
|
|
| varexp { $$ = 1;}
|
|
|
|
| NUMBER { code_number($1); $$ = 1; }
|
|
|
|
| STRING
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
code_byte(PUSHSTRING);
|
1994-11-15 00:40:14 +03:00
|
|
|
code_word($1);
|
1993-12-17 21:53:07 +03:00
|
|
|
$$ = 1;
|
|
|
|
}
|
1994-11-02 23:30:53 +03:00
|
|
|
| NIL {code_byte(PUSHNIL); $$ = 1; }
|
1994-11-09 21:07:38 +03:00
|
|
|
| functioncall { $$ = 0; }
|
1993-12-17 21:53:07 +03:00
|
|
|
| NOT expr1 { code_byte(NOTOP); $$ = 1;}
|
1994-11-02 23:30:53 +03:00
|
|
|
| expr1 AND PrepJump {code_byte(POP); } expr1
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
basepc[$3] = ONFJMP;
|
|
|
|
code_word_at(basepc+$3+1, pc - ($3 + sizeof(Word)+1));
|
1993-12-17 21:53:07 +03:00
|
|
|
$$ = 1;
|
|
|
|
}
|
1994-11-02 23:30:53 +03:00
|
|
|
| expr1 OR PrepJump {code_byte(POP); } expr1
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-20 20:22:21 +04:00
|
|
|
basepc[$3] = ONTJMP;
|
|
|
|
code_word_at(basepc+$3+1, pc - ($3 + sizeof(Word)+1));
|
1993-12-17 21:53:07 +03:00
|
|
|
$$ = 1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-10-11 16:02:39 +03:00
|
|
|
table :
|
|
|
|
{
|
|
|
|
code_byte(CREATEARRAY);
|
1994-11-01 21:25:20 +03:00
|
|
|
$<vLong>$ = pc; code_word(0);
|
1994-10-11 16:02:39 +03:00
|
|
|
}
|
|
|
|
'{' fieldlist '}'
|
|
|
|
{
|
|
|
|
code_word_at(basepc+$<vLong>1, $3);
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
functioncall : funcvalue funcParams
|
|
|
|
{ code_byte(CALLFUNC); code_byte($1+$2); }
|
1994-10-17 22:05:32 +03:00
|
|
|
;
|
1994-11-02 23:30:53 +03:00
|
|
|
|
|
|
|
funcvalue : varexp { $$ = 0; }
|
1994-10-17 22:05:32 +03:00
|
|
|
| varexp ':' NAME
|
|
|
|
{
|
1994-11-02 23:30:53 +03:00
|
|
|
code_byte(PUSHSELF);
|
1994-12-06 17:27:18 +03:00
|
|
|
code_word(luaI_findconstant($3));
|
1994-11-02 23:30:53 +03:00
|
|
|
$$ = 1;
|
1994-10-17 22:05:32 +03:00
|
|
|
}
|
1994-10-11 16:02:39 +03:00
|
|
|
;
|
1994-11-02 23:30:53 +03:00
|
|
|
|
1994-10-17 22:05:32 +03:00
|
|
|
funcParams : '(' exprlist ')'
|
1994-11-02 23:30:53 +03:00
|
|
|
{ if ($2<0) { code_byte(1); $$ = -$2; } else $$ = $2; }
|
|
|
|
| table { $$ = 1; }
|
1994-10-17 22:05:32 +03:00
|
|
|
;
|
1994-11-02 23:30:53 +03:00
|
|
|
|
|
|
|
exprlist : /* empty */ { $$ = 0; }
|
1993-12-17 21:53:07 +03:00
|
|
|
| exprlist1 { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
exprlist1 : expr { if ($1 == 0) $$ = -1; else $$ = 1; }
|
|
|
|
| exprlist1 ',' { if ($1 < 0) code_byte(1); } expr
|
|
|
|
{
|
|
|
|
int r = $1 < 0 ? -$1 : $1;
|
|
|
|
$$ = ($4 == 0) ? -(r+1) : r+1;
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
parlist : /* empty */ { lua_codeadjust(0); }
|
|
|
|
| parlist1 { lua_codeadjust(0); }
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-04-15 23:02:04 +04:00
|
|
|
parlist1 : NAME
|
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
localvar[nlocalvar]=luaI_findsymbol($1);
|
1994-04-15 23:02:04 +04:00
|
|
|
add_nlocalvar(1);
|
|
|
|
}
|
|
|
|
| parlist1 ',' NAME
|
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
localvar[nlocalvar]=luaI_findsymbol($3);
|
1994-04-15 23:02:04 +04:00
|
|
|
add_nlocalvar(1);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-10-11 16:02:39 +03:00
|
|
|
fieldlist : /* empty */ { $$ = 0; }
|
|
|
|
| lfieldlist1 lastcomma
|
|
|
|
{ $$ = $1; flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); }
|
|
|
|
| ffieldlist1 lastcomma
|
|
|
|
{ $$ = $1; flush_record($1%FIELDS_PER_FLUSH); }
|
|
|
|
| lfieldlist1 ';'
|
|
|
|
{ flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); }
|
|
|
|
ffieldlist1 lastcomma
|
|
|
|
{ $$ = $1+$4; flush_record($4%FIELDS_PER_FLUSH); }
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-10-11 16:02:39 +03:00
|
|
|
lastcomma : /* empty */
|
|
|
|
| ','
|
|
|
|
;
|
1993-12-17 21:53:07 +03:00
|
|
|
|
|
|
|
ffieldlist1 : ffield {$$=1;}
|
1994-02-13 23:38:20 +03:00
|
|
|
| ffieldlist1 ',' ffield
|
|
|
|
{
|
|
|
|
$$=$1+1;
|
|
|
|
if ($$%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
ffield : NAME '=' expr1
|
1994-04-15 23:02:04 +04:00
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
push_field(luaI_findconstant($1));
|
1994-04-15 23:02:04 +04:00
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-02-13 23:38:20 +03:00
|
|
|
lfieldlist1 : expr1 {$$=1;}
|
|
|
|
| lfieldlist1 ',' expr1
|
|
|
|
{
|
|
|
|
$$=$1+1;
|
|
|
|
if ($$%FIELDS_PER_FLUSH == 0)
|
|
|
|
flush_list($$/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
varlist1 : var
|
|
|
|
{
|
|
|
|
nvarbuffer = 0;
|
|
|
|
varbuffer[nvarbuffer] = $1; incr_nvarbuffer();
|
|
|
|
$$ = ($1 == 0) ? 1 : 0;
|
|
|
|
}
|
|
|
|
| varlist1 ',' var
|
|
|
|
{
|
|
|
|
varbuffer[nvarbuffer] = $3; incr_nvarbuffer();
|
|
|
|
$$ = ($3 == 0) ? $1 + 1 : $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
var : singlevar { $$ = $1; }
|
1994-10-17 22:05:32 +03:00
|
|
|
| varexp '[' expr1 ']'
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
$$ = 0; /* indexed variable */
|
|
|
|
}
|
1994-10-17 22:05:32 +03:00
|
|
|
| varexp '.' NAME
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
code_byte(PUSHSTRING);
|
1994-11-15 00:40:14 +03:00
|
|
|
code_word(luaI_findconstant($3));
|
1993-12-17 21:53:07 +03:00
|
|
|
$$ = 0; /* indexed variable */
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1994-08-05 23:31:09 +04:00
|
|
|
singlevar : NAME
|
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
Word s = luaI_findsymbol($1);
|
1994-08-05 23:31:09 +04:00
|
|
|
int local = lua_localname (s);
|
|
|
|
if (local == -1) /* global var */
|
|
|
|
$$ = s + 1; /* return positive value */
|
|
|
|
else
|
|
|
|
$$ = -(local+1); /* return negative value */
|
|
|
|
}
|
|
|
|
;
|
1994-10-17 22:05:32 +03:00
|
|
|
|
|
|
|
varexp : var { lua_pushvar($1); }
|
|
|
|
;
|
1994-08-05 23:31:09 +04:00
|
|
|
|
1994-11-15 00:40:14 +03:00
|
|
|
localdeclist : NAME {localvar[nlocalvar]=luaI_findsymbol($1); $$ = 1;}
|
1994-04-15 23:02:04 +04:00
|
|
|
| localdeclist ',' NAME
|
|
|
|
{
|
1994-11-15 00:40:14 +03:00
|
|
|
localvar[nlocalvar+$1]=luaI_findsymbol($3);
|
1994-04-15 23:02:04 +04:00
|
|
|
$$ = $1+1;
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
1994-11-02 23:30:53 +03:00
|
|
|
decinit : /* empty */ { $$ = 0; }
|
|
|
|
| '=' exprlist1 { $$ = $2; }
|
1993-12-17 21:53:07 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
setdebug : DEBUG {lua_debug = $1;}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
1994-02-13 23:38:20 +03:00
|
|
|
#if LISTING
|
1993-12-17 21:53:07 +03:00
|
|
|
|
1994-04-19 23:06:15 +04:00
|
|
|
static void PrintCode (Byte *code, Byte *end)
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
1994-04-19 23:06:15 +04:00
|
|
|
Byte *p = code;
|
1993-12-17 21:53:07 +03:00
|
|
|
printf ("\n\nCODE\n");
|
1994-02-13 23:38:20 +03:00
|
|
|
while (p != end)
|
1993-12-17 21:53:07 +03:00
|
|
|
{
|
|
|
|
switch ((OpCode)*p)
|
|
|
|
{
|
|
|
|
case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break;
|
|
|
|
case PUSH0: case PUSH1: case PUSH2:
|
|
|
|
printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0');
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case PUSHBYTE:
|
|
|
|
printf ("%d PUSHBYTE %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case PUSHWORD:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d PUSHWORD %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case PUSHFLOAT:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeFloat c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_float(c,p);
|
|
|
|
printf ("%d PUSHFLOAT %f\n", n, c.f);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case PUSHSTRING:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d PUSHSTRING %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
1994-08-05 23:31:09 +04:00
|
|
|
case PUSHFUNCTION:
|
|
|
|
{
|
|
|
|
CodeCode c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_code(c,p);
|
|
|
|
printf ("%d PUSHFUNCTION %p\n", n, c.b);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1993-12-17 21:53:07 +03:00
|
|
|
case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
|
|
|
|
case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
|
|
|
|
case PUSHLOCAL8: case PUSHLOCAL9:
|
|
|
|
printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0');
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case PUSHGLOBAL:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d PUSHGLOBAL %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
|
|
|
|
case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
|
|
|
|
case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
|
|
|
|
case STORELOCAL8: case STORELOCAL9:
|
|
|
|
printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0');
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case STORELOCAL:
|
1994-02-13 23:38:20 +03:00
|
|
|
printf ("%d STORELOCAL %d\n", p-code, *(++p));
|
1993-12-17 21:53:07 +03:00
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case STOREGLOBAL:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d STOREGLOBAL %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
1994-12-06 17:27:18 +03:00
|
|
|
case PUSHSELF:
|
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d PUSHSELF %d\n", n, c.w);
|
|
|
|
}
|
|
|
|
break;
|
1993-12-17 21:53:07 +03:00
|
|
|
case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break;
|
|
|
|
case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
1994-02-13 23:38:20 +03:00
|
|
|
case STORELIST0:
|
|
|
|
printf("%d STORELIST0 %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
case STORELIST:
|
|
|
|
printf("%d STORELIST %d %d\n", p-code, *(p+1), *(p+2));
|
|
|
|
p+=3;
|
|
|
|
break;
|
|
|
|
case STORERECORD:
|
|
|
|
printf("%d STORERECORD %d\n", p-code, *(++p));
|
|
|
|
p += *p*sizeof(Word) + 1;
|
|
|
|
break;
|
1994-11-02 23:30:53 +03:00
|
|
|
case ADJUST0: printf ("%d ADJUST0\n", (p++)-code); break;
|
1993-12-17 21:53:07 +03:00
|
|
|
case ADJUST:
|
|
|
|
printf ("%d ADJUST %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
1994-11-01 21:25:20 +03:00
|
|
|
case CREATEARRAY:
|
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
1994-11-02 23:30:53 +03:00
|
|
|
printf ("%d CREATEARRAY %d\n", n, c.w);
|
1994-11-01 21:25:20 +03:00
|
|
|
break;
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
case EQOP: printf ("%d EQOP\n", (p++)-code); break;
|
|
|
|
case LTOP: printf ("%d LTOP\n", (p++)-code); break;
|
|
|
|
case LEOP: printf ("%d LEOP\n", (p++)-code); break;
|
|
|
|
case ADDOP: printf ("%d ADDOP\n", (p++)-code); break;
|
|
|
|
case SUBOP: printf ("%d SUBOP\n", (p++)-code); break;
|
|
|
|
case MULTOP: printf ("%d MULTOP\n", (p++)-code); break;
|
|
|
|
case DIVOP: printf ("%d DIVOP\n", (p++)-code); break;
|
1994-11-17 22:09:46 +03:00
|
|
|
case POWOP: printf ("%d POWOP\n", (p++)-code); break;
|
1993-12-17 21:53:07 +03:00
|
|
|
case CONCOP: printf ("%d CONCOP\n", (p++)-code); break;
|
|
|
|
case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break;
|
|
|
|
case NOTOP: printf ("%d NOTOP\n", (p++)-code); break;
|
|
|
|
case ONTJMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d ONTJMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case ONFJMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d ONFJMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case JMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d JMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case UPJMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d UPJMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case IFFJMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d IFFJMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case IFFUPJMP:
|
1994-04-14 01:37:20 +04:00
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d IFFUPJMP %d\n", n, c.w);
|
|
|
|
}
|
1993-12-17 21:53:07 +03:00
|
|
|
break;
|
|
|
|
case POP: printf ("%d POP\n", (p++)-code); break;
|
1994-11-02 23:30:53 +03:00
|
|
|
case CALLFUNC:
|
|
|
|
printf ("%d CALLFUNC %d %d\n", p-code, *(p+1), *(p+2));
|
|
|
|
p+=3;
|
|
|
|
break;
|
|
|
|
case RETCODE0: printf ("%d RETCODE0\n", (p++)-code); break;
|
1993-12-17 21:53:07 +03:00
|
|
|
case RETCODE:
|
|
|
|
printf ("%d RETCODE %d\n", p-code, *(++p));
|
|
|
|
p++;
|
|
|
|
break;
|
1994-04-16 01:30:12 +04:00
|
|
|
case SETFUNCTION:
|
|
|
|
{
|
1994-10-17 22:05:32 +03:00
|
|
|
CodeCode c1;
|
1994-11-02 23:30:53 +03:00
|
|
|
CodeWord c2;
|
1994-04-16 01:30:12 +04:00
|
|
|
int n = p-code;
|
|
|
|
p++;
|
1994-10-17 22:05:32 +03:00
|
|
|
get_code(c1,p);
|
1994-04-16 01:30:12 +04:00
|
|
|
get_word(c2,p);
|
1994-10-17 22:05:32 +03:00
|
|
|
printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.b, c2.w);
|
1994-04-16 01:30:12 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SETLINE:
|
|
|
|
{
|
|
|
|
CodeWord c;
|
|
|
|
int n = p-code;
|
|
|
|
p++;
|
|
|
|
get_word(c,p);
|
|
|
|
printf ("%d SETLINE %d\n", n, c.w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-04-19 23:06:15 +04:00
|
|
|
case RESET: printf ("%d RESET\n", (p++)-code); break;
|
1994-04-14 01:37:20 +04:00
|
|
|
default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break;
|
1993-12-17 21:53:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|