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

Append bytes bigger than 0x79 properly #1750

Merged
merged 2 commits into from
Feb 17, 2021
Merged

Append bytes bigger than 0x79 properly #1750

merged 2 commits into from
Feb 17, 2021

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Feb 16, 2021

Close #1749 .

I works, but I am currently thinking how we can handle byte varargs in a more general way, including user-defined functions.

@codecov
Copy link

codecov bot commented Feb 16, 2021

Codecov Report

Merging #1750 (d16ef53) into master (608df7f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1750      +/-   ##
==========================================
+ Coverage   82.52%   82.55%   +0.02%     
==========================================
  Files         272      272              
  Lines       22152    22177      +25     
==========================================
+ Hits        18281    18308      +27     
+ Misses       2745     2744       -1     
+ Partials     1126     1125       -1     
Impacted Files Coverage Δ
pkg/compiler/codegen.go 91.01% <100.00%> (+0.17%) ⬆️
pkg/services/notary/notary.go 94.17% <0.00%> (+1.05%) ⬆️

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 608df7f...d16ef53. Read the comment docs.

@roman-khimov
Copy link
Member

roman-khimov commented Feb 16, 2021

NeoVM lacks opcode for array append

Like APPEND? Edit: I see what you mean now.

emit.Opcodes(c.prog.BinWriter, opcode.APPEND)
if expr.Ellipsis.IsValid() {
ast.Walk(c, expr.Args[1]) // append(x, y...) -> x, y on stack
emit.Opcodes(c.prog.BinWriter, opcode.DUP, opcode.REVERSEITEMS) // POPITEM pops last element
Copy link
Member

Choose a reason for hiding this comment

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

But this will change y.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, inserted conversion to Struct, added test.

Copy link
Member

Choose a reason for hiding this comment

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

REVERSEITEMS is quite costly and now we also CONVERT, maybe it's easier with PICKITEM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

NeoVM encoding for int(0x80) is []byte{0x80, 0x00} and
byte constant can be used both as integer and as an element
of byte-slice. Thus special case needs to be taken in
`append`.
NeoVM lacks opcode for array append, thus some
kind of loop is needed for this.
@roman-khimov roman-khimov merged commit f5767ec into master Feb 17, 2021
@roman-khimov roman-khimov deleted the compiler/append branch February 17, 2021 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Go smart contract compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't correctly append bytes bigger than 0x79
2 participants