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

Introduce bitwise operators (in a module) #461

Open
masak opened this issue Feb 9, 2019 · 0 comments
Open

Introduce bitwise operators (in a module) #461

masak opened this issue Feb 9, 2019 · 0 comments

Comments

@masak
Copy link
Owner

masak commented Feb 9, 2019

Operators that treat integers as bit sequences could definitely have a place in today's 007, if it weren't for the fact that they aren't so much on the hot path for the inner workings of a compiler tool chain.

My thinking lately though is that they have a place both (a) as opcodes in an eventual runtime/VM, and (b) as user-exposed operators through a language-extending module or two.

Why? Basically three reasons:

  • While they aren't vital for the inner workings of a compiler tool chain, they do tend to be vital on the periphery. Reading and writing from files means dealing with bytes and encoding/decoding. Something like a checksum algorithm will want to take a byte view on things.

  • Ever since I wrote examples/nim-addition.007, I've felt that it's quite silly that we don't have anything neat and low-level to use for bitwise exclusive or. Even if the base language doesn't expose an operator for it, there should be a bytecode opcode that we can just dig down to and use. (It's a rare case of being stuck at too high an abstraction level!)

  • There are a fair amount of optimizations that generate opcodes doing bitwise arithmetic.

There are two possible syntaxes to choose from for all the bitwise operators:

name C-family style Perl 6 style
bitwise negation ~ prefix:<+^>
bitwise and & infix:<+&>
bitwise or | infix:<+|>
bitwise xor ^ infix:<+^>
left shift << infix:«+<»
right shift >> infix:«+>»

In order to make this issue actionable, I'd consider it closed when both of those syntaxes are available through language-extending modules. The runtime/VM opcodes can wait until we have a dedicated runtime.

@masak masak changed the title Introduce binary operators (in a module) Introduce bitwise operators (in a module) Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant