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

[6.0] Box.getReg implementation #1015

Merged
merged 2 commits into from
Sep 3, 2024
Merged

[6.0] Box.getReg implementation #1015

merged 2 commits into from
Sep 3, 2024

Conversation

kushti
Copy link
Member

@kushti kushti commented Jun 28, 2024

In this PR, Box.getReg to get register contents by index is implemented

Example:

{
   val x = SELF
   x.getReg[Long](0).get == SELF.value &&
   x.getReg[Coll[(Coll[Byte], Long)]](2).get == SELF.tokens &&
   x.getReg[Int](9).isEmpty
}

close #416

@kushti kushti changed the base branch from v6.0.0 to v6.0-methodcall June 28, 2024 12:13
@kushti kushti added this to the v6.0 milestone Jun 29, 2024
Base automatically changed from v6.0-methodcall to v6.0.0 August 6, 2024 07:14
@kushti kushti requested a review from aslesarenko August 20, 2024 15:05
@@ -367,7 +367,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit {
MInfo(4, BytesWithoutRefMethod),
MInfo(5, IdMethod),
MInfo(6, creationInfoMethod),
MInfo(7, getRegMethod),
MInfo(7, getRegMethodV5),
Copy link
Member

Choose a reason for hiding this comment

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

It is better to version this test as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

FuncValue(
Array((1, SBox)),
OptionGet(ExtractRegisterAs(ValUse(1, SBox), ErgoBox.R0, SOption(SLong)))
),
Copy link
Member

Choose a reason for hiding this comment

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

The idea behind getReg was to have "computable" index, not just constant.
For example the index can come from Context variable and thus the concrete register will not be fixed in the ErgoTree. This will allow code like:
val x = box.getReg[Int](getVar[Int](varId).get).get

So I suggest to add additional test with variable register passed as function argument and have a series of cases in verifyCases.
"{ (x: (Box, Int)) => x._1.getReg[Long](x._2).get }"

Copy link
Member Author

Choose a reason for hiding this comment

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

{ (x: (Box, Int)) => x._1.getReg[Long](x._2).get } is way different from box.getReg[Int](getVar[Int](varId).get).get ,
so I've made a test in BasicOpsSpecification which is checking exactly context variable usage:

{
   val x = SELF.getReg[Long](getVar[Int](1).get).get
   x == SELF.value
}

and so the new test can also be used for reference for people asked for computable index.

@kushti
Copy link
Member Author

kushti commented Sep 1, 2024

@aslesarenko comments addressed, please make another pass!

@kushti kushti requested a review from aslesarenko September 1, 2024 18:21
@kushti kushti merged commit 8e46b69 into v6.0.0 Sep 3, 2024
0 of 4 checks passed
@kushti kushti deleted the i416 branch September 3, 2024 09:52
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.

2 participants