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

Improve the view for VM/Instruction output #1035

Closed
jasonwilliams opened this issue Jan 3, 2021 · 0 comments
Closed

Improve the view for VM/Instruction output #1035

jasonwilliams opened this issue Jan 3, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@jasonwilliams
Copy link
Member

For debugging purposes it would be useful to see what our stack and instructions look like at a particular time.
Our output is quite basic currently.

Running let a = 1; for example with "vm" feature set will give you:
(cargo run --features vm ../tests/js/test.js)

[boa/src/context.rs:761] &compiler = Compiler {
    instructions: [
        DefLet(
            0,
        ),
        One,
        InitLexical(
            0,
        ),
    ],
    pool: [
        String(
            RcString(
                "a",
            ),
        ),
    ],
}

It would be good to get some better output like the below. This would be achieved by adding some output to a buffer for each action take in the match arm here: https://github.com/boa-dev/boa/blob/master/boa/src/vm/mod.rs#L54 then printing the whole buffer when its finished.

The code for doing this should be behind a flag or an argument and not ran by default.

For timing https://doc.rust-lang.org/std/time/struct.Instant.html should do the job.

Example output below

$ cargo run -- --trace
> function fibo(x) { if (x<2) return 1; return fibo(x-1)+fibo(x-2)}
00020m 00000 Return                    <empty>
undefined
> fibo(3)
00009m 00000 PushInt8 3                <empty>
00015m 00002 GetValue 'fibo'           3.0
00066m 00007 Call 1                    Function
--> call function
  module_id:0 func_id:0
00007m 00000 GetValue 'x'              <empty>
00001m 00005 PushInt8 2                3.0
00013m 00007 Lt                        2.0

...

00001m 00007 Lt                        2.0
00000m 00008 JmpIfFalse 00016          true
00000m 00013 PushInt8 1                <empty>
00167m 00015 Return                    1.0
<-- return value(1.0)
  module_id:0 func_id:2
00001m 00052 Add                       1.0
00044m 00053 Return                    3.0
<-- return value(3.0)
  module_id:0 func_id:0
00000m 00012 Return                    3.0
3
> 
   |     |     |                        | 
   |     |     |                        \- value at the top of exec stack
   |     |     \-------------------------- instruction
   |     \-------------------------------- program counter
   \-------------------------------------- execution time per inst. (in microsecs)
@jasonwilliams jasonwilliams added enhancement New feature or request good first issue Good for newcomers labels Jan 3, 2021
@jasonwilliams jasonwilliams self-assigned this Jan 5, 2021
Razican pushed a commit that referenced this issue May 22, 2021
* no more need for dbg!()
* pass -t or --trace for tracing output
* documentation on output
@Razican Razican added this to the v0.12.0 milestone Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants