Clean up class definition recording
parent
3e27a82f8e
commit
0052e129fd
|
@ -351,12 +351,18 @@ M: curry '
|
||||||
: emit-words ( -- )
|
: emit-words ( -- )
|
||||||
all-words [ emit-word ] each ;
|
all-words [ emit-word ] each ;
|
||||||
|
|
||||||
|
: fix-source-files
|
||||||
|
[
|
||||||
|
clone dup source-file-definitions H{ } clone 2array
|
||||||
|
over set-source-file-definitions
|
||||||
|
] assoc-map ;
|
||||||
|
|
||||||
: emit-global ( -- )
|
: emit-global ( -- )
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
dictionary source-files
|
dictionary source-files
|
||||||
typemap builtins class<map update-map
|
typemap builtins class<map update-map
|
||||||
} [ dup get swap bootstrap-word set ] each
|
} [ dup get swap [ source-files eq? [ fix-source-files ] when ] keep bootstrap-word set ] each
|
||||||
] H{ } make-assoc
|
] H{ } make-assoc
|
||||||
bootstrap-global set
|
bootstrap-global set
|
||||||
bootstrap-global emit-userenv ;
|
bootstrap-global emit-userenv ;
|
||||||
|
@ -444,7 +450,6 @@ PRIVATE>
|
||||||
|
|
||||||
: make-image ( arch -- )
|
: make-image ( arch -- )
|
||||||
[
|
[
|
||||||
[ drop ] recompile-hook set
|
|
||||||
prepare-image
|
prepare-image
|
||||||
begin-image
|
begin-image
|
||||||
"resource:/core/bootstrap/stage1.factor" run-file
|
"resource:/core/bootstrap/stage1.factor" run-file
|
||||||
|
|
|
@ -19,7 +19,11 @@ crossref off
|
||||||
"syntax" vocab vocab-words bootstrap-syntax set
|
"syntax" vocab vocab-words bootstrap-syntax set
|
||||||
|
|
||||||
"resource:core/bootstrap/syntax.factor" parse-file
|
"resource:core/bootstrap/syntax.factor" parse-file
|
||||||
|
|
||||||
H{ } clone dictionary set
|
H{ } clone dictionary set
|
||||||
|
H{ } clone changed-words set
|
||||||
|
[ drop ] recompile-hook set
|
||||||
|
|
||||||
call
|
call
|
||||||
|
|
||||||
! Create some empty vocabs where the below primitives and
|
! Create some empty vocabs where the below primitives and
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2007 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays generator generator.fixup io.binary kernel
|
USING: arrays generator.fixup io.binary kernel
|
||||||
combinators kernel.private math namespaces parser sequences
|
combinators kernel.private math namespaces parser sequences
|
||||||
words system ;
|
words system ;
|
||||||
IN: cpu.x86.assembler
|
IN: cpu.x86.assembler
|
||||||
|
|
|
@ -88,12 +88,7 @@ HELP: redefine-error
|
||||||
{ $description "Throws a " { $link redefine-error } "." }
|
{ $description "Throws a " { $link redefine-error } "." }
|
||||||
{ $error-description "Indicates that a single source file contains two definitions for the same artifact, one of which shadows the other. This is an error since it indicates a likely mistake, such as two words accidentally named the same by the developer; the error is restartable." } ;
|
{ $error-description "Indicates that a single source file contains two definitions for the same artifact, one of which shadows the other. This is an error since it indicates a likely mistake, such as two words accidentally named the same by the developer; the error is restartable." } ;
|
||||||
|
|
||||||
HELP: redefinition?
|
HELP: remember-definition
|
||||||
{ $values { "definition" "a definition specifier" } { "?" "a boolean" } }
|
|
||||||
{ $description "Tests if this definition is already present in the current source file." }
|
|
||||||
$parsing-note ;
|
|
||||||
|
|
||||||
HELP: (save-location)
|
|
||||||
{ $values { "definition" "a definition specifier" } { "loc" "a " { $snippet "{ path line# }" } " pair" } }
|
{ $values { "definition" "a definition specifier" } { "loc" "a " { $snippet "{ path line# }" } " pair" } }
|
||||||
{ $description "Saves the location of a definition and associates this definition with the current source file."
|
{ $description "Saves the location of a definition and associates this definition with the current source file."
|
||||||
$nl
|
$nl
|
||||||
|
|
|
@ -54,26 +54,37 @@ TUPLE: redefine-error def ;
|
||||||
\ redefine-error construct-boa
|
\ redefine-error construct-boa
|
||||||
{ { "Continue" t } } throw-restarts drop ;
|
{ { "Continue" t } } throw-restarts drop ;
|
||||||
|
|
||||||
: redefinition? ( definition -- ? )
|
: add-once ( key assoc -- )
|
||||||
new-definitions get key? ;
|
2dup key? [ drop redefine-error ] when dupd set-at ;
|
||||||
|
|
||||||
: (save-location) ( definition loc -- )
|
: (remember-definition) ( definition loc assoc -- )
|
||||||
over redefinition? [ over redefine-error ] when
|
>r over set-where r> add-once ;
|
||||||
over set-where
|
|
||||||
dup new-definitions get set-at ;
|
: remember-definition ( definition loc -- )
|
||||||
|
new-definitions get first (remember-definition) ;
|
||||||
|
|
||||||
|
: remember-class ( class loc -- )
|
||||||
|
new-definitions get second (remember-definition) ;
|
||||||
|
|
||||||
TUPLE: forward-error word ;
|
TUPLE: forward-error word ;
|
||||||
|
|
||||||
: forward-error ( word -- )
|
: forward-error ( word -- )
|
||||||
\ forward-error construct-boa throw ;
|
\ forward-error construct-boa throw ;
|
||||||
|
|
||||||
|
: forward-reference? ( word -- ? )
|
||||||
|
dup old-definitions get assoc-stack
|
||||||
|
[ new-definitions get assoc-stack not ]
|
||||||
|
[ drop f ] if ;
|
||||||
|
|
||||||
SYMBOL: recompile-hook
|
SYMBOL: recompile-hook
|
||||||
|
|
||||||
|
: <definitions> ( -- pair ) { H{ } H{ } } [ clone ] map ;
|
||||||
|
|
||||||
: with-compilation-unit ( quot -- new-defs )
|
: with-compilation-unit ( quot -- new-defs )
|
||||||
[
|
[
|
||||||
H{ } clone changed-words set
|
H{ } clone changed-words set
|
||||||
H{ } clone new-definitions set
|
<definitions> new-definitions set
|
||||||
old-definitions off
|
<definitions> old-definitions set
|
||||||
call
|
call
|
||||||
changed-words get keys recompile-hook get call
|
changed-words get keys recompile-hook get call
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
|
@ -229,7 +229,7 @@ HELP: <lexer>
|
||||||
|
|
||||||
HELP: location
|
HELP: location
|
||||||
{ $values { "loc" "a " { $snippet "{ path line# }" } " pair" } }
|
{ $values { "loc" "a " { $snippet "{ path line# }" } " pair" } }
|
||||||
{ $description "Outputs the current parser location. This value can be passed to " { $link set-where } " or " { $link (save-location) } "." } ;
|
{ $description "Outputs the current parser location. This value can be passed to " { $link set-where } " or " { $link remember-definition } "." } ;
|
||||||
|
|
||||||
HELP: save-location
|
HELP: save-location
|
||||||
{ $values { "definition" "a definition specifier" } }
|
{ $values { "definition" "a definition specifier" } }
|
||||||
|
|
|
@ -141,7 +141,7 @@ IN: temporary
|
||||||
"IN: temporary : smudge-me ;" <string-reader> "foo"
|
"IN: temporary : smudge-me ;" <string-reader> "foo"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"foo" source-file source-file-definitions assoc-size
|
"foo" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ "smudge-me" "temporary" lookup >boolean ] unit-test
|
[ t ] [ "smudge-me" "temporary" lookup >boolean ] unit-test
|
||||||
|
@ -158,21 +158,21 @@ IN: temporary
|
||||||
"IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
|
"IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"foo" source-file source-file-definitions assoc-size
|
"foo" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 1 ] [
|
[ 1 ] [
|
||||||
"IN: temporary USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
|
"IN: temporary USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"bar" source-file source-file-definitions assoc-size
|
"bar" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 2 ] [
|
[ 2 ] [
|
||||||
"IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
|
"IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"foo" source-file source-file-definitions assoc-size
|
"foo" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
|
@ -217,7 +217,7 @@ IN: temporary
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
[
|
[
|
||||||
"IN: temporary : x ; : y 3 throw ; parsing y"
|
"IN: temporary : x ; : y 3 throw ; this is an error"
|
||||||
<string-reader> "a" parse-stream
|
<string-reader> "a" parse-stream
|
||||||
] catch parse-error?
|
] catch parse-error?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
@ -376,9 +376,9 @@ IN: temporary
|
||||||
: ~c ;
|
: ~c ;
|
||||||
: ~d ;
|
: ~d ;
|
||||||
|
|
||||||
H{ { ~a ~a } { ~c ~c } { ~d ~d } } old-definitions set
|
{ H{ { ~a ~a } { ~c ~c } { ~d ~d } } H{ } } old-definitions set
|
||||||
|
|
||||||
H{ { ~d ~d } } new-definitions set
|
{ H{ { ~d ~d } } H{ } } new-definitions set
|
||||||
|
|
||||||
[ V{ ~b } { ~a } { ~a ~c } ] [
|
[ V{ ~b } { ~a } { ~a ~c } ] [
|
||||||
smudged-usage
|
smudged-usage
|
||||||
|
|
|
@ -20,7 +20,10 @@ TUPLE: lexer text line column ;
|
||||||
[ >r source-file-path r> 2array ] [ 2drop f ] if ;
|
[ >r source-file-path r> 2array ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: save-location ( definition -- )
|
: save-location ( definition -- )
|
||||||
location (save-location) ;
|
location remember-definition ;
|
||||||
|
|
||||||
|
: save-class-location ( class -- )
|
||||||
|
location remember-class ;
|
||||||
|
|
||||||
SYMBOL: parser-notes
|
SYMBOL: parser-notes
|
||||||
|
|
||||||
|
@ -217,7 +220,7 @@ PREDICATE: unexpected unexpected-eof
|
||||||
|
|
||||||
: CREATE-CLASS ( -- word )
|
: CREATE-CLASS ( -- word )
|
||||||
scan in get create
|
scan in get create
|
||||||
dup <class-definition> save-location
|
dup save-class-location
|
||||||
dup predicate-word save-location ;
|
dup predicate-word save-location ;
|
||||||
|
|
||||||
: word-restarts ( possibilities -- restarts )
|
: word-restarts ( possibilities -- restarts )
|
||||||
|
@ -235,14 +238,6 @@ M: no-word summary
|
||||||
swap words-named word-restarts throw-restarts
|
swap words-named word-restarts throw-restarts
|
||||||
dup word-vocabulary (use+) ;
|
dup word-vocabulary (use+) ;
|
||||||
|
|
||||||
: forward-reference? ( word -- ? )
|
|
||||||
{
|
|
||||||
{ [ dup old-definitions get key? over <class-definition> old-definitions get key? or not ] [ f ] }
|
|
||||||
{ [ dup new-definitions get key? ] [ f ] }
|
|
||||||
{ [ dup <class-definition> new-definitions get key? ] [ f ] }
|
|
||||||
{ [ t ] [ t ] }
|
|
||||||
} cond nip ;
|
|
||||||
|
|
||||||
: check-forward ( str word -- word )
|
: check-forward ( str word -- word )
|
||||||
dup forward-reference? [
|
dup forward-reference? [
|
||||||
drop
|
drop
|
||||||
|
@ -270,7 +265,8 @@ M: staging-violation summary
|
||||||
"A parsing word cannot be used in the same file it is defined in." ;
|
"A parsing word cannot be used in the same file it is defined in." ;
|
||||||
|
|
||||||
: execute-parsing ( word -- )
|
: execute-parsing ( word -- )
|
||||||
dup new-definitions get key? [ staging-violation ] when
|
dup
|
||||||
|
new-definitions get first key? [ staging-violation ] when
|
||||||
execute ;
|
execute ;
|
||||||
|
|
||||||
: parse-step ( accum end -- accum ? )
|
: parse-step ( accum end -- accum ? )
|
||||||
|
@ -380,9 +376,10 @@ SYMBOL: bootstrap-syntax
|
||||||
file get source-file-path =
|
file get source-file-path =
|
||||||
] assoc-subset ;
|
] assoc-subset ;
|
||||||
|
|
||||||
|
: removed-definitions ( -- definitions ) new-definitions get old-definitions get [ first2 union ] 2apply diff ;
|
||||||
|
|
||||||
: smudged-usage ( -- usages referenced removed )
|
: smudged-usage ( -- usages referenced removed )
|
||||||
new-definitions get old-definitions get diff filter-moved
|
removed-definitions filter-moved keys [
|
||||||
keys [
|
|
||||||
outside-usages
|
outside-usages
|
||||||
[ empty? swap pathname? or not ] assoc-subset
|
[ empty? swap pathname? or not ] assoc-subset
|
||||||
dup values concat prune swap keys
|
dup values concat prune swap keys
|
||||||
|
|
|
@ -37,7 +37,7 @@ HELP: source-file
|
||||||
{ { $link source-file-modified } " - the result of " { $link file-modified } " at the time the source file was most recently loaded." }
|
{ { $link source-file-modified } " - the result of " { $link file-modified } " at the time the source file was most recently loaded." }
|
||||||
{ { $link source-file-checksum } " - the CRC32 checksum of the source file's contents at the time it was most recently loaded." }
|
{ { $link source-file-checksum } " - the CRC32 checksum of the source file's contents at the time it was most recently loaded." }
|
||||||
{ { $link source-file-uses } " - an assoc whose keys are words referenced from this source file's top level form." }
|
{ { $link source-file-uses } " - an assoc whose keys are words referenced from this source file's top level form." }
|
||||||
{ { $link source-file-definitions } " - an assoc whose keys are definitions defined in this source file." }
|
{ { $link source-file-definitions } " - a pair of assocs, containing definitions and classes defined in this source file, respectively" }
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,9 @@ uses definitions ;
|
||||||
new-definitions get swap set-source-file-definitions ;
|
new-definitions get swap set-source-file-definitions ;
|
||||||
|
|
||||||
: <source-file> ( path -- source-file )
|
: <source-file> ( path -- source-file )
|
||||||
{ set-source-file-path } \ source-file construct ;
|
<definitions>
|
||||||
|
{ set-source-file-path set-source-file-definitions }
|
||||||
|
\ source-file construct ;
|
||||||
|
|
||||||
: source-file ( path -- source-file )
|
: source-file ( path -- source-file )
|
||||||
source-files get [ <source-file> ] cache ;
|
source-files get [ <source-file> ] cache ;
|
||||||
|
@ -74,13 +76,13 @@ M: pathname where pathname-string 1 2array ;
|
||||||
: forget-source ( path -- )
|
: forget-source ( path -- )
|
||||||
dup source-file
|
dup source-file
|
||||||
dup unxref-source
|
dup unxref-source
|
||||||
source-file-definitions keys forget-all
|
source-file-definitions [ keys forget-all ] each
|
||||||
source-files get delete-at ;
|
source-files get delete-at ;
|
||||||
|
|
||||||
M: pathname forget pathname-string forget-source ;
|
M: pathname forget pathname-string forget-source ;
|
||||||
|
|
||||||
: rollback-source-file ( source-file -- )
|
: rollback-source-file ( source-file -- )
|
||||||
dup source-file-definitions new-definitions get union
|
dup source-file-definitions new-definitions get [ union ] 2map
|
||||||
swap set-source-file-definitions ;
|
swap set-source-file-definitions ;
|
||||||
|
|
||||||
SYMBOL: file
|
SYMBOL: file
|
||||||
|
|
|
@ -95,7 +95,7 @@ IN: bootstrap.syntax
|
||||||
|
|
||||||
"DEFER:" [
|
"DEFER:" [
|
||||||
scan in get create
|
scan in get create
|
||||||
dup old-definitions get delete-at
|
dup old-definitions get first delete-at
|
||||||
set-word
|
set-word
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ IN: bootstrap.syntax
|
||||||
location >r
|
location >r
|
||||||
scan-word bootstrap-word scan-word
|
scan-word bootstrap-word scan-word
|
||||||
[ parse-definition <method> -rot define-method ] 2keep
|
[ parse-definition <method> -rot define-method ] 2keep
|
||||||
2array r> (save-location)
|
2array r> remember-definition
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"UNION:" [
|
"UNION:" [
|
||||||
|
|
|
@ -12,7 +12,7 @@ IN: temporary
|
||||||
"IN: temporary USING: help.syntax ; : hello ; HELP: hello \"test\" ; ARTICLE: \"hello\" \"world\" ; ARTICLE: \"hello2\" \"world\" ;" <string-reader> "foo"
|
"IN: temporary USING: help.syntax ; : hello ; HELP: hello \"test\" ; ARTICLE: \"hello\" \"world\" ; ARTICLE: \"hello2\" \"world\" ;" <string-reader> "foo"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"foo" source-file source-file-definitions assoc-size
|
"foo" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ "hello" articles get key? ] unit-test
|
[ t ] [ "hello" articles get key? ] unit-test
|
||||||
|
@ -25,7 +25,7 @@ IN: temporary
|
||||||
"IN: temporary USING: help.syntax ; : hello ; ARTICLE: \"hello\" \"world\" ;" <string-reader> "foo"
|
"IN: temporary USING: help.syntax ; : hello ; ARTICLE: \"hello\" \"world\" ;" <string-reader> "foo"
|
||||||
parse-stream drop
|
parse-stream drop
|
||||||
|
|
||||||
"foo" source-file source-file-definitions assoc-size
|
"foo" source-file source-file-definitions first assoc-size
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ "hello" articles get key? ] unit-test
|
[ t ] [ "hello" articles get key? ] unit-test
|
||||||
|
|
|
@ -13,7 +13,7 @@ IN: help.syntax
|
||||||
: ARTICLE:
|
: ARTICLE:
|
||||||
location >r
|
location >r
|
||||||
\ ; parse-until >array [ first2 ] keep 2 tail <article>
|
\ ; parse-until >array [ first2 ] keep 2 tail <article>
|
||||||
over add-article >link r> (save-location) ; parsing
|
over add-article >link r> remember-definition ; parsing
|
||||||
|
|
||||||
: ABOUT:
|
: ABOUT:
|
||||||
scan-word dup parsing? [
|
scan-word dup parsing? [
|
||||||
|
|
Loading…
Reference in New Issue