new syntax for function declarations: "function a.x () ... "
new semantics for function declarations: function f () is valid only at run-time.
This commit is contained in:
35
lua.stx
35
lua.stx
@@ -1,6 +1,6 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 3.21 1995/10/17 11:58:41 roberto Exp roberto $";
|
char *rcs_luastx = "$Id: lua.stx,v 3.22 1995/10/25 13:05:51 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -447,10 +447,10 @@ globalstat : stat sc
|
|||||||
|
|
||||||
function : functiontoken NAME body
|
function : functiontoken NAME body
|
||||||
{
|
{
|
||||||
Word func = luaI_findsymbol($2);
|
code_byte(PUSHFUNCTION);
|
||||||
luaI_insertfunction($3); /* may take part in GC */
|
code_code($3);
|
||||||
s_tag(func) = LUA_T_FUNCTION;
|
code_byte(STOREGLOBAL);
|
||||||
lua_table[func].object.value.tf = $3;
|
code_word(luaI_findsymbol($2));
|
||||||
$3->lineDefined = $1;
|
$3->lineDefined = $1;
|
||||||
$3->name1 = $2->ts.str;
|
$3->name1 = $2->ts.str;
|
||||||
$3->name2 = NULL;
|
$3->name2 = NULL;
|
||||||
@@ -458,23 +458,19 @@ function : functiontoken NAME body
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
method : functiontoken NAME ':' NAME
|
method : functiontoken NAME methkind NAME body
|
||||||
{
|
|
||||||
add_localvar(luaI_findsymbolbyname("self"));
|
|
||||||
}
|
|
||||||
body
|
|
||||||
{
|
{
|
||||||
/* assign function to table field */
|
/* assign function to table field */
|
||||||
lua_pushvar(luaI_findsymbol($2)+1);
|
lua_pushvar(luaI_findsymbol($2)+1);
|
||||||
code_byte(PUSHSTRING);
|
code_byte(PUSHSTRING);
|
||||||
code_word(luaI_findconstant($4));
|
code_word(luaI_findconstant($4));
|
||||||
code_byte(PUSHFUNCTION);
|
code_byte(PUSHFUNCTION);
|
||||||
code_code($6);
|
code_code($5);
|
||||||
code_byte(STOREINDEXED0);
|
code_byte(STOREINDEXED0);
|
||||||
$6->lineDefined = $1;
|
$5->lineDefined = $1;
|
||||||
$6->name1 = $4->ts.str;
|
$5->name1 = $4->ts.str;
|
||||||
$6->name2 = $2->ts.str;
|
$5->name2 = $2->ts.str;
|
||||||
$6->fileName = lua_parsedfile;
|
$5->fileName = lua_parsedfile;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -493,6 +489,10 @@ functiontoken : FUNCTION
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
methkind : ':' { add_localvar(luaI_findsymbolbyname("self")); }
|
||||||
|
| '.' /* no self */
|
||||||
|
;
|
||||||
|
|
||||||
body : '(' parlist ')' block END
|
body : '(' parlist ')' block END
|
||||||
{
|
{
|
||||||
codereturn();
|
codereturn();
|
||||||
@@ -581,10 +581,7 @@ PrepJump : /* empty */
|
|||||||
code_word (0);
|
code_word (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
expr1 : expr
|
expr1 : expr { adjust_functioncall($1, 1); }
|
||||||
{
|
|
||||||
adjust_functioncall($1, 1);
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
expr : '(' expr ')' { $$ = $2; }
|
expr : '(' expr ')' { $$ = $2; }
|
||||||
|
|||||||
Reference in New Issue
Block a user