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 ;
18 : record-top-level-form ( quot source-file -- )
20 [ ] [ f notify-definition-observers ] if-bootstrapping ;
22 : record-checksum ( lines source-file -- )
23 [ crc32 checksum-lines ] dip checksum<< ;
25 : record-definitions ( source-file -- )
26 new-definitions get >>definitions drop ;
28 : <source-file> ( path -- source-file )
31 <definitions> >>definitions ;
33 ERROR: invalid-source-file-path path ;
35 : path>source-file ( path -- source-file )
36 dup string? [ invalid-source-file-path ] unless
37 source-files get [ <source-file> ] cache ;
39 : reset-checksums ( -- )
42 [ utf8 file-lines ] dip record-checksum
46 M: pathname where string>> 1 2array ;
48 : forget-source ( path -- )
49 source-files get delete-at*
50 [ definitions>> [ members forget-all ] each ] [ drop ] if ;
53 string>> forget-source ;
55 : rollback-source-file ( source-file -- )
57 new-definitions get [ union ] 2map
58 ] change-definitions drop ;
60 SYMBOL: current-source-file
62 : wrap-source-file-error ( error -- * )
63 current-source-file get rollback-source-file
66 current-source-file get path>> >>path
67 swap >>error rethrow ;
69 : with-source-file ( name quot -- )
70 ! Should be called from inside with-compilation-unit.
74 [ current-source-file namespaces:set ]
75 [ definitions>> old-definitions namespaces:set ] bi
77 [ wrap-source-file-error ] recover
78 ] with-variables ; inline