Merge git://factorcode.org/git/factor
commit
0df27b26ff
|
@ -87,7 +87,7 @@ $nl
|
|||
HELP: alien-invoke-error
|
||||
{ $error-description "Thrown if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
|
||||
{ $list
|
||||
{ "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word and then call " { $link recompile } ". See " { $link "compiler" } "." }
|
||||
{ "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
|
||||
{ "The return type or parameter list references an unknown C type." }
|
||||
{ "The symbol or library could not be found." }
|
||||
{ "One of the four inputs to " { $link alien-invoke } " is not a literal value. To call functions which are not known at compile-time, use " { $link alien-indirect } "." }
|
||||
|
@ -103,7 +103,7 @@ HELP: alien-invoke
|
|||
HELP: alien-indirect-error
|
||||
{ $error-description "Thrown if the word calling " { $link alien-indirect } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
|
||||
{ $list
|
||||
{ "This can happen when experimenting with " { $link alien-indirect } " in this listener. To fix the problem, place the " { $link alien-indirect } " call in a word and then call " { $link recompile } ". See " { $link "compiler" } "." }
|
||||
{ "This can happen when experimenting with " { $link alien-indirect } " in this listener. To fix the problem, place the " { $link alien-indirect } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
|
||||
{ "The return type or parameter list references an unknown C type." }
|
||||
{ "One of the three inputs to " { $link alien-indirect } " is not a literal value." }
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ HELP: alien-indirect
|
|||
HELP: alien-callback-error
|
||||
{ $error-description "Thrown if the word calling " { $link alien-callback } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
|
||||
{ $list
|
||||
{ "This can happen when experimenting with " { $link alien-callback } " in this listener. To fix the problem, place the " { $link alien-callback } " call in a word and then call " { $link recompile } ". See " { $link "compiler" } "." }
|
||||
{ "This can happen when experimenting with " { $link alien-callback } " in this listener. To fix the problem, place the " { $link alien-callback } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
|
||||
{ "The return type or parameter list references an unknown C type." }
|
||||
{ "One of the four inputs to " { $link alien-callback } " is not a literal value." }
|
||||
}
|
||||
|
@ -199,9 +199,7 @@ ARTICLE: "alien-invoke" "Calling C from Factor"
|
|||
{ $subsection alien-invoke }
|
||||
"Sometimes it is necessary to invoke a C function pointer, rather than a named C function:"
|
||||
{ $subsection alien-indirect }
|
||||
"There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-data" } "."
|
||||
$nl
|
||||
"Don't forget to compile your binding word after defining it; C library calls cannot be made from an interpreted definition. Words defined in source files are automatically compiled when the source file is loaded, but words defined in the listener are not; when interactively testing C libraries, use " { $link compile } " or " { $link recompile } " to compile binding words." ;
|
||||
"There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-data" } "." ;
|
||||
|
||||
ARTICLE: "alien-callback-gc" "Callbacks and code GC"
|
||||
"A callback consits of two parts; the callback word, which pushes the address of the callback on the stack when executed, and the callback body itself. If the callback word is redefined, removed from the dictionary using " { $link forget } ", or recompiled, the callback body will not be reclaimed by the garbage collector, since potentially C code may be holding a reference to the callback body."
|
||||
|
|
|
@ -16,6 +16,14 @@ IN: bootstrap.compiler
|
|||
|
||||
"cpu." cpu append require
|
||||
|
||||
: enable-compiler ( -- )
|
||||
[ optimized-recompile-hook ] recompile-hook set-global ;
|
||||
|
||||
: disable-compiler ( -- )
|
||||
[ default-recompile-hook ] recompile-hook set-global ;
|
||||
|
||||
enable-compiler
|
||||
|
||||
nl
|
||||
"Compiling some words to speed up bootstrap..." write flush
|
||||
|
||||
|
@ -74,12 +82,4 @@ nl
|
|||
malloc free memcpy
|
||||
} compile
|
||||
|
||||
: enable-compiler ( -- )
|
||||
[ compiled-usages recompile ] recompile-hook set-global ;
|
||||
|
||||
: disable-compiler ( -- )
|
||||
[ default-recompile-hook ] recompile-hook set-global ;
|
||||
|
||||
enable-compiler
|
||||
|
||||
" done" print flush
|
||||
|
|
|
@ -30,7 +30,7 @@ crossref off
|
|||
"syntax" vocab vocab-words bootstrap-syntax set
|
||||
H{ } clone dictionary set
|
||||
H{ } clone changed-words set
|
||||
[ drop ] recompile-hook set
|
||||
[ default-recompile-hook ] recompile-hook set
|
||||
|
||||
call
|
||||
call
|
||||
|
|
|
@ -29,9 +29,7 @@ SYMBOL: bootstrap-time
|
|||
|
||||
: compile-remaining ( -- )
|
||||
"Compiling remaining words..." print flush
|
||||
vocabs [
|
||||
words "compile" "compiler" lookup execute
|
||||
] each ;
|
||||
vocabs [ words [ compiled? not ] subset compile ] each ;
|
||||
|
||||
: count-words ( pred -- )
|
||||
all-words swap subset length number>string write ;
|
||||
|
|
|
@ -255,8 +255,7 @@ PRIVATE>
|
|||
|
||||
: (define-class) ( word props -- )
|
||||
over reset-class
|
||||
over reset-generic
|
||||
over define-symbol
|
||||
over deferred? [ over define-symbol ] when
|
||||
>r dup word-props r> union over set-word-props
|
||||
t "class" set-word-prop ;
|
||||
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
USING: generator help.markup help.syntax words io parser
|
||||
assocs words.private sequences ;
|
||||
assocs words.private sequences compiler.units ;
|
||||
IN: compiler
|
||||
|
||||
ARTICLE: "compiler-usage" "Calling the optimizing compiler"
|
||||
"Normally, new word definitions are recompiled automatically, however in some circumstances the optimizing compiler may need to be called directly."
|
||||
$nl
|
||||
"The main entry points to the optimizing compiler:"
|
||||
{ $subsection compile }
|
||||
{ $subsection recompile }
|
||||
{ $subsection recompile-all }
|
||||
"The main entry point to the optimizing compiler:"
|
||||
{ $subsection optimized-recompile-hook }
|
||||
"Removing a word's optimized definition:"
|
||||
{ $subsection decompile }
|
||||
"The optimizing compiler can also compile and call a single quotation:"
|
||||
{ $subsection compile-call } ;
|
||||
{ $subsection decompile } ;
|
||||
|
||||
ARTICLE: "compiler" "Optimizing compiler"
|
||||
"Factor is a fully compiled language implementation with two distinct compilers:"
|
||||
|
@ -26,22 +22,6 @@ ARTICLE: "compiler" "Optimizing compiler"
|
|||
|
||||
ABOUT: "compiler"
|
||||
|
||||
HELP: compile
|
||||
{ $values { "seq" "a sequence of words" } }
|
||||
{ $description "Compiles a set of words. Ignores words which are already compiled." } ;
|
||||
|
||||
HELP: recompile
|
||||
{ $values { "seq" "a sequence of words" } }
|
||||
{ $description "Compiles a set of words. Re-compiles words which are already compiled." } ;
|
||||
|
||||
HELP: compile-call
|
||||
{ $values { "quot" "a quotation" } }
|
||||
{ $description "Compiles and runs a quotation." }
|
||||
{ $errors "Throws an error if the stack effect of the quotation cannot be inferred." } ;
|
||||
|
||||
HELP: recompile-all
|
||||
{ $description "Recompiles all words." } ;
|
||||
|
||||
HELP: decompile
|
||||
{ $values { "word" word } }
|
||||
{ $description "Removes a word's optimized definition. The word will be compiled with the non-optimizing compiler until recompiled with the optimizing compiler again." } ;
|
||||
|
@ -50,3 +30,8 @@ HELP: (compile)
|
|||
{ $values { "word" word } }
|
||||
{ $description "Compile a single word." }
|
||||
{ $notes "This is an internal word, and user code should call " { $link compile } " instead." } ;
|
||||
|
||||
HELP: optimized-recompile-hook
|
||||
{ $values { "words" "a sequence of words" } { "alist" "an association list" } }
|
||||
{ $description "Compile a set of words." }
|
||||
{ $notes "This is an internal word, and user code should call " { $link compile } " instead." } ;
|
||||
|
|
|
@ -4,14 +4,9 @@ USING: kernel namespaces arrays sequences io inference.backend
|
|||
inference.state generator debugger math.parser prettyprint words
|
||||
compiler.units continuations vocabs assocs alien.compiler dlists
|
||||
optimizer definitions math compiler.errors threads graphs
|
||||
generic ;
|
||||
generic inference ;
|
||||
IN: compiler
|
||||
|
||||
: compiled-usages ( words -- seq )
|
||||
[ [ dup ] H{ } map>assoc dup ] keep [
|
||||
compiled-usage [ nip +inlined+ eq? ] assoc-subset update
|
||||
] with each keys ;
|
||||
|
||||
: ripple-up ( word -- )
|
||||
compiled-usage [ drop queue-compile ] assoc-each ;
|
||||
|
||||
|
@ -49,27 +44,17 @@ IN: compiler
|
|||
compile-loop
|
||||
] if ;
|
||||
|
||||
: recompile ( words -- )
|
||||
: decompile ( word -- )
|
||||
f 2array 1array t modify-code-heap ;
|
||||
|
||||
: optimized-recompile-hook ( words -- alist )
|
||||
[
|
||||
H{ } clone compile-queue set
|
||||
H{ } clone compiled set
|
||||
[ queue-compile ] each
|
||||
compile-queue get compile-loop
|
||||
compiled get >alist
|
||||
dup [ drop crossref? ] assoc-contains?
|
||||
modify-code-heap
|
||||
] with-scope ; inline
|
||||
|
||||
: compile ( words -- )
|
||||
[ compiled? not ] subset recompile ;
|
||||
|
||||
: compile-call ( quot -- )
|
||||
H{ } clone changed-words
|
||||
[ define-temp dup 1array compile ] with-variable
|
||||
execute ;
|
||||
] with-scope ;
|
||||
|
||||
: recompile-all ( -- )
|
||||
[ all-words recompile ] with-compiler-errors ;
|
||||
|
||||
: decompile ( word -- )
|
||||
f 2array 1array t modify-code-heap ;
|
||||
forget-errors all-words compile ;
|
||||
|
|
|
@ -61,3 +61,11 @@ HELP: modify-code-heap ( alist -- )
|
|||
{ { $snippet "{ code labels rel words literals }" } " - in this case, a code heap block is allocated with the given data." }
|
||||
} }
|
||||
{ $notes "This word is called at the end of " { $link with-compilation-unit } "." } ;
|
||||
|
||||
HELP: compile
|
||||
{ $values { "seq" "a sequence of words" } }
|
||||
{ $description "Compiles a set of words." } ;
|
||||
|
||||
HELP: compile-call
|
||||
{ $values { "quot" "a quotation" } }
|
||||
{ $description "Compiles and runs a quotation." } ;
|
||||
|
|
|
@ -63,24 +63,45 @@ GENERIC: definitions-changed ( assoc obj -- )
|
|||
dup changed-words get update
|
||||
dup dup changed-vocabs update ;
|
||||
|
||||
: compile ( words -- )
|
||||
recompile-hook get call
|
||||
dup [ drop crossref? ] assoc-contains?
|
||||
modify-code-heap ;
|
||||
|
||||
SYMBOL: post-compile-tasks
|
||||
|
||||
: after-compilation ( quot -- )
|
||||
post-compile-tasks get push ;
|
||||
|
||||
: call-recompile-hook ( -- )
|
||||
changed-words get keys
|
||||
compiled-usages recompile-hook get call ;
|
||||
|
||||
: call-post-compile-tasks ( -- )
|
||||
post-compile-tasks get [ call ] each ;
|
||||
|
||||
: finish-compilation-unit ( -- )
|
||||
changed-words get keys recompile-hook get call
|
||||
call-recompile-hook
|
||||
call-post-compile-tasks
|
||||
dup [ drop crossref? ] assoc-contains? modify-code-heap
|
||||
changed-definitions notify-definition-observers ;
|
||||
|
||||
: with-compilation-unit ( quot -- )
|
||||
[
|
||||
H{ } clone changed-words set
|
||||
H{ } clone forgotten-definitions set
|
||||
V{ } clone post-compile-tasks set
|
||||
<definitions> new-definitions set
|
||||
<definitions> old-definitions set
|
||||
[ finish-compilation-unit ]
|
||||
[ ] cleanup
|
||||
] with-scope ; inline
|
||||
|
||||
: default-recompile-hook
|
||||
[ f ] { } map>assoc
|
||||
dup [ drop crossref? ] assoc-contains?
|
||||
modify-code-heap ;
|
||||
: compile-call ( quot -- )
|
||||
[ define-temp ] with-compilation-unit execute ;
|
||||
|
||||
: default-recompile-hook ( words -- alist )
|
||||
[ f ] { } map>assoc ;
|
||||
|
||||
recompile-hook global
|
||||
[ [ default-recompile-hook ] or ]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
! Copyright (C) 2005, 2007 Slava Pestov.
|
||||
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.c-types arrays cpu.x86.assembler
|
||||
cpu.x86.architecture cpu.x86.intrinsics cpu.x86.allot
|
||||
cpu.architecture kernel kernel.private math namespaces sequences
|
||||
generator.registers generator.fixup generator system
|
||||
alien.compiler combinators command-line
|
||||
compiler io vocabs.loader ;
|
||||
compiler compiler.units io vocabs.loader ;
|
||||
IN: cpu.x86.32
|
||||
|
||||
PREDICATE: x86-backend x86-32-backend
|
||||
|
@ -281,7 +281,10 @@ T{ x86-backend f 4 } compiler-backend set-global
|
|||
|
||||
"-no-sse2" cli-args member? [
|
||||
"Checking if your CPU supports SSE2..." print flush
|
||||
[ sse2? ] compile-call [
|
||||
[ optimized-recompile-hook ] recompile-hook [
|
||||
[ sse2? ] compile-call
|
||||
] with-variable
|
||||
[
|
||||
" - yes" print
|
||||
"cpu.x86.sse2" require
|
||||
] [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs namespaces sequences kernel ;
|
||||
USING: assocs namespaces sequences kernel words ;
|
||||
IN: inference.state
|
||||
|
||||
! Nesting state to solve recursion
|
||||
|
@ -31,9 +31,6 @@ SYMBOL: current-node
|
|||
! Words that the current dataflow IR depends on
|
||||
SYMBOL: dependencies
|
||||
|
||||
SYMBOL: +inlined+
|
||||
SYMBOL: +called+
|
||||
|
||||
: depends-on ( word how -- )
|
||||
swap dependencies get dup [
|
||||
2dup at +inlined+ eq? [ 3drop ] [ set-at ] if
|
||||
|
|
|
@ -47,8 +47,8 @@ HELP: gc-time ( -- n )
|
|||
{ $values { "n" "a timestamp in milliseconds" } }
|
||||
{ $description "Outputs the total time spent in garbage collection during this Factor session." } ;
|
||||
|
||||
HELP: data-room ( -- cards semi generations )
|
||||
{ $values { "cards" "number of bytes reserved for card marking" } { "semi" "number of bytes reserved for tenured semi-space" } { "generations" "array of free/total bytes pairs" } }
|
||||
HELP: data-room ( -- cards generations )
|
||||
{ $values { "cards" "number of bytes reserved for card marking" } { "generations" "array of free/total bytes pairs" } }
|
||||
{ $description "Queries the runtime for memory usage information." } ;
|
||||
|
||||
HELP: code-room ( -- code-free code-total )
|
||||
|
|
|
@ -395,3 +395,34 @@ IN: temporary
|
|||
[ t ] [
|
||||
"foo?" "temporary" lookup word eq?
|
||||
] unit-test
|
||||
|
||||
[ ] [
|
||||
"IN: temporary TUPLE: foo ; GENERIC: foo"
|
||||
<string-reader> "redefining-a-class-5" parse-stream drop
|
||||
] unit-test
|
||||
|
||||
[ ] [
|
||||
"IN: temporary M: f foo ;"
|
||||
<string-reader> "redefining-a-class-6" parse-stream drop
|
||||
] unit-test
|
||||
|
||||
[ f ] [ f "foo" "temporary" lookup execute ] unit-test
|
||||
|
||||
[ ] [
|
||||
"IN: temporary TUPLE: foo ; GENERIC: foo"
|
||||
<string-reader> "redefining-a-class-5" parse-stream drop
|
||||
] unit-test
|
||||
|
||||
[ f ] [ f "foo" "temporary" lookup execute ] unit-test
|
||||
|
||||
[ ] [
|
||||
"IN: temporary TUPLE: foo ; GENERIC: foo"
|
||||
<string-reader> "redefining-a-class-7" parse-stream drop
|
||||
] unit-test
|
||||
|
||||
[ ] [
|
||||
"IN: temporary TUPLE: foo ;"
|
||||
<string-reader> "redefining-a-class-7" parse-stream drop
|
||||
] unit-test
|
||||
|
||||
[ t ] [ "foo" "temporary" lookup symbol? ] unit-test
|
||||
|
|
|
@ -464,9 +464,16 @@ SYMBOL: interactive-vocabs
|
|||
dup values concat prune swap keys
|
||||
] keep ;
|
||||
|
||||
: fix-class-words ( -- )
|
||||
#! If a class word had a compound definition which was
|
||||
#! removed, it must go back to being a symbol.
|
||||
new-definitions get first2 diff
|
||||
[ nip define-symbol ] assoc-each ;
|
||||
|
||||
: forget-smudged ( -- )
|
||||
smudged-usage forget-all
|
||||
over empty? [ 2dup smudged-usage-warning ] unless 2drop ;
|
||||
over empty? [ 2dup smudged-usage-warning ] unless 2drop
|
||||
fix-class-words ;
|
||||
|
||||
: finish-parsing ( lines quot -- )
|
||||
file get
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: help.markup help.syntax kernel kernel.private io
|
||||
threads.private continuations dlists init quotations strings
|
||||
assocs heaps boxes ;
|
||||
assocs heaps boxes namespaces ;
|
||||
IN: threads
|
||||
|
||||
ARTICLE: "threads-start/stop" "Starting and stopping threads"
|
||||
|
@ -127,7 +127,10 @@ HELP: spawn
|
|||
{ $values { "quot" quotation } { "name" string } }
|
||||
{ $description "Spawns a new thread. The thread begins executing the given quotation; the name is for debugging purposes. The new thread begins running immediately and the current thread is added to the end of the run queue."
|
||||
$nl
|
||||
"The new thread begins with an empty data stack, an empty catch stack, and a name stack containing the global namespace only. This means that the only way to pass data to the new thread is to explicitly construct a quotation containing the data, for example using " { $link curry } " or " { $link compose } "." }
|
||||
"The new thread begins with an empty data stack, an empty retain stack, and an empty catch stack. The name stack is inherited from the parent thread but may be cleared with " { $link init-namespaces } "." }
|
||||
{ $notes
|
||||
"The recommended way to pass data to the new thread is to explicitly construct a quotation containing the data, for example using " { $link curry } " or " { $link compose } "."
|
||||
}
|
||||
{ $examples
|
||||
{ $code "1 2 [ + . ] 2curry \"Addition thread\" spawn" }
|
||||
} ;
|
||||
|
|
|
@ -165,7 +165,6 @@ M: f nap nap-until ;
|
|||
resume-now [
|
||||
dup set-self
|
||||
dup register-thread
|
||||
init-namespaces
|
||||
V{ } set-catchstack
|
||||
{ } set-retainstack
|
||||
>r { } set-datastack r>
|
||||
|
|
|
@ -237,3 +237,40 @@ C: <erg's-reshape-problem> erg's-reshape-problem
|
|||
[
|
||||
"IN: temporary SYMBOL: not-a-class C: <not-a-class> not-a-class" eval
|
||||
] [ [ check-tuple? ] is? ] must-fail-with
|
||||
|
||||
! Hardcore unit tests
|
||||
USE: threads
|
||||
|
||||
\ thread "slot-names" word-prop "slot-names" set
|
||||
|
||||
[ ] [
|
||||
[
|
||||
\ thread { "xxx" } "slot-names" get append
|
||||
define-tuple-class
|
||||
] with-compilation-unit
|
||||
|
||||
[ 1337 sleep ] "Test" spawn drop
|
||||
|
||||
[
|
||||
\ thread "slot-names" get
|
||||
define-tuple-class
|
||||
] with-compilation-unit
|
||||
] unit-test
|
||||
|
||||
USE: vocabs
|
||||
|
||||
\ vocab "slot-names" word-prop "slot-names" set
|
||||
|
||||
[ ] [
|
||||
[
|
||||
\ vocab { "xxx" } "slot-names" get append
|
||||
define-tuple-class
|
||||
] with-compilation-unit
|
||||
|
||||
all-words drop
|
||||
|
||||
[
|
||||
\ vocab "slot-names" get
|
||||
define-tuple-class
|
||||
] with-compilation-unit
|
||||
] unit-test
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
USING: arrays definitions hashtables kernel
|
||||
kernel.private math namespaces sequences sequences.private
|
||||
strings vectors words quotations memory combinators generic
|
||||
classes classes.private slots slots.private ;
|
||||
classes classes.private slots slots.private compiler.units ;
|
||||
IN: tuples
|
||||
|
||||
M: tuple delegate 3 slot ;
|
||||
|
@ -35,9 +35,12 @@ M: tuple class class-of-tuple ;
|
|||
append (>tuple) ;
|
||||
|
||||
: reshape-tuples ( class newslots -- )
|
||||
>r dup [ swap class eq? ] curry instances dup
|
||||
rot "slot-names" word-prop r> permutation
|
||||
[ reshape-tuple ] curry map become ;
|
||||
>r dup "slot-names" word-prop r> permutation
|
||||
[
|
||||
>r [ swap class eq? ] curry instances dup r>
|
||||
[ reshape-tuple ] curry map
|
||||
become
|
||||
] 2curry after-compilation ;
|
||||
|
||||
: old-slots ( class newslots -- seq )
|
||||
swap "slots" word-prop 1 tail-slice
|
||||
|
@ -55,6 +58,7 @@ M: tuple class class-of-tuple ;
|
|||
over "slot-names" word-prop over = [
|
||||
2dup forget-slots
|
||||
2dup reshape-tuples
|
||||
over changed-word
|
||||
over redefined
|
||||
] unless
|
||||
] when 2drop ;
|
||||
|
|
|
@ -76,9 +76,9 @@ $nl
|
|||
ARTICLE: "declarations" "Declarations"
|
||||
"Declarations give special behavior to a word. Declarations are parsing words that set a word property in the most recently defined word."
|
||||
$nl
|
||||
"The first declaration specifies the time when a word runs. It affects both interpreted and compiled definitions."
|
||||
"The first declaration specifies the time when a word runs. It affects both the non-optimizing and optimizing compilers:"
|
||||
{ $subsection POSTPONE: parsing }
|
||||
"The remaining declarations only affect compiled definitions. They do not change evaluation semantics of a word, but instead declare that the word follows a certain contract, and thus may be compiled differently."
|
||||
"The remaining declarations only affect definitions compiled with the optimizing compiler. They do not change evaluation semantics of a word, but instead declare that the word follows a certain contract, and thus may be compiled differently."
|
||||
{ $warning "If a generic word is declared " { $link POSTPONE: foldable } " or " { $link POSTPONE: flushable } ", all methods must satisfy the contract, otherwise unpredicable behavior will occur." }
|
||||
{ $subsection POSTPONE: inline }
|
||||
{ $subsection POSTPONE: foldable }
|
||||
|
|
|
@ -111,9 +111,17 @@ compiled-crossref global [ H{ } assoc-like ] change-at
|
|||
dup compiled-unxref
|
||||
compiled-crossref get delete-at ;
|
||||
|
||||
SYMBOL: +inlined+
|
||||
SYMBOL: +called+
|
||||
|
||||
: compiled-usage ( word -- assoc )
|
||||
compiled-crossref get at ;
|
||||
|
||||
: compiled-usages ( words -- seq )
|
||||
[ [ dup ] H{ } map>assoc dup ] keep [
|
||||
compiled-usage [ nip +inlined+ eq? ] assoc-subset update
|
||||
] with each keys ;
|
||||
|
||||
M: word redefined* ( word -- )
|
||||
{ "inferred-effect" "no-effect" } reset-props ;
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
IN: temporary
|
||||
USING: tools.test benchmark.reverse-complement crypto.md5
|
||||
io.files kernel ;
|
||||
|
||||
[ "c071aa7e007a9770b2fb4304f55a17e5" ] [
|
||||
"extra/benchmark/reverse-complement/reverse-complement-test-in.txt"
|
||||
"extra/benchmark/reverse-complement/reverse-complement-test-out.txt"
|
||||
[ resource-path ] 2apply
|
||||
reverse-complement
|
||||
|
||||
"extra/benchmark/reverse-complement/reverse-complement-test-out.txt"
|
||||
resource-path file>md5str
|
||||
] unit-test
|
|
@ -35,6 +35,9 @@ SYMBOL: edit-hook
|
|||
: edit ( defspec -- )
|
||||
where [ first2 edit-location ] when* ;
|
||||
|
||||
: edit-vocab ( name -- )
|
||||
vocab-source-path 1 edit-location ;
|
||||
|
||||
: :edit ( -- )
|
||||
error get delegates [ parse-error? ] find-last nip [
|
||||
dup parse-error-file source-file-path ?resource-path
|
||||
|
|
|
@ -6,7 +6,7 @@ IN: editors.editpadpro
|
|||
: editpadpro-path
|
||||
\ editpadpro-path get-global [
|
||||
program-files "JGsoft" path+
|
||||
[ >lower "editpadpro.exe" tail? ] find-file-breadth
|
||||
t [ >lower "editpadpro.exe" tail? ] find-file
|
||||
] unless* ;
|
||||
|
||||
: editpadpro ( file line -- )
|
||||
|
|
|
@ -5,5 +5,5 @@ IN: editors.gvim.windows
|
|||
M: windows-io gvim-path
|
||||
\ gvim-path get-global [
|
||||
program-files "vim" path+
|
||||
[ "gvim.exe" tail? ] find-file-breadth
|
||||
t [ "gvim.exe" tail? ] find-file
|
||||
] unless* ;
|
||||
|
|
|
@ -1,49 +1,52 @@
|
|||
USING: arrays assocs combinators.lib dlists io.files
|
||||
kernel namespaces sequences shuffle vectors ;
|
||||
USING: io.files kernel sequences new-slots accessors
|
||||
dlists arrays ;
|
||||
IN: io.paths
|
||||
|
||||
! HOOK: library-roots io-backend ( -- seq )
|
||||
! HOOK: binary-roots io-backend ( -- seq )
|
||||
TUPLE: directory-iterator path bfs queue ;
|
||||
|
||||
<PRIVATE
|
||||
: append-path ( path files -- paths )
|
||||
[ >r path+ r> ] with* assoc-map ;
|
||||
: qualified-directory ( path -- seq )
|
||||
dup directory [ first2 >r path+ r> 2array ] with map ;
|
||||
|
||||
: get-paths ( dir -- paths )
|
||||
dup directory append-path ;
|
||||
: push-directory ( path iter -- )
|
||||
>r qualified-directory r> [
|
||||
dup queue>> swap bfs>>
|
||||
[ push-front ] [ push-back ] if
|
||||
] curry each ;
|
||||
|
||||
: (walk-dir) ( path -- )
|
||||
first2 [
|
||||
get-paths dup keys % [ (walk-dir) ] each
|
||||
: <directory-iterator> ( path bfs? -- iterator )
|
||||
<dlist> directory-iterator construct-boa
|
||||
dup path>> over push-directory ;
|
||||
|
||||
: next-file ( iter -- file/f )
|
||||
dup queue>> dlist-empty? [ drop f ] [
|
||||
dup queue>> pop-back first2
|
||||
[ over push-directory next-file ] [ nip ] if
|
||||
] if ;
|
||||
|
||||
: iterate-directory ( iter quot -- obj )
|
||||
2dup >r >r >r next-file dup [
|
||||
r> call dup [
|
||||
r> r> 2drop
|
||||
] [
|
||||
drop r> r> iterate-directory
|
||||
] if
|
||||
] [
|
||||
drop r> r> r> 3drop f
|
||||
] if ; inline
|
||||
|
||||
: prepare-find-file ( path bfs? quot -- iter quot' )
|
||||
>r <directory-iterator> r> [ keep and ] curry ; inline
|
||||
|
||||
: find-file ( path bfs? quot -- path/f )
|
||||
prepare-find-file iterate-directory ;
|
||||
|
||||
: find-all-files ( path bfs? quot -- paths )
|
||||
prepare-find-file V{ } clone [
|
||||
[ over [ push ] [ 2drop ] if f ] curry compose
|
||||
iterate-directory
|
||||
drop
|
||||
] if ;
|
||||
PRIVATE>
|
||||
] keep ; inline
|
||||
|
||||
: walk-dir ( path -- seq )
|
||||
dup directory? 2array [ (walk-dir) ] { } make ;
|
||||
|
||||
GENERIC# find-file* 1 ( obj quot -- path/f )
|
||||
|
||||
M: dlist find-file* ( dlist quot -- path/f )
|
||||
over dlist-empty? [ 2drop f ] [
|
||||
2dup >r pop-front get-paths dup r> assoc-find
|
||||
[ drop 3nip ]
|
||||
[ 2drop [ nip ] assoc-subset keys pick push-all-back find-file* ] if
|
||||
] if ;
|
||||
|
||||
M: vector find-file* ( vector quot -- path/f )
|
||||
over empty? [ 2drop f ] [
|
||||
2dup >r pop get-paths dup r> assoc-find
|
||||
[ drop 3nip ]
|
||||
[ 2drop [ nip ] assoc-subset keys pick push-all find-file* ] if
|
||||
] if ;
|
||||
|
||||
: prepare-find-file ( quot -- quot )
|
||||
[ drop ] swap compose ;
|
||||
|
||||
: find-file-depth ( path quot -- path/f )
|
||||
prepare-find-file >r 1vector r> find-file* ;
|
||||
|
||||
: find-file-breadth ( path quot -- path/f )
|
||||
prepare-find-file >r 1dlist r> find-file* ;
|
||||
: recursive-directory ( path bfs? -- paths )
|
||||
<directory-iterator>
|
||||
[ dup next-file dup ] [ ] [ drop ] unfold nip ;
|
||||
|
|
|
@ -10,10 +10,6 @@ SYMBOL: servers
|
|||
|
||||
<PRIVATE
|
||||
|
||||
: spawn-vars ( quot vars name -- )
|
||||
>r [ dup get ] H{ } map>assoc [ swap bind ] 2curry r>
|
||||
spawn drop ;
|
||||
|
||||
LOG: accepted-connection NOTICE
|
||||
|
||||
: with-client ( client quot -- )
|
||||
|
@ -26,8 +22,7 @@ LOG: accepted-connection NOTICE
|
|||
|
||||
: accept-loop ( server quot -- )
|
||||
[
|
||||
>r accept r> [ with-client ] 2curry
|
||||
{ log-service servers } "Client" spawn-vars
|
||||
>r accept r> [ with-client ] 2curry "Client" spawn drop
|
||||
] 2keep accept-loop ; inline
|
||||
|
||||
: server-loop ( addrspec quot -- )
|
||||
|
|
|
@ -133,7 +133,7 @@ M: stack-display tool-scroller
|
|||
|
||||
: restart-listener ( listener -- )
|
||||
dup com-end dup clear-output
|
||||
[ listener-thread ] curry
|
||||
[ init-namespaces listener-thread ] curry
|
||||
"Listener" spawn drop ;
|
||||
|
||||
: init-listener ( listener -- )
|
||||
|
|
|
@ -58,7 +58,7 @@ SYMBOL: cgi-root
|
|||
] with-stream ;
|
||||
|
||||
: serve-regular-file ( -- )
|
||||
cgi-root get "doc-root" [ file-responder ] with-variable ;
|
||||
cgi-root get doc-root [ file-responder ] with-variable ;
|
||||
|
||||
: do-cgi ( name -- )
|
||||
{
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
! Copyright (C) 2004, 2007 Slava Pestov.
|
||||
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: calendar html io io.files kernel math math.parser
|
||||
http.server.responders http.server.templating namespaces parser
|
||||
sequences strings assocs hashtables debugger http.mime sorting
|
||||
html.elements logging ;
|
||||
|
||||
IN: webapps.file
|
||||
|
||||
SYMBOL: doc-root
|
||||
|
||||
: serving-path ( filename -- filename )
|
||||
"" or "doc-root" get swap path+ ;
|
||||
"" or doc-root get swap path+ ;
|
||||
|
||||
: file-http-date ( filename -- string )
|
||||
file-modified unix-time>timestamp timestamp>http-string ;
|
||||
|
@ -61,7 +62,7 @@ SYMBOL: page
|
|||
\ run-page DEBUG add-input-logging
|
||||
|
||||
: include-page ( filename -- )
|
||||
"doc-root" get swap path+ run-page ;
|
||||
serving-path run-page ;
|
||||
|
||||
: serve-fhtml ( filename -- )
|
||||
serving-html
|
||||
|
@ -115,14 +116,14 @@ SYMBOL: page
|
|||
] if ;
|
||||
|
||||
: file-responder ( -- )
|
||||
"doc-root" get [
|
||||
doc-root get [
|
||||
"argument" get serve-object
|
||||
] [
|
||||
"404 doc-root not set" httpd-error
|
||||
] if ;
|
||||
|
||||
global [
|
||||
! Serves files from a directory stored in the "doc-root"
|
||||
! Serves files from a directory stored in the doc-root
|
||||
! variable. You can set the variable in the global
|
||||
! namespace, or inside the responder.
|
||||
"file" [ file-responder ] add-simple-responder
|
||||
|
|
|
@ -53,7 +53,7 @@ IN: webapps.fjsc
|
|||
! the 'fjsc' responder.
|
||||
"fjsc-resources" [
|
||||
[
|
||||
"extra/fjsc/resources/" resource-path "doc-root" set
|
||||
"extra/fjsc/resources/" resource-path doc-root set
|
||||
file-responder
|
||||
] with-scope
|
||||
] add-simple-responder
|
||||
|
@ -62,7 +62,7 @@ IN: webapps.fjsc
|
|||
! 'termlib'.
|
||||
"fjsc-repl-resources" [
|
||||
[
|
||||
"extra/webapps/fjsc/resources/" resource-path "doc-root" set
|
||||
"extra/webapps/fjsc/resources/" resource-path doc-root set
|
||||
file-responder
|
||||
] with-scope
|
||||
] add-simple-responder ;
|
||||
|
|
|
@ -15,14 +15,16 @@ IN: webapps.source
|
|||
: source-responder ( path mime-type -- )
|
||||
drop
|
||||
serving-html
|
||||
[ dup <file-reader> htmlize-stream ] with-html-stream ;
|
||||
[
|
||||
dup file-name swap <file-reader> htmlize-stream
|
||||
] with-html-stream ;
|
||||
|
||||
global [
|
||||
! Serve up our own source code
|
||||
"source" [
|
||||
"argument" get check-source-path [
|
||||
[
|
||||
"" resource-path "doc-root" set
|
||||
"" resource-path doc-root set
|
||||
[ source-responder ] serve-file-hook set
|
||||
file-responder
|
||||
] with-scope
|
||||
|
|
Loading…
Reference in New Issue