Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locations in dumps of compiled code blocks are off by one #1998

Closed
tsutton opened this issue Apr 2, 2022 · 0 comments
Closed

Locations in dumps of compiled code blocks are off by one #1998

tsutton opened this issue Apr 2, 2022 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@tsutton
Copy link
Contributor

tsutton commented Apr 2, 2022

Describe the bug

When boa is printing a compiled CodeBlock, the locations printed correspond to the location of the wrong instruction (they are the following instruction, not the current instruction)

To Reproduce

// bug.js
if (false){
    1;
} else{
    0;
}

Then run cargo run -- -t bug.js:

...
----------------------Compiled Output: '<main>'-----------------------
Location  Count   Opcode                     Operands

000001    0000    PushFalse
000006    0001    JumpIfFalse                19
000011    0002    PushDeclarativeEnvironment 0
000012    0003    PushOne
000013    0004    Pop
000014    0005    PopEnvironment
000019    0006    Jump                       27
000024    0007    PushDeclarativeEnvironment 0
000025    0008    PushZero
000026    0009    Pop
000027    0010    PopEnvironment
...

Expected behavior
In this output, you can see a few weird things:

  1. The first instruction is at location 1, not 0
  2. The Jump operands don't line up printed Locations - the first JumpIfFalse has operand 19, but the instruction listed at location 19 is another Jump.

Build environment (please complete the following information):

  • OS: Windows
  • Version: 0.14 (on the latest main as of writing)
  • Target triple: x86_64-pc-windows-msvc
  • Rustc version: rustc 1.59.0 (9d1b2106e 2022-02-23)
@tsutton tsutton added the bug Something isn't working label Apr 2, 2022
@tsutton tsutton changed the title Locations in Locations in dumps of compiled code blocks are off by one Apr 2, 2022
@raskad raskad added this to the v0.15.0 milestone Apr 2, 2022
@bors bors bot closed this as completed in 998a7b1 Apr 2, 2022
Razican pushed a commit that referenced this issue Jun 8, 2022
Acked-by: Taylor Sutton <[email protected]>

This Pull Request fixes/closes #1998 

The call to retrieve operands modifies pc, setting it to the index of
the *next* instruction. So, we save its initial value and use that
for printing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants