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

Add support for bitwise operators #425

Merged
merged 5 commits into from
Nov 17, 2020

Conversation

bmakuh
Copy link
Contributor

@bmakuh bmakuh commented Nov 12, 2020

Addresses #297

Todo

  • rebase to bring in unboxing operator removal
  • tests

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

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

Yikes, I checked out your branch to see what error you got and it's definitely one of our least helpful errors. That error just means that there's an ambiguity in the grammar.

In this case, it's because ^ is both an infix and a prefix operator (I knew it would be ^ that bit us!). The parser can't tell which you mean whenever you write ^. This also made me realize that unboxing is currently a function bound to the identifier ^. To actually get both to work, we'd need to make it something statement-like which would be a bit out of scope for this PR (and would also be a breaking change), so I think the move is to just leave ^ out for now.

Also, it looks like you just didn't add the new tokens to the lexer:
https://github.com/grain-lang/grain/blob/master/compiler/src/parsing/lexer.mll#L194-L196

Forgetting that one would just give you a regular syntax error, though 🙂

@ospencer
Copy link
Member

But I'm really glad to see this come through! 😄

@phated
Copy link
Member

phated commented Nov 13, 2020

I also previously ran into issues with this operator at #183 - I believe we chatted in the past about just dropping that symbol as the unbox operator. It's also not really needed much anymore since almost all mutable data can be handled with let mut.

I'll try to land a PR tonight that removes that operator as unbox so we can keep it for bitwise operations in this PR!

@bmakuh
Copy link
Contributor Author

bmakuh commented Nov 13, 2020

Thanks for the tips @ospencer and thanks for the unboxing PR @phated! Learning a lot trying to make this work 😅

@bmakuh
Copy link
Contributor Author

bmakuh commented Nov 13, 2020

Are we going to have ambiguity in situations like these for right shift operators?

mut next: Option<Bucket<k, v>>
mut buckets: Array<Option<Bucket<k, v>>>

@ospencer
Copy link
Member

Nope, we shouldn't have to worry about that! Speaking of which, though, we should probably stick to having only one token each for the carets... We would totally run into some issues if there was a token for >>> versus just matching a token for a single > three times.

@phated
Copy link
Member

phated commented Nov 13, 2020

@bmakuh feel free to rebase on master now that I landed the removal of ^ as unbox 🍻

@bmakuh bmakuh changed the title [WIP] add parser support for bitwise operators Add parser support for bitwise operators Nov 16, 2020
@bmakuh bmakuh changed the title Add parser support for bitwise operators Add support for bitwise operators Nov 17, 2020
@bmakuh bmakuh marked this pull request as ready for review November 17, 2020 16:29
@bmakuh
Copy link
Contributor Author

bmakuh commented Nov 17, 2020

@ospencer this should be ready for review now.

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

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

Woohoo! I left one comment about the priorities, but otherwise it looks great! We might want to keep the original names of the bit-shifting operators in Pervasives in addition to the new syntax, since otherwise it'd be a breaking change. I'm going to double check with the core team though.

Excellent work!

compiler/src/parsing/parser.dyp Outdated Show resolved Hide resolved
@ospencer
Copy link
Member

@bmakuh We chatted, and we're just going to have the breaking change. I dropped your fix commit (and thank you for changing it so quickly!) and we're pretty much good to merge.

@ospencer ospencer merged commit 9228e16 into grain-lang:master Nov 17, 2020
ospencer pushed a commit that referenced this pull request Jan 11, 2021
* add bitwise operators to parser.dyp

* add tokens to lexer

* add operator sigils to pervasives

* add tests for bitwise operators

* fix: operator precedence levels
ospencer pushed a commit that referenced this pull request Jan 16, 2021
* add bitwise operators to parser.dyp

* add tokens to lexer

* add operator sigils to pervasives

* add tests for bitwise operators

* fix: operator precedence levels
ospencer pushed a commit that referenced this pull request Jan 16, 2021
* add bitwise operators to parser.dyp

* add tokens to lexer

* add operator sigils to pervasives

* add tests for bitwise operators

* fix: operator precedence levels
ospencer pushed a commit that referenced this pull request Jan 16, 2021
* add bitwise operators to parser.dyp

* add tokens to lexer

* add operator sigils to pervasives

* add tests for bitwise operators

* fix: operator precedence levels
ospencer pushed a commit that referenced this pull request Jan 16, 2021
* add bitwise operators to parser.dyp

* add tokens to lexer

* add operator sigils to pervasives

* add tests for bitwise operators

* fix: operator precedence levels
@github-actions github-actions bot mentioned this pull request Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants