Merge branch 'master' of git://factorcode.org/git/factor
commit
eed6cd89ef
|
@ -2,26 +2,6 @@ IN: definitions.tests
|
|||
USING: tools.test generic kernel definitions sequences
|
||||
compiler.units words ;
|
||||
|
||||
TUPLE: combination-1 ;
|
||||
|
||||
M: combination-1 perform-combination drop [ ] define ;
|
||||
|
||||
M: combination-1 make-default-method 2drop [ "No method" throw ] ;
|
||||
|
||||
SYMBOL: generic-1
|
||||
|
||||
[
|
||||
generic-1 T{ combination-1 } define-generic
|
||||
|
||||
object \ generic-1 create-method [ ] define
|
||||
] with-compilation-unit
|
||||
|
||||
[ ] [
|
||||
[
|
||||
{ combination-1 { object generic-1 } } forget-all
|
||||
] with-compilation-unit
|
||||
] unit-test
|
||||
|
||||
GENERIC: some-generic ( a -- b )
|
||||
|
||||
USE: arrays
|
||||
|
|
|
@ -110,6 +110,8 @@ IN: vocabs.loader.tests
|
|||
] with-compilation-unit
|
||||
] unit-test
|
||||
|
||||
[ ] [ "vocabs.loader.test.b" changed-vocab ] unit-test
|
||||
|
||||
[ ] [ "vocabs.loader.test.b" refresh ] unit-test
|
||||
|
||||
[ 3 ] [ "count-me" get-global ] unit-test
|
||||
|
|
|
@ -224,7 +224,7 @@ $nl
|
|||
":errors - print 2 compiler errors."
|
||||
":warnings - print 50 compiler warnings."
|
||||
}
|
||||
"These warnings arise from the compiler's stack effect checker. Warnings are non-fatal conditions -- not all code has a static stack effect, so you try to minimize warnings but understand that in many cases they cannot be eliminated. Errors indicate programming mistakes, such as erronous stack effect declarations."
|
||||
"These warnings arise from the compiler's stack effect checker. Warnings are non-fatal conditions -- not all code has a static stack effect, so you try to minimize warnings but understand that in many cases they cannot be eliminated. Errors indicate programming mistakes, such as erroneous stack effect declarations."
|
||||
{ $references
|
||||
"To learn more about the compiler and static stack effect inference, read these articles:"
|
||||
"compiler"
|
||||
|
@ -259,7 +259,7 @@ $nl
|
|||
{ $code "#! /usr/bin/env factor -script" }
|
||||
"Running the text file will run it through Factor, assuming the " { $snippet "factor" } " binary is in your " { $snippet "$PATH" } "."
|
||||
$nl
|
||||
"The space between " { $snippet "#!" } " and " { $snippet "/usr/bin/env" } " is necessary, since " { $link POSTPONE: #! } " is a parsing word, and a syntax error would otherwise result. The " { $snippet "-script" } " switch supresses compiler messages, and exits Factor when the script finishes."
|
||||
"The space between " { $snippet "#!" } " and " { $snippet "/usr/bin/env" } " is necessary, since " { $link POSTPONE: #! } " is a parsing word, and a syntax error would otherwise result. The " { $snippet "-script" } " switch suppresses compiler messages, and exits Factor when the script finishes."
|
||||
{ $references
|
||||
{ }
|
||||
"cli"
|
||||
|
@ -273,7 +273,7 @@ $nl
|
|||
$nl
|
||||
"Keep the following guidelines in mind to avoid losing your sense of balance:"
|
||||
{ $list
|
||||
"SImplify, simplify, simplify. Break your program up into small words which operate on a few values at a time. Most word definitions should fit on a single line; very rarely should they exceed two or three lines."
|
||||
"Simplify, simplify, simplify. Break your program up into small words which operate on a few values at a time. Most word definitions should fit on a single line; very rarely should they exceed two or three lines."
|
||||
"In addition to keeping your words short, keep them meaningful. Give them good names, and make sure each word only does one thing. Try documenting your words; if the documentation for a word is unclear or complex, chances are the word definition is too. Don't be afraid to refactor your code."
|
||||
"If your code looks repetitive, factor it some more."
|
||||
"If after factoring, your code still looks repetitive, introduce combinators."
|
||||
|
@ -285,7 +285,7 @@ $nl
|
|||
"Every time you define a word which simply manipulates sequences, hashtables or objects in an abstract way which is not related to your program domain, check the library to see if you can reuse an existing definition."
|
||||
{ "Learn to use the " { $link "inference" } " tool." }
|
||||
{ "Write unit tests. Factor provides good support for unit testing; see " { $link "tools.test" } ". Once your program has a good test suite you can refactor with confidence and catch regressions early." }
|
||||
"Don't write Factor as if it were C. Imperitive programming and indexed loops are almost always not the most idiomatic solution."
|
||||
"Don't write Factor as if it were C. Imperative programming and indexed loops are almost always not the most idiomatic solution."
|
||||
{ "Use sequences, assocs and objects to group related data. Object allocation is very cheap. Don't be afraid to create tuples, pairs and triples. Don't be afraid of operations which allocate new objects either, such as " { $link append } "." }
|
||||
{ "If you find yourself writing a loop with a sequence and an index, there's almost always a better way. Learn the " { $link "sequences-combinators" } " by heart." }
|
||||
{ "If you find yourself writing a heavily nested loop which performs several steps on each iteration, there is almost always a better way. Break the problem down into a series of passes over the data instead, gradually transforming it into the desired result with a series of simple loops. Factor the loops out and reuse them. If you're working on anything math-related, learn " { $link "math-vectors" } " by heart." }
|
||||
|
@ -312,7 +312,7 @@ ARTICLE: "cookbook-pitfalls" "Pitfalls to avoid"
|
|||
$nl
|
||||
"Unit tests for the " { $vocab-link "inference" } " vocabulary can be used to ensure that any methods your vocabulary defines on core generic words have static stack effects:"
|
||||
{ $code "\"inference\" test" }
|
||||
"In general, you should strive to write code with inferrable stack effects, even for sections of a program which are not performance sensitive; the " { $link infer. } " tool together with the optimizing compiler's error reporting can catch many bugs ahead of time." }
|
||||
"In general, you should strive to write code with inferable stack effects, even for sections of a program which are not performance sensitive; the " { $link infer. } " tool together with the optimizing compiler's error reporting can catch many bugs ahead of time." }
|
||||
{ "Be careful when calling words which access variables from a " { $link make-assoc } " which constructs an assoc with arbitrary keys, since those keys might shadow variables." }
|
||||
{ "If " { $link run-file } " throws a stack depth assertion, it means that the top-level form in the file left behind values on the stack. The stack depth is compared before and after loading a source file, since this type of situation is almost always an error. If you have a legitimate need to load a source file which returns data in some manner, define a word in the source file which produces this data on the stack and call the word after loading the file." }
|
||||
} ;
|
||||
|
|
|
@ -1,29 +1,38 @@
|
|||
IN: io.monitors.tests
|
||||
USING: io.monitors tools.test io.files system sequences
|
||||
continuations namespaces concurrency.count-downs kernel io
|
||||
threads calendar ;
|
||||
threads calendar prettyprint ;
|
||||
|
||||
os { winnt macosx linux } member? [
|
||||
[ "monitor-test" temp-file delete-tree ] ignore-errors
|
||||
|
||||
[ ] [ "monitor-test" temp-file make-directory ] unit-test
|
||||
[ ] [ "monitor-test/xyz" temp-file make-directories ] unit-test
|
||||
|
||||
[ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
|
||||
|
||||
[ ] [ 1 <count-down> "b" set ] unit-test
|
||||
|
||||
[ ] [ 1 <count-down> "c" set ] unit-test
|
||||
|
||||
[ ] [
|
||||
[
|
||||
"b" get count-down
|
||||
[
|
||||
"m" get next-change drop
|
||||
dup print flush
|
||||
"test.txt" tail? not
|
||||
dup print flush right-trim-separators
|
||||
"xyz" tail? not
|
||||
] [ ] [ ] while
|
||||
"c" get count-down
|
||||
] "Monitor test thread" spawn drop
|
||||
] unit-test
|
||||
|
||||
[ ] [ "monitor-test/test.txt" touch-file ] unit-test
|
||||
[ ] [ "b" get await ] unit-test
|
||||
|
||||
[ ] [ "monitor-test/xyz/test.txt" temp-file touch-file ] unit-test
|
||||
|
||||
[ ] [ "c" get 30 seconds await-timeout ] unit-test
|
||||
|
||||
[ ] [ "m" get dispose ] unit-test
|
||||
|
||||
[ "m" get dispose ] must-fail
|
||||
] when
|
||||
|
|
|
@ -10,8 +10,7 @@ IN: tools.vocabs.monitor
|
|||
{ { CHAR: / CHAR: . } { CHAR: \\ CHAR: . } } substitute ;
|
||||
|
||||
: path>vocab-name ( path -- vocab )
|
||||
dup ".factor" tail? [ parent-directory ] when
|
||||
;
|
||||
dup ".factor" tail? [ parent-directory ] when ;
|
||||
|
||||
: chop-vocab-root ( path -- path' )
|
||||
"resource:" prepend-path (normalize-path)
|
||||
|
@ -23,10 +22,6 @@ IN: tools.vocabs.monitor
|
|||
: path>vocab ( path -- vocab )
|
||||
chop-vocab-root path>vocab-name vocab-dir>vocab-name ;
|
||||
|
||||
: changed-vocab ( vocab -- )
|
||||
dup vocab
|
||||
[ dup changed-vocabs get-global set-at ] [ drop ] if ;
|
||||
|
||||
: monitor-thread ( monitor -- )
|
||||
#! On OS X, monitors give us the full path, so we chop it
|
||||
#! off if its there.
|
||||
|
|
|
@ -32,43 +32,6 @@ IN: tools.vocabs
|
|||
[ vocab-tests % ] tri
|
||||
] { } make ;
|
||||
|
||||
: source-modified? ( path -- ? )
|
||||
dup source-files get at [
|
||||
dup source-file-path
|
||||
dup exists? [
|
||||
utf8 file-lines lines-crc32
|
||||
swap source-file-checksum = not
|
||||
] [
|
||||
2drop f
|
||||
] if
|
||||
] [
|
||||
exists?
|
||||
] ?if ;
|
||||
|
||||
: modified ( seq quot -- seq )
|
||||
[ dup ] swap compose { } map>assoc
|
||||
[ nip ] assoc-subset
|
||||
[ nip source-modified? ] assoc-subset keys ; inline
|
||||
|
||||
: modified-sources ( vocabs -- seq )
|
||||
[ vocab-source-path ] modified ;
|
||||
|
||||
: modified-docs ( vocabs -- seq )
|
||||
[ vocab-docs-path ] modified ;
|
||||
|
||||
SYMBOL: changed-vocabs
|
||||
|
||||
[ f changed-vocabs set-global ] "tools.vocabs" add-init-hook
|
||||
|
||||
: filter-changed ( vocabs -- vocabs' )
|
||||
changed-vocabs get [
|
||||
[ delete-at* nip ] curry subset
|
||||
] when* ;
|
||||
|
||||
: to-refresh ( prefix -- modified-sources modified-docs )
|
||||
child-vocabs filter-changed
|
||||
[ modified-sources ] [ modified-docs ] bi ;
|
||||
|
||||
: vocab-heading. ( vocab -- )
|
||||
nl
|
||||
"==== " write
|
||||
|
@ -95,12 +58,87 @@ SYMBOL: failures
|
|||
failures get
|
||||
] with-compiler-errors ;
|
||||
|
||||
: do-refresh ( modified-sources modified-docs -- )
|
||||
: source-modified? ( path -- ? )
|
||||
dup source-files get at [
|
||||
dup source-file-path
|
||||
dup exists? [
|
||||
utf8 file-lines lines-crc32
|
||||
swap source-file-checksum = not
|
||||
] [
|
||||
2drop f
|
||||
] if
|
||||
] [
|
||||
exists?
|
||||
] ?if ;
|
||||
|
||||
SYMBOL: changed-vocabs
|
||||
|
||||
[ f changed-vocabs set-global ] "tools.vocabs" add-init-hook
|
||||
|
||||
: changed-vocab ( vocab -- )
|
||||
dup vocab
|
||||
[ dup changed-vocabs get-global set-at ] [ drop ] if ;
|
||||
|
||||
: unchanged-vocab ( vocab -- )
|
||||
changed-vocabs get-global delete-at ;
|
||||
|
||||
: unchanged-vocabs ( vocabs -- )
|
||||
[ unchanged-vocab ] each ;
|
||||
|
||||
: filter-changed ( vocabs -- vocabs' )
|
||||
changed-vocabs get [
|
||||
[ key? ] curry subset
|
||||
] when* ;
|
||||
|
||||
SYMBOL: modified-sources
|
||||
SYMBOL: modified-docs
|
||||
|
||||
: (to-refresh) ( vocab variable loaded? path -- )
|
||||
dup [
|
||||
swap [
|
||||
pick changed-vocabs get key? [
|
||||
source-modified? [ get push ] [ 2drop ] if
|
||||
] [ 3drop ] if
|
||||
] [ drop get push ] if
|
||||
] [ 2drop 2drop ] if ;
|
||||
|
||||
: to-refresh ( prefix -- modified-sources modified-docs unchanged )
|
||||
[
|
||||
V{ } clone modified-sources set
|
||||
V{ } clone modified-docs set
|
||||
|
||||
child-vocabs [
|
||||
[
|
||||
[
|
||||
[ modified-sources ]
|
||||
[ vocab-source-loaded? ]
|
||||
[ vocab-source-path ]
|
||||
tri (to-refresh)
|
||||
] [
|
||||
[ modified-docs ]
|
||||
[ vocab-docs-loaded? ]
|
||||
[ vocab-docs-path ]
|
||||
tri (to-refresh)
|
||||
] bi
|
||||
] each
|
||||
|
||||
modified-sources get
|
||||
modified-docs get
|
||||
]
|
||||
[ modified-sources get modified-docs get append swap seq-diff ] bi
|
||||
] with-scope ;
|
||||
|
||||
: do-refresh ( modified-sources modified-docs unchanged -- )
|
||||
unchanged-vocabs
|
||||
[
|
||||
[ [ f swap set-vocab-source-loaded? ] each ]
|
||||
[ [ f swap set-vocab-docs-loaded? ] each ] bi*
|
||||
]
|
||||
[ append prune require-all load-failures. ] 2bi ;
|
||||
[
|
||||
append prune
|
||||
[ unchanged-vocabs ]
|
||||
[ require-all load-failures. ] bi
|
||||
] 2bi ;
|
||||
|
||||
: refresh ( prefix -- ) to-refresh do-refresh ;
|
||||
|
||||
|
|
|
@ -315,7 +315,7 @@ INLINE void* allot_object(CELL type, CELL a)
|
|||
{
|
||||
CELL *object;
|
||||
|
||||
if(nursery->size - ALLOT_BUFFER_ZONE > a)
|
||||
if(HAVE_NURSERY_P && nursery->size - ALLOT_BUFFER_ZONE > a)
|
||||
{
|
||||
/* If there is insufficient room, collect the nursery */
|
||||
if(nursery->here + ALLOT_BUFFER_ZONE + a > nursery->end)
|
||||
|
|
Loading…
Reference in New Issue