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

Convert Bytes type #40

Merged
merged 1 commit into from
Jun 15, 2020
Merged

Convert Bytes type #40

merged 1 commit into from
Jun 15, 2020

Conversation

meevee98
Copy link
Collaborator

  • Implemented conversion of literal bytes
  • Implemented get to bytes indexes. Python's bytes object does not support item assignment
  • Implemented bytes len() method.

@meevee98 meevee98 requested review from melanke and lock9 June 11, 2020 15:30
@meevee98 meevee98 self-assigned this Jun 11, 2020
@ixje
Copy link
Member

ixje commented Jun 11, 2020

I quickly scrolled through the code and I believe we map Python bytes to the VM Buffer stackitem right?

As far as I know the only difference between bytes and bytearray is the former is immutable and the latter is mutable. I believe the equivalent for the VM would be Buffer and ByteString. I don't know if you are aware of this distinction in the NEO VM? Even though they currently still work slightly different, but I'm working on trying to get that resolved in neo-project/neo-vm#332

What do you think? Should bytes map to ByteString and bytearray to Buffer or is there a good reason not to do this?

@meevee98
Copy link
Collaborator Author

meevee98 commented Jun 11, 2020

I was thinking of resolving this difference between bytes and bytearray with the type checking that is made by the compiler. I think the relationship between bytes and bytearray is the same between tuple and list. Both tuple and list are mapped to VM Array, but we are not allowing to change variables typed as tuple aside of reassigning them

The main point to map the bytes to Buffer it's because of the type of values. As far I tested, when you use PICKITEM opcode with VM Buffer the return is an Integer and using the same opcode with a VM ByteString the return is a Buffer. Between these two, the one having the same behavior of Python bytes get is the first.

@ixje
Copy link
Member

ixje commented Jun 11, 2020 via email

@melanke melanke merged commit a12ff4f into development Jun 15, 2020
@lock9 lock9 deleted the convert-bytearray branch August 26, 2020 20:00
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.

None yet

3 participants