1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

vm bugfixes

This commit is contained in:
ton 2020-02-28 18:59:47 +04:00
parent e27fb1e09c
commit dd4ac0f440
9 changed files with 107 additions and 30 deletions

View file

@ -85,7 +85,8 @@ library TonUtil // TON Blockchain Fift Library
// ( nanograms -- S )
{ dup abs <# ' # 9 times char . hold #s rot sign #>
nip -trailing0 } : (.GR)
{ (.GR) ."GR$" type space } : .GR
{ (.GR) ."GR$" type } : .GR_
{ .GR_ space } : .GR
// b x -- b' ( serializes a Gram amount )
{ -1 { 1+ 2dup 8 * ufits } until
@ -105,19 +106,49 @@ nip -trailing0 } : (.GR)
' VarUInt32, : val,
' VarUInt32@ : val@
// d k v -- d'
{ <b swap val, b> <s swap rot cc-key-bits idict! not abort"cannot add key-value to CurrencyCollection" } : +ccpair
{ <b swap val, b> <s swap rot cc-key-bits idict!+ not abort"cannot add key-value to CurrencyCollection"
} : +newccpair
{ dup { -rot tuck swap cc-key-bits idict@- { val@ 2swap -rot + } { swap rot } cond +newccpair
} { 2drop } cond
} : +ccpair
dictnew constant cc0 // zero currency collection
// ( v k -- d ) Creates currency collection representing v units of currency k
{ cc0 swap rot +ccpair } : of-cc
{ dictnew { over null? not } { swap uncons -rot unpair +ccpair } while nip } : list>cc
{ dup null? { ."(null) " drop } { val@ . } cond } dup : .maybeVarUInt32 : .val
{ cc-key-bits { swap 32 1<< rmod . ."-> " .val ."; " true } dictforeach drop cr } : .cc
{ dup null? { ."(null)" drop } { val@ ._ } cond } dup : .maybeVarUInt32 : .val
{ swap cc-key-bits { rot { ."+" } if .val ."*$" ._ true true } idictforeach drop } : (.cc)
{ false (.cc) { ."0" } ifnot } : .cc_
{ .cc_ space } : .cc
{ true (.cc) } : .+cc_
{ .+cc_ space } : .+cc
{ cc-key-bits { rot . ."-> " swap .val .val ."; " true } dictdiff drop cr } : show-cc-diff
{ cc-key-bits { val@ swap val@ + val, true } dictmerge } : cc+
{ null swap cc-key-bits { val@ pair swap cons true } dictforeach drop } : cc>list-rev
{ null swap cc-key-bits { val@ pair swap cons true } idictforeach drop } : cc>list-rev
{ cc>list-rev list-reverse } : cc>list
forget val, forget val@ forget .val
// ( S -- x -1 or 0 )
{ (number) dup 2 = { -rot 2drop } if 1 = } : int?
{ int? dup { drop dup 0< { drop false } { true } cond } if } : pos-int?
// ( S -- k v -1 or 0 ) Parses expression <value>*<currency> or <value>*$<currency>
{ dup "*" $pos dup 0< { 2drop false } {
$| dup $len 2 < { 2drop false } {
1 $| nip dup 1 $| swap "$" $= { swap } if drop
int? dup { over 32 fits { 2drop false } ifnot } if
not { drop false } {
swap pos-int? not { drop false } {
true
} cond } cond } cond } cond
} : cc-key-value?
// ( S -- D -1 or 0 ) Parses an extra currency collection
{ dictnew { // S D
swap dup "+" $pos dup 0< { drop null -rot } { $| 1 $| nip -rot } cond
cc-key-value? { +ccpair over null? dup { rot drop true } if } { 2drop false true } cond
} until
} : $>cc?
{ $>cc? not abort"invalid extra currency collection" } : $>cc
{ char } word dup $len { $>cc } { drop dictnew } cond 1 'nop } ::_ CX{
// Libraries
// ( -- D ) New empty library collection
' dictnew : Libs{