Merge branch 'master' of git://factorcode.org/git/factor
commit
20e599251b
|
@ -51,9 +51,11 @@ ARTICLE: "vocabulary-search-errors" "Word lookup errors"
|
||||||
ARTICLE: "vocabulary-search" "Vocabulary search path"
|
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."
|
"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
|
$nl
|
||||||
"For a source file the vocabulary search path starts off with two vocabularies:"
|
"For a source file the vocabulary search path starts off with one vocabulary:"
|
||||||
{ $code "syntax\nscratchpad" }
|
{ $code "syntax" }
|
||||||
"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."
|
"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
|
$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" } "."
|
"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
|
$nl
|
||||||
|
@ -294,6 +296,10 @@ HELP: use
|
||||||
HELP: in
|
HELP: in
|
||||||
{ $var-description "A variable holding the name of the current vocabulary for new definitions." } ;
|
{ $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+)
|
HELP: (use+)
|
||||||
{ $values { "vocab" "an assoc mapping strings to words" } }
|
{ $values { "vocab" "an assoc mapping strings to words" } }
|
||||||
{ $description "Adds an assoc at the front of the search path." }
|
{ $description "Adds an assoc at the front of the search path." }
|
||||||
|
@ -323,7 +329,7 @@ HELP: set-in
|
||||||
$parsing-note ;
|
$parsing-note ;
|
||||||
|
|
||||||
HELP: create-in
|
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." }
|
{ $description "Creates a word in the current vocabulary. Until re-defined, the word throws an error when invoked." }
|
||||||
$parsing-note ;
|
$parsing-note ;
|
||||||
|
|
||||||
|
@ -451,7 +457,7 @@ HELP: bootstrap-syntax
|
||||||
|
|
||||||
HELP: with-file-vocabs
|
HELP: with-file-vocabs
|
||||||
{ $values { "quot" quotation } }
|
{ $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
|
HELP: parse-fresh
|
||||||
{ $values { "lines" "a sequence of strings" } { "quot" quotation } }
|
{ $values { "lines" "a sequence of strings" } { "quot" quotation } }
|
||||||
|
|
|
@ -3,6 +3,7 @@ io.streams.string namespaces classes effects source-files
|
||||||
assocs sequences strings io.files definitions continuations
|
assocs sequences strings io.files definitions continuations
|
||||||
sorting classes.tuple compiler.units debugger vocabs
|
sorting classes.tuple compiler.units debugger vocabs
|
||||||
vocabs.loader accessors ;
|
vocabs.loader accessors ;
|
||||||
|
|
||||||
IN: parser.tests
|
IN: parser.tests
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -429,3 +430,5 @@ must-fail-with
|
||||||
[
|
[
|
||||||
"USE: this-better-not-exist" eval
|
"USE: this-better-not-exist" eval
|
||||||
] must-fail
|
] must-fail
|
||||||
|
|
||||||
|
[ ": foo ;" eval ] [ error>> no-current-vocab? ] must-fail-with
|
||||||
|
|
|
@ -233,8 +233,16 @@ PREDICATE: unexpected-eof < unexpected
|
||||||
: parse-tokens ( end -- seq )
|
: parse-tokens ( end -- seq )
|
||||||
100 <vector> swap (parse-tokens) >array ;
|
100 <vector> swap (parse-tokens) >array ;
|
||||||
|
|
||||||
: create-in ( string -- word )
|
ERROR: no-current-vocab ;
|
||||||
in get create dup set-word dup save-location ;
|
|
||||||
|
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 ;
|
: CREATE ( -- word ) scan create-in ;
|
||||||
|
|
||||||
|
@ -243,7 +251,7 @@ PREDICATE: unexpected-eof < unexpected
|
||||||
: CREATE-WORD ( -- word ) CREATE dup reset-generic ;
|
: CREATE-WORD ( -- word ) CREATE dup reset-generic ;
|
||||||
|
|
||||||
: create-class-in ( word -- word )
|
: create-class-in ( word -- word )
|
||||||
in get create
|
current-vocab create
|
||||||
dup save-class-location
|
dup save-class-location
|
||||||
dup predicate-word dup set-word save-location ;
|
dup predicate-word dup set-word save-location ;
|
||||||
|
|
||||||
|
@ -440,8 +448,7 @@ SYMBOL: bootstrap-syntax
|
||||||
|
|
||||||
: with-file-vocabs ( quot -- )
|
: with-file-vocabs ( quot -- )
|
||||||
[
|
[
|
||||||
"scratchpad" in set
|
f in set { "syntax" } set-use
|
||||||
{ "syntax" "scratchpad" } set-use
|
|
||||||
bootstrap-syntax get [ use get push ] when*
|
bootstrap-syntax get [ use get push ] when*
|
||||||
call
|
call
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
|
@ -2,9 +2,11 @@ USING: io io.mmap io.files kernel tools.test continuations
|
||||||
sequences io.encodings.ascii accessors ;
|
sequences io.encodings.ascii accessors ;
|
||||||
IN: io.mmap.tests
|
IN: io.mmap.tests
|
||||||
|
|
||||||
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
|
[ "resource:mmap-test-file.txt" delete-file ] ignore-errors
|
||||||
[ ] [ "12345" "mmap-test-file.txt" resource-path ascii set-file-contents ] unit-test
|
[ ] [ "12345" "resource:mmap-test-file.txt" 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
|
[ ] [ "resource:mmap-test-file.txt" 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
|
[ 5 ] [ "resource:mmap-test-file.txt" dup file-info size>> [ length ] with-mapped-file ] unit-test
|
||||||
[ "22345" ] [ "mmap-test-file.txt" resource-path ascii file-contents ] unit-test
|
[ "22345" ] [ "resource:mmap-test-file.txt" ascii file-contents ] unit-test
|
||||||
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
|
[ "resource:mmap-test-file.txt" delete-file ] ignore-errors
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,10 @@ M: mapped-file set-nth-unsafe
|
||||||
|
|
||||||
INSTANCE: mapped-file sequence
|
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 -- )
|
HOOK: close-mapped-file io-backend ( mmap -- )
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ IN: io.unix.mmap
|
||||||
>r f -roll r> open-r/w [ 0 mmap ] keep
|
>r f -roll r> open-r/w [ 0 mmap ] keep
|
||||||
over MAP_FAILED = [ close (io-error) ] when ;
|
over MAP_FAILED = [ close (io-error) ] when ;
|
||||||
|
|
||||||
M: unix <mapped-file> ( path length -- obj )
|
M: unix (mapped-file) ( path length -- obj )
|
||||||
swap >r
|
swap >r
|
||||||
dup PROT_READ PROT_WRITE bitor MAP_FILE MAP_SHARED bitor
|
dup PROT_READ PROT_WRITE bitor MAP_FILE MAP_SHARED bitor
|
||||||
r> mmap-open f mapped-file boa ;
|
r> mmap-open f mapped-file boa ;
|
||||||
|
|
|
@ -70,7 +70,7 @@ M: wince with-privileges
|
||||||
dup close-later
|
dup close-later
|
||||||
] with-privileges ;
|
] with-privileges ;
|
||||||
|
|
||||||
M: windows <mapped-file> ( path length -- mmap )
|
M: windows (mapped-file) ( path length -- mmap )
|
||||||
[
|
[
|
||||||
swap
|
swap
|
||||||
GENERIC_WRITE GENERIC_READ bitor
|
GENERIC_WRITE GENERIC_READ bitor
|
||||||
|
|
|
@ -98,7 +98,7 @@ TUPLE: win32-monitor < monitor port ;
|
||||||
|
|
||||||
M:: winnt (monitor) ( path recursive? mailbox -- monitor )
|
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>
|
path open-directory \ win32-monitor-port <buffered-port>
|
||||||
recursive? >>recursive
|
recursive? >>recursive
|
||||||
>>port
|
>>port
|
||||||
|
|
|
@ -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
|
math.functions math.ranges namespaces random sequences
|
||||||
hashtables sets ;
|
hashtables sets ;
|
||||||
IN: math.miller-rabin
|
IN: math.miller-rabin
|
||||||
|
@ -76,7 +76,9 @@ TUPLE: miller-rabin-bounds ;
|
||||||
: find-relative-prime ( n -- p )
|
: find-relative-prime ( n -- p )
|
||||||
dup random find-relative-prime* ;
|
dup random find-relative-prime* ;
|
||||||
|
|
||||||
|
ERROR: too-few-primes ;
|
||||||
|
|
||||||
: unique-primes ( numbits n -- seq )
|
: unique-primes ( numbits n -- seq )
|
||||||
#! generate two primes
|
#! 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 ;
|
[ [ drop random-prime ] with map ] [ all-unique? ] generate ;
|
||||||
|
|
|
@ -131,7 +131,7 @@ M: email clone
|
||||||
"-" %
|
"-" %
|
||||||
millis #
|
millis #
|
||||||
"@" %
|
"@" %
|
||||||
smtp-domain get %
|
smtp-domain get [ host-name ] unless* %
|
||||||
">" %
|
">" %
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue