From 8bc4b0d741f73109e761e73a7932f8fe47b242d5 Mon Sep 17 00:00:00 2001 From: Waldemar Celes Date: Tue, 27 Dec 1994 18:04:29 -0200 Subject: routines are defined before rules, to allow correct compilation with bison --- lua.stx | 369 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 184 insertions(+), 185 deletions(-) diff --git a/lua.stx b/lua.stx index 5ab2d2cc..2742da2e 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 3.13 1994/12/06 14:27:18 roberto Exp roberto $"; +char *rcs_luastx = "$Id: lua.stx,v 3.14 1994/12/20 21:20:36 roberto Exp celes $"; #include #include @@ -177,6 +177,189 @@ static void code_number (float f) } } +/* +** 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 = 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