Skip to content

Commit

Permalink
Improve func
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed May 22, 2024
1 parent a6b2722 commit 1299b01
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Add BlockId / BlockIdExt python native support in C++, add wrappers
- Allow VmDict initialization from PyDict
- Add `combine_with` in VmDict to fast combine dictionaries
- Add FunC string / sources support (tonpy.func.func)
- Critical change: TLB dump - forced `dump_bin_as_hex` to true. This means if bitsting is `x % 8 == 0` then it'll be
dumped as hex (this is most of use-cases)
- Critical change: Run method in TVM will throw error on unsuccessful exit code
Expand Down
25 changes: 1 addition & 24 deletions src/tonpy/fift/fift.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

from tonpy import Cell
from tonpy.libs.python_ton import PyFift, func_string_to_asm, func_to_asm
from tonpy.libs.python_ton import PyFift
from tonpy.types import Stack

libs_root = Path(__file__).parents[0]
Expand Down Expand Up @@ -48,26 +48,3 @@ def convert_assembler(assembler_code: str) -> Cell:
f.run(assembler_code)
return f.last()


def func_to_assembler(sources: list[str],
preamble: bool = False,
indent: int = 0,
verbosity: bool = False,
optimization: int = 2,
envelope: bool = True,
stack_comments: bool = False,
op_comments: bool = False) -> str:
result = func_to_asm(sources, preamble, indent, verbosity, optimization, envelope, stack_comments, op_comments)
return result


def func_string_to_assembler(source: str,
preamble: bool = False,
indent: int = 0,
verbosity: bool = False,
optimization: int = 2,
envelope: bool = True,
stack_comments: bool = False,
op_comments: bool = False) -> str:
result = func_string_to_asm(source, preamble, indent, verbosity, optimization, envelope, stack_comments, op_comments)
return result
32 changes: 32 additions & 0 deletions src/tonpy/func/func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from tonpy.libs.python_ton import func_string_to_asm, func_to_asm


def func_to_assembler(sources: list[str],
preamble: bool = False,
indent: int = 0,
verbosity: bool = False,
optimization: int = 2,
envelope: bool = True,
stack_comments: bool = False,
op_comments: bool = False,
convert_to_cell: bool = True) -> str:
result = func_to_asm(sources, preamble, indent, verbosity, optimization, envelope, stack_comments, op_comments)
if convert_to_cell:
result = convert_assembler(result)
return result


def func_string_to_assembler(source: str,
preamble: bool = False,
indent: int = 0,
verbosity: bool = False,
optimization: int = 2,
envelope: bool = True,
stack_comments: bool = False,
op_comments: bool = False,
convert_to_cell: bool = True) -> str:
result = func_string_to_asm(source, preamble, indent, verbosity, optimization, envelope, stack_comments,
op_comments)
if convert_to_cell:
result = convert_assembler(result)
return result
10 changes: 4 additions & 6 deletions src/tonpy/tests/test_fift.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os

from tonpy.fift import Fift
from tonpy.fift.fift import (convert_assembler, func_string_to_assembler,
func_to_assembler)
from tonpy.fift.fift import convert_assembler
from tonpy.func.func import *
from tonpy.types.stack import StackEntry


Expand Down Expand Up @@ -50,8 +50,7 @@ def test_func_to_asm():
'test-nft-item/nft-item.fc']
sources = [os.path.join(script_dir, rel_path) for rel_path in relative_sources]

asm = func_to_assembler(sources, preamble=True, stack_comments=True, envelope=True)
cell = convert_assembler(asm)
cell = func_to_assembler(sources, preamble=True, stack_comments=True, envelope=True)
assert cell.get_hash() == "BA4D975D2B66231C1F0A0CCCA6E8FF8F7BA0610C4B7639584B8E98303DC3128C"


Expand All @@ -73,6 +72,5 @@ def test_func_string_to_asm():
throw_unless(104, sdeq(s, "abacaba"));
}
"""
asm = func_string_to_assembler(string)
cell = convert_assembler(asm)
cell = func_string_to_assembler(string)
assert cell.get_hash() == "456F78EC3453CE253D4CD43F27EF9A9811FA300448C9620B28819C919212B6EC"

0 comments on commit 1299b01

Please sign in to comment.