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

VM: Implement variable declaration (var, const, and let) #1030

Merged
merged 7 commits into from
Jan 7, 2021

Conversation

AnnikaCodes
Copy link
Contributor

This Pull Request fixes #1028.

It changes the following:

  • Adds a DefVar VM instruction
  • Includes Context in the function signature of CodeGen::compile
  • Compiles LetDeclLists into DefVar instructions

@codecov
Copy link

codecov bot commented Jan 2, 2021

Codecov Report

Merging #1030 (d8d2c27) into master (1052ccd) will decrease coverage by 0.32%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1030      +/-   ##
==========================================
- Coverage   58.72%   58.39%   -0.33%     
==========================================
  Files         172      172              
  Lines       11728    11861     +133     
==========================================
+ Hits         6887     6926      +39     
- Misses       4841     4935      +94     
Impacted Files Coverage Δ
boa/src/vm/compilation.rs 0.00% <0.00%> (ø)
boa/src/vm/instructions.rs 0.00% <0.00%> (ø)
boa/src/vm/mod.rs 0.00% <0.00%> (ø)
boa/src/builtins/object/mod.rs 62.29% <0.00%> (-5.57%) ⬇️
boa/src/builtins/regexp/mod.rs 67.25% <0.00%> (-2.88%) ⬇️
boa/src/object/mod.rs 51.36% <0.00%> (-0.15%) ⬇️
boa/src/value/display.rs 85.00% <0.00%> (ø)
boa/src/object/internal_methods.rs 62.93% <0.00%> (ø)
boa/src/object/gcobject.rs 67.93% <0.00%> (+0.34%) ⬆️
boa/src/builtins/string/mod.rs 62.80% <0.00%> (+1.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1052ccd...d8d2c27. Read the comment docs.

@AnnikaCodes
Copy link
Contributor Author

I made this support var and const as well.

@AnnikaCodes AnnikaCodes changed the title VM: Implement LetDeclList and the let keyword VM: Implement variable declaration (var, const, and let) Jan 3, 2021

DefVar(usize, usize),
DefLet(usize, usize),
DefConst(usize, usize),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some documentation/comments to these? So others know what the 2 usize arguments are for
As a bonus putting these in some alphabetical order would be nice (but not essential)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even use attributes in a struct-like variant, with names. Would make things much more clear.

boa/src/vm/mod.rs Show resolved Hide resolved
- DefLet doesn't need the value
- InitLexical initializes value if set
@jasonwilliams
Copy link
Member

jasonwilliams commented Jan 3, 2021

let a = 1;

generates

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

@AnnikaCodes if you look at the changes ive made, letDecl now doesn't use run instead it calls compile and that in terms puts One on the stack. We will need to do something similar with Var and Const.

There's optimization that can be done here, we know DefLet will always be a string, so we don't need to convert it back and forth between a Value and a String. It will be converted from a &str to a Value when the instruction is created, then back to a String when we make the binding. We can defer this for now though and look at it at a later date

@Razican Razican added the vm Issues and PRs related to the Boa Virtual Machine. label Jan 6, 2021
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my side, I think a bit of documentation is needed in the definition of the enums. Give it a look, but from the rest, I'm happy with it :)

boa/src/vm/instructions.rs Outdated Show resolved Hide resolved
boa/src/vm/instructions.rs Outdated Show resolved Hide resolved
@Razican Razican requested a review from jasonwilliams January 7, 2021 08:35
Copy link
Member

@jasonwilliams jasonwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep looks good to me.
Thanks for your contribution AnnikaCodes !

@jasonwilliams jasonwilliams merged commit 89419e2 into boa-dev:master Jan 7, 2021
@RageKnify RageKnify added this to the v0.11.0 milestone Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement let declaration list instruction (VM)
4 participants