-
Notifications
You must be signed in to change notification settings - Fork 0
Type funcs 2 #4
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
Type funcs 2 #4
Conversation
jannotti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good. Just a few comments. Then I'd say make it under a nice branch name and PR it to go-algorand.
data/transactions/logic/assembler.go
Outdated
| topTwo[1] = ops.typeStack[top] | ||
| topTwo[0] = ops.typeStack[top] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do this nicely as return {ops.typeStack[top], ops.typeStack[top]}
A comment like "stackargs should have the same type" would be good.
data/transactions/logic/assembler.go
Outdated
| topTwo[1] = ops.typeStack[top] | ||
| topTwo[0] = ops.typeStack[top] | ||
| } | ||
| return topTwo, oneInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you would not even define topTwo and return with a composite literal here too.
| return topTwo, oneInt | ||
| } | ||
|
|
||
| func typeDup(ops *OpStream, args []string) (StackTypes, StackTypes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar literal handling.
|
|
||
| func TestDupTypeCheck(t *testing.T) { | ||
| t.Parallel() | ||
| testProg(t, "int 1; byte 0x1234; dup; +", AssemblerMaxVersion, expect{4, "+ arg 1..."}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would have failed before (maybe the error changes slightly with the better checking, but stack for + would be {int, bytes, any} which is bad.
Better to try dup and then put a 1 on the stack, and see if + works, so top of stack was {any, int} but is now {byte, int}
This PR adds the remaining typeFuncs (for ==, !=, dup, dup2, select, and setbit)