1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays definitions generic assocs kernel math namespaces
4 sequences strings vectors words quotations io io.files
5 io.pathnames combinators sorting splitting math.parser effects
6 continuations checksums checksums.crc32 vocabs hashtables graphs
7 compiler.units io.encodings.utf8 accessors ;
17 : record-checksum ( lines source-file -- )
18 [ crc32 checksum-lines ] dip (>>checksum) ;
20 : (xref-source) ( source-file -- pathname uses )
22 [ uses>> [ crossref? ] filter ] bi ;
24 : xref-source ( source-file -- )
25 (xref-source) crossref get add-vertex ;
27 : unxref-source ( source-file -- )
28 (xref-source) crossref get remove-vertex ;
31 source-files get [ nip xref-source ] assoc-each ;
33 : record-form ( quot source-file -- )
34 [ quot-uses keys ] dip
35 [ unxref-source ] [ (>>uses) ] [ xref-source ] tri ;
37 : record-definitions ( file -- )
38 new-definitions get >>definitions drop ;
40 : <source-file> ( path -- source-file )
43 <definitions> >>definitions ;
45 ERROR: invalid-source-file-path path ;
47 : source-file ( path -- source-file )
48 dup string? [ invalid-source-file-path ] unless
49 source-files get [ <source-file> ] cache ;
51 : reset-checksums ( -- )
54 utf8 file-lines swap record-checksum
58 M: pathname where string>> 1 2array ;
60 : forget-source ( path -- )
64 [ definitions>> [ keys forget-all ] each ]
67 [ source-files get delete-at ]
71 string>> forget-source ;
73 : rollback-source-file ( file -- )
75 new-definitions get [ assoc-union ] 2map
76 ] change-definitions drop ;
80 TUPLE: source-file-error error file ;
82 : <source-file-error> ( msg -- error )
83 \ source-file-error new
87 : with-source-file ( name quot -- )
88 #! Should be called from inside with-compilation-unit.
92 definitions>> old-definitions set
94 file get rollback-source-file
95 <source-file-error> rethrow