1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs checksums checksums.crc32
4 compiler.units continuations definitions io.encodings.utf8
5 io.files io.pathnames kernel namespaces sequences sets
6 source-files.errors strings words ;
7 FROM: namespaces => set ;
12 TUPLE: source-file-tuple
19 : record-top-level-form ( quot file -- )
21 [ ] [ f notify-definition-observers ] if-bootstrapping ;
23 : record-checksum ( lines source-file -- )
24 [ crc32 checksum-lines ] dip checksum<< ;
26 : record-definitions ( file -- )
27 new-definitions get >>definitions drop ;
29 : <source-file> ( path -- source-file )
30 \ source-file-tuple new
32 <definitions> >>definitions ;
34 ERROR: invalid-source-file-path path ;
36 : source-file ( path -- source-file )
37 dup string? [ invalid-source-file-path ] unless
38 source-files get [ <source-file> ] cache ;
40 : reset-checksums ( -- )
43 [ utf8 file-lines ] dip record-checksum
47 M: pathname where string>> 1 2array ;
49 : forget-source ( path -- )
50 source-files get delete-at*
51 [ definitions>> [ members forget-all ] each ] [ drop ] if ;
54 string>> forget-source ;
56 : rollback-source-file ( file -- )
58 new-definitions get [ union ] 2map
59 ] change-definitions drop ;
63 : wrap-source-file-error ( error -- * )
64 file get rollback-source-file
65 \ source-file-error new
67 file get path>> >>file
68 swap >>error rethrow ;
70 : with-source-file ( name quot -- )
71 #! Should be called from inside with-compilation-unit.
76 [ definitions>> old-definitions set ] bi
78 [ wrap-source-file-error ] recover