diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-24 16:43:11 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-24 16:43:11 -0300 |
| commit | 0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532 (patch) | |
| tree | 172953fb17b51eabde010564c86e27317f1bcc29 /lvm.c | |
| parent | 3c820d622ec105815b6510015db8f9e6d81a05bc (diff) | |
| download | lua-0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532.tar.gz lua-0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532.tar.bz2 lua-0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532.zip | |
new opcode variants.
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 85 |
1 files changed, 55 insertions, 30 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.3 1997/09/19 21:17:52 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.4 1997/09/22 20:53:20 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 | */ |
| @@ -22,9 +22,9 @@ | |||
| 22 | #include "lvm.h" | 22 | #include "lvm.h" |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | #define get_prevword(pc) (*(pc-2)+(*(pc-1)<<8)) | 25 | #define skip_word(pc) (pc+=2) |
| 26 | #define get_word(pc) (pc+=2, get_prevword(pc)) | 26 | #define get_word(pc) (*(pc)+(*((pc)+1)<<8)) |
| 27 | #define skip_word(pc) {pc+=2;} | 27 | #define next_word(pc) (pc+=2, get_word(pc-2)) |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* Extra stack to run a function: LUA_T_LINE(1), TM calls(2), ... */ | 30 | /* Extra stack to run a function: LUA_T_LINE(1), TM calls(2), ... */ |
| @@ -300,7 +300,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 300 | aux = *pc++; goto pushnumber; | 300 | aux = *pc++; goto pushnumber; |
| 301 | 301 | ||
| 302 | case PUSHWORD: | 302 | case PUSHWORD: |
| 303 | aux = get_word(pc); goto pushnumber; | 303 | aux = next_word(pc); goto pushnumber; |
| 304 | 304 | ||
| 305 | case PUSH0: case PUSH1: case PUSH2: | 305 | case PUSH0: case PUSH1: case PUSH2: |
| 306 | aux -= PUSH0; | 306 | aux -= PUSH0; |
| @@ -323,10 +323,16 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 323 | break; | 323 | break; |
| 324 | 324 | ||
| 325 | case GETGLOBAL: | 325 | case GETGLOBAL: |
| 326 | aux = get_word(pc); goto getglobal; | 326 | aux = next_word(pc); goto getglobal; |
| 327 | 327 | ||
| 328 | case GETGLOBALB: | 328 | case GETGLOBALB: |
| 329 | aux = *pc++; | 329 | aux = *pc++; goto getglobal; |
| 330 | |||
| 331 | case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: | ||
| 332 | case GETGLOBAL3: case GETGLOBAL4: case GETGLOBAL5: | ||
| 333 | case GETGLOBAL6: case GETGLOBAL7: case GETGLOBAL8: | ||
| 334 | case GETGLOBAL9: | ||
| 335 | aux -= GETGLOBAL0; | ||
| 330 | getglobal: | 336 | getglobal: |
| 331 | luaV_getglobal(luaG_findsymbol(tsvalue(&consts[aux]))); | 337 | luaV_getglobal(luaG_findsymbol(tsvalue(&consts[aux]))); |
| 332 | break; | 338 | break; |
| @@ -336,7 +342,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 336 | break; | 342 | break; |
| 337 | 343 | ||
| 338 | case PUSHSELF: | 344 | case PUSHSELF: |
| 339 | aux = get_word(pc); goto pushself; | 345 | aux = next_word(pc); goto pushself; |
| 340 | 346 | ||
| 341 | case PUSHSELFB: | 347 | case PUSHSELFB: |
| 342 | aux = *pc++; | 348 | aux = *pc++; |
| @@ -349,10 +355,16 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 349 | } | 355 | } |
| 350 | 356 | ||
| 351 | case PUSHCONSTANT: | 357 | case PUSHCONSTANT: |
| 352 | aux = get_word(pc); goto pushconstant; | 358 | aux = next_word(pc); goto pushconstant; |
| 353 | 359 | ||
| 354 | case PUSHCONSTANTB: | 360 | case PUSHCONSTANTB: |
| 355 | aux = *pc++; | 361 | aux = *pc++; goto pushconstant; |
| 362 | |||
| 363 | case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: | ||
| 364 | case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: | ||
| 365 | case PUSHCONSTANT6: case PUSHCONSTANT7: case PUSHCONSTANT8: | ||
| 366 | case PUSHCONSTANT9: | ||
| 367 | aux -= PUSHCONSTANT0; | ||
| 356 | pushconstant: | 368 | pushconstant: |
| 357 | *luaD_stack.top++ = consts[aux]; | 369 | *luaD_stack.top++ = consts[aux]; |
| 358 | break; | 370 | break; |
| @@ -360,8 +372,8 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 360 | case PUSHUPVALUE: | 372 | case PUSHUPVALUE: |
| 361 | aux = *pc++; goto pushupvalue; | 373 | aux = *pc++; goto pushupvalue; |
| 362 | 374 | ||
| 363 | case PUSHUPVALUE0: | 375 | case PUSHUPVALUE0: case PUSHUPVALUE1: |
| 364 | aux = 0; | 376 | aux -= PUSHUPVALUE0; |
| 365 | pushupvalue: | 377 | pushupvalue: |
| 366 | *luaD_stack.top++ = cl->consts[aux+1]; | 378 | *luaD_stack.top++ = cl->consts[aux+1]; |
| 367 | break; | 379 | break; |
| @@ -379,7 +391,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 379 | break; | 391 | break; |
| 380 | 392 | ||
| 381 | case SETGLOBAL: | 393 | case SETGLOBAL: |
| 382 | aux = get_word(pc); goto setglobal; | 394 | aux = next_word(pc); goto setglobal; |
| 383 | 395 | ||
| 384 | case SETGLOBALB: | 396 | case SETGLOBALB: |
| 385 | aux = *pc++; | 397 | aux = *pc++; |
| @@ -442,7 +454,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 442 | 454 | ||
| 443 | case CREATEARRAY: | 455 | case CREATEARRAY: |
| 444 | luaC_checkGC(); | 456 | luaC_checkGC(); |
| 445 | avalue(luaD_stack.top) = luaH_new(get_word(pc)); | 457 | avalue(luaD_stack.top) = luaH_new(next_word(pc)); |
| 446 | ttype(luaD_stack.top) = LUA_T_ARRAY; | 458 | ttype(luaD_stack.top) = LUA_T_ARRAY; |
| 447 | luaD_stack.top++; | 459 | luaD_stack.top++; |
| 448 | break; | 460 | break; |
| @@ -554,45 +566,58 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 554 | break; | 566 | break; |
| 555 | 567 | ||
| 556 | case ONTJMP: | 568 | case ONTJMP: |
| 557 | skip_word(pc); | ||
| 558 | if (ttype(luaD_stack.top-1) != LUA_T_NIL) | 569 | if (ttype(luaD_stack.top-1) != LUA_T_NIL) |
| 559 | pc += get_prevword(pc); | 570 | pc += *pc; |
| 560 | else | 571 | else { |
| 572 | pc++; | ||
| 561 | luaD_stack.top--; | 573 | luaD_stack.top--; |
| 574 | } | ||
| 562 | break; | 575 | break; |
| 563 | 576 | ||
| 564 | case ONFJMP: | 577 | case ONFJMP: |
| 565 | skip_word(pc); | ||
| 566 | if (ttype(luaD_stack.top-1) == LUA_T_NIL) | 578 | if (ttype(luaD_stack.top-1) == LUA_T_NIL) |
| 567 | pc += get_prevword(pc); | 579 | pc += *pc; |
| 568 | else | 580 | else { |
| 581 | pc++; | ||
| 569 | luaD_stack.top--; | 582 | luaD_stack.top--; |
| 583 | } | ||
| 570 | break; | 584 | break; |
| 571 | 585 | ||
| 572 | case JMP: | 586 | case JMP: |
| 573 | skip_word(pc); | 587 | pc += get_word(pc); |
| 574 | pc += get_prevword(pc); | 588 | break; |
| 589 | |||
| 590 | case UPJMPB: | ||
| 591 | pc -= *pc; | ||
| 575 | break; | 592 | break; |
| 576 | 593 | ||
| 577 | case UPJMP: | 594 | case UPJMP: |
| 578 | skip_word(pc); | 595 | pc -= get_word(pc); |
| 579 | pc -= get_prevword(pc); | ||
| 580 | break; | 596 | break; |
| 581 | 597 | ||
| 582 | case IFFJMP: | 598 | case IFFJMP: |
| 583 | skip_word(pc); | ||
| 584 | if (ttype(--luaD_stack.top) == LUA_T_NIL) | 599 | if (ttype(--luaD_stack.top) == LUA_T_NIL) |
| 585 | pc += get_prevword(pc); | 600 | pc += get_word(pc); |
| 601 | else | ||
| 602 | skip_word(pc); | ||
| 603 | break; | ||
| 604 | |||
| 605 | case IFFUPJMPB: | ||
| 606 | if (ttype(--luaD_stack.top) == LUA_T_NIL) | ||
| 607 | pc -= *pc; | ||
| 608 | else | ||
| 609 | pc++; | ||
| 586 | break; | 610 | break; |
| 587 | 611 | ||
| 588 | case IFFUPJMP: | 612 | case IFFUPJMP: |
| 589 | skip_word(pc); | ||
| 590 | if (ttype(--luaD_stack.top) == LUA_T_NIL) | 613 | if (ttype(--luaD_stack.top) == LUA_T_NIL) |
| 591 | pc -= get_prevword(pc); | 614 | pc -= get_word(pc); |
| 615 | else | ||
| 616 | skip_word(pc); | ||
| 592 | break; | 617 | break; |
| 593 | 618 | ||
| 594 | case CLOSURE: | 619 | case CLOSURE: |
| 595 | aux = get_word(pc); goto closure; | 620 | aux = next_word(pc); goto closure; |
| 596 | 621 | ||
| 597 | case CLOSUREB: | 622 | case CLOSUREB: |
| 598 | aux = *pc++; | 623 | aux = *pc++; |
| @@ -617,7 +642,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 617 | return (base + ((aux==RETCODE) ? *pc : 0)); | 642 | return (base + ((aux==RETCODE) ? *pc : 0)); |
| 618 | 643 | ||
| 619 | case SETLINE: { | 644 | case SETLINE: { |
| 620 | int line = get_word(pc); | 645 | int line = next_word(pc); |
| 621 | if ((luaD_stack.stack+base-1)->ttype != LUA_T_LINE) { | 646 | if ((luaD_stack.stack+base-1)->ttype != LUA_T_LINE) { |
| 622 | /* open space for LINE value */ | 647 | /* open space for LINE value */ |
| 623 | luaD_openstack((luaD_stack.top-luaD_stack.stack)-base); | 648 | luaD_openstack((luaD_stack.top-luaD_stack.stack)-base); |
