| 
									
										
										
										
											2008-02-21 00:13:31 -05:00
										 |  |  | ! Copyright (C) 2005, 2008 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-12-06 01:20:49 -05:00
										 |  |  | USING: accessors kernel math sorting words parser io summary | 
					
						
							|  |  |  | quotations sequences prettyprint continuations effects | 
					
						
							|  |  |  | definitions compiler.units namespaces assocs tools.walker | 
					
						
							|  |  |  | tools.time generic inspector fry ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: tools.annotations | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-05 23:59:31 -04:00
										 |  |  | GENERIC: reset ( word -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: generic reset | 
					
						
							|  |  |  |     [ call-next-method ] | 
					
						
							|  |  |  |     [ subwords [ reset ] each ] bi ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: word reset | 
					
						
							| 
									
										
										
										
											2008-01-05 21:07:13 -05:00
										 |  |  |     dup "unannotated-def" word-prop [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |             dup dup "unannotated-def" word-prop define | 
					
						
							| 
									
										
										
										
											2008-01-05 21:07:13 -05:00
										 |  |  |         ] with-compilation-unit | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |         f "unannotated-def" set-word-prop | 
					
						
							| 
									
										
										
										
											2008-01-05 21:07:13 -05:00
										 |  |  |     ] [ drop ] if ;
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-06 01:20:49 -05:00
										 |  |  | ERROR: cannot-annotate-twice word ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : annotate ( word quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |     over "unannotated-def" word-prop [ | 
					
						
							| 
									
										
										
										
											2008-12-06 01:20:49 -05:00
										 |  |  |         over cannot-annotate-twice | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |     ] when
 | 
					
						
							| 
									
										
										
										
											2008-01-05 21:07:13 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |         over dup def>> "unannotated-def" set-word-prop | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |         [ dup def>> ] dip call define | 
					
						
							| 
									
										
										
										
											2008-01-05 21:07:13 -05:00
										 |  |  |     ] with-compilation-unit ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | : word-inputs ( word -- seq )
 | 
					
						
							| 
									
										
										
										
											2007-11-25 04:35:16 -05:00
										 |  |  |     stack-effect [ | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |         [ datastack ] dip in>> length tail*
 | 
					
						
							| 
									
										
										
										
											2007-11-25 04:35:16 -05:00
										 |  |  |     ] [ | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |         datastack
 | 
					
						
							|  |  |  |     ] if* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : entering ( str -- )
 | 
					
						
							|  |  |  |     "/-- Entering: " write dup .
 | 
					
						
							|  |  |  |     word-inputs stack. | 
					
						
							|  |  |  |     "\\--" print flush ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  | : word-outputs ( word -- seq )
 | 
					
						
							| 
									
										
										
										
											2007-11-25 04:35:16 -05:00
										 |  |  |     stack-effect [ | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |         [ datastack ] dip out>> length tail*
 | 
					
						
							| 
									
										
										
										
											2007-11-25 04:35:16 -05:00
										 |  |  |     ] [ | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |         datastack
 | 
					
						
							|  |  |  |     ] if* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : leaving ( str -- )
 | 
					
						
							|  |  |  |     "/-- Leaving: " write dup .
 | 
					
						
							|  |  |  |     word-outputs stack. | 
					
						
							|  |  |  |      "\\--" print flush ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  | : (watch) ( word def -- def )
 | 
					
						
							|  |  |  |     over '[ _ entering @ _ leaving ] ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : watch ( word -- )
 | 
					
						
							| 
									
										
										
										
											2007-11-25 04:35:16 -05:00
										 |  |  |     dup [ (watch) ] annotate ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  | : (watch-vars) ( word vars quot -- newquot )
 | 
					
						
							| 
									
										
										
										
											2008-09-13 12:12:36 -04:00
										 |  |  |    '[ | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |         "--- Entering: " write _ .
 | 
					
						
							| 
									
										
										
										
											2008-09-13 12:12:36 -04:00
										 |  |  |         "--- Variable values:" print _ [ dup get ] H{ } map>assoc describe | 
					
						
							|  |  |  |         @ | 
					
						
							|  |  |  |     ] ;
 | 
					
						
							| 
									
										
										
										
											2008-02-10 02:38:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : watch-vars ( word vars -- )
 | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |     dupd '[ [ _ _ ] dip (watch-vars) ] annotate ;
 | 
					
						
							| 
									
										
										
										
											2008-02-10 02:38:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-05 23:59:31 -04:00
										 |  |  | GENERIC# annotate-methods 1 ( word quot -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: generic annotate-methods | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |     [ "methods" word-prop values ] dip [ annotate ] curry each ;
 | 
					
						
							| 
									
										
										
										
											2008-04-05 23:59:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: word annotate-methods | 
					
						
							|  |  |  |     annotate ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : breakpoint ( word -- )
 | 
					
						
							| 
									
										
										
										
											2008-04-05 23:59:31 -04:00
										 |  |  |     [ add-breakpoint ] annotate-methods ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-28 21:46:06 -05:00
										 |  |  | : breakpoint-if ( word quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-11-29 01:37:37 -05:00
										 |  |  |     '[ [ _ [ [ break ] when ] ] dip 3append ] annotate-methods ;
 | 
					
						
							| 
									
										
										
										
											2008-12-06 01:20:49 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: word-timing | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-06 02:36:25 -05:00
										 |  |  | word-timing global [ H{ } clone or ] change-at
 | 
					
						
							| 
									
										
										
										
											2008-12-06 01:20:49 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : reset-word-timing ( -- )
 | 
					
						
							|  |  |  |     word-timing get clear-assoc ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (add-timing) ( def word -- def' )
 | 
					
						
							|  |  |  |     '[ _ benchmark _ word-timing get at+ ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : add-timing ( word -- )
 | 
					
						
							|  |  |  |     dup '[ _ (add-timing) ] annotate ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : word-timing. ( -- )
 | 
					
						
							|  |  |  |     word-timing get
 | 
					
						
							|  |  |  |     >alist [ 1000000 /f ] assoc-map sort-values | 
					
						
							|  |  |  |     simple-table. ;
 |