Minor cleanups and documentation fixes

slava 2006-03-27 07:34:07 +00:00
parent 5e5cbd50d4
commit 56bb99fa56
9 changed files with 14 additions and 32 deletions

View File

@ -51,6 +51,7 @@
- variable width word wrap - variable width word wrap
- fix top level window positioning - fix top level window positioning
- changing window titles - changing window titles
- remove distinction between a word and a link to a word
+ compiler/ffi: + compiler/ffi:

View File

@ -35,13 +35,11 @@ ARTICLE: "alien-invoke" "Calling C from Factor"
$terpri $terpri
"The above parsing words create word definitions which call a lower-level word; you can use it directly, too:" "The above parsing words create word definitions which call a lower-level word; you can use it directly, too:"
{ $subsection alien-invoke } { $subsection alien-invoke }
$terpri
"There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-types" } "." ; "There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-types" } "." ;
ARTICLE: "alien-callback" "Calling Factor from C" ARTICLE: "alien-callback" "Calling Factor from C"
"Callbacks can be defined and passed to C code as function pointers; the C code can then invoke the callback and run Factor code:" "Callbacks can be defined and passed to C code as function pointers; the C code can then invoke the callback and run Factor code:"
{ $subsection alien-callback } { $subsection alien-callback }
$terpri
"There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-types" } "." ; "There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-types" } "." ;
ARTICLE: "c-types" "C types" ARTICLE: "c-types" "C types"
@ -262,6 +260,7 @@ $terpri
{ $subsection malloc } { $subsection malloc }
{ $subsection calloc } { $subsection calloc }
{ $subsection realloc } { $subsection realloc }
{ $subsection check-ptr }
"You must always free pointers returned by any of the above words:" "You must always free pointers returned by any of the above words:"
{ $subsection free } ; { $subsection free } ;

View File

