From 29b35d086b18da5b940b106e596d994fe0255eac Mon Sep 17 00:00:00 2001 From: Andrey Tvorozhkov Date: Tue, 9 Jan 2024 18:34:41 +0300 Subject: [PATCH 1/5] Add disasm libs --- crypto/fift/lib/Disasm.fif | 25 +++++++++++++++++++++++-- crypto/fift/words.cpp | 19 +++++++++++++------ crypto/test/fift/disasm-libs.fif | 21 +++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 crypto/test/fift/disasm-libs.fif diff --git a/crypto/fift/lib/Disasm.fif b/crypto/fift/lib/Disasm.fif index a46eb5b27..469871e39 100644 --- a/crypto/fift/lib/Disasm.fif +++ b/crypto/fift/lib/Disasm.fif @@ -6,12 +6,12 @@ variable 'disasm { 'disasm @ execute } : disasm // disassemble a slice // usage: x{74B0} disasm +variable @vmlibs dictnew @vmlibs ! variable @dismode @dismode 0! { rot over @ and rot xor swap ! } : andxor! { -2 0 @dismode andxor! } : stack-disasm // output 's1 s4 XCHG' { -2 1 @dismode andxor! } : std-disasm // output 'XCHG s1, s4' { -3 2 @dismode andxor! } : show-vm-code -{ -3 0 @dismode andxor! } : hide-vm-code { @dismode @ 1 and 0= } : stack-disasm? variable @indent @indent 0! @@ -56,7 +56,28 @@ variable @contX variable @contY variable @cdict { atom>$ type } : .atom { dup first .atom dup count 1 > { space 0 over count 2- { 1+ 2dup [] type .", " } swap times 1+ [] type } { drop } cond } : std-show-op { 0 over count 1- { 1+ 2dup [] type space } swap times drop first .atom } : stk-show-op -{ @dismode @ 2 and { .indent ."// " @curop @ csr. } if } : .curop? + +{ + @curop @ dup 8 u@ + dup 0x88 = { // PUSHREF + drop ref@ cs{true, vm::NoVmOrd(), std::move(cell)}; - if (!cs->is_valid()) { - throw IntError{"deserializing a special cell as ordinary"}; + bool is_special; + td::Ref cs = td::make_ref(vm::load_cell_slice_special(cell, is_special)); + if (!load_special) { + if (is_special) { + throw IntError{"deserializing a special cell as ordinary"}; + } + stack.push(cs); + } else { + stack.push(cs); + stack.push_bool(is_special); } - stack.push(cs); } // cs n -- cs' x @@ -3301,7 +3307,8 @@ void init_words_common(Dictionary& d) { d.def_stack_word("hashu ", std::bind(interpret_cell_hash, _1, true)); d.def_stack_word("hashB ", std::bind(interpret_cell_hash, _1, false)); // cellslice manipulation (read from cells) - d.def_stack_word(" + foo4 PROC:<{ UNPAIR SWAP DIV }> + main PROC:<{ 70 PUSHINT DIV }> +}END>c constant code-1 + +// add lib cell to vmlibs + spec PUSHREF + BLESS + EXECUTE +}>c Date: Wed, 10 Jan 2024 13:04:42 +0300 Subject: [PATCH 2/5] Add disasm for cell with lib support, add PUSHREFSLICE lib disasm support, allow to load lib in PUSHCONT --- crypto/fift/lib/Disasm.fif | 37 ++++++++++++++++++++++---------- crypto/test/fift/disasm-libs.fif | 14 +++++++++--- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/crypto/fift/lib/Disasm.fif b/crypto/fift/lib/Disasm.fif index 469871e39..b3623d009 100644 --- a/crypto/fift/lib/Disasm.fif +++ b/crypto/fift/lib/Disasm.fif @@ -2,11 +2,25 @@ library TVM_Disasm // simple TVM Disassembler "Lists.fif" include +variable @vmlibs dictnew @vmlibs ! +{ 256 u@ dup @vmlibs @ 256 udict@ } : vmlib@ +{ 8 u@+ swap 2 = } : libspecial? + variable 'disasm { 'disasm @ execute } : disasm // disassemble a slice +{ { space 0 over count 2- { 1+ 2dup [] type .", " } swap times 1+ [] type } { drop } cond } : std-show-op { 0 over count 1- { 1+ 2dup [] type space } swap times drop first .atom } : stk-show-op +{ ."// LIB: " swap X. cr ref@ spec PUSHREF - BLESS - EXECUTE }>c spec PUSHREFSLICE +}>c spec disasmc + From 4eb14ed4d09685b9118ea03d66ce121835d463b8 Mon Sep 17 00:00:00 2001 From: Andrey Tvorozhkov Date: Wed, 10 Jan 2024 13:12:00 +0300 Subject: [PATCH 3/5] Fix --- crypto/fift/lib/Disasm.fif | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crypto/fift/lib/Disasm.fif b/crypto/fift/lib/Disasm.fif index b3623d009..0e2faa9c8 100644 --- a/crypto/fift/lib/Disasm.fif +++ b/crypto/fift/lib/Disasm.fif @@ -172,6 +172,4 @@ variable @contX variable @contY variable @cdict { { fetch-one-op } { swap @curop ! adjust-op show-op } while } : disasm-slice { { disasm-slice dup sbitrefs 1- or 0= } { ref@ Date: Wed, 10 Jan 2024 17:10:50 +0600 Subject: [PATCH 4/5] Fix 2drop --- crypto/fift/lib/Disasm.fif | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/fift/lib/Disasm.fif b/crypto/fift/lib/Disasm.fif index 0e2faa9c8..d35c9e504 100644 --- a/crypto/fift/lib/Disasm.fif +++ b/crypto/fift/lib/Disasm.fif @@ -13,7 +13,7 @@ variable 'disasm vmlib@ { ."// LIB: " swap X. cr ref@ <{" cr +indent disasm -indent .indent ."}>" cr true - } swap ' idictforeach ' dictforeach cond drop + } swap ' idictforeach ' dictforeach cond drop -indent .indent ."}" cr } : show-const-dict-op @@ -172,4 +172,4 @@ variable @contX variable @contY variable @cdict { { fetch-one-op } { swap @curop ! adjust-op show-op } while } : disasm-slice { { disasm-slice dup sbitrefs 1- or 0= } { ref@ Date: Wed, 10 Jan 2024 15:47:27 +0300 Subject: [PATCH 5/5] Fix slice in PUSHREFCONT --- crypto/fift/lib/Disasm.fif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/fift/lib/Disasm.fif b/crypto/fift/lib/Disasm.fif index 0e2faa9c8..ae9711b68 100644 --- a/crypto/fift/lib/Disasm.fif +++ b/crypto/fift/lib/Disasm.fif @@ -94,7 +94,7 @@ variable @contX variable @contY variable @cdict dup 7 u@ 0x47 = { 7 u@+ nip 2 u@+ 7 u@+ -rot 3 << swap sr@ } { dup 8 u@ 0x8A = { ref@