Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-04-25 03:27:05 -05:00
commit 20e599251b
10 changed files with 46 additions and 23 deletions

View File

@ -51,9 +51,11 @@ ARTICLE: "vocabulary-search-errors" "Word lookup errors"
ARTICLE: "vocabulary-search" "Vocabulary search path"
"When the parser reads a token, it attempts to look up a word named by that token. The lookup is performed by searching each vocabulary in the search path, in order."
$nl
"For a source file the vocabulary search path starts off with two vocabularies:"
{ $code "syntax\nscratchpad" }
"The " { $vocab-link "syntax" } " vocabulary consists of a set of parsing words for reading Factor data and defining new words. The " { $vocab-link "scratchpad" } " vocabulary is the default vocabulary for new word definitions."
"For a source file the vocabulary search path starts off with one vocabulary:"
{ $code "syntax" }
"The " { $vocab-link "syntax" } " vocabulary consists of a set of parsing words for reading Factor data and defining new words."
$nl
"In the listener, the " { $vocab-link "scratchpad" } " is the default vocabulary for new word definitions. However, when loading source files, there is no default vocabulary. Defining words before declaring a vocabulary with " { $link POSTPONE: IN: } " results in an error."
$nl
"At the interactive listener, the default search path contains many more vocabularies. Details on the default search path and parser invocation are found in " { $link "parser" } "."
$nl
@ -294,6 +296,10 @@ HELP: use
HELP: in
{ $var-description "A variable holding the name of the current vocabulary for new definitions." } ;
HELP: current-vocab
{ $values { "str" "a vocabulary" } }
{ $description "Returns the vocabulary stored in the " { $link in } " symbol. Throws an error if the current vocabulary is " { $link f } "." } ;
HELP: (use+)
{ $values { "vocab" "an assoc mapping strings to words" } }
{ $description "Adds an assoc at the front of the search path." }
@ -323,7 +329,7 @@ HELP: set-in
$parsing-note ;
HELP: create-in
{ $values { "string" "a word name" } { "word" "a new word" } }
{ $values { "str" "a word name" } { "word" "a new word" } }
{ $description "Creates a word in the current vocabulary. Until re-defined, the word throws an error when invoked." }
$parsing-note ;
@ -451,7 +457,7 @@ HELP: bootstrap-syntax
HELP: with-file-vocabs
{ $values { "quot" quotation } }
{ $description "Calls the quotation in a scope with the initial the vocabulary search path for parsing a file. This consists of the " { $snippet "syntax" } " vocabulary together with the " { $snippet "scratchpad" } " vocabulary." } ;
{ $description "Calls the quotation in a scope with the initial the vocabulary search path for parsing a file. This consists of just the " { $snippet "syntax" } " vocabulary." } ;
HELP: parse-fresh
{ $values { "lines" "a sequence of strings" } { "quot" quotation } }

View File

