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

db4
Joe Groff 2010-02-21 09:58:41 -08:00
commit 420e2d2308
24 changed files with 157 additions and 136 deletions

View File

@ -76,13 +76,13 @@ MACRO: (send) ( selector super? -- quot )
: super-send ( receiver args... selector -- return... ) t (send) ; inline
! Runtime introspection
SYMBOL: class-startup-hooks
SYMBOL: class-init-hooks
class-startup-hooks [ H{ } clone ] initialize
class-init-hooks [ H{ } clone ] initialize
: (objc-class) ( name word -- class )
2dup execute dup [ 2nip ] [
drop over class-startup-hooks get at [ call( -- ) ] when*
drop over class-init-hooks get at [ call( -- ) ] when*
2dup execute dup [ 2nip ] [
2drop "No such class: " prepend throw
] if
@ -229,7 +229,7 @@ ERROR: no-objc-type name ;
: class-exists? ( string -- class ) objc_getClass >boolean ;
: define-objc-class-word ( quot name -- )
[ class-startup-hooks get set-at ]
[ class-init-hooks get set-at ]
[
[ "cocoa.classes" create ] [ '[ _ objc-class ] ] bi
(( -- class )) define-declared
@ -237,8 +237,10 @@ ERROR: no-objc-type name ;
: import-objc-class ( name quot -- )
over define-objc-class-word
[ objc-class register-objc-methods ]
[ objc-meta-class register-objc-methods ] bi ;
dup objc_getClass [
[ objc-class register-objc-methods ]
[ objc-meta-class register-objc-methods ] bi
] [ drop ] if ;
: root-class ( class -- root )
dup class_getSuperclass [ root-class ] [ ] ?if ;

View File

@ -1,15 +1,14 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs byte-arrays calendar classes
combinators combinators.short-circuit concurrency.promises
continuations destructors ftp io io.backend io.directories
io.encodings io.encodings.binary
tools.files io.encodings.utf8 io.files io.files.info
io.pathnames io.launcher.unix.parser io.servers.connection
io.sockets io.streams.duplex io.streams.string io.timeouts
kernel make math math.bitwise math.parser namespaces sequences
splitting threads unicode.case logging calendar.format
strings io.files.links io.files.types io.encodings.8-bit.latin1 ;
USING: accessors assocs byte-arrays calendar classes combinators
combinators.short-circuit concurrency.promises continuations
destructors ftp io io.backend io.directories io.encodings
io.encodings.binary tools.files io.encodings.utf8 io.files
io.files.info io.pathnames io.servers.connection io.sockets
io.streams.duplex io.streams.string io.timeouts kernel make math
math.bitwise math.parser namespaces sequences splitting threads
unicode.case logging calendar.format strings io.files.links
io.files.types io.encodings.8-bit.latin1 simple-tokenizer ;
IN: ftp.server
SYMBOL: server
@ -24,7 +23,7 @@ TUPLE: ftp-command raw tokenized ;
dup \ <ftp-command> DEBUG log-message
ftp-command new
over >>raw
swap tokenize-command >>tokenized ;
swap tokenize >>tokenized ;
TUPLE: ftp-get path ;
: <ftp-get> ( path -- obj )

View File

@ -1,33 +0,0 @@
IN: io.launcher.unix.parser.tests
USING: io.launcher.unix.parser tools.test ;
[ "" tokenize-command ] must-fail
[ " " tokenize-command ] must-fail
[ V{ "a" } ] [ "a" tokenize-command ] unit-test
[ V{ "abc" } ] [ "abc" tokenize-command ] unit-test
[ V{ "abc" } ] [ "abc " tokenize-command ] unit-test
[ V{ "abc" } ] [ " abc" tokenize-command ] unit-test
[ V{ "abc" "def" } ] [ "abc def" tokenize-command ] unit-test
[ V{ "abc def" } ] [ "abc\\ def" tokenize-command ] unit-test
[ V{ "abc\\" "def" } ] [ "abc\\\\ def" tokenize-command ] unit-test
[ V{ "abc\\ def" } ] [ "\"abc\\\\ def\"" tokenize-command ] unit-test
[ V{ "abc\\ def" } ] [ " \"abc\\\\ def\"" tokenize-command ] unit-test
[ V{ "abc\\ def" "hey" } ] [ "\"abc\\\\ def\" hey" tokenize-command ] unit-test
[ V{ "abc def" "hey" } ] [ "\"abc def\" \"hey\"" tokenize-command ] unit-test
[ "\"abc def\" \"hey" tokenize-command ] must-fail
[ "\"abc def" tokenize-command ] must-fail
[ V{ "abc def" "h\"ey" } ] [ "\"abc def\" \"h\\\"ey\" " tokenize-command ] unit-test
[
V{
"Hello world.app/Contents/MacOS/hello-ui"
"-i=boot.macosx-ppc.image"
"-include= math compiler ui"
"-deploy-vocab=hello-ui"
"-output-image=Hello world.app/Contents/Resources/hello-ui.image"
"-no-stack-traces"
"-no-user-init"
}
] [
"\"Hello world.app/Contents/MacOS/hello-ui\" -i=boot.macosx-ppc.image \"-include= math compiler ui\" -deploy-vocab=hello-ui \"-output-image=Hello world.app/Contents/Resources/hello-ui.image\" -no-stack-traces -no-user-init" tokenize-command
] unit-test

View File

@ -1 +0,0 @@
unix

View File

@ -1,15 +1,14 @@
! Copyright (C) 2007, 2008 Slava Pestov.
! Copyright (C) 2007, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays assocs combinators
continuations environment io io.backend io.backend.unix
io.files io.files.private io.files.unix io.launcher
io.launcher.unix.parser io.pathnames io.ports kernel math
namespaces sequences strings system threads unix
unix.process unix.ffi ;
io.files io.files.private io.files.unix io.launcher io.pathnames
io.ports kernel math namespaces sequences strings system threads
unix unix.process unix.ffi simple-tokenizer ;
IN: io.launcher.unix
: get-arguments ( process -- seq )
command>> dup string? [ tokenize-command ] when ;
command>> dup string? [ tokenize ] when ;
: assoc>env ( assoc -- env )
[ "=" glue ] { } assoc>map ;

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,13 @@
USING: help.markup help.syntax strings ;
IN: simple-tokenizer
HELP: tokenize
{ $values { "input" string } { "ast" "a sequence of strings" } }
{ $description
"Tokenize a string. Supported syntax:"
{ $list
{ { $snippet "foo bar baz" } " - simple tokens" }
{ { $snippet "foo\\ bar" } " - token with an escaped space"}
{ { $snippet "\"foo bar\"" } " - quoted token" }
}
} ;

View File

@ -0,0 +1,33 @@
IN: simple-tokenizer.tests
USING: simple-tokenizer tools.test ;
[ "" tokenize ] must-fail
[ " " tokenize ] must-fail
[ V{ "a" } ] [ "a" tokenize ] unit-test
[ V{ "abc" } ] [ "abc" tokenize ] unit-test
[ V{ "abc" } ] [ "abc " tokenize ] unit-test
[ V{ "abc" } ] [ " abc" tokenize ] unit-test
[ V{ "abc" "def" } ] [ "abc def" tokenize ] unit-test
[ V{ "abc def" } ] [ "abc\\ def" tokenize ] unit-test
[ V{ "abc\\" "def" } ] [ "abc\\\\ def" tokenize ] unit-test
[ V{ "abc\\ def" } ] [ "\"abc\\\\ def\"" tokenize ] unit-test
[ V{ "abc\\ def" } ] [ " \"abc\\\\ def\"" tokenize ] unit-test
[ V{ "abc\\ def" "hey" } ] [ "\"abc\\\\ def\" hey" tokenize ] unit-test
[ V{ "abc def" "hey" } ] [ "\"abc def\" \"hey\"" tokenize ] unit-test
[ "\"abc def\" \"hey" tokenize ] must-fail
[ "\"abc def" tokenize ] must-fail
[ V{ "abc def" "h\"ey" } ] [ "\"abc def\" \"h\\\"ey\" " tokenize ] unit-test
[
V{
"Hello world.app/Contents/MacOS/hello-ui"
"-i=boot.macosx-ppc.image"
"-include= math compiler ui"
"-deploy-vocab=hello-ui"
"-output-image=Hello world.app/Contents/Resources/hello-ui.image"
"-no-stack-traces"
"-no-user-init"
}
] [
"\"Hello world.app/Contents/MacOS/hello-ui\" -i=boot.macosx-ppc.image \"-include= math compiler ui\" -deploy-vocab=hello-ui \"-output-image=Hello world.app/Contents/Resources/hello-ui.image\" -no-stack-traces -no-user-init" tokenize
] unit-test

View File

@ -1,13 +1,9 @@
! Copyright (C) 2008 Slava Pestov
! Copyright (C) 2008, 2010 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
USING: peg peg.ebnf arrays sequences strings kernel ;
IN: io.launcher.unix.parser
IN: simple-tokenizer
! Our command line parser. Supported syntax:
! foo bar baz -- simple tokens
! foo\ bar -- escaping the space
! "foo bar" -- quotation
EBNF: tokenize-command
EBNF: tokenize
space = " "
escaped-char = "\" .:ch => [[ ch ]]
quoted = '"' (escaped-char | [^"])*:a '"' => [[ a ]]

View File

@ -0,0 +1 @@
text

View File

@ -61,18 +61,17 @@ M: pathname uses string>> source-file top-level-form>> [ uses ] [ { } ] if* ;
! To make UI browser happy
M: vocab uses drop f ;
GENERIC: crossref-def ( defspec -- )
M: object crossref-def
: crossref-def ( defspec -- )
dup uses crossref get add-vertex ;
M: word crossref-def
[ call-next-method ] [ subwords [ crossref-def ] each ] bi ;
: defs-to-crossref ( -- seq )
[
all-words [ generic? not ] filter
all-words
[ [ generic? not ] filter ]
[ [ subwords ] map concat ] bi
all-articles [ >link ] map
source-files get keys [ <pathname> ] map
] append-outputs ;

View File

@ -13,7 +13,7 @@ ARTICLE: "prepare-deploy" "Preparing to deploy an application"
ARTICLE: "deploy-resources" "Deployed resource files"
"To include additional files in your deployed application, specify their names in a vocabulary's " { $snippet "resources.txt" } " file. The " { $snippet "resources.txt" } " file contains one glob pattern per line. These patterns are expanded relative to the vocabulary directory; files outside of the vocabulary directory cannot be referenced. If a file inside the vocabulary directory matches any of these patterns, it will be included in deployed applications that reference the vocabulary. If a subdirectory matches, its contents will be included recursively."
$nl
"If the deployed vocabulary includes an icon file for the current platform (" { $snippet "icon.ico" } " on Windows, or " { $snippet "icon.icns" } " on MacOS X), it will be embedded in the deployed application as its GUI icon." ;
"If the deployed vocabulary includes an icon file for the current platform, it will be embedded in the deployed application as its GUI icon. See " { $link "vocabs.icons" } "." ;
ARTICLE: "tools.deploy.usage" "Deploy tool usage"
"Once the necessary deployment flags have been set, the application can be deployed:"

View File

@ -0,0 +1,4 @@
linux
freebsd
netbsd
openbsd

View File

@ -1 +0,0 @@
untested

View File

@ -1 +0,0 @@
unix

View File

@ -1,22 +1,20 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax unix.utmpx unix.bsd.netbsd accessors
unix.utmpx system kernel unix combinators ;
USING: alien.syntax unix unix.utmpx unix.ffi.bsd.netbsd accessors
system kernel combinators ;
IN: unix.utmpx.netbsd
TUPLE: netbsd-utmpx-record < utmpx-record termination exit
sockaddr ;
TUPLE: netbsd-utmpx-record < utmpx-record
termination exit sockaddr ;
M: netbsd new-utmpx-record ( -- utmpx-record )
netbsd-utmpx-record new ;
netbsd-utmpx-record new ;
M: netbsd utmpx>utmpx-record ( utmpx -- record )
[ new-utmpx-record ] keep
{
[
utmpx-ut_exit
[ exit_struct-e_termination >>termination ]
[ exit_struct-e_exit >>exit ] bi
]
[ utmpx-ut_ss >>sockaddr ]
} cleave ;
[ new-utmpx-record ] dip
[
ut_exit>>
[ e_termination>> >>termination ]
[ e_exit>> >>exit ] bi
]
[ ut_ss>> >>sockaddr ] bi ;

View File

@ -1 +1,2 @@
unix
macosx
netbsd

View File

@ -2,23 +2,36 @@ USING: help.markup help.syntax strings ;
IN: vocabs.metadata
ARTICLE: "vocabs.metadata" "Vocabulary metadata"
"Vocabulary summaries:"
"Vocabulary directories can contain text files with metadata:"
{ $list
{ { $snippet "authors.txt" } " - a series of lines, with one author name per line. These are listed under " { $link "vocab-authors" } "." }
{ { $snippet "platforms.txt" } " - a series of lines, with one operating system name per line." }
{ { $snippet "resources.txt" } " - a series of lines, with one file glob pattern per line. Files inside the vocabulary directory whose names match any of these glob patterns will be included with the compiled application as " { $link "deploy-resources" } "." }
{ { $snippet "summary.txt" } " - a one-line description." }
{ { $snippet "tags.txt" } " - a series of lines, with one tag per line. Tags help classify the vocabulary. Consult " { $link "vocab-tags" } " for a list of existing tags you can reuse." }
}
"Words for reading and writing " { $snippet "summary.txt" } ":"
{ $subsections
vocab-summary
set-vocab-summary
}
"Vocabulary authors:"
"Words for reading and writing " { $snippet "authors.txt" } ":"
{ $subsections
vocab-authors
set-vocab-authors
}
"Vocabulary tags:"
"Words for reading and writing " { $snippet "tags.txt" } ":"
{ $subsections
vocab-tags
set-vocab-tags
add-vocab-tags
}
"Vocabulary resources:"
"Words for reading and writing " { $snippet "platforms.txt" } ":"
{ $subsections
vocab-platforms
set-vocab-platforms
}
"Words for reading and writing " { $snippet "resources.txt" } ":"
{ $subsections
vocab-resources
set-vocab-resources
@ -55,6 +68,16 @@ HELP: set-vocab-tags
{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }
{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;
HELP: vocab-platforms
{ $values { "vocab" "a vocabulary specifier" } { "platforms" "a sequence of operating system symbols" } }
{ $description "Outputs a list of operating systems supported by " { $snippet "vocab" } ", as specified by the " { $snippet "platforms.txt" } " file in the vocabulary's directory. Outputs an empty array if the file doesn't exist." }
{ $notes "Operating system symbols are defined in the " { $vocab-link "system" } " vocabulary." } ;
HELP: set-vocab-platforms
{ $values { "platforms" "a sequence of operating system symbols" } { "vocab" "a vocabulary specifier" } }
{ $description "Stores a list of operating systems supported by " { $snippet "vocab" } " to the " { $snippet "platforms.txt" } " file in the vocabulary's directory." }
{ $notes "Operating system symbols are defined in the " { $vocab-link "system" } " vocabulary." } ;
HELP: vocab-resources
{ $values { "vocab" "a vocabulary specifier" } { "patterns" "a sequence of glob patterns" } }
{ $description "Outputs a list of glob patterns matching files that will be deployed with an application that includes " { $snippet "vocab" } ", as specified by the " { $snippet "resources.txt" } " file in the vocabulary's directory. Outputs an empty array if the file doesn't exist." }

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008, 2009 Slava Pestov.
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays sequences kernel kernel.private accessors math
alien.accessors byte-arrays io io.encodings io.encodings.utf8
@ -37,17 +37,16 @@ M: string string>alien
M: tuple string>alien drop underlying>> ;
HOOK: alien>native-string os ( alien -- string )
HOOK: native-string-encoding os ( -- encoding ) foldable
M: windows alien>native-string utf16n alien>string ;
M: unix native-string-encoding utf8 ;
M: windows native-string-encoding utf16n ;
M: unix alien>native-string utf8 alien>string ;
: alien>native-string ( alien -- string )
native-string-encoding alien>string ; inline
HOOK: native-string>alien os ( string -- alien )
M: windows native-string>alien utf16n string>alien ;
M: unix native-string>alien utf8 string>alien ;
: native-string>alien ( string -- alien )
native-string-encoding string>alien ; inline
: dll-path ( dll -- string )
path>> alien>native-string ;

View File

@ -27,10 +27,11 @@ ARTICLE: "vocabs.roots" "Vocabulary roots"
"You can store your own vocabularies in the " { $snippet "work" } " directory."
{ $subsections "add-vocab-roots" } ;
ARTICLE: "vocabs.icons" "Vocabulary icons"
"An icon file representing the vocabulary can be provided for use by " { $link "tools.deploy" } ". A file named " { $snippet "icon.ico" } " will be used as the application icon when the application is deployed on Windows. A file named " { $snippet "icon.icns" } " will be used when the application is deployed on MacOS X." ;
ARTICLE: "vocabs.loader" "Vocabulary loader"
"The vocabulary loader combines the vocabulary system with " { $link "parser" } " in order to implement automatic loading of vocabulary source files. The vocabulary loader is implemented in the " { $vocab-link "vocabs.loader" } " vocabulary."
$nl
"When an attempt is made to use a vocabulary that has not been loaded into the image, the vocabulary loader is asked to locate the vocabulary's source files, and load them."
"The " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " words load vocabularies using the vocabulary loader. The vocabulary loader is implemented in the " { $vocab-link "vocabs.loader" } " vocabulary."
$nl
"The vocabulary loader searches for vocabularies in a set of directories known as vocabulary roots."
{ $subsections "vocabs.roots" }
@ -45,17 +46,8 @@ $nl
{ { $snippet "foo/bar/bar-docs.factor" } " - documentation, see " { $link "writing-help" } }
{ { $snippet "foo/bar/bar-tests.factor" } " - unit tests, see " { $link "tools.test" } }
}
"Finally, four optional text files may contain metadata:"
{ $list
{ { $snippet "foo/bar/authors.txt" } " - a series of lines, with one author name per line. These are listed under " { $link "vocab-authors" } "." }
{ { $snippet "foo/bar/resources.txt" } " - a series of lines with one file glob pattern per line. Files inside the vocabulary directory whose names match any of these glob patterns will be included with the compiled application as " { $link "deploy-resources" } "." }
{ { $snippet "foo/bar/summary.txt" } " - a one-line description." }
{ { $snippet "foo/bar/tags.txt" } " - a whitespace-separated list of tags which classify the vocabulary. Consult " { $link "vocab-tags" } " for a list of existing tags you can reuse." }
}
"An icon file representing the vocabulary can also be provided. A file named " { $snippet "icon.ico" } " will be used as the application icon when the application is deployed on Windows. A file named " { $snippet "icon.icns" } " will be used when the application is deployed on MacOS X."
$nl
"The " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " words load vocabularies which have not been loaded yet, as needed."
$nl
"Optional text files may contain metadata."
{ $subsections "vocabs.metadata" "vocabs.icons" }
"Vocabularies can also be loaded at run time, without altering the vocabulary search path. This is done by calling a word which loads a vocabulary if it is not in the image, doing nothing if it is:"
{ $subsections require }
"The above word will only ever load a vocabulary once in a given session. There is another word which unconditionally loads vocabulary from disk, regardless of whether or not is has already been loaded:"

View File

@ -1,9 +1,8 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files.windows io.streams.duplex kernel math
math.bitwise windows.kernel32 accessors alien.c-types
windows io.files.windows fry locals continuations
classes.struct ;
math.bitwise windows windows.kernel32 windows.errors accessors
alien.c-types fry locals continuations classes.struct ;
IN: io.serial.windows
: <serial-stream> ( path encoding -- duplex )

View File

@ -1,26 +1,24 @@
USING: alien.c-types alien.syntax io io.encodings.utf16n
io.encodings.utf8 io.files kernel namespaces sequences system threads
! Copyright (C) 2009 Phil Dawes.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.strings alien.syntax io
io.encodings.utf8 io.files kernel sequences system threads
unix.utilities ;
IN: native-thread-test
FUNCTION: void* start_standalone_factor_in_new_thread ( int argc, char** argv ) ;
HOOK: native-string-encoding os ( -- encoding )
M: windows native-string-encoding utf16n ;
M: unix native-string-encoding utf8 ;
: start-vm-in-os-thread ( args -- threadhandle )
\ vm get-global prefix
vm prefix
[ length ] [ native-string-encoding strings>alien ] bi
start_standalone_factor_in_new_thread ;
start_standalone_factor_in_new_thread ;
: start-tetris-in-os-thread ( -- )
{ "-run=tetris" } start-vm-in-os-thread drop ;
{ "-run=tetris" } start-vm-in-os-thread drop ;
: start-testthread-in-os-thread ( -- )
{ "-run=native-thread-test" } start-vm-in-os-thread drop ;
: testthread ( -- )
"/tmp/hello" utf8 [ "hello!\n" write ] with-file-appender 5000000 sleep ;
: start-test-thread-in-os-thread ( -- )
{ "-run=native-thread-test" } start-vm-in-os-thread drop ;
MAIN: testthread
: test-thread ( -- )
"/tmp/hello" utf8 [ "hello!\n" write ] with-file-appender 5000000 sleep ;
MAIN: test-thread