File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -323,10 +323,17 @@ and compile_expression env = function
323323 end
324324
325325 | UnwrapPanic input ->
326- let input = compile_expression env input in
327- input @ compile_branch [EVM. DUP 1 ; EVM. ISZERO ]
328- (EVM. pop @ EVM. revert0)
329- [EVM. SLOAD ]
326+ begin match type_of_expression input with
327+ | Optional _ ->
328+ let cond_value = compile_expression env input in
329+ let none_block = EVM. revert0 in
330+ compile_branch cond_value [] none_block
331+ | Response _ ->
332+ let cond_value = compile_expression env input in
333+ let err_block = EVM. pop1 @ EVM. revert0 in
334+ compile_branch cond_value [] err_block
335+ | t -> unsupported_function " unwrap-panic" t
336+ end
330337
331338 | VarGet var ->
332339 let var_slot = lookup_variable_slot env var in
Original file line number Diff line number Diff line change @@ -517,9 +517,30 @@ unwrap-panic:
517517 $ clarc -t opcode -f only-function= test << EOF
518518 > (define-read-only (test) (unwrap-panic none ))
519519 > EOF
520- PUSH1 0x00 DUP1 ISZERO ISZERO PC PUSH1 0x0f ADD JUMPI POP PUSH1 0x00 DUP1
521- REVERT PC PUSH1 0x07 ADD JUMP JUMPDEST SLOAD JUMPDEST PUSH1 0x00 MSTORE
522- PUSH1 0x20 PUSH1 0x00 RETURN STOP
520+ PUSH1 0x00 ISZERO PC PUSH1 0x0a ADD JUMPI PC PUSH1 0x0a ADD JUMP JUMPDEST
521+ PUSH1 0x00 DUP1 REVERT JUMPDEST PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x00
522+ RETURN STOP
523+
524+ $ clarc -t opcode -f only-function= test << EOF
525+ > (define-read-only (test) (unwrap-panic (some 7 )))
526+ > EOF
527+ PUSH1 0x07 PUSH1 0x01 ISZERO PC PUSH1 0x0a ADD JUMPI PC PUSH1 0x0a ADD JUMP
528+ JUMPDEST PUSH1 0x00 DUP1 REVERT JUMPDEST PUSH1 0x00 MSTORE PUSH1 0x20
529+ PUSH1 0x00 RETURN STOP
530+
531+ $ clarc -t opcode -f only-function= test << EOF
532+ > (define-read-only (test) (unwrap-panic (err 7 )))
533+ > EOF
534+ PUSH1 0x07 PUSH1 0x00 ISZERO PC PUSH1 0x0a ADD JUMPI PC PUSH1 0x0b ADD JUMP
535+ JUMPDEST POP PUSH1 0x00 DUP1 REVERT JUMPDEST PUSH1 0x00 MSTORE PUSH1 0x20
536+ PUSH1 0x00 RETURN STOP
537+
538+ $ clarc -t opcode -f only-function= test << EOF
539+ > (define-read-only (test) (unwrap-panic (ok 7 )))
540+ > EOF
541+ PUSH1 0x07 PUSH1 0x01 ISZERO PC PUSH1 0x0a ADD JUMPI PC PUSH1 0x0b ADD JUMP
542+ JUMPDEST POP PUSH1 0x00 DUP1 REVERT JUMPDEST PUSH1 0x00 MSTORE PUSH1 0x20
543+ PUSH1 0x00 RETURN STOP
523544
524545unwrap !:
525546
You can’t perform that action at this time.
0 commit comments