@ -56,21 +56,21 @@ HELP: alien>string "( c-ptr -- string )"
HELP: <malloc-array> "( n type -- alien )" HELP: <malloc-array> "( n type -- alien )"
{ $values { "n" "a non-negative integer" } { "type" "a string" } { "alien" "an alien address" } } { $values { "n" "a non-negative integer" } { "type" "a string" } { "alien" "an alien address" } }
{ $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type." } { $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
{ $errors "Throws an error if the type does not exist, if the requested size is negative, or if memory allocation fails." } { $errors "Throws an error if the type does not exist, if the requested size is negative, or if memory allocation fails." }
{ $see-also <c-array> } ; { $see-also <c-array> } ;
HELP: <malloc-object> "( type -- alien )" HELP: <malloc-object> "( type -- alien )"
{ $values { "type" "a string" } { "alien" "an alien address" } } { $values { "type" "a string" } { "alien" "an alien address" } }
{ $description "Allocates an unmanaged memory block large enough to hold a value of a C type." } { $description "Allocates an unmanaged memory block large enough to hold a value of a C type." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
{ $errors "Throws an error if the type does not exist or if memory allocation fails." } { $errors "Throws an error if the type does not exist or if memory allocation fails." }
{ $see-also <c-object> } ; { $see-also <c-object> } ;
HELP: <malloc-string> "( string -- alien )" HELP: <malloc-string> "( string -- alien )"
{ $values { "string" "a string" } { "alien" "an alien address" } } { $values { "string" "a string" } { "alien" "an alien address" } }
{ $description "Copies a string to an unmanaged memory block large enough to hold a copy of the string in 8-bit ASCII encoding, with a trailing null byte." } { $description "Copies a string to an unmanaged memory block large enough to hold a copy of the string in 8-bit ASCII encoding, with a trailing null byte." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
{ $errors "Throws an error if memory allocation fails." } { $errors "Throws an error if memory allocation fails." }
{ $see-also string>alien } ; { $see-also string>alien } ;

View File

@ -6,21 +6,21 @@ HELP: malloc "( size -- alien )"
{ $description "Allocates a block of " { $snippet "size" } " bytes from the operating system. The contents of the block are undefined." { $description "Allocates a block of " { $snippet "size" } " bytes from the operating system. The contents of the block are undefined."
$terpri $terpri
"Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." } "Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ; { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ;
HELP: calloc "( count size -- alien )" HELP: calloc "( count size -- alien )"
{ $values { "count" "a non-negative integer" } { "size" "a non-negative integer" } { "alien" "an alien address" } } { $values { "count" "a non-negative integer" } { "size" "a non-negative integer" } { "alien" "an alien address" } }
{ $description "Allocates a block of " { $snippet "count * size" } " bytes from the operating system. The contents of the block are initially zero." { $description "Allocates a block of " { $snippet "count * size" } " bytes from the operating system. The contents of the block are initially zero."
$terpri $terpri
"Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." } "Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ; { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ;
HELP: realloc "( alien size -- newalien )" HELP: realloc "( alien size -- newalien )"
{ $values { "alien" "an alien address" } { "size" "a non-negative integer" } { "newalien" "an alien address" } } { $values { "alien" "an alien address" } { "size" "a non-negative integer" } { "newalien" "an alien address" } }
{ $description "Allocates a new block of " { $snippet "size" } " bytes from the operating system. The contents of " { $snippet "alien" } ", which itself must be a block previously returned by " { $link malloc } " or " { $link realloc } ", are copied into the new block, and the old block is freed." { $description "Allocates a new block of " { $snippet "size" } " bytes from the operating system. The contents of " { $snippet "alien" } ", which itself must be a block previously returned by " { $link malloc } " or " { $link realloc } ", are copied into the new block, and the old block is freed."
$terpri $terpri
"Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." } "Outputs " { $link f } " if memory allocation failed, so calls to this word should be followed by a call to " { $link check-ptr } "." }
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ; { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } ;
HELP: memcpy "( dst src size -- newalien )" HELP: memcpy "( dst src size -- newalien )"
{ $values { "dst" "an alien address" } { "src" "an alien address" } { "size" "a non-negative integer" } } { $values { "dst" "an alien address" } { "src" "an alien address" } { "size" "a non-negative integer" } }

View File

@ -7,8 +7,6 @@ strings styles words ;
! Markup ! Markup
GENERIC: print-element GENERIC: print-element
GENERIC: article-name
! Help articles ! Help articles
SYMBOL: articles SYMBOL: articles
@ -21,15 +19,10 @@ TUPLE: article title content ;
M: string article-title article article-title ; M: string article-title article article-title ;
M: string article-name article article-name ;
M: string article-content article article-content ; M: string article-content article article-content ;
M: article article-name article-title ;
! Special case: f help ! Special case: f help
M: f article-title drop \ f article-title ; M: f article-title drop \ f article-title ;
M: f article-name drop \ f article-name ;
M: f article-content drop \ f article-content ; M: f article-content drop \ f article-content ;
! Glossary of terms ! Glossary of terms
@ -39,8 +32,6 @@ TUPLE: term entry ;
M: term article-title term-entry ; M: term article-title term-entry ;
M: term article-name term-entry ;
M: term article-content M: term article-content
term-entry terms get hash term-entry terms get hash
[ "No such glossary entry" ] unless* ; [ "No such glossary entry" ] unless* ;

View File

@ -116,8 +116,6 @@ TUPLE: link name ;
M: link article-title link-name article-title ; M: link article-title link-name article-title ;
M: link article-name link-name article-name ;
M: link article-content link-name article-content ; M: link article-content link-name article-content ;
DEFER: help DEFER: help
@ -136,7 +134,7 @@ DEFER: help
pprint pprint
] [ ] [
link-style [ link-style [
dup article-name swap <link> simple-object dup article-title swap <link> simple-object
] with-style ] with-style
] if ; ] if ;

View File

@ -1,15 +1,9 @@
! Copyright (C) 2005, 2006 Slava Pestov. ! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: help IN: help
USING: arrays generic kernel namespaces prettyprint sequences USING: arrays kernel namespaces prettyprint sequences words ;
words ;
M: word article-title M: word article-title word-name ;
[
"The " % dup word-name % class? " class" " word" ? %
] "" make ;
M: word article-name word-name ;
: word-article ( word -- article ) "help" word-prop ; : word-article ( word -- article ) "help" word-prop ;

View File

@ -5,11 +5,12 @@ USE: compiler
USE: compiler-frontend USE: compiler-frontend
USE: inference USE: inference
USE: words USE: words
USE: sequences
: fie [ ] [ ] if ; : fie [ ] [ ] if ;
[ ] [ \ fie dup word-def dataflow linearize drop ] unit-test [ ] [ \ fie dup word-def dataflow linearize drop ] unit-test
: foo [ drop ] each-word ; : foo all-words [ drop ] each ;
[ ] [ \ foo dup word-def dataflow linearize drop ] unit-test [ ] [ \ foo dup word-def dataflow linearize drop ] unit-test

View File

@ -22,8 +22,6 @@ SYMBOL: vocabularies
: all-words ( -- list ) vocabs [ words ] map concat ; : all-words ( -- list ) vocabs [ words ] map concat ;
: each-word ( quot -- ) all-words swap each ; inline
: word-subset ( pred -- list ) : word-subset ( pred -- list )
all-words swap subset ; inline all-words swap subset ; inline
@ -31,7 +29,7 @@ SYMBOL: vocabularies
all-words swap subset-with ; inline all-words swap subset-with ; inline
: recrossref ( -- ) : recrossref ( -- )
crossref get clear-hash [ add-crossref ] each-word ; crossref get clear-hash all-words [ add-crossref ] each ;
: lookup ( name vocab -- word ) vocab ?hash ; : lookup ( name vocab -- word ) vocab ?hash ;