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

feat: new functions in stdlib from stdlib.fc and math.fc #986

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Gusarich
Copy link
Member

Issue

Closes #770.

Checklist

  • I have updated CHANGELOG.md
  • I have documented my contribution in docs/ and made the build locally
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@Gusarich Gusarich added this to the v1.6.0 milestone Oct 25, 2024
Copy link
Member

@novusnota novusnota left a comment

Choose a reason for hiding this comment

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

Sorry for reviewing the draft, I just wanted to keep those notes around :)

int get_original_fwd_fee(int workchain, int fwd_fee) asm(fwd_fee workchain) "GETORIGINALFWDFEE";
int my_storage_due() asm "DUEPAYMENT";

tuple get_fee_cofigs() asm "UNPACKEDCONFIGTUPLE";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tuple get_fee_cofigs() asm "UNPACKEDCONFIGTUPLE";
tuple get_fee_configs() asm "UNPACKEDCONFIGTUPLE";

@@ -440,7 +440,7 @@ builder store_ref(builder b, cell c) asm(c b) "STREF";
;;; Stores `slice` [s] into `builder` [b]
builder store_slice(builder b, slice s) asm "STSLICER";

;;; Stores (serializes) an integer [x] in the range `0..2^120 − 1` into `builder` [b].
;;; Stores (serializes) an integer [x] in the range `0..2^128 − 1` into `builder` [b].
Copy link
Member

Choose a reason for hiding this comment

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

These things keep bubbling up :)

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, again, haha 😆
it's from the copy-pasting the latest stdlib from Core team projects

@@ -645,3 +645,22 @@ builder store_builder(builder to, builder from) asm "STBR";

;;; Retrieves code of smart-contract from c7
cell my_code() asm "MYCODE";

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, it would be handy to visually separate the regular stdlib.fc (from TON monorepo) and the additions you make specifically for Tact's use. Like, ;;; --- Tact-adjusted ---, or something

asm fun pow2(exp: Int): Int { POW2 }

asm fun sgn(x: Int): Int { SGN }
Copy link
Member

Choose a reason for hiding this comment

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

Maybe, name it sign() for it to look less cryptic and be simpler to type

Suggested change
asm fun sgn(x: Int): Int { SGN }
asm fun sign(x: Int): Int { SGN }

asm fun computeSliceDataSize(slice: Slice, maxCells: Int): DataSize { SDATASIZE TRIPLE }

asm fun cellDepth(cell: Cell): Int { CDEPTH }
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be an extension function

Suggested change
asm fun cellDepth(cell: Cell): Int { CDEPTH }
asm extends fun depth(self: Cell): Int { CDEPTH }


asm extends fun sliceLast(self: Slice, len: Int): Slice { SDCUTLAST }

asm fun sliceDepth(slice: Slice): Int { SDEPTH }
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be an extension function

Suggested change
asm fun sliceDepth(slice: Slice): Int { SDEPTH }
asm extends fun depth(self: Slice): Int { SDEPTH }

@@ -48,6 +48,8 @@ asm extends fun refs(self: Builder): Int { BREFS }

asm extends fun bits(self: Builder): Int { BBITS }

asm fun builderDepth(builder: Builder): Int { BDEPTH }
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be an extension function

Suggested change
asm fun builderDepth(builder: Builder): Int { BDEPTH }
asm extends fun depth(self: Builder): Int { BDEPTH }

}

asm fun stringHash(data: Slice): Int { SHA256U }
Copy link
Member

Choose a reason for hiding this comment

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

This one doesn't make much sense, since in Tact String and Slice are considered different types, while the Slice already has the .hash() method which uses the same TVM instruction. And for both that method and this function, the user would have to do explicit conversion theirString.asSlice(), so this function stringHash() is probably redundant and should be removed :)

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.

Port stdlib.fc and mathlib.fc's asm functions to Tact's stdlib
2 participants