factor/core/source-files/source-files.factor

105 lines
2.9 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays definitions generic assocs kernel math
namespaces prettyprint sequences strings vectors words
quotations inspector io.styles io combinators sorting
splitting math.parser effects continuations debugger
io.files io.crc32 io.streams.string io.streams.lines vocabs
hashtables graphs compiler.units ;
2007-09-20 18:09:08 -04:00
IN: source-files
SYMBOL: source-files
TUPLE: source-file
path
modified checksum
uses definitions ;
: (source-modified?) ( path modified checksum -- ? )
pick file-modified rot [ 0 or ] 2apply >
[ swap file-lines lines-crc32 = not ] [ 2drop f ] if ;
2007-09-20 18:09:08 -04:00
: source-modified? ( path -- ? )
dup source-files get at [
dup source-file-path ?resource-path
over source-file-modified
rot source-file-checksum
(source-modified?)
] [
resource-exists?
2007-09-20 18:09:08 -04:00
] ?if ;
: record-modified ( source-file -- )
dup source-file-path ?resource-path file-modified
swap set-source-file-modified ;
2008-01-09 21:13:59 -05:00
: record-checksum ( lines source-file -- )
swap lines-crc32 swap set-source-file-checksum ;
2007-09-20 18:09:08 -04:00
: (xref-source) ( source-file -- pathname uses )
dup source-file-path <pathname> swap source-file-uses
2008-02-06 13:47:15 -05:00
[ crossref? ] subset ;
2007-09-20 18:09:08 -04:00
: xref-source ( source-file -- )
(xref-source) crossref get add-vertex ;
: unxref-source ( source-file -- )
(xref-source) crossref get remove-vertex ;
: xref-sources ( -- )
source-files get [ nip xref-source ] assoc-each ;
: record-form ( quot source-file -- )
dup unxref-source
swap quot-uses keys over set-source-file-uses
xref-source ;
: record-definitions ( file -- )
new-definitions get swap set-source-file-definitions ;
2007-09-20 18:09:08 -04:00
: <source-file> ( path -- source-file )
2007-12-24 17:18:26 -05:00
<definitions>
{ set-source-file-path set-source-file-definitions }
\ source-file construct ;
2007-09-20 18:09:08 -04:00
: source-file ( path -- source-file )
source-files get [ <source-file> ] cache ;
: reset-checksums ( -- )
source-files get [
swap ?resource-path dup exists?
2008-01-29 01:35:44 -05:00
[ file-lines swap record-checksum ] [ 2drop ] if
2007-09-20 18:09:08 -04:00
] assoc-each ;
M: pathname where pathname-string 1 2array ;
2008-01-09 19:13:26 -05:00
: forget-source ( path -- )
2007-12-24 19:40:09 -05:00
dup source-file
dup unxref-source
source-file-definitions [ keys forget-all ] each
source-files get delete-at ;
2007-09-20 18:09:08 -04:00
2008-01-09 19:13:26 -05:00
M: pathname forget*
pathname-string forget-source ;
: rollback-source-file ( source-file -- )
2007-12-24 17:18:26 -05:00
dup source-file-definitions new-definitions get [ union ] 2map
swap set-source-file-definitions ;
SYMBOL: file
: with-source-file ( name quot -- )
#! Should be called from inside with-compilation-unit.
[
swap source-file
dup file set
source-file-definitions old-definitions set
[ ] [ file get rollback-source-file ] cleanup
] with-scope ; inline
2008-02-05 00:30:59 -05:00
: outside-usages ( seq -- usages )
dup [
2008-02-23 23:29:29 -05:00
over usage
[ dup pathname? not swap where and ] subset seq-diff
2008-02-05 00:30:59 -05:00
] curry { } map>assoc ;