1 USING: alien fry generalizations io io.ports kernel locals math
2 sequences sequences.private tools.annotations ;
3 IN: tools.annotations.assertions
5 ERROR: invalid-nth-unsafe n seq word ;
7 : check-nth-unsafe ( n seq word -- n seq )
8 2over length >= [ invalid-nth-unsafe ] [ drop ] if ; inline
10 : (assert-nth-unsafe) ( word -- )
11 dup [ swap '[ _ check-nth-unsafe @ ] ] curry annotate ;
13 : assert-nth-unsafe ( -- )
14 \ nth-unsafe (assert-nth-unsafe)
15 \ set-nth-unsafe (assert-nth-unsafe) ;
17 : reset-nth-unsafe ( -- )
19 \ set-nth-unsafe reset ;
21 ERROR: invalid-stream-read-unsafe len buf port word ;
22 ERROR: invalid-stream-read-unsafe-return out-len in-len buf port word ;
24 :: check-stream-read-unsafe-before ( n buf stream word -- n buf stream )
25 buf alien? [ n buf port ] [
27 [ n buf stream word throw-invalid-stream-read-unsafe ]
31 :: check-stream-read-unsafe-after ( count n buf stream word -- count )
33 [ count n buf stream word throw-invalid-stream-read-unsafe-return ]
36 : (assert-stream-read-unsafe) ( word -- )
38 [ check-stream-read-unsafe-before @ ]
39 [ check-stream-read-unsafe-after ] 4 nbi
42 : assert-stream-read-unsafe ( -- )
43 \ stream-read-unsafe (assert-stream-read-unsafe)
44 \ stream-read-partial-unsafe (assert-stream-read-unsafe) ;
46 : reset-stream-read-unsafe ( -- )
47 \ stream-read-unsafe reset
48 \ stream-read-partial-unsafe reset ;