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 -- )
38 : record-definitions ( file -- )
39 new-definitions get >>definitions drop ;
41 : <source-file> ( path -- source-file )
44 <definitions> >>definitions ;
46 ERROR: invalid-source-file-path path ;
48 : source-file ( path -- source-file )
49 dup string? [ invalid-source-file-path ] unless
50 source-files get [ <source-file> ] cache ;
52 : reset-checksums ( -- )
55 utf8 file-lines swap record-checksum
59 M: pathname where string>> 1 2array ;
61 : forget-source ( path -- )
65 [ definitions>> [ keys forget-all ] each ]
68 [ source-files get delete-at ]
72 string>> forget-source ;
74 : rollback-source-file ( file -- )
76 new-definitions get [ assoc-union ] 2map
77 ] change-definitions drop ;
81 TUPLE: source-file-error error file ;
83 : <source-file-error> ( msg -- error )
84 \ source-file-error new
88 : with-source-file ( name quot -- )
89 #! Should be called from inside with-compilation-unit.
93 definitions>> old-definitions set
95 file get rollback-source-file
96 <source-file-error> rethrow