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 bitwise operations support #208

Merged
merged 4 commits into from
Dec 13, 2021
Merged

Conversation

metoule
Copy link
Contributor

@metoule metoule commented Dec 11, 2021

Add support of the unary bitwise complement operator (~)
Add support of the shift operators (>> and <<)
Fix #206

var target = new Interpreter();
var x = 0b_1100_1001_0000_0000_0000_0000_0001_0001;
target.SetVariable("x", x);

Assert.Equal(~x, target.Eval<uint>("~x"));
Assert.Equal(x >> 4, target.Eval<uint>("x >> 4"));
Assert.Equal(x << 4, target.Eval<uint>("x << 4"));

Added support of the shift operators (>> and <<).
Fix dynamicexpresso#206
@metoule
Copy link
Contributor Author

metoule commented Dec 11, 2021

Note that I didn't add new tokens for the shift operators >> and << because it would prevent the proper parsing of generic type definitions such as List<List<int>>.

Copy link
Member

@davideicardi davideicardi left a comment

Choose a reason for hiding this comment

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

Very good! Just a small comment.

src/DynamicExpresso.Core/Parsing/Parser.cs Outdated Show resolved Hide resolved
@metoule metoule merged commit 23fd9c2 into dynamicexpresso:master Dec 13, 2021
@metoule metoule deleted the fix_206 branch December 13, 2021 09:06
@waclaw66
Copy link

Could you please add directives to unit tests for language versions that do not support it yet?

@metoule
Copy link
Contributor Author

metoule commented Dec 14, 2021

Which language versions don't support it? The tests ran successfully for .NET Framework 4.5 and 4.6.1 and .NET Core 3.1 and 5.0.

@waclaw66
Copy link

obrazek

@metoule
Copy link
Contributor Author

metoule commented Dec 14, 2021

That's really strange - which version of Visual Studio are you using? It should work out of the box from VS2019 onwards.
If you can't upgrade Visual Studio, that's not a huge deal: it's just syntaxic sugar to declare an integer from its binary representation.

You can replace replace that variable declaration with any integer, for example var x = 123, and the test will be the same.

For the other tests,

var a = 0b_1111_1000;
var b = 0b_0001_1100;

can be replaced with

var a = 248;
var b = 28;

Be careful for test Bitwise_operations_uint_int, the variable x must be an unsigned integer var x = 248u.

@metoule
Copy link
Contributor Author

metoule commented Dec 14, 2021

Or you can install VS community edition :)

@waclaw66
Copy link

waclaw66 commented Dec 14, 2021

I use VS2017, that is the problem :D
Problem solved. I just needed to switch to latest minor...

obrazek

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.

Does it support bitwise operations
3 participants