Skip to content

Conversation

@iten-alg
Copy link
Owner

@iten-alg iten-alg commented Aug 6, 2021

This PR adds the remaining typeFuncs (for ==, !=, dup, dup2, select, and setbit)

@iten-alg iten-alg requested a review from jannotti August 6, 2021 17:58
Copy link
Collaborator

@jannotti jannotti left a 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.

Comment on lines 1108 to 1109
topTwo[1] = ops.typeStack[top]
topTwo[0] = ops.typeStack[top]
Copy link
Collaborator

@jannotti jannotti Aug 6, 2021

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.

topTwo[1] = ops.typeStack[top]
topTwo[0] = ops.typeStack[top]
}
return topTwo, oneInt
Copy link
Collaborator

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) {
Copy link
Collaborator

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..."})
Copy link
Collaborator

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}

@iten-alg iten-alg merged commit 71e503a into master Aug 6, 2021
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.

3 participants