factor/core/definitions/definitions.factor

113 lines
2.7 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2006, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: definitions
USING: kernel sequences namespaces assocs graphs continuations ;
2007-09-20 18:09:08 -04:00
GENERIC: where ( defspec -- loc )
M: object where drop f ;
GENERIC: set-where ( loc defspec -- )
GENERIC: forget ( defspec -- )
M: object forget drop ;
2007-10-09 17:35:09 -04:00
: forget-all ( definitions -- ) [ forget ] each ;
2007-09-20 18:09:08 -04:00
GENERIC: synopsis* ( defspec -- )
GENERIC: definer ( defspec -- start end )
GENERIC: definition ( defspec -- seq )
SYMBOL: crossref
GENERIC: uses ( defspec -- seq )
M: object uses drop f ;
: xref ( defspec -- ) dup uses crossref get add-vertex ;
: usage ( defspec -- seq ) crossref get at keys ;
GENERIC: redefined* ( defspec -- )
M: object redefined* drop ;
: redefined ( defspec -- )
[ crossref get at ] closure [ drop redefined* ] assoc-each ;
: unxref ( defspec -- )
dup uses crossref get remove-vertex ;
: delete-xref ( defspec -- )
dup unxref crossref get delete-at ;
2008-01-04 21:10:49 -05:00
GENERIC: update-methods ( class -- )
SYMBOL: changed-words
2008-01-05 21:06:01 -05:00
! SYMBOL: changed-classes
SYMBOL: old-definitions
SYMBOL: new-definitions
TUPLE: redefine-error def ;
: redefine-error ( definition -- )
\ redefine-error construct-boa
{ { "Continue" t } } throw-restarts drop ;
2007-12-24 17:18:26 -05:00
: add-once ( key assoc -- )
2007-12-25 18:10:05 -05:00
2dup key? [ over redefine-error ] when dupd set-at ;
2007-12-24 17:18:26 -05:00
: (remember-definition) ( definition loc assoc -- )
>r over set-where r> add-once ;
: remember-definition ( definition loc -- )
new-definitions get first (remember-definition) ;
: remember-class ( class loc -- )
2007-12-25 18:10:05 -05:00
over new-definitions get first key? [ dup redefine-error ] when
2007-12-24 17:18:26 -05:00
new-definitions get second (remember-definition) ;
TUPLE: forward-error word ;
: forward-error ( word -- )
\ forward-error construct-boa throw ;
2007-12-24 17:18:26 -05:00
: forward-reference? ( word -- ? )
dup old-definitions get assoc-stack
[ new-definitions get assoc-stack not ]
[ drop f ] if ;
SYMBOL: recompile-hook
2007-12-24 17:18:26 -05:00
: <definitions> ( -- pair ) { H{ } H{ } } [ clone ] map ;
2007-12-30 15:08:48 -05:00
TUPLE: no-compilation-unit word ;
: no-compilation-unit ( word -- * )
\ no-compilation-unit construct-boa throw ;
: changed-word ( word -- )
dup changed-words get
[ no-compilation-unit ] unless*
set-at ;
2008-01-05 21:06:01 -05:00
! : changed-class ( class -- )
! dup changed-classes get
! [ no-compilation-unit ] unless*
! set-at ;
2008-01-04 21:10:49 -05:00
2007-12-30 15:08:48 -05:00
: with-compilation-unit ( quot -- )
[
H{ } clone changed-words set
2008-01-05 21:06:01 -05:00
! H{ } clone changed-classes set
2007-12-24 17:18:26 -05:00
<definitions> new-definitions set
<definitions> old-definitions set
2007-12-24 20:56:23 -05:00
[
2008-01-05 21:06:01 -05:00
! changed-classes get keys [ update-methods ] each
2007-12-24 20:56:23 -05:00
changed-words get keys recompile-hook get call
] [ ] cleanup
] with-scope ; inline