diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-28 18:07:32 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-28 18:07:32 -0300 |
| commit | 9863223fbf512d903a1677c861e4beb4f8feda4d (patch) | |
| tree | 964f1b36a5a7c9aff238d454fa4bffe88dacbe2d | |
| parent | 9a1948e67d940d988260e738f2a251087835a318 (diff) | |
| download | lua-9863223fbf512d903a1677c861e4beb4f8feda4d.tar.gz lua-9863223fbf512d903a1677c861e4beb4f8feda4d.tar.bz2 lua-9863223fbf512d903a1677c861e4beb4f8feda4d.zip | |
first version of vararg facility (plus new function "call").
| -rw-r--r-- | inout.c | 63 | ||||
| -rw-r--r-- | inout.h | 3 | ||||
| -rw-r--r-- | lex.c | 10 | ||||
| -rw-r--r-- | lua.stx | 81 | ||||
| -rw-r--r-- | opcode.c | 140 | ||||
| -rw-r--r-- | opcode.h | 32 | ||||
| -rw-r--r-- | table.c | 3 |
7 files changed, 217 insertions, 115 deletions
| @@ -5,7 +5,7 @@ | |||
| 5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | char *rcs_inout="$Id: inout.c,v 2.35 1996/03/19 16:50:24 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.36 1996/03/19 22:28:37 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | 11 | ||
| @@ -93,6 +93,17 @@ void lua_closestring (void) | |||
| 93 | { | 93 | { |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | |||
| 97 | static void check_arg (int cond, char *func) | ||
| 98 | { | ||
| 99 | if (!cond) | ||
| 100 | { | ||
| 101 | char buff[100]; | ||
| 102 | sprintf(buff, "incorrect argument to function `%s'", func); | ||
| 103 | lua_error(buff); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 96 | 107 | ||
| 97 | /* | 108 | /* |
| 98 | ** Internal function: do a string | 109 | ** Internal function: do a string |
| @@ -230,8 +241,7 @@ void luaI_setglobal (void) | |||
| 230 | { | 241 | { |
| 231 | lua_Object name = lua_getparam(1); | 242 | lua_Object name = lua_getparam(1); |
| 232 | lua_Object value = lua_getparam(2); | 243 | lua_Object value = lua_getparam(2); |
| 233 | if (!lua_isstring(name)) | 244 | check_arg(lua_isstring(name), "setglobal"); |
| 234 | lua_error("incorrect argument to function `setglobal'"); | ||
| 235 | lua_pushobject(value); | 245 | lua_pushobject(value); |
| 236 | lua_storeglobal(lua_getstring(name)); | 246 | lua_storeglobal(lua_getstring(name)); |
| 237 | lua_pushobject(value); /* return given value */ | 247 | lua_pushobject(value); /* return given value */ |
| @@ -240,7 +250,50 @@ void luaI_setglobal (void) | |||
| 240 | void luaI_getglobal (void) | 250 | void luaI_getglobal (void) |
| 241 | { | 251 | { |
| 242 | lua_Object name = lua_getparam(1); | 252 | lua_Object name = lua_getparam(1); |
| 243 | if (!lua_isstring(name)) | 253 | check_arg(lua_isstring(name), "getglobal"); |
| 244 | lua_error("incorrect argument to function `getglobal'"); | ||
| 245 | lua_pushobject(lua_getglobal(lua_getstring(name))); | 254 | lua_pushobject(lua_getglobal(lua_getstring(name))); |
| 246 | } | 255 | } |
| 256 | |||
| 257 | #define MAXPARAMS 256 | ||
| 258 | void luaI_call (void) | ||
| 259 | { | ||
| 260 | lua_Object f = lua_getparam(1); | ||
| 261 | lua_Object arg = lua_getparam(2); | ||
| 262 | lua_Object temp, params[MAXPARAMS]; | ||
| 263 | int narg, i; | ||
| 264 | check_arg(lua_istable(arg), "call"); | ||
| 265 | check_arg(lua_isfunction(f), "call"); | ||
| 266 | /* narg = arg.n */ | ||
| 267 | lua_pushobject(arg); | ||
| 268 | lua_pushstring("n"); | ||
| 269 | temp = lua_getsubscript(); | ||
| 270 | narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1; | ||
| 271 | /* read arg[1...n] */ | ||
| 272 | for (i=0; i<narg; i++) | ||
| 273 | { | ||
| 274 | if (i>=MAXPARAMS) | ||
| 275 | lua_error("argument list too long in function `call'"); | ||
| 276 | lua_pushobject(arg); | ||
| 277 | lua_pushnumber(i+1); | ||
| 278 | params[i] = lua_getsubscript(); | ||
| 279 | if (narg == MAXPARAMS+1 && lua_isnil(params[i])) | ||
| 280 | { | ||
| 281 | narg = i; | ||
| 282 | break; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | /* push parameters and do the call */ | ||
| 286 | for (i=0; i<narg; i++) | ||
| 287 | lua_pushobject(params[i]); | ||
| 288 | if (lua_callfunction(f)) | ||
| 289 | { /* error */ | ||
| 290 | lua_error(NULL); | ||
| 291 | } | ||
| 292 | else | ||
| 293 | { /* push results */ | ||
| 294 | Object r; | ||
| 295 | arg = lua_getresult(1); | ||
| 296 | luaI_packarg((arg == LUA_NOOBJECT)?NULL:luaI_Address(arg), &r); | ||
| 297 | luaI_pushobject(&r); | ||
| 298 | } | ||
| 299 | } | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: inout.h,v 1.14 1996/03/15 13:13:13 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.15 1996/03/15 18:21:58 roberto Exp roberto $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | 5 | ||
| @@ -29,5 +29,6 @@ void luaI_error (void); | |||
| 29 | void luaI_assert (void); | 29 | void luaI_assert (void); |
| 30 | void luaI_setglobal (void); | 30 | void luaI_setglobal (void); |
| 31 | void luaI_getglobal (void); | 31 | void luaI_getglobal (void); |
| 32 | void luaI_call (void); | ||
| 32 | 33 | ||
| 33 | #endif | 34 | #endif |
| @@ -1,4 +1,4 @@ | |||
| 1 | char *rcs_lex = "$Id: lex.c,v 2.31 1996/03/19 16:50:24 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.32 1996/03/21 16:33:47 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | #include <ctype.h> | 4 | #include <ctype.h> |
| @@ -280,7 +280,13 @@ int luaY_lex (void) | |||
| 280 | if (current == '.') | 280 | if (current == '.') |
| 281 | { | 281 | { |
| 282 | save_and_next(); | 282 | save_and_next(); |
| 283 | return CONC; | 283 | if (current == '.') |
| 284 | { | ||
| 285 | save_and_next(); | ||
| 286 | return DOTS; /* ... */ | ||
| 287 | } | ||
| 288 | else | ||
| 289 | return CONC; /* .. */ | ||
| 284 | } | 290 | } |
| 285 | else if (!isdigit(current)) return '.'; | 291 | else if (!isdigit(current)) return '.'; |
| 286 | /* current is a digit: goes through to number */ | 292 | /* current is a digit: goes through to number */ |
| @@ -1,9 +1,10 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | 2 | ||
| 3 | char *rcs_luastx = "$Id: lua.stx,v 3.35 1996/03/08 12:02:37 roberto Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.36 1996/03/21 16:31:32 roberto Exp roberto $"; |
| 4 | 4 | ||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 7 | #include <string.h> | ||
| 7 | 8 | ||
| 8 | #include "luadebug.h" | 9 | #include "luadebug.h" |
| 9 | #include "mem.h" | 10 | #include "mem.h" |
| @@ -67,49 +68,45 @@ static void yyerror (char *s) | |||
| 67 | lua_error (msg); | 68 | lua_error (msg); |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 71 | static void check_space (int i) | ||
| 72 | { | ||
| 73 | if (pc+i>maxcurr-1) /* 1 byte free to code HALT of main code */ | ||
| 74 | maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT); | ||
| 75 | } | ||
| 76 | |||
| 70 | static void code_byte (Byte c) | 77 | static void code_byte (Byte c) |
| 71 | { | 78 | { |
| 72 | if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ | 79 | check_space(1); |
| 73 | maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT); | ||
| 74 | basepc[pc++] = c; | 80 | basepc[pc++] = c; |
| 75 | } | 81 | } |
| 76 | 82 | ||
| 77 | static void code_word (Word n) | 83 | static void code_word (Word n) |
| 78 | { | 84 | { |
| 79 | CodeWord code; | 85 | check_space(sizeof(Word)); |
| 80 | code.w = n; | 86 | memcpy(basepc+pc, &n, sizeof(Word)); |
| 81 | code_byte(code.m.c1); | 87 | pc += sizeof(Word); |
| 82 | code_byte(code.m.c2); | ||
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | static void code_float (float n) | 90 | static void code_float (real n) |
| 86 | { | 91 | { |
| 87 | CodeFloat code; | 92 | check_space(sizeof(real)); |
| 88 | code.f = n; | 93 | memcpy(basepc+pc, &n, sizeof(real)); |
| 89 | code_byte(code.m.c1); | 94 | pc += sizeof(real); |
| 90 | code_byte(code.m.c2); | ||
| 91 | code_byte(code.m.c3); | ||
| 92 | code_byte(code.m.c4); | ||
| 93 | } | 95 | } |
| 94 | 96 | ||
| 95 | static void code_code (TFunc *tf) | 97 | static void code_code (TFunc *tf) |
| 96 | { | 98 | { |
| 97 | CodeCode code; | 99 | check_space(sizeof(TFunc *)); |
| 98 | code.tf = tf; | 100 | memcpy(basepc+pc, &tf, sizeof(TFunc *)); |
| 99 | code_byte(code.m.c1); | 101 | pc += sizeof(TFunc *); |
| 100 | code_byte(code.m.c2); | ||
| 101 | code_byte(code.m.c3); | ||
| 102 | code_byte(code.m.c4); | ||
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | static void code_word_at (Byte *p, int n) | 104 | static void code_word_at (Byte *p, int n) |
| 106 | { | 105 | { |
| 107 | CodeWord code; | 106 | Word w = n; |
| 108 | if ((Word)n != n) | 107 | if (w != n) |
| 109 | yyerror("block too big"); | 108 | yyerror("block too big"); |
| 110 | code.w = (Word)n; | 109 | memcpy(p, &w, sizeof(Word)); |
| 111 | *p++ = code.m.c1; | ||
| 112 | *p++ = code.m.c2; | ||
| 113 | } | 110 | } |
| 114 | 111 | ||
| 115 | static void push_field (Word name) | 112 | static void push_field (Word name) |
| @@ -322,6 +319,19 @@ static void adjust_mult_assign (int vars, Long exps, int temps) | |||
| 322 | lua_codeadjust(temps); | 319 | lua_codeadjust(temps); |
| 323 | } | 320 | } |
| 324 | 321 | ||
| 322 | static int close_parlist (int dots) | ||
| 323 | { | ||
| 324 | if (!dots) | ||
| 325 | lua_codeadjust(0); | ||
| 326 | else | ||
| 327 | { | ||
| 328 | code_byte(VARARGS); | ||
| 329 | code_byte(nlocalvar); | ||
| 330 | add_localvar(luaI_createfixedstring("arg")); | ||
| 331 | } | ||
| 332 | return lua_linenumber; | ||
| 333 | } | ||
| 334 | |||
| 325 | static void storesinglevar (Long v) | 335 | static void storesinglevar (Long v) |
| 326 | { | 336 | { |
| 327 | if (v > 0) /* global var */ | 337 | if (v > 0) /* global var */ |
| @@ -426,6 +436,7 @@ void lua_parse (TFunc *tf) | |||
| 426 | %token RETURN | 436 | %token RETURN |
| 427 | %token LOCAL | 437 | %token LOCAL |
| 428 | %token FUNCTION | 438 | %token FUNCTION |
| 439 | %token DOTS | ||
| 429 | %token <vFloat> NUMBER | 440 | %token <vFloat> NUMBER |
| 430 | %token <vWord> STRING | 441 | %token <vWord> STRING |
| 431 | %token <pTStr> NAME | 442 | %token <pTStr> NAME |
| @@ -440,7 +451,7 @@ void lua_parse (TFunc *tf) | |||
| 440 | %type <vInt> fieldlist, localdeclist, decinit | 451 | %type <vInt> fieldlist, localdeclist, decinit |
| 441 | %type <vInt> ffieldlist, ffieldlist1, semicolonpart | 452 | %type <vInt> ffieldlist, ffieldlist1, semicolonpart |
| 442 | %type <vInt> lfieldlist, lfieldlist1 | 453 | %type <vInt> lfieldlist, lfieldlist1 |
| 443 | %type <vInt> parlist | 454 | %type <vInt> parlist, parlist1, par |
| 444 | %type <vLong> var, singlevar, funcname | 455 | %type <vLong> var, singlevar, funcname |
| 445 | %type <pFunc> body | 456 | %type <pFunc> body |
| 446 | 457 | ||
| @@ -674,13 +685,21 @@ exprlist1 : expr { if ($1 != 0) $$ = $1; else $$ = -1; } | |||
| 674 | } | 685 | } |
| 675 | ; | 686 | ; |
| 676 | 687 | ||
| 677 | parlist : /* empty */ { lua_codeadjust(0); $$ = lua_linenumber; } | 688 | parlist : /* empty */ { $$ = close_parlist(0); } |
| 678 | | parlist1 { lua_codeadjust(0); $$ = lua_linenumber; } | 689 | | parlist1 { $$ = close_parlist($1); } |
| 679 | ; | 690 | ; |
| 680 | 691 | ||
| 681 | parlist1 : NAME { add_localvar($1); } | 692 | parlist1 : par { $$ = $1; } |
| 682 | | parlist1 ',' NAME { add_localvar($3); } | 693 | | parlist1 ',' par |
| 694 | { | ||
| 695 | if ($1) | ||
| 696 | lua_error("invalid parameter list"); | ||
| 697 | $$ = $3; | ||
| 698 | } | ||
| 683 | ; | 699 | ; |
| 700 | |||
| 701 | par : NAME { add_localvar($1); $$ = 0; } | ||
| 702 | | DOTS { $$ = 1; } | ||
| 684 | 703 | ||
| 685 | fieldlist : lfieldlist | 704 | fieldlist : lfieldlist |
| 686 | { flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); } | 705 | { flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); } |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 3.67 1996/04/22 18:00:37 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.68 1996/04/25 14:10:00 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -117,7 +117,7 @@ static void growstack (void) | |||
| 117 | */ | 117 | */ |
| 118 | static char *lua_strconc (char *l, char *r) | 118 | static char *lua_strconc (char *l, char *r) |
| 119 | { | 119 | { |
| 120 | int nl = strlen(l); | 120 | size_t nl = strlen(l); |
| 121 | char *buffer = luaI_buffer(nl+strlen(r)+1); | 121 | char *buffer = luaI_buffer(nl+strlen(r)+1); |
| 122 | strcpy(buffer, l); | 122 | strcpy(buffer, l); |
| 123 | strcpy(buffer+nl, r); | 123 | strcpy(buffer+nl, r); |
| @@ -886,6 +886,40 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, | |||
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | 888 | ||
| 889 | void luaI_packarg (Object *firstelem, Object *arg) | ||
| 890 | { | ||
| 891 | int nvararg = (firstelem != NULL) ? top-firstelem : 0; | ||
| 892 | int i; | ||
| 893 | if (nvararg < 0) nvararg = 0; | ||
| 894 | avalue(arg) = lua_createarray(nvararg+1); /* +1 for field 'n' */ | ||
| 895 | tag(arg) = LUA_T_ARRAY; | ||
| 896 | for (i=0; i<nvararg; i++) | ||
| 897 | { | ||
| 898 | Object index; | ||
| 899 | tag(&index) = LUA_T_NUMBER; | ||
| 900 | nvalue(&index) = i+1; | ||
| 901 | *(lua_hashdefine(avalue(arg), &index)) = *(firstelem+i); | ||
| 902 | } | ||
| 903 | /* store counter in field "n" */ | ||
| 904 | { | ||
| 905 | Object index, extra; | ||
| 906 | tag(&index) = LUA_T_STRING; | ||
| 907 | tsvalue(&index) = lua_createstring("n"); | ||
| 908 | tag(&extra) = LUA_T_NUMBER; | ||
| 909 | nvalue(&extra) = nvararg; | ||
| 910 | *(lua_hashdefine(avalue(arg), &index)) = extra; | ||
| 911 | } | ||
| 912 | } | ||
| 913 | |||
| 914 | |||
| 915 | static void adjust_varargs (StkId first_extra_arg) | ||
| 916 | { | ||
| 917 | Object arg; | ||
| 918 | luaI_packarg(stack+first_extra_arg, &arg); | ||
| 919 | adjust_top(first_extra_arg); | ||
| 920 | *top = arg; incr_top; | ||
| 921 | } | ||
| 922 | |||
| 889 | 923 | ||
| 890 | /* | 924 | /* |
| 891 | ** Execute the given opcode, until a RET. Parameters are between | 925 | ** Execute the given opcode, until a RET. Parameters are between |
| @@ -914,38 +948,38 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 914 | 948 | ||
| 915 | case PUSHWORD: | 949 | case PUSHWORD: |
| 916 | { | 950 | { |
| 917 | CodeWord code; | 951 | Word w; |
| 918 | get_word(code,pc); | 952 | get_word(w,pc); |
| 919 | tag(top) = LUA_T_NUMBER; nvalue(top) = code.w; | 953 | tag(top) = LUA_T_NUMBER; nvalue(top) = w; |
| 920 | incr_top; | 954 | incr_top; |
| 921 | } | 955 | } |
| 922 | break; | 956 | break; |
| 923 | 957 | ||
| 924 | case PUSHFLOAT: | 958 | case PUSHFLOAT: |
| 925 | { | 959 | { |
| 926 | CodeFloat code; | 960 | real num; |
| 927 | get_float(code,pc); | 961 | get_float(num,pc); |
| 928 | tag(top) = LUA_T_NUMBER; nvalue(top) = code.f; | 962 | tag(top) = LUA_T_NUMBER; nvalue(top) = num; |
| 929 | incr_top; | 963 | incr_top; |
| 930 | } | 964 | } |
| 931 | break; | 965 | break; |
| 932 | 966 | ||
| 933 | case PUSHSTRING: | 967 | case PUSHSTRING: |
| 934 | { | 968 | { |
| 935 | CodeWord code; | 969 | Word w; |
| 936 | get_word(code,pc); | 970 | get_word(w,pc); |
| 937 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w]; | 971 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; |
| 938 | incr_top; | 972 | incr_top; |
| 939 | } | 973 | } |
| 940 | break; | 974 | break; |
| 941 | 975 | ||
| 942 | case PUSHFUNCTION: | 976 | case PUSHFUNCTION: |
| 943 | { | 977 | { |
| 944 | CodeCode code; | 978 | TFunc *f; |
| 945 | get_code(code,pc); | 979 | get_code(f,pc); |
| 946 | luaI_insertfunction(code.tf); /* may take part in GC */ | 980 | luaI_insertfunction(f); /* may take part in GC */ |
| 947 | top->tag = LUA_T_FUNCTION; | 981 | top->tag = LUA_T_FUNCTION; |
| 948 | top->value.tf = code.tf; | 982 | top->value.tf = f; |
| 949 | incr_top; | 983 | incr_top; |
| 950 | } | 984 | } |
| 951 | break; | 985 | break; |
| @@ -960,9 +994,9 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 960 | 994 | ||
| 961 | case PUSHGLOBAL: | 995 | case PUSHGLOBAL: |
| 962 | { | 996 | { |
| 963 | CodeWord code; | 997 | Word w; |
| 964 | get_word(code,pc); | 998 | get_word(w,pc); |
| 965 | getglobal(code.w); | 999 | getglobal(w); |
| 966 | } | 1000 | } |
| 967 | break; | 1001 | break; |
| 968 | 1002 | ||
| @@ -973,9 +1007,9 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 973 | case PUSHSELF: | 1007 | case PUSHSELF: |
| 974 | { | 1008 | { |
| 975 | Object receiver = *(top-1); | 1009 | Object receiver = *(top-1); |
| 976 | CodeWord code; | 1010 | Word w; |
| 977 | get_word(code,pc); | 1011 | get_word(w,pc); |
| 978 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w]; | 1012 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; |
| 979 | incr_top; | 1013 | incr_top; |
| 980 | pushsubscript(); | 1014 | pushsubscript(); |
| 981 | *top = receiver; | 1015 | *top = receiver; |
| @@ -994,9 +1028,9 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 994 | 1028 | ||
| 995 | case STOREGLOBAL: | 1029 | case STOREGLOBAL: |
| 996 | { | 1030 | { |
| 997 | CodeWord code; | 1031 | Word w; |
| 998 | get_word(code,pc); | 1032 | get_word(w,pc); |
| 999 | s_object(code.w) = *(--top); | 1033 | s_object(w) = *(--top); |
| 1000 | } | 1034 | } |
| 1001 | break; | 1035 | break; |
| 1002 | 1036 | ||
| @@ -1050,9 +1084,9 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1050 | Object *arr = top-n-1; | 1084 | Object *arr = top-n-1; |
| 1051 | while (n) | 1085 | while (n) |
| 1052 | { | 1086 | { |
| 1053 | CodeWord code; | 1087 | Word w; |
| 1054 | get_word(code,pc); | 1088 | get_word(w,pc); |
| 1055 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w]; | 1089 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; |
| 1056 | *(lua_hashdefine (avalue(arr), top)) = *(top-1); | 1090 | *(lua_hashdefine (avalue(arr), top)) = *(top-1); |
| 1057 | top--; | 1091 | top--; |
| 1058 | n--; | 1092 | n--; |
| @@ -1068,11 +1102,15 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1068 | adjust_top(base + *(pc++)); | 1102 | adjust_top(base + *(pc++)); |
| 1069 | break; | 1103 | break; |
| 1070 | 1104 | ||
| 1105 | case VARARGS: | ||
| 1106 | adjust_varargs(base + *(pc++)); | ||
| 1107 | break; | ||
| 1108 | |||
| 1071 | case CREATEARRAY: | 1109 | case CREATEARRAY: |
| 1072 | { | 1110 | { |
| 1073 | CodeWord size; | 1111 | Word size; |
| 1074 | get_word(size,pc); | 1112 | get_word(size,pc); |
| 1075 | avalue(top) = lua_createarray(size.w); | 1113 | avalue(top) = lua_createarray(size); |
| 1076 | tag(top) = LUA_T_ARRAY; | 1114 | tag(top) = LUA_T_ARRAY; |
| 1077 | incr_top; | 1115 | incr_top; |
| 1078 | } | 1116 | } |
| @@ -1195,51 +1233,51 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1195 | 1233 | ||
| 1196 | case ONTJMP: | 1234 | case ONTJMP: |
| 1197 | { | 1235 | { |
| 1198 | CodeWord code; | 1236 | Word w; |
| 1199 | get_word(code,pc); | 1237 | get_word(w,pc); |
| 1200 | if (tag(top-1) != LUA_T_NIL) pc += code.w; | 1238 | if (tag(top-1) != LUA_T_NIL) pc += w; |
| 1201 | } | 1239 | } |
| 1202 | break; | 1240 | break; |
| 1203 | 1241 | ||
| 1204 | case ONFJMP: | 1242 | case ONFJMP: |
| 1205 | { | 1243 | { |
| 1206 | CodeWord code; | 1244 | Word w; |
| 1207 | get_word(code,pc); | 1245 | get_word(w,pc); |
| 1208 | if (tag(top-1) == LUA_T_NIL) pc += code.w; | 1246 | if (tag(top-1) == LUA_T_NIL) pc += w; |
| 1209 | } | 1247 | } |
| 1210 | break; | 1248 | break; |
| 1211 | 1249 | ||
| 1212 | case JMP: | 1250 | case JMP: |
| 1213 | { | 1251 | { |
| 1214 | CodeWord code; | 1252 | Word w; |
| 1215 | get_word(code,pc); | 1253 | get_word(w,pc); |
| 1216 | pc += code.w; | 1254 | pc += w; |
| 1217 | } | 1255 | } |
| 1218 | break; | 1256 | break; |
| 1219 | 1257 | ||
| 1220 | case UPJMP: | 1258 | case UPJMP: |
| 1221 | { | 1259 | { |
| 1222 | CodeWord code; | 1260 | Word w; |
| 1223 | get_word(code,pc); | 1261 | get_word(w,pc); |
| 1224 | pc -= code.w; | 1262 | pc -= w; |
| 1225 | } | 1263 | } |
| 1226 | break; | 1264 | break; |
| 1227 | 1265 | ||
| 1228 | case IFFJMP: | 1266 | case IFFJMP: |
| 1229 | { | 1267 | { |
| 1230 | CodeWord code; | 1268 | Word w; |
| 1231 | get_word(code,pc); | 1269 | get_word(w,pc); |
| 1232 | top--; | 1270 | top--; |
| 1233 | if (tag(top) == LUA_T_NIL) pc += code.w; | 1271 | if (tag(top) == LUA_T_NIL) pc += w; |
| 1234 | } | 1272 | } |
| 1235 | break; | 1273 | break; |
| 1236 | 1274 | ||
| 1237 | case IFFUPJMP: | 1275 | case IFFUPJMP: |
| 1238 | { | 1276 | { |
| 1239 | CodeWord code; | 1277 | Word w; |
| 1240 | get_word(code,pc); | 1278 | get_word(w,pc); |
| 1241 | top--; | 1279 | top--; |
| 1242 | if (tag(top) == LUA_T_NIL) pc -= code.w; | 1280 | if (tag(top) == LUA_T_NIL) pc -= w; |
| 1243 | } | 1281 | } |
| 1244 | break; | 1282 | break; |
| 1245 | 1283 | ||
| @@ -1262,8 +1300,8 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1262 | 1300 | ||
| 1263 | case SETLINE: | 1301 | case SETLINE: |
| 1264 | { | 1302 | { |
| 1265 | CodeWord code; | 1303 | Word line; |
| 1266 | get_word(code,pc); | 1304 | get_word(line,pc); |
| 1267 | if ((stack+base-1)->tag != LUA_T_LINE) | 1305 | if ((stack+base-1)->tag != LUA_T_LINE) |
| 1268 | { | 1306 | { |
| 1269 | /* open space for LINE value */ | 1307 | /* open space for LINE value */ |
| @@ -1271,9 +1309,9 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1271 | base++; | 1309 | base++; |
| 1272 | (stack+base-1)->tag = LUA_T_LINE; | 1310 | (stack+base-1)->tag = LUA_T_LINE; |
| 1273 | } | 1311 | } |
| 1274 | (stack+base-1)->value.i = code.w; | 1312 | (stack+base-1)->value.i = line; |
| 1275 | if (lua_linehook) | 1313 | if (lua_linehook) |
| 1276 | lineHook (code.w); | 1314 | lineHook (line); |
| 1277 | break; | 1315 | break; |
| 1278 | } | 1316 | } |
| 1279 | 1317 | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
| 3 | ** $Id: opcode.h,v 3.19 1996/03/06 13:11:23 roberto Exp $ | 3 | ** $Id: opcode.h,v 3.20 1996/03/15 13:13:13 roberto Exp roberto $ |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
| @@ -65,7 +65,8 @@ typedef enum | |||
| 65 | CALLFUNC, | 65 | CALLFUNC, |
| 66 | RETCODE0, | 66 | RETCODE0, |
| 67 | RETCODE, | 67 | RETCODE, |
| 68 | SETLINE | 68 | SETLINE, |
| 69 | VARARGS | ||
| 69 | } OpCode; | 70 | } OpCode; |
| 70 | 71 | ||
| 71 | #define MULT_RET 255 | 72 | #define MULT_RET 255 |
| @@ -107,28 +108,10 @@ typedef struct Object | |||
| 107 | #define s_fvalue(i) (fvalue(&s_object(i))) | 108 | #define s_fvalue(i) (fvalue(&s_object(i))) |
| 108 | #define s_uvalue(i) (uvalue(&s_object(i))) | 109 | #define s_uvalue(i) (uvalue(&s_object(i))) |
| 109 | 110 | ||
| 110 | typedef union | 111 | #define get_word(code,pc) {memcpy(&code, pc, sizeof(Word)); pc+=sizeof(Word);} |
| 111 | { | 112 | #define get_float(code,pc){memcpy(&code, pc, sizeof(real)); pc+=sizeof(real);} |
| 112 | struct {Byte c1; Byte c2;} m; | 113 | #define get_code(code,pc) {memcpy(&code, pc, sizeof(TFunc *)); \ |
| 113 | Word w; | 114 | pc+=sizeof(TFunc *);} |
| 114 | } CodeWord; | ||
| 115 | #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;} | ||
| 116 | |||
| 117 | typedef union | ||
| 118 | { | ||
| 119 | struct {Byte c1; Byte c2; Byte c3; Byte c4;} m; | ||
| 120 | float f; | ||
| 121 | } CodeFloat; | ||
| 122 | #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ | ||
| 123 | code.m.c3 = *pc++; code.m.c4 = *pc++;} | ||
| 124 | |||
| 125 | typedef union | ||
| 126 | { | ||
| 127 | struct {Byte c1; Byte c2; Byte c3; Byte c4;} m; | ||
| 128 | TFunc *tf; | ||
| 129 | } CodeCode; | ||
| 130 | #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ | ||
| 131 | code.m.c3 = *pc++; code.m.c4 = *pc++;} | ||
| 132 | 115 | ||
| 133 | 116 | ||
| 134 | /* Exported functions */ | 117 | /* Exported functions */ |
| @@ -139,5 +122,6 @@ Object *luaI_Address (lua_Object o); | |||
| 139 | void luaI_pushobject (Object *o); | 122 | void luaI_pushobject (Object *o); |
| 140 | void luaI_gcFB (Object *o); | 123 | void luaI_gcFB (Object *o); |
| 141 | int luaI_dorun (TFunc *tf); | 124 | int luaI_dorun (TFunc *tf); |
| 125 | void luaI_packarg (Object *firstelem, Object *arg); | ||
| 142 | 126 | ||
| 143 | #endif | 127 | #endif |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.53 1996/04/29 18:53:53 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.54 1996/05/06 14:29:35 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include "mem.h" | 8 | #include "mem.h" |
| 9 | #include "opcode.h" | 9 | #include "opcode.h" |
| @@ -39,6 +39,7 @@ static struct { | |||
| 39 | lua_CFunction func; | 39 | lua_CFunction func; |
| 40 | } int_funcs[] = { | 40 | } int_funcs[] = { |
| 41 | {"assert", luaI_assert}, | 41 | {"assert", luaI_assert}, |
| 42 | {"call", luaI_call}, | ||
| 42 | {"dofile", lua_internaldofile}, | 43 | {"dofile", lua_internaldofile}, |
| 43 | {"dostring", lua_internaldostring}, | 44 | {"dostring", lua_internaldostring}, |
| 44 | {"error", luaI_error}, | 45 | {"error", luaI_error}, |