@ -3,6 +3,7 @@ io.streams.string namespaces classes effects source-files
assocs sequences strings io.files definitions continuations
sorting classes.tuple compiler.units debugger vocabs
vocabs.loader accessors ;
IN: parser.tests
[
@ -429,3 +430,5 @@ must-fail-with
[
"USE: this-better-not-exist" eval
] must-fail
[ ": foo ;" eval ] [ error>> no-current-vocab? ] must-fail-with

View File

@ -233,8 +233,16 @@ PREDICATE: unexpected-eof < unexpected
: parse-tokens ( end -- seq )
100 <vector> swap (parse-tokens) >array ;
: create-in ( string -- word )
in get create dup set-word dup save-location ;
ERROR: no-current-vocab ;
M: no-current-vocab summary ( obj -- )
drop "Current vocabulary is f, use IN:" ;
: current-vocab ( -- str )
in get [ no-current-vocab ] unless* ;
: create-in ( str -- word )
current-vocab create dup set-word dup save-location ;
: CREATE ( -- word ) scan create-in ;
@ -243,7 +251,7 @@ PREDICATE: unexpected-eof < unexpected
: CREATE-WORD ( -- word ) CREATE dup reset-generic ;
: create-class-in ( word -- word )
in get create
current-vocab create
dup save-class-location
dup predicate-word dup set-word save-location ;
@ -440,8 +448,7 @@ SYMBOL: bootstrap-syntax
: with-file-vocabs ( quot -- )
[
"scratchpad" in set
{ "syntax" "scratchpad" } set-use
f in set { "syntax" } set-use
bootstrap-syntax get [ use get push ] when*
call
] with-scope ; inline

View File

@ -2,9 +2,11 @@ USING: io io.mmap io.files kernel tools.test continuations
sequences io.encodings.ascii accessors ;
IN: io.mmap.tests
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
[ ] [ "12345" "mmap-test-file.txt" resource-path ascii set-file-contents ] unit-test
[ ] [ "mmap-test-file.txt" resource-path dup file-info size>> [ CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test
[ 5 ] [ "mmap-test-file.txt" resource-path dup file-info size>> [ length ] with-mapped-file ] unit-test
[ "22345" ] [ "mmap-test-file.txt" resource-path ascii file-contents ] unit-test
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
[ "resource:mmap-test-file.txt" delete-file ] ignore-errors
[ ] [ "12345" "resource:mmap-test-file.txt" ascii set-file-contents ] unit-test
[ ] [ "resource:mmap-test-file.txt" dup file-info size>> [ CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test
[ 5 ] [ "resource:mmap-test-file.txt" dup file-info size>> [ length ] with-mapped-file ] unit-test
[ "22345" ] [ "resource:mmap-test-file.txt" ascii file-contents ] unit-test
[ "resource:mmap-test-file.txt" delete-file ] ignore-errors

View File

@ -21,7 +21,10 @@ M: mapped-file set-nth-unsafe
INSTANCE: mapped-file sequence
HOOK: <mapped-file> io-backend ( path length -- mmap )
HOOK: (mapped-file) io-backend ( path length -- mmap )
: <mapped-file> ( path length -- mmap )
>r normalize-path r> (mapped-file) ;
HOOK: close-mapped-file io-backend ( mmap -- )

View File

@ -10,7 +10,7 @@ IN: io.unix.mmap
>r f -roll r> open-r/w [ 0 mmap ] keep
over MAP_FAILED = [ close (io-error) ] when ;
M: unix <mapped-file> ( path length -- obj )
M: unix (mapped-file) ( path length -- obj )
swap >r
dup PROT_READ PROT_WRITE bitor MAP_FILE MAP_SHARED bitor
r> mmap-open f mapped-file boa ;

View File

@ -70,7 +70,7 @@ M: wince with-privileges
dup close-later
] with-privileges ;
M: windows <mapped-file> ( path length -- mmap )
M: windows (mapped-file) ( path length -- mmap )
[
swap
GENERIC_WRITE GENERIC_READ bitor

View File

@ -98,7 +98,7 @@ TUPLE: win32-monitor < monitor port ;
M:: winnt (monitor) ( path recursive? mailbox -- monitor )
[
path mailbox win32-monitor new-monitor
path normalize-path mailbox win32-monitor new-monitor
path open-directory \ win32-monitor-port <buffered-port>
recursive? >>recursive
>>port

View File

@ -1,4 +1,4 @@
USING: combinators combinators.lib io locals kernel math
eSING: combinators combinators.lib io locals kernel math
math.functions math.ranges namespaces random sequences
hashtables sets ;
IN: math.miller-rabin
@ -76,7 +76,9 @@ TUPLE: miller-rabin-bounds ;
: find-relative-prime ( n -- p )
dup random find-relative-prime* ;
ERROR: too-few-primes ;
: unique-primes ( numbits n -- seq )
#! generate two primes
over 5 < [ "not enough primes below 5 bits" throw ] when
over 5 < [ too-few-primes ] when
[ [ drop random-prime ] with map ] [ all-unique? ] generate ;

View File

@ -131,7 +131,7 @@ M: email clone
"-" %
millis #
"@" %
smtp-domain get %
smtp-domain get [ host-name ] unless* %
">" %
] "" make ;