diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-02 17:41:17 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-02 17:41:17 -0200 |
| commit | 27407fc1f5fc4e0d97dadeda5939efa62fe7e380 (patch) | |
| tree | a47a3f41547509627999963896b5ce3c8a335bf7 /lvm.c | |
| parent | 1a17da2ff9dce06a0405f549522a4e08026c3124 (diff) | |
| download | lua-27407fc1f5fc4e0d97dadeda5939efa62fe7e380.tar.gz lua-27407fc1f5fc4e0d97dadeda5939efa62fe7e380.tar.bz2 lua-27407fc1f5fc4e0d97dadeda5939efa62fe7e380.zip | |
new syntax: assignment expressions + better order for opcodes
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 78 |
1 files changed, 46 insertions, 32 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.41 1999/01/25 17:39:28 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.42 1999/02/02 17:57:49 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -330,12 +330,24 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 330 | register int aux = 0; | 330 | register int aux = 0; |
| 331 | switch ((OpCode)*pc++) { | 331 | switch ((OpCode)*pc++) { |
| 332 | 332 | ||
| 333 | case ENDCODE: aux = 1; | ||
| 334 | S->top = S->stack + base; | ||
| 335 | /* goes through */ | ||
| 336 | case RETCODE: | ||
| 337 | if (lua_callhook) | ||
| 338 | luaD_callHook(base, NULL, 1); | ||
| 339 | return base + (aux ? 0 : *pc); | ||
| 340 | |||
| 333 | case PUSHNIL: aux = *pc++; | 341 | case PUSHNIL: aux = *pc++; |
| 334 | do { | 342 | do { |
| 335 | ttype(S->top++) = LUA_T_NIL; | 343 | ttype(S->top++) = LUA_T_NIL; |
| 336 | } while (aux--); | 344 | } while (aux--); |
| 337 | break; | 345 | break; |
| 338 | 346 | ||
| 347 | case POP: aux = *pc++; | ||
| 348 | S->top -= (aux+1); | ||
| 349 | break; | ||
| 350 | |||
| 339 | case PUSHNUMBERW: aux = highbyte(*pc++); | 351 | case PUSHNUMBERW: aux = highbyte(*pc++); |
| 340 | case PUSHNUMBER: aux += *pc++; | 352 | case PUSHNUMBER: aux += *pc++; |
| 341 | ttype(S->top) = LUA_T_NUMBER; | 353 | ttype(S->top) = LUA_T_NUMBER; |
| @@ -343,6 +355,15 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 343 | S->top++; | 355 | S->top++; |
| 344 | break; | 356 | break; |
| 345 | 357 | ||
| 358 | case PUSHCONSTANTW: aux = highbyte(*pc++); | ||
| 359 | case PUSHCONSTANT: aux += *pc++; | ||
| 360 | *S->top++ = consts[aux]; | ||
| 361 | break; | ||
| 362 | |||
| 363 | case PUSHUPVALUE: aux = *pc++; | ||
| 364 | *S->top++ = cl->consts[aux+1]; | ||
| 365 | break; | ||
| 366 | |||
| 346 | case PUSHLOCAL: aux = *pc++; | 367 | case PUSHLOCAL: aux = *pc++; |
| 347 | *S->top++ = *((S->stack+base) + aux); | 368 | *S->top++ = *((S->stack+base) + aux); |
| 348 | break; | 369 | break; |
| @@ -371,28 +392,45 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 371 | break; | 392 | break; |
| 372 | } | 393 | } |
| 373 | 394 | ||
| 374 | case PUSHCONSTANTW: aux = highbyte(*pc++); | 395 | case CREATEARRAYW: aux = highbyte(*pc++); |
| 375 | case PUSHCONSTANT: aux += *pc++; | 396 | case CREATEARRAY: aux += *pc++; |
| 376 | *S->top++ = consts[aux]; | 397 | luaC_checkGC(); |
| 377 | break; | 398 | avalue(S->top) = luaH_new(aux); |
| 378 | 399 | ttype(S->top) = LUA_T_ARRAY; | |
| 379 | case PUSHUPVALUE: aux = *pc++; | 400 | S->top++; |
| 380 | *S->top++ = cl->consts[aux+1]; | ||
| 381 | break; | 401 | break; |
| 382 | 402 | ||
| 383 | case SETLOCAL: aux = *pc++; | 403 | case SETLOCAL: aux = *pc++; |
| 384 | *((S->stack+base) + aux) = *(--S->top); | 404 | *((S->stack+base) + aux) = *(--S->top); |
| 385 | break; | 405 | break; |
| 386 | 406 | ||
| 407 | case SETLOCALDUP: aux = *pc++; | ||
| 408 | *((S->stack+base) + aux) = *(S->top-1); | ||
| 409 | break; | ||
| 410 | |||
| 387 | case SETGLOBALW: aux = highbyte(*pc++); | 411 | case SETGLOBALW: aux = highbyte(*pc++); |
| 388 | case SETGLOBAL: aux += *pc++; | 412 | case SETGLOBAL: aux += *pc++; |
| 389 | luaV_setglobal(tsvalue(&consts[aux])); | 413 | luaV_setglobal(tsvalue(&consts[aux])); |
| 390 | break; | 414 | break; |
| 391 | 415 | ||
| 416 | case SETGLOBALDUPW: aux = highbyte(*pc++); | ||
| 417 | case SETGLOBALDUP: aux += *pc++; | ||
| 418 | *S->top = *(S->top-1); | ||
| 419 | S->top++; | ||
| 420 | luaV_setglobal(tsvalue(&consts[aux])); | ||
| 421 | break; | ||
| 422 | |||
| 392 | case SETTABLE0: | 423 | case SETTABLE0: |
| 393 | luaV_settable(S->top-3, 0); | 424 | luaV_settable(S->top-3, 0); |
| 394 | break; | 425 | break; |
| 395 | 426 | ||
| 427 | case SETTABLEDUP: { | ||
| 428 | TObject temp = *(S->top-1); | ||
| 429 | luaV_settable(S->top-3, 0); | ||
| 430 | *(S->top++) = temp; | ||
| 431 | break; | ||
| 432 | } | ||
| 433 | |||
| 396 | case SETTABLE: | 434 | case SETTABLE: |
| 397 | luaV_settable(S->top-3-(*pc++), 1); | 435 | luaV_settable(S->top-3-(*pc++), 1); |
| 398 | break; | 436 | break; |
| @@ -416,18 +454,6 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 416 | break; | 454 | break; |
| 417 | } | 455 | } |
| 418 | 456 | ||
| 419 | case POP: aux = *pc++; | ||
| 420 | S->top -= (aux+1); | ||
| 421 | break; | ||
| 422 | |||
| 423 | case CREATEARRAYW: aux = highbyte(*pc++); | ||
| 424 | case CREATEARRAY: aux += *pc++; | ||
| 425 | luaC_checkGC(); | ||
| 426 | avalue(S->top) = luaH_new(aux); | ||
| 427 | ttype(S->top) = LUA_T_ARRAY; | ||
| 428 | S->top++; | ||
| 429 | break; | ||
| 430 | |||
| 431 | case NEQOP: aux = 1; | 457 | case NEQOP: aux = 1; |
| 432 | case EQOP: { | 458 | case EQOP: { |
| 433 | int res = luaO_equalObj(S->top-2, S->top-1); | 459 | int res = luaO_equalObj(S->top-2, S->top-1); |
| @@ -579,14 +605,6 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 579 | break; | 605 | break; |
| 580 | } | 606 | } |
| 581 | 607 | ||
| 582 | case ENDCODE: aux = 1; | ||
| 583 | S->top = S->stack + base; | ||
| 584 | /* goes through */ | ||
| 585 | case RETCODE: | ||
| 586 | if (lua_callhook) | ||
| 587 | luaD_callHook(base, NULL, 1); | ||
| 588 | return base + (aux ? 0 : *pc); | ||
| 589 | |||
| 590 | case SETLINEW: aux = highbyte(*pc++); | 608 | case SETLINEW: aux = highbyte(*pc++); |
| 591 | case SETLINE: aux += *pc++; | 609 | case SETLINE: aux += *pc++; |
| 592 | if ((S->stack+base-1)->ttype != LUA_T_LINE) { | 610 | if ((S->stack+base-1)->ttype != LUA_T_LINE) { |
| @@ -600,10 +618,6 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 600 | luaD_lineHook(aux); | 618 | luaD_lineHook(aux); |
| 601 | break; | 619 | break; |
| 602 | 620 | ||
| 603 | #ifdef DEBUG | ||
| 604 | default: | ||
| 605 | LUA_INTERNALERROR("opcode doesn't match"); | ||
| 606 | #endif | ||
| 607 | } | 621 | } |
| 608 | } | 622 | } |
| 609 | } | 623 | } |
