mirror of https://github.com/rusefi/lua.git
power operator (^).
no more contructors (@). methods can be called on indexed variables. fixed debuging information.
This commit is contained in:
parent
e9049cbfc9
commit
424db1db0c
91
lua.stx
91
lua.stx
|
@ -1,6 +1,6 @@
|
||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 2.8 1994/10/11 13:02:39 celes Exp celes $";
|
char *rcs_luastx = "$Id: lua.stx,v 2.9 1994/10/11 14:38:17 celes Exp celes $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -237,11 +237,10 @@ static void init_function (void)
|
||||||
%token <vInt> DEBUG
|
%token <vInt> DEBUG
|
||||||
|
|
||||||
%type <vLong> PrepJump
|
%type <vLong> PrepJump
|
||||||
%type <vInt> expr, exprlist, exprlist1, varlist1
|
%type <vInt> expr, exprlist, exprlist1, varlist1, funcvalue
|
||||||
%type <vInt> fieldlist, localdeclist
|
%type <vInt> fieldlist, localdeclist
|
||||||
%type <vInt> ffieldlist1
|
%type <vInt> ffieldlist1
|
||||||
%type <vInt> lfieldlist1
|
%type <vInt> lfieldlist1
|
||||||
%type <vInt> functionvalue
|
|
||||||
%type <vLong> var, singlevar
|
%type <vLong> var, singlevar
|
||||||
|
|
||||||
|
|
||||||
|
@ -251,6 +250,7 @@ static void init_function (void)
|
||||||
%left '+' '-'
|
%left '+' '-'
|
||||||
%left '*' '/'
|
%left '*' '/'
|
||||||
%left UNARY NOT
|
%left UNARY NOT
|
||||||
|
%right '^'
|
||||||
|
|
||||||
|
|
||||||
%% /* beginning of rules section */
|
%% /* beginning of rules section */
|
||||||
|
@ -322,7 +322,7 @@ method : FUNCTION NAME { $<vWord>$ = lua_findsymbol($2); } ':' NAME
|
||||||
if (lua_debug)
|
if (lua_debug)
|
||||||
{
|
{
|
||||||
code_byte(SETFUNCTION);
|
code_byte(SETFUNCTION);
|
||||||
code_word(lua_nfile-1);
|
code_code((Byte *)lua_file[lua_nfile-1]);
|
||||||
code_word($<vWord>6);
|
code_word($<vWord>6);
|
||||||
}
|
}
|
||||||
lua_codeadjust (0);
|
lua_codeadjust (0);
|
||||||
|
@ -425,7 +425,6 @@ stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| functioncall { lua_codeadjust (0); }
|
| functioncall { lua_codeadjust (0); }
|
||||||
| constructor { lua_codeadjust (0); }
|
|
||||||
| LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
|
| LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -480,8 +479,8 @@ PrepJump : /* empty */
|
||||||
expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
|
expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
|
||||||
;
|
;
|
||||||
|
|
||||||
expr : '(' expr ')' { $$ = $2; }
|
expr : '(' expr ')' { $$ = $2; }
|
||||||
| expr1 EQ expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
|
| expr1 EQ expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
|
| expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
| expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
||||||
| expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
| expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
||||||
|
@ -491,14 +490,14 @@ expr : '(' expr ')' { $$ = $2; }
|
||||||
| expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;}
|
| expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;}
|
| expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;}
|
| expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;}
|
||||||
|
| expr1 '^' expr1 { code_byte(POWOP); $$ = 1; ntemp--;}
|
||||||
| expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
|
| expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
|
||||||
| '+' expr1 %prec UNARY { $$ = 1; }
|
| '+' expr1 %prec UNARY { $$ = 1; }
|
||||||
| '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
|
| '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
|
||||||
| constructor { $$ = 0; }
|
|
||||||
| table { $$ = 1; }
|
| table { $$ = 1; }
|
||||||
| var { lua_pushvar ($1); $$ = 1;}
|
| varexp { $$ = 1;}
|
||||||
| NUMBER { code_number($1); $$ = 1; }
|
| NUMBER { code_number($1); $$ = 1; }
|
||||||
| STRING
|
| STRING
|
||||||
{
|
{
|
||||||
code_byte(PUSHSTRING);
|
code_byte(PUSHSTRING);
|
||||||
code_word(lua_findconstant($1));
|
code_word(lua_findconstant($1));
|
||||||
|
@ -506,7 +505,7 @@ expr : '(' expr ')' { $$ = $2; }
|
||||||
incr_ntemp();
|
incr_ntemp();
|
||||||
}
|
}
|
||||||
| NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();}
|
| NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();}
|
||||||
| functioncall
|
| functioncall
|
||||||
{
|
{
|
||||||
$$ = 0;
|
$$ = 0;
|
||||||
if (lua_debug)
|
if (lua_debug)
|
||||||
|
@ -529,21 +528,6 @@ expr : '(' expr ')' { $$ = $2; }
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
constructor : '@' singlevar table
|
|
||||||
{
|
|
||||||
lua_pushvar ($2);
|
|
||||||
code_byte(PUSHMARK);
|
|
||||||
incr_ntemp();
|
|
||||||
code_byte(PUSHOBJECT);
|
|
||||||
incr_ntemp();
|
|
||||||
code_byte(CALLFUNC);
|
|
||||||
ntemp -= 4;
|
|
||||||
if (lua_debug)
|
|
||||||
{
|
|
||||||
code_byte(SETLINE); code_word(lua_linenumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
;
|
|
||||||
table :
|
table :
|
||||||
{
|
{
|
||||||
code_byte(PUSHWORD);
|
code_byte(PUSHWORD);
|
||||||
|
@ -557,25 +541,25 @@ table :
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
functioncall : functionvalue
|
functioncall : funcvalue funcParams { code_byte(CALLFUNC); ntemp = $1-1; }
|
||||||
{
|
|
||||||
code_byte(PUSHMARK); $<vInt>$ = ntemp; incr_ntemp();
|
|
||||||
if ($1 != 0) lua_pushvar($1);
|
|
||||||
}
|
|
||||||
'(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;}
|
|
||||||
;
|
;
|
||||||
|
funcvalue : varexp
|
||||||
functionvalue : var {lua_pushvar ($1); $$ = 0; }
|
{
|
||||||
| singlevar ':' NAME
|
$$ = ntemp; code_byte(PUSHMARK); incr_ntemp();
|
||||||
{
|
}
|
||||||
$$ = $1;
|
| varexp ':' NAME
|
||||||
lua_pushvar($1);
|
{
|
||||||
code_byte(PUSHSTRING);
|
code_byte(PUSHSTRING);
|
||||||
code_word(lua_findconstant($3));
|
code_word(lua_findconstant($3));
|
||||||
incr_ntemp();
|
incr_ntemp();
|
||||||
lua_pushvar(0);
|
$$ = ntemp-1;
|
||||||
}
|
code_byte(PUSHMARKMET);
|
||||||
;
|
incr_ntemp();
|
||||||
|
}
|
||||||
|
;
|
||||||
|
funcParams : '(' exprlist ')'
|
||||||
|
| table
|
||||||
|
;
|
||||||
|
|
||||||
exprlist : /* empty */ { $$ = 1; }
|
exprlist : /* empty */ { $$ = 1; }
|
||||||
| exprlist1 { $$ = $1; }
|
| exprlist1 { $$ = $1; }
|
||||||
|
@ -654,14 +638,14 @@ varlist1 : var
|
||||||
;
|
;
|
||||||
|
|
||||||
var : singlevar { $$ = $1; }
|
var : singlevar { $$ = $1; }
|
||||||
| var {lua_pushvar ($1);} '[' expr1 ']'
|
| varexp '[' expr1 ']'
|
||||||
{
|
{
|
||||||
$$ = 0; /* indexed variable */
|
$$ = 0; /* indexed variable */
|
||||||
}
|
}
|
||||||
| var {lua_pushvar ($1);} '.' NAME
|
| varexp '.' NAME
|
||||||
{
|
{
|
||||||
code_byte(PUSHSTRING);
|
code_byte(PUSHSTRING);
|
||||||
code_word(lua_findconstant($4)); incr_ntemp();
|
code_word(lua_findconstant($3)); incr_ntemp();
|
||||||
$$ = 0; /* indexed variable */
|
$$ = 0; /* indexed variable */
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -676,6 +660,9 @@ singlevar : NAME
|
||||||
$$ = -(local+1); /* return negative value */
|
$$ = -(local+1); /* return negative value */
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
varexp : var { lua_pushvar($1); }
|
||||||
|
;
|
||||||
|
|
||||||
localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;}
|
localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;}
|
||||||
| localdeclist ',' NAME
|
| localdeclist ',' NAME
|
||||||
|
@ -894,7 +881,6 @@ static void PrintCode (Byte *code, Byte *end)
|
||||||
break;
|
break;
|
||||||
case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
|
case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
|
||||||
case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break;
|
case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break;
|
||||||
case PUSHOBJECT: printf ("%d PUSHOBJECT\n", (p++)-code); break;
|
|
||||||
case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
|
case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
|
||||||
case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
|
case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
|
||||||
case STORELOCAL8: case STORELOCAL9:
|
case STORELOCAL8: case STORELOCAL9:
|
||||||
|
@ -1008,12 +994,13 @@ static void PrintCode (Byte *code, Byte *end)
|
||||||
case HALT: printf ("%d HALT\n", (p++)-code); break;
|
case HALT: printf ("%d HALT\n", (p++)-code); break;
|
||||||
case SETFUNCTION:
|
case SETFUNCTION:
|
||||||
{
|
{
|
||||||
CodeWord c1, c2;
|
CodeCode c1;
|
||||||
|
CodeWord c1;
|
||||||
int n = p-code;
|
int n = p-code;
|
||||||
p++;
|
p++;
|
||||||
get_word(c1,p);
|
get_code(c1,p);
|
||||||
get_word(c2,p);
|
get_word(c2,p);
|
||||||
printf ("%d SETFUNCTION %d %d\n", n, c1.w, c2.w);
|
printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.b, c2.w);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETLINE:
|
case SETLINE:
|
||||||
|
|
Loading…
Reference in New Issue