core: Don't use with-scope. H{ } clone [ ] with-variables is the same thing and is more explicit.

db4
Doug Coleman 2016-03-02 17:18:42 -08:00
parent 3c48141689
commit 9c4ed3ddae
7 changed files with 42 additions and 45 deletions

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008, 2010 Slava Pestov. ! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes classes.private USING: accessors arrays assocs classes classes.private
classes.tuple classes.tuple.private continuations definitions classes.tuple.private continuations definitions generic
generic hash-sets init kernel kernel.private math namespaces hash-sets init kernel kernel.private math namespaces sequences
sequences sets source-files.errors vocabs words ; sets source-files.errors vocabs words ;
IN: compiler.units IN: compiler.units
PRIMITIVE: modify-code-heap ( alist update-existing? reset-pics? -- ) PRIMITIVE: modify-code-heap ( alist update-existing? reset-pics? -- )
@ -184,24 +184,24 @@ M: nesting-observer definitions-changed
PRIVATE> PRIVATE>
: with-nested-compilation-unit ( quot -- ) : with-nested-compilation-unit ( quot -- )
[ H{ } clone
HS{ } clone changed-definitions set HS{ } clone changed-definitions pick set-at
HS{ } clone maybe-changed set HS{ } clone maybe-changed pick set-at
HS{ } clone changed-effects set HS{ } clone changed-effects pick set-at
HS{ } clone outdated-generics set HS{ } clone outdated-generics pick set-at
H{ } clone outdated-tuples set H{ } clone outdated-tuples pick set-at
HS{ } clone new-words set HS{ } clone new-words pick set-at [
add-nesting-observer add-nesting-observer
[ [
remove-nesting-observer remove-nesting-observer
finish-compilation-unit finish-compilation-unit
] [ ] cleanup ] [ ] cleanup
] with-scope ; inline ] with-variables ; inline
: with-compilation-unit ( quot -- ) : with-compilation-unit ( quot -- )
[ H{ } clone
<definitions> new-definitions set <definitions> new-definitions pick set-at
<definitions> old-definitions set <definitions> old-definitions pick set-at
HS{ } clone forgotten-definitions set HS{ } clone forgotten-definitions pick set-at [
with-nested-compilation-unit with-nested-compilation-unit
] with-scope ; inline ] with-variables ; inline

View File

@ -1,5 +1,6 @@
USING: accessors arrays continuations debugger eval io kernel kernel.private USING: accessors continuations debugger eval hashtables io
math memory namespaces parser sequences system tools.test vectors words ; kernel kernel.private math memory namespaces sequences
tools.test vectors words ;
IN: continuations.tests IN: continuations.tests
: (callcc1-test) ( n obj -- n' obj ) : (callcc1-test) ( n obj -- n' obj )
@ -15,10 +16,9 @@ IN: continuations.tests
: callcc-namespace-test ( -- ? ) : callcc-namespace-test ( -- ? )
[ [
"test-cc" set "test-cc" set
5 "x" set 5 "x" [
[
6 "x" set "test-cc" get continue 6 "x" set "test-cc" get continue
] with-scope ] with-variable
] callcc0 "x" get 5 = ; ] callcc0 "x" get 5 = ;
{ t } [ 10 callcc1-test 10 iota reverse >vector = ] unit-test { t } [ 10 callcc1-test 10 iota reverse >vector = ] unit-test
@ -64,9 +64,9 @@ IN: continuations.tests
SYMBOL: always-counter SYMBOL: always-counter
SYMBOL: error-counter SYMBOL: error-counter
0 always-counter
0 error-counter 2hashtable
[ [
0 always-counter set
0 error-counter set
[ ] [ always-counter inc ] [ error-counter inc ] cleanup [ ] [ always-counter inc ] [ error-counter inc ] cleanup
@ -90,7 +90,7 @@ SYMBOL: error-counter
[ 3 ] [ always-counter get ] unit-test [ 3 ] [ always-counter get ] unit-test
[ 1 ] [ error-counter get ] unit-test [ 1 ] [ error-counter get ] unit-test
] with-scope ] with-variables
{ } [ [ return ] with-return ] unit-test { } [ [ return ] with-return ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007, 2010 Doug Coleman, Slava Pestov. ! Copyright (C) 2007, 2010 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs continuations init kernel make USING: accessors continuations hashtables init kernel namespaces
namespaces sequences sets ; sequences sets ;
IN: destructors IN: destructors
SYMBOL: disposables SYMBOL: disposables
@ -82,13 +82,13 @@ PRIVATE>
dup error-destructors get push ; inline dup error-destructors get push ; inline
: with-destructors ( quot -- ) : with-destructors ( quot -- )
[ V{ } clone always-destructors
V{ } clone always-destructors set V{ } clone error-destructors
V{ } clone error-destructors set 2hashtable [
[ do-always-destructors ] [ do-always-destructors ]
[ do-error-destructors ] [ do-error-destructors ]
cleanup cleanup
] with-scope ; inline ] with-variables ; inline
[ [
HS{ } clone disposables set-global HS{ } clone disposables set-global

View File

@ -1,7 +1,6 @@
USING: io.pathnames io.files.temp io.directories USING: continuations hashtables io.backend io.directories
continuations math io.files.private kernel io.files.private io.files.temp io.pathnames kernel math
namespaces sequences system tools.test namespaces system tools.test ;
io.backend io.pathnames.private ;
IN: io.pathnames.tests IN: io.pathnames.tests
{ "passwd" } [ "/etc/passwd" file-name ] unit-test { "passwd" } [ "/etc/passwd" file-name ] unit-test
@ -58,13 +57,12 @@ IN: io.pathnames.tests
{ } [ 2 [ "touch-twice-test" temp-file touch-file ] times ] unit-test { } [ 2 [ "touch-twice-test" temp-file touch-file ] times ] unit-test
! aum's bug ! aum's bug
[ "." current-directory
"." current-directory set ".." "resource-path" 2hashtable [
".." "resource-path" set
[ "../core/bootstrap/stage2.factor" ] [ "../core/bootstrap/stage2.factor" ]
[ "resource:core/bootstrap/stage2.factor" absolute-path ] [ "resource:core/bootstrap/stage2.factor" absolute-path ]
unit-test unit-test
] with-scope ] with-variables
{ t } [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test { t } [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test

View File

@ -68,11 +68,11 @@ SYMBOL: current-source-file
: with-source-file ( name quot -- ) : with-source-file ( name quot -- )
! Should be called from inside with-compilation-unit. ! Should be called from inside with-compilation-unit.
[ H{ } clone source-files [
[ [
path>source-file path>source-file
[ current-source-file set ] [ current-source-file set ]
[ definitions>> old-definitions set ] bi [ definitions>> old-definitions set ] bi
] dip ] dip
[ wrap-source-file-error ] recover [ wrap-source-file-error ] recover
] with-scope ; inline ] with-variable ; inline

View File

@ -81,10 +81,9 @@ IN: vectors.tests
] unit-test ] unit-test
{ 0 } [ { 0 } [
[ 10 <vector> "x" [
10 <vector> "x" set
"x" get clone length "x" get clone length
] with-scope ] with-variable
] unit-test ] unit-test
{ f } [ 5 V{ } index ] unit-test { f } [ 5 V{ } index ] unit-test

View File

@ -31,11 +31,11 @@ DEFER: plist-test
"create-test" "scratchpad" lookup-word "testing" word-prop "create-test" "scratchpad" lookup-word "testing" word-prop
] unit-test ] unit-test
[ H{ } clone [
[ t ] [ \ array? "array?" "arrays" lookup-word = ] unit-test [ t ] [ \ array? "array?" "arrays" lookup-word = ] unit-test
[ ] [ [ "test-scope" "scratchpad" create-word drop ] with-compilation-unit ] unit-test [ ] [ [ "test-scope" "scratchpad" create-word drop ] with-compilation-unit ] unit-test
] with-scope ] with-variables
{ "test-scope" } [ { "test-scope" } [
"test-scope" "scratchpad" lookup-word name>> "test-scope" "scratchpad" lookup-word name>>