From 29b35d086b18da5b940b106e596d994fe0255eac Mon Sep 17 00:00:00 2001 From: Andrey Tvorozhkov Date: Tue, 9 Jan 2024 18:34:41 +0300 Subject: [PATCH] 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 a46eb5b2..469871e3 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