| 
									
										
										
										
											2011-10-18 18:13:02 -04:00
										 |  |  | USING: alien fry generalizations io io.ports kernel locals math | 
					
						
							|  |  |  | sequences sequences.private tools.annotations ;
 | 
					
						
							|  |  |  | IN: tools.annotations.assertions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ERROR: invalid-nth-unsafe n seq word ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-nth-unsafe ( n seq word -- n seq )
 | 
					
						
							|  |  |  |     2over length >= [ invalid-nth-unsafe ] [ drop ] if ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (assert-nth-unsafe) ( word -- )
 | 
					
						
							|  |  |  |     dup [ swap '[ _ check-nth-unsafe @ ] ] curry annotate ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : assert-nth-unsafe ( -- )
 | 
					
						
							|  |  |  |     \ nth-unsafe (assert-nth-unsafe) | 
					
						
							|  |  |  |     \ set-nth-unsafe (assert-nth-unsafe) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : reset-nth-unsafe ( -- )
 | 
					
						
							|  |  |  |     \ nth-unsafe reset | 
					
						
							|  |  |  |     \ set-nth-unsafe reset ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ERROR: invalid-stream-read-unsafe len buf port word ;
 | 
					
						
							|  |  |  | ERROR: invalid-stream-read-unsafe-return out-len in-len buf port word ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :: check-stream-read-unsafe-before ( n buf stream word -- n buf stream )
 | 
					
						
							|  |  |  |     buf alien? [ n buf port ] [ | 
					
						
							|  |  |  |         n buf byte-length >
 | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |         [ n buf stream word invalid-stream-read-unsafe ] | 
					
						
							| 
									
										
										
										
											2011-10-18 18:13:02 -04:00
										 |  |  |         [ n buf stream ] if
 | 
					
						
							|  |  |  |     ] if ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :: check-stream-read-unsafe-after ( count n buf stream word -- count )
 | 
					
						
							|  |  |  |     count n >
 | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |     [ count n buf stream word invalid-stream-read-unsafe-return ] | 
					
						
							| 
									
										
										
										
											2011-10-18 18:13:02 -04:00
										 |  |  |     [ count ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (assert-stream-read-unsafe) ( word -- )
 | 
					
						
							|  |  |  |     dup [ swap '[ _ | 
					
						
							|  |  |  |         [ check-stream-read-unsafe-before @ ] | 
					
						
							|  |  |  |         [ check-stream-read-unsafe-after ] 4 nbi | 
					
						
							|  |  |  |     ] ] curry annotate ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : assert-stream-read-unsafe ( -- )
 | 
					
						
							|  |  |  |     \ stream-read-unsafe (assert-stream-read-unsafe) | 
					
						
							|  |  |  |     \ stream-read-partial-unsafe (assert-stream-read-unsafe) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : reset-stream-read-unsafe ( -- )
 | 
					
						
							|  |  |  |     \ stream-read-unsafe reset | 
					
						
							|  |  |  |     \ stream-read-partial-unsafe reset ;
 |