From 11fceeaad94cb96cf3e94f7f12f1f69f1bf04caf Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 11 Aug 2023 20:43:09 +0400 Subject: [PATCH] Task 1: adjusted asm try-again trick --- contracts/1.fc | 56 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/contracts/1.fc b/contracts/1.fc index 135e3d8..eff5e90 100644 --- a/contracts/1.fc +++ b/contracts/1.fc @@ -9,26 +9,44 @@ () recv_internal() { } +cell solution(int hash, cell cur) asm """ + // hash cur + DUP HASHCU + s2 PUSH EQUAL + IFJMP:<{ + NIP + }> // hash cur -cell empty_cell() asm " PUSHREF"; + PUSHNULL CONS // hash t + <{ + AGAINBRK: + UNCONS // hash c t + SWAP CTOS // hash t cs + DUP SREFS // hash t cs srefs + REPEAT:<{ // hash t cs + LDREF // hash t ref cs + OVER // hash t ref cs ref + HASHCU // hash t ref cs _16 + s4 PUSH // hash t ref cs _16 hash + EQUAL // hash t ref cs _17 + IFJMP:<{ // hash t ref cs + s1 s3 XCHG + 3 BLKDROP // ref + RETALT + }> // hash t ref cs + s0 s2 XCHG // hash cs ref t + CONS // hash cs t + SWAP // hash t cs + }> + DROP // hash t + }>CONT // hash t + <{ 2DROP + PUSHREF + }>CONT + TRY +"""; ;; testable -(cell) find_branch_by_hash(int hash, cell cur) method_id { - if (cell_hash(cur) == hash) { - return cur; - } - - tuple t = cons(cur, null()); - do { - cell c = t~list_next(); - slice cs = c.begin_parse(); - repeat (cs.slice_refs()) { - cell ref = cs~load_ref(); - if (cell_hash(ref) == hash) { - return ref; - } - t = cons(ref, t); - } - } until t.null?(); - return empty_cell(); +(cell) find_branch_by_hash(int hash, cell tree) method_id { + return solution(hash, cur); }