From 82fd581e9fdd8fdf214bca1fd671e686e0494b10 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Sun, 13 Jan 2008 10:41:35 -0500 Subject: [PATCH 01/18] Fix circular doc errors --- extra/editors/vim/vim-docs.factor | 4 ++-- extra/math/statistics/statistics-docs.factor | 21 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/extra/editors/vim/vim-docs.factor b/extra/editors/vim/vim-docs.factor index 9f141f524f..020117564d 100644 --- a/extra/editors/vim/vim-docs.factor +++ b/extra/editors/vim/vim-docs.factor @@ -1,5 +1,5 @@ -USING: definitions editors.vim help help.markup help.syntax io io.files -editors words ; +USING: definitions help help.markup help.syntax io io.files editors words ; +IN: editors.vim ARTICLE: { "vim" "vim" } "Vim support" "This module makes the " { $link edit } " word work with Vim by setting the " { $link edit-hook } " global variable to call " { $link vim-location } ". The " { $link vim-path } " variable contains the name of the vim executable. The default " { $link vim-path } " is " { $snippet "\"gvim\"" } "." diff --git a/extra/math/statistics/statistics-docs.factor b/extra/math/statistics/statistics-docs.factor index bb92178e6d..4787a85aed 100644 --- a/extra/math/statistics/statistics-docs.factor +++ b/extra/math/statistics/statistics-docs.factor @@ -1,49 +1,50 @@ -USING: math.statistics help.markup help.syntax debugger ; +USING: help.markup help.syntax debugger ; +IN: math.statistics HELP: geometric-mean { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $description "Computes the geometric mean of all elements in " { $snippet "seq" } ". The geometric mean measures the central tendency of a data set that minimizes the effects of extreme values." } -{ $examples { $example "USE: math.statistics" "{ 1 2 3 } geometric-mean ." "1.81712059283214" } } +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } geometric-mean ." "1.81712059283214" } } { $errors "Throws a " { $link signal-error. } " (square-root of 0) if the sequence is empty." } ; HELP: harmonic-mean { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." } -{ $examples { $example "USE: math.statistics" "{ 1 2 3 } harmonic-mean ." "6/11" } } +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } harmonic-mean ." "6/11" } } { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; HELP: mean { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $description "Computes the arithmetic mean of all elements in " { $snippet "seq" } "." } -{ $examples { $example "USE: math.statistics" "{ 1 2 3 } mean ." "2" } } +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } mean ." "2" } } { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; HELP: median { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $description "Computes the median of " { $snippet "seq" } " by sorting the sequence from lowest value to highest and outputting the middle one. If there is an even number of elements in the sequence, the median is not unique, so the mean of the two middle values is outputted." } -{ $examples +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } median ." "2" } - { $example "USE: math.statistics" "{ 1 2 3 4 } median ." "5/2" } } + { $example "USE: math.statistics" "{ 1 2 3 4 } median ." "5/2" } } { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; HELP: range { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $description "Computes the distance of the maximum and minimum values in " { $snippet "seq" } "." } -{ $examples +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } range ." "2" } { $example "USE: math.statistics" "{ 1 2 3 4 } range ." "3" } } ; HELP: std { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $description "Computes the standard deviation of " { $snippet "seq" } " by squaring the variance of the sequence. It measures how widely spread the values in a sequence are about the mean." } -{ $examples +{ $examples { $example "USE: math.statistics" "{ 1 2 3 } std ." "1.0" } { $example "USE: math.statistics" "{ 1 2 3 4 } std ." "1.290994448735806" } } ; HELP: ste { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $description "Computes the standard error of the mean for " { $snippet "seq" } ". It's defined as the standard deviation divided by the square root of the length of the sequence, and measures uncertainty associated with the estimate of the mean." } - { $examples + { $examples { $example "USE: math.statistics" "{ -2 2 } ste ." "2.0" } { $example "USE: math.statistics" "{ -2 2 2 } ste ." "1.333333333333333" } } ; @@ -51,7 +52,7 @@ HELP: var { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $description "Computes the variance of " { $snippet "seq" } ". It's a measurement of the spread of values in a sequence. The larger the variance, the larger the distance of values from the mean." } { $notes "If the number of elements in " { $snippet "seq" } " is 1 or less, it outputs 0." } -{ $examples +{ $examples { $example "USE: math.statistics" "{ 1 } var ." "0" } { $example "USE: math.statistics" "{ 1 2 3 } var ." "1" } { $example "USE: math.statistics" "{ 1 2 3 4 } var ." "5/3" } } ; From c27d17e1ec7e15672ece8e258c7b82ee0d0e54f2 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 13 Jan 2008 10:33:36 -1000 Subject: [PATCH 02/18] unbreak singleton? --- extra/sequences/lib/lib.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index 37b00042d2..e46ce3b107 100755 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -59,7 +59,7 @@ IN: sequences.lib ] { } make ; : singleton? ( seq -- ? ) - length 1 = ; foldable + length 1 = ; : delete-random ( seq -- value ) [ length random ] keep [ nth ] 2keep delete-nth ; From 952c559b52a52e92a299fcec1bd769a4d9128698 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 13 Jan 2008 17:07:59 -0500 Subject: [PATCH 03/18] Faster compilation of dispatch primitive --- core/compiler/test/simple.factor | 6 ++ core/cpu/architecture/architecture.factor | 15 ++++- core/cpu/ppc/architecture/architecture.factor | 55 +++++++++++++------ core/cpu/ppc/intrinsics/intrinsics.factor | 38 ++++++------- core/generator/fixup/fixup.factor | 7 +++ core/generator/generator.factor | 47 +++++++++------- core/inference/class/class-tests.factor | 21 ++++--- core/optimizer/known-words/known-words.factor | 6 +- vm/code_heap.c | 2 + vm/code_heap.h | 4 +- 10 files changed, 129 insertions(+), 72 deletions(-) diff --git a/core/compiler/test/simple.factor b/core/compiler/test/simple.factor index 7ce82c9a1f..9f831bb1f8 100755 --- a/core/compiler/test/simple.factor +++ b/core/compiler/test/simple.factor @@ -63,3 +63,9 @@ IN: temporary ! Regression [ ] [ [ callstack ] compile-call drop ] unit-test + +! Regression + +: empty ; + +[ "b" ] [ 1 [ empty { [ "a" ] [ "b" ] } dispatch ] compile-call ] unit-test diff --git a/core/cpu/architecture/architecture.factor b/core/cpu/architecture/architecture.factor index 3550dcadc0..2409eafaf0 100755 --- a/core/cpu/architecture/architecture.factor +++ b/core/cpu/architecture/architecture.factor @@ -51,19 +51,28 @@ HOOK: %save-dispatch-xt compiler-backend ( -- ) M: object %save-dispatch-xt %save-word-xt ; +! Call C primitive +HOOK: %call-primitive compiler-backend ( label -- ) + ! Call another label HOOK: %call-label compiler-backend ( label -- ) +! Far jump to C primitive +HOOK: %jump-primitive compiler-backend ( label -- ) + ! Local jump for branches HOOK: %jump-label compiler-backend ( label -- ) ! Test if vreg is 'f' or not HOOK: %jump-t compiler-backend ( label -- ) -! We pass the offset of the jump table start in the world table -HOOK: %call-dispatch compiler-backend ( word-table# -- ) +HOOK: %call-dispatch compiler-backend ( -- label ) -HOOK: %jump-dispatch compiler-backend ( word-table# -- ) +HOOK: %jump-dispatch compiler-backend ( -- ) + +HOOK: %dispatch-label compiler-backend ( word -- ) + +HOOK: %end-dispatch compiler-backend ( label -- ) ! Return to caller HOOK: %return compiler-backend ( -- ) diff --git a/core/cpu/ppc/architecture/architecture.factor b/core/cpu/ppc/architecture/architecture.factor index e93d092b10..a156c173a1 100755 --- a/core/cpu/ppc/architecture/architecture.factor +++ b/core/cpu/ppc/architecture/architecture.factor @@ -97,6 +97,22 @@ M: ppc-backend %epilogue ( n -- ) 1 1 rot ADDI 0 MTLR ; +: %prepare-primitive ( word -- ) + #! Save stack pointer to stack_chain->callstack_top, load XT + 4 1 MR + 0 11 LOAD32 + rc-absolute-ppc-2/2 rel-primitive ; + +: (%call) 11 MTLR BLRL ; + +M: ppc-backend %call-primitive ( word -- ) + %prepare-primitive (%call) ; + +: (%jump) 11 MTCTR BCTR ; + +M: ppc-backend %jump-primitive ( word -- ) + %prepare-primitive (%jump) ; + : %load-dlsym ( symbol dll register -- ) 0 swap LOAD32 rc-absolute-ppc-2/2 rel-dlsym ; @@ -107,26 +123,29 @@ M: ppc-backend %jump-label ( label -- ) B ; M: ppc-backend %jump-t ( label -- ) 0 "flag" operand f v>operand CMPI BNE ; -: (%call) 11 MTLR BLRL ; - -: dispatch-template ( word-table# quot -- ) - [ - >r - "offset" operand "n" operand 1 SRAWI - 0 11 LOAD32 rc-absolute-ppc-2/2 rel-dispatch - 11 dup "offset" operand LWZX - 11 dup word-xt-offset LWZ - r> call - ] H{ - { +input+ { { f "n" } } } - { +scratch+ { { f "offset" } } } - } with-template ; inline +: (%dispatch) ( len -- ) + 0 11 LOAD32 rc-absolute-ppc-2/2 rel-here + "offset" operand "n" operand 1 SRAWI + 11 11 "offset" operand ADD + 11 dup rot cells LWZ ; M: ppc-backend %call-dispatch ( word-table# -- ) - [ (%call) ] dispatch-template ; + [ 7 (%dispatch) (%call)