sequence cleanups
parent
d6b42a1f5c
commit
94c1a8bcd7
|
@ -6,7 +6,6 @@
|
||||||
- add a socket timeout
|
- add a socket timeout
|
||||||
- unix ffi i/o
|
- unix ffi i/o
|
||||||
- powerpc has weird callstack residue
|
- powerpc has weird callstack residue
|
||||||
- make-vector and make-string should not need a reverse step
|
|
||||||
- console with presentations
|
- console with presentations
|
||||||
|
|
||||||
+ plugin:
|
+ plugin:
|
||||||
|
@ -35,7 +34,8 @@
|
||||||
- out parameters
|
- out parameters
|
||||||
- bitfields in C structs
|
- bitfields in C structs
|
||||||
- SDL_Rect** type
|
- SDL_Rect** type
|
||||||
- struct membres that are not *
|
- setting struct members that are not *
|
||||||
|
- char[14], etc members -- generalize char255
|
||||||
- FFI float types
|
- FFI float types
|
||||||
|
|
||||||
+ compiler:
|
+ compiler:
|
||||||
|
@ -57,22 +57,22 @@
|
||||||
|
|
||||||
+ sequences
|
+ sequences
|
||||||
|
|
||||||
|
- generic ensure-capacity
|
||||||
- dipping seq-2nmap, seq-2each
|
- dipping seq-2nmap, seq-2each
|
||||||
- remove seq- prefixes
|
- remove seq- prefixes
|
||||||
- seq-append --> nappend
|
|
||||||
- generic each some? all? member? memq? all=? top
|
- generic each some? all? member? memq? all=? top
|
||||||
index? subseq?
|
index? subseq?
|
||||||
- index and index* are very slow with lists
|
- index and index* are very slow with lists
|
||||||
- list map, subset, project, append: not tail recursive
|
- list map, subset, project, append: not tail recursive
|
||||||
- : , sequence get push ; : % sequence get nappend ;
|
|
||||||
- phase out sbuf-append
|
- phase out sbuf-append
|
||||||
- decide what to do with index-of
|
- decide what to do with index-of
|
||||||
- GENERIC: map
|
- GENERIC: map
|
||||||
- list impl same as now
|
- list impl same as now
|
||||||
- sequence impl: clone sequence and call nmap
|
- sequence impl: clone sequence and call nmap
|
||||||
- string impl: string>sbuf nmap sbuf>string
|
- string impl: string>sbuf nmap sbuf>string
|
||||||
- GENERIC: append
|
- GENERIC: append, append3, append*
|
||||||
- list>vector --> >vector
|
- list>vector --> >vector
|
||||||
|
- move >list to lists
|
||||||
|
|
||||||
+ kernel:
|
+ kernel:
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ M: alien = ( obj obj -- ? )
|
||||||
<namespace> [
|
<namespace> [
|
||||||
"abi" set
|
"abi" set
|
||||||
"name" set
|
"name" set
|
||||||
] extend put
|
] extend swap set
|
||||||
] bind ;
|
] bind ;
|
||||||
|
|
||||||
: library-abi ( library -- abi )
|
: library-abi ( library -- abi )
|
||||||
|
|
|
@ -54,7 +54,10 @@ math namespaces parser strings words ;
|
||||||
dup struct-constructor
|
dup struct-constructor
|
||||||
dup array-constructor
|
dup array-constructor
|
||||||
dup define-nth
|
dup define-nth
|
||||||
[ "width" set ] "struct-name" get define-c-type
|
[
|
||||||
|
"width" set
|
||||||
|
[ swap <displaced-alien> ] "getter" set
|
||||||
|
] "struct-name" get define-c-type
|
||||||
"void*" c-type "struct-name" get "*" cat2
|
"void*" c-type "struct-name" get "*" cat2
|
||||||
c-types get set-hash ;
|
c-types get set-hash ;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ hashtables ;
|
||||||
|
|
||||||
"/library/bootstrap/primitives.factor" run-resource
|
"/library/bootstrap/primitives.factor" run-resource
|
||||||
|
|
||||||
: pull-in ( list -- ) [ dup print parse-resource append, ] each ;
|
: pull-in ( list -- ) [ dup print parse-resource % ] each ;
|
||||||
|
|
||||||
! The make-list form creates a boot quotation
|
! The make-list form creates a boot quotation
|
||||||
[
|
[
|
||||||
|
@ -16,26 +16,26 @@ hashtables ;
|
||||||
"/version.factor"
|
"/version.factor"
|
||||||
"/library/stack.factor"
|
"/library/stack.factor"
|
||||||
"/library/combinators.factor"
|
"/library/combinators.factor"
|
||||||
"/library/sequences.factor"
|
"/library/collections/sequences.factor"
|
||||||
"/library/arrays.factor"
|
"/library/collections/arrays.factor"
|
||||||
"/library/kernel.factor"
|
"/library/kernel.factor"
|
||||||
"/library/cons.factor"
|
"/library/collections/cons.factor"
|
||||||
"/library/assoc.factor"
|
"/library/collections/assoc.factor"
|
||||||
"/library/math/math.factor"
|
"/library/math/math.factor"
|
||||||
"/library/math/integer.factor"
|
"/library/math/integer.factor"
|
||||||
"/library/math/ratio.factor"
|
"/library/math/ratio.factor"
|
||||||
"/library/math/float.factor"
|
"/library/math/float.factor"
|
||||||
"/library/math/complex.factor"
|
"/library/math/complex.factor"
|
||||||
"/library/lists.factor"
|
"/library/collections/lists.factor"
|
||||||
"/library/vectors.factor"
|
"/library/collections/vectors.factor"
|
||||||
"/library/strings.factor"
|
"/library/collections/strings.factor"
|
||||||
"/library/sequences-epilogue.factor"
|
"/library/collections/sequences-epilogue.factor"
|
||||||
"/library/vectors-epilogue.factor"
|
"/library/collections/vectors-epilogue.factor"
|
||||||
"/library/hashtables.factor"
|
"/library/collections/hashtables.factor"
|
||||||
"/library/namespaces.factor"
|
"/library/collections/namespaces.factor"
|
||||||
"/library/words.factor"
|
"/library/words.factor"
|
||||||
"/library/vocabularies.factor"
|
"/library/vocabularies.factor"
|
||||||
"/library/sbuf.factor"
|
"/library/collections/sbuf.factor"
|
||||||
"/library/errors.factor"
|
"/library/errors.factor"
|
||||||
"/library/continuations.factor"
|
"/library/continuations.factor"
|
||||||
"/library/threads.factor"
|
"/library/threads.factor"
|
||||||
|
|
|
@ -1,41 +1,11 @@
|
||||||
! :folding=indent:collapseFolds=1:
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
||||||
|
! See http://factor.sf.net/license.txt for BSD license.
|
||||||
! $Id$
|
|
||||||
!
|
|
||||||
! Copyright (C) 2004 Slava Pestov.
|
|
||||||
!
|
|
||||||
! Redistribution and use in source and binary forms, with or without
|
|
||||||
! modification, are permitted provided that the following conditions are met:
|
|
||||||
!
|
|
||||||
! 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
! this list of conditions and the following disclaimer.
|
|
||||||
!
|
|
||||||
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
! this list of conditions and the following disclaimer in the documentation
|
|
||||||
! and/or other materials provided with the distribution.
|
|
||||||
!
|
|
||||||
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
IN: kernel
|
IN: kernel
|
||||||
USE: namespaces
|
USING: namespaces parser stdio streams threads words ;
|
||||||
USE: parser
|
|
||||||
USE: stdio
|
|
||||||
USE: streams
|
|
||||||
USE: threads
|
|
||||||
USE: words
|
|
||||||
|
|
||||||
: boot ( -- )
|
: boot ( -- )
|
||||||
#! Initialize an interpreter with the basic services.
|
#! Initialize an interpreter with the basic services.
|
||||||
init-namespaces
|
global >n
|
||||||
init-threads
|
init-threads
|
||||||
init-stdio
|
init-stdio
|
||||||
"HOME" os-env [ "." ] unless* "~" set
|
"HOME" os-env [ "." ] unless* "~" set
|
||||||
|
|
|
@ -22,7 +22,7 @@ kernel-internals ;
|
||||||
|
|
||||||
: cli-var-param ( name value -- ) swap ":" split set-path ;
|
: cli-var-param ( name value -- ) swap ":" split set-path ;
|
||||||
|
|
||||||
: cli-bool-param ( name -- ) "no-" ?string-head not put ;
|
: cli-bool-param ( name -- ) "no-" ?string-head not swap set ;
|
||||||
|
|
||||||
: cli-param ( param -- )
|
: cli-param ( param -- )
|
||||||
#! Handle a command-line argument starting with '-' by
|
#! Handle a command-line argument starting with '-' by
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2003, 2005 Slava Pestov.
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
||||||
! See http://factor.sf.net/license.txt for BSD license.
|
! See http://factor.sf.net/license.txt for BSD license.
|
||||||
IN: namespaces
|
IN: namespaces
|
||||||
USING: hashtables kernel kernel-internals lists math
|
USING: hashtables kernel kernel-internals lists math sequences
|
||||||
strings vectors ;
|
strings vectors ;
|
||||||
|
|
||||||
! Other languages have classes, objects, variables, etc.
|
! Other languages have classes, objects, variables, etc.
|
||||||
|
@ -26,6 +26,7 @@ strings vectors ;
|
||||||
! namespace pushed on the namespace stack.
|
! namespace pushed on the namespace stack.
|
||||||
|
|
||||||
: namestack ( -- ns ) 3 getenv ; inline
|
: namestack ( -- ns ) 3 getenv ; inline
|
||||||
|
|
||||||
: set-namestack ( ns -- ) 3 setenv ; inline
|
: set-namestack ( ns -- ) 3 setenv ; inline
|
||||||
|
|
||||||
: namespace ( -- namespace )
|
: namespace ( -- namespace )
|
||||||
|
@ -33,18 +34,14 @@ strings vectors ;
|
||||||
namestack car ;
|
namestack car ;
|
||||||
|
|
||||||
: >n ( namespace -- n:namespace )
|
: >n ( namespace -- n:namespace )
|
||||||
#! Push a namespace on the namespace stack.
|
#! Push a namespace on the name stack.
|
||||||
namestack cons set-namestack ; inline
|
namestack cons set-namestack ; inline
|
||||||
|
|
||||||
: n> ( n:namespace -- namespace )
|
: n> ( n:namespace -- namespace )
|
||||||
#! Pop the top of the namespace stack.
|
#! Pop the top of the name stack.
|
||||||
namestack uncons set-namestack ; inline
|
namestack uncons set-namestack ; inline
|
||||||
|
|
||||||
: global ( -- g ) 4 getenv ;
|
: global ( -- g ) 4 getenv ;
|
||||||
: set-global ( g -- ) 4 setenv ;
|
|
||||||
|
|
||||||
: init-namespaces ( -- )
|
|
||||||
global >n ;
|
|
||||||
|
|
||||||
: <namespace> ( -- n )
|
: <namespace> ( -- n )
|
||||||
#! Create a new namespace.
|
#! Create a new namespace.
|
||||||
|
@ -68,7 +65,10 @@ strings vectors ;
|
||||||
namestack (get) ;
|
namestack (get) ;
|
||||||
|
|
||||||
: set ( value variable -- ) namespace set-hash ;
|
: set ( value variable -- ) namespace set-hash ;
|
||||||
: put ( variable value -- ) swap set ;
|
|
||||||
|
: on ( var -- ) t swap set ;
|
||||||
|
|
||||||
|
: off ( var -- ) f swap set ;
|
||||||
|
|
||||||
: nest ( variable -- hash )
|
: nest ( variable -- hash )
|
||||||
#! If the variable is set in the current namespace, return
|
#! If the variable is set in the current namespace, return
|
||||||
|
@ -90,7 +90,7 @@ strings vectors ;
|
||||||
#! namestack.
|
#! namestack.
|
||||||
<namespace> >n call n> drop ; inline
|
<namespace> >n call n> drop ; inline
|
||||||
|
|
||||||
: extend ( object code -- object )
|
: extend ( namespace code -- namespace )
|
||||||
#! Used in code like this:
|
#! Used in code like this:
|
||||||
#! : <subclass>
|
#! : <subclass>
|
||||||
#! <superclass> [
|
#! <superclass> [
|
||||||
|
@ -98,67 +98,46 @@ strings vectors ;
|
||||||
#! ] extend ;
|
#! ] extend ;
|
||||||
over >r bind r> ; inline
|
over >r bind r> ; inline
|
||||||
|
|
||||||
: on ( var -- ) t put ;
|
! Building sequences
|
||||||
: off ( var -- ) f put ;
|
SYMBOL: sequence
|
||||||
: inc ( var -- ) [ 1 + ] change ;
|
|
||||||
: dec ( var -- ) [ 1 - ] change ;
|
|
||||||
|
|
||||||
: cons@ ( x var -- )
|
: make-seq ( quot sequence -- sequence )
|
||||||
#! Prepend x to the list stored in var.
|
#! Call , and % from the quotation to append to a sequence.
|
||||||
[ cons ] change ;
|
[ sequence set call sequence get ] with-scope ; inline
|
||||||
|
|
||||||
: unique@ ( elem var -- )
|
|
||||||
#! Prepend an element to the proper list stored in a
|
|
||||||
#! variable if it is not already contained in the list.
|
|
||||||
[ unique ] change ;
|
|
||||||
|
|
||||||
SYMBOL: list-buffer
|
|
||||||
|
|
||||||
: make-rlist ( quot -- list )
|
|
||||||
#! Call a quotation. The quotation can call , to prepend
|
|
||||||
#! objects to the list that is returned when the quotation
|
|
||||||
#! is done.
|
|
||||||
[ list-buffer off call list-buffer get ] with-scope ;
|
|
||||||
inline
|
|
||||||
|
|
||||||
: make-list ( quot -- list )
|
|
||||||
#! Return a list whose entries are in the same order that ,
|
|
||||||
#! was called.
|
|
||||||
make-rlist reverse ; inline
|
|
||||||
|
|
||||||
: make-string ( quot -- string )
|
|
||||||
#! Call a quotation. The quotation can call , to prepend
|
|
||||||
#! objects to the list that is returned when the quotation
|
|
||||||
#! is done.
|
|
||||||
make-list cat ; inline
|
|
||||||
|
|
||||||
: make-rstring ( quot -- string )
|
|
||||||
#! Return a string whose entries are in the same order that ,
|
|
||||||
#! was called.
|
|
||||||
make-rlist cat ; inline
|
|
||||||
|
|
||||||
: make-vector ( quot -- list )
|
|
||||||
#! Return a vector whose entries are in the same order that
|
|
||||||
#! , was called.
|
|
||||||
make-list list>vector ; inline
|
|
||||||
|
|
||||||
: , ( obj -- )
|
: , ( obj -- )
|
||||||
#! Append an object to the currently constructing list.
|
#! Add to the sequence being built with make-seq.
|
||||||
list-buffer cons@ ;
|
sequence get dup sbuf? [ sbuf-append ] [ push ] ifte ;
|
||||||
|
|
||||||
: unique, ( obj -- )
|
|
||||||
#! Append an object to the currently constructing list, only
|
|
||||||
#! if the object does not already occur in the list.
|
|
||||||
list-buffer unique@ ;
|
|
||||||
|
|
||||||
: append, ( list -- )
|
|
||||||
[ , ] each ;
|
|
||||||
|
|
||||||
: literal, ( word -- )
|
: literal, ( word -- )
|
||||||
#! Append some code that pushes the word on the stack. Used
|
#! Append some code that pushes the word on the stack. Used
|
||||||
#! when building quotations.
|
#! when building quotations.
|
||||||
unit , \ car , ;
|
unit , \ car , ;
|
||||||
|
|
||||||
|
: unique, ( obj -- )
|
||||||
|
#! Add the object to the sequence being built with make-seq
|
||||||
|
#! unless an equal object has already been added.
|
||||||
|
sequence get 2dup index -1 = [ push ] [ 2drop ] ifte ;
|
||||||
|
|
||||||
|
: % ( seq -- )
|
||||||
|
#! Append to the sequence being built with make-seq.
|
||||||
|
sequence get swap nappend ;
|
||||||
|
|
||||||
|
: make-vector ( quot -- vector )
|
||||||
|
100 <vector> make-seq ; inline
|
||||||
|
|
||||||
|
: make-list ( quot -- list )
|
||||||
|
make-vector >list ; inline
|
||||||
|
|
||||||
|
: make-sbuf ( quot -- sbuf )
|
||||||
|
100 <sbuf> make-seq ; inline
|
||||||
|
|
||||||
|
: make-string ( quot -- string )
|
||||||
|
make-sbuf sbuf>string ; inline
|
||||||
|
|
||||||
|
: make-rstring ( quot -- string )
|
||||||
|
make-sbuf dup nreverse sbuf>string ; inline
|
||||||
|
|
||||||
! Building hashtables, and computing a transitive closure.
|
! Building hashtables, and computing a transitive closure.
|
||||||
SYMBOL: hash-buffer
|
SYMBOL: hash-buffer
|
||||||
|
|
|
@ -96,10 +96,17 @@ M: sequence (tree-each) [ swap call ] seq-each-with ;
|
||||||
|
|
||||||
: >pop> ( stack -- stack ) dup pop drop ;
|
: >pop> ( stack -- stack ) dup pop drop ;
|
||||||
|
|
||||||
|
: (exchange) ( seq i j -- seq[i] j seq )
|
||||||
|
pick >r >r swap nth r> r> ;
|
||||||
|
|
||||||
|
: exchange ( seq i j -- )
|
||||||
|
#! Exchange seq[i] and seq[j].
|
||||||
|
3dup >r >r >r (exchange) r> r> r>
|
||||||
|
swap (exchange) set-nth set-nth ;
|
||||||
|
|
||||||
: (nreverse) ( seq i -- )
|
: (nreverse) ( seq i -- )
|
||||||
#! Swap seq[i] with seq[length-i-1].
|
#! Swap seq[i] with seq[length-i-1].
|
||||||
|
over length over - 1 - exchange ;
|
||||||
;
|
|
||||||
|
|
||||||
: nreverse ( seq -- )
|
: nreverse ( seq -- )
|
||||||
#! Destructively reverse seq.
|
#! Destructively reverse seq.
|
|
@ -87,7 +87,9 @@ C: relative ( word -- )
|
||||||
[ just-compiled swap set-relative-where ] keep
|
[ just-compiled swap set-relative-where ] keep
|
||||||
[ compiled-offset swap set-relative-to ] keep ;
|
[ compiled-offset swap set-relative-to ] keep ;
|
||||||
|
|
||||||
: relative ( word -- ) <relative> deferred-xts cons@ ;
|
: deferred-xt deferred-xts [ cons ] change ;
|
||||||
|
|
||||||
|
: relative ( word -- ) <relative> deferred-xt ;
|
||||||
|
|
||||||
: relative-fixup ( relative -- addr )
|
: relative-fixup ( relative -- addr )
|
||||||
dup relative-word compiled-xt swap relative-to - ;
|
dup relative-word compiled-xt swap relative-to - ;
|
||||||
|
@ -102,7 +104,7 @@ C: absolute ( word -- )
|
||||||
[ just-compiled swap set-absolute-where ] keep ;
|
[ just-compiled swap set-absolute-where ] keep ;
|
||||||
|
|
||||||
: absolute ( word -- )
|
: absolute ( word -- )
|
||||||
dup f rel-word <absolute> deferred-xts cons@ ;
|
dup f rel-word <absolute> deferred-xt ;
|
||||||
|
|
||||||
: >absolute dup absolute-word compiled-xt swap absolute-where ;
|
: >absolute dup absolute-word compiled-xt swap absolute-where ;
|
||||||
|
|
||||||
|
@ -120,11 +122,11 @@ C: relative-bitfld ( word mask -- )
|
||||||
|
|
||||||
: relative-24 ( word -- )
|
: relative-24 ( word -- )
|
||||||
BIN: 11111111111111111111111100 <relative-bitfld>
|
BIN: 11111111111111111111111100 <relative-bitfld>
|
||||||
deferred-xts cons@ ;
|
deferred-xt ;
|
||||||
|
|
||||||
: relative-14 ( word -- )
|
: relative-14 ( word -- )
|
||||||
BIN: 1111111111111100 <relative-bitfld>
|
BIN: 1111111111111100 <relative-bitfld>
|
||||||
deferred-xts cons@ ;
|
deferred-xt ;
|
||||||
|
|
||||||
: or-compiled ( n off -- )
|
: or-compiled ( n off -- )
|
||||||
[ compiled-cell bitor ] keep set-compiled-cell ;
|
[ compiled-cell bitor ] keep set-compiled-cell ;
|
||||||
|
@ -146,8 +148,7 @@ C: absolute-16/16 ( word -- )
|
||||||
|
|
||||||
M: absolute-16/16 fixup ( absolute -- ) >absolute fixup-16/16 ;
|
M: absolute-16/16 fixup ( absolute -- ) >absolute fixup-16/16 ;
|
||||||
|
|
||||||
: absolute-16/16 ( word -- )
|
: absolute-16/16 ( word -- ) <absolute-16/16> deferred-xt ;
|
||||||
<absolute-16/16> deferred-xts cons@ ;
|
|
||||||
|
|
||||||
: compiling? ( word -- ? )
|
: compiling? ( word -- ? )
|
||||||
#! A word that is compiling or already compiled will not be
|
#! A word that is compiling or already compiled will not be
|
||||||
|
@ -169,4 +170,8 @@ M: absolute-16/16 fixup ( absolute -- ) >absolute fixup-16/16 ;
|
||||||
[ call fixup-xts commit-xts ] with-scope ;
|
[ call fixup-xts commit-xts ] with-scope ;
|
||||||
|
|
||||||
: postpone-word ( word -- )
|
: postpone-word ( word -- )
|
||||||
dup compiling? [ drop ] [ compile-words unique@ ] ifte ;
|
dup compiling? [
|
||||||
|
drop
|
||||||
|
] [
|
||||||
|
compile-words [ unique ] change
|
||||||
|
] ifte ;
|
||||||
|
|
|
@ -9,7 +9,7 @@ SYMBOL: predicate
|
||||||
|
|
||||||
: predicate-dispatch ( existing definition class -- dispatch )
|
: predicate-dispatch ( existing definition class -- dispatch )
|
||||||
[
|
[
|
||||||
\ dup , "predicate" word-prop append, , , \ ifte ,
|
\ dup , "predicate" word-prop % , , \ ifte ,
|
||||||
] make-list ;
|
] make-list ;
|
||||||
|
|
||||||
: predicate-method ( vtable definition class type# -- )
|
: predicate-method ( vtable definition class type# -- )
|
||||||
|
@ -44,7 +44,7 @@ predicate [
|
||||||
: define-predicate ( class predicate definition -- )
|
: define-predicate ( class predicate definition -- )
|
||||||
pick over "definition" set-word-prop
|
pick over "definition" set-word-prop
|
||||||
pick "superclass" word-prop "predicate" word-prop
|
pick "superclass" word-prop "predicate" word-prop
|
||||||
[ \ dup , append, , [ drop f ] , \ ifte , ] make-list
|
[ \ dup , % , [ drop f ] , \ ifte , ] make-list
|
||||||
define-compound
|
define-compound
|
||||||
predicate "metaclass" set-word-prop ;
|
predicate "metaclass" set-word-prop ;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ union [ 2drop t ] "class<" set-word-prop
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
\ dup ,
|
\ dup ,
|
||||||
unswons "predicate" word-prop append,
|
unswons "predicate" word-prop %
|
||||||
[ drop t ] ,
|
[ drop t ] ,
|
||||||
union-predicate ,
|
union-predicate ,
|
||||||
\ ifte ,
|
\ ifte ,
|
||||||
|
|
|
@ -78,7 +78,7 @@ errors unparser logging listener url-encoding hashtables memory ;
|
||||||
: write-word-source ( vocab word -- )
|
: write-word-source ( vocab word -- )
|
||||||
#! Write the source for the given word from the vocab as HTML.
|
#! Write the source for the given word from the vocab as HTML.
|
||||||
<namespace> [
|
<namespace> [
|
||||||
"allow-edit?" get [ "Edit" [ "edit-state" t put ] quot-href <br/> ] when
|
"allow-edit?" get [ "Edit" [ "edit-state" on ] quot-href <br/> ] when
|
||||||
"edit-state" get [
|
"edit-state" get [
|
||||||
write-editable-word-source
|
write-editable-word-source
|
||||||
] [
|
] [
|
||||||
|
@ -131,10 +131,10 @@ errors unparser logging listener url-encoding hashtables memory ;
|
||||||
#! Return a list of vocabularies that all words in a vocabulary
|
#! Return a list of vocabularies that all words in a vocabulary
|
||||||
#! uses.
|
#! uses.
|
||||||
<namespace> [
|
<namespace> [
|
||||||
"result" f put
|
"result" off
|
||||||
words [
|
words [
|
||||||
word-uses [
|
word-uses [
|
||||||
"result" unique@
|
"result" [ unique ] change
|
||||||
] each
|
] each
|
||||||
] each
|
] each
|
||||||
"result" get
|
"result" get
|
||||||
|
@ -202,7 +202,7 @@ errors unparser logging listener url-encoding hashtables memory ;
|
||||||
] show [
|
] show [
|
||||||
"allow-edit?" get [
|
"allow-edit?" get [
|
||||||
"eval" get [
|
"eval" get [
|
||||||
"eval" f put
|
"eval" off
|
||||||
"Editing has been disabled." show-message-page
|
"Editing has been disabled." show-message-page
|
||||||
] when
|
] when
|
||||||
] unless
|
] unless
|
||||||
|
|
|
@ -91,7 +91,7 @@ USE: words
|
||||||
#! and sets it's value to the current value on the stack.
|
#! and sets it's value to the current value on the stack.
|
||||||
#! If there is no previous attribute, no value is expected
|
#! If there is no previous attribute, no value is expected
|
||||||
#! on the stack.
|
#! on the stack.
|
||||||
"current-attribute" get [ swons "attrs" cons@ ] when* ;
|
"current-attribute" get [ swons "attrs" [ cons ] change ] when* ;
|
||||||
|
|
||||||
! HTML tag words
|
! HTML tag words
|
||||||
!
|
!
|
||||||
|
|
|
@ -156,7 +156,7 @@ SYMBOL: cloned
|
||||||
over [
|
over [
|
||||||
>r
|
>r
|
||||||
dupd cons
|
dupd cons
|
||||||
recursive-state cons@
|
recursive-state [ cons ] change
|
||||||
r> call
|
r> call
|
||||||
] (with-block) ;
|
] (with-block) ;
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ SYMBOL: node-param
|
||||||
|
|
||||||
: dataflow, ( param op -- node )
|
: dataflow, ( param op -- node )
|
||||||
#! Add a node to the dataflow IR.
|
#! Add a node to the dataflow IR.
|
||||||
<dataflow-node> dup dataflow-graph cons@ ;
|
<dataflow-node> dup dataflow-graph [ cons ] change ;
|
||||||
|
|
||||||
: dataflow-drop, ( -- )
|
: dataflow-drop, ( -- )
|
||||||
#! Remove the top stack element and add a dataflow node
|
#! Remove the top stack element and add a dataflow node
|
||||||
|
|
|
@ -119,10 +119,10 @@ M: compound apply-word ( word -- )
|
||||||
|
|
||||||
: with-recursion ( quot -- )
|
: with-recursion ( quot -- )
|
||||||
[
|
[
|
||||||
inferring-base-case inc
|
inferring-base-case [ 1 + ] change
|
||||||
call
|
call
|
||||||
] [
|
] [
|
||||||
inferring-base-case dec
|
inferring-base-case [ 1 - ] change
|
||||||
rethrow
|
rethrow
|
||||||
] catch ;
|
] catch ;
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ M: matrix v. ( m1 m2 -- m )
|
||||||
|
|
||||||
: ]M
|
: ]M
|
||||||
reverse [ dup car length swap length ] keep
|
reverse [ dup car length swap length ] keep
|
||||||
[ [ append, ] each ] make-vector <matrix> swons ; parsing
|
[ [ % ] each ] make-vector <matrix> swons ; parsing
|
||||||
|
|
||||||
: row-list ( matrix -- list )
|
: row-list ( matrix -- list )
|
||||||
#! A list of lists, where each sublist is a row of the
|
#! A list of lists, where each sublist is a row of the
|
||||||
|
|
|
@ -95,17 +95,17 @@ BUILTIN: f 9 ; : f f swons ; parsing
|
||||||
|
|
||||||
: USE:
|
: USE:
|
||||||
#! Add vocabulary to search path.
|
#! Add vocabulary to search path.
|
||||||
scan "use" cons@ ; parsing
|
scan use+ ; parsing
|
||||||
|
|
||||||
: USING:
|
: USING:
|
||||||
#! A list of vocabularies terminated with ;
|
#! A list of vocabularies terminated with ;
|
||||||
string-mode on
|
string-mode on
|
||||||
[ string-mode off [ "use" cons@ ] each ]
|
[ string-mode off [ use+ ] each ]
|
||||||
f ; parsing
|
f ; parsing
|
||||||
|
|
||||||
: IN:
|
: IN:
|
||||||
#! Set vocabulary for new definitions.
|
#! Set vocabulary for new definitions.
|
||||||
scan dup "use" cons@ "in" set ; parsing
|
scan dup use+ "in" set ; parsing
|
||||||
|
|
||||||
! Char literal
|
! Char literal
|
||||||
: CHAR: ( -- ) 0 scan next-char drop swons ; parsing
|
: CHAR: ( -- ) 0 scan next-char drop swons ; parsing
|
||||||
|
|
|
@ -8,7 +8,7 @@ presentation stdio streams strings unparser words ;
|
||||||
: vocab-actions ( search -- list )
|
: vocab-actions ( search -- list )
|
||||||
[
|
[
|
||||||
[[ "Words" "words ." ]]
|
[[ "Words" "words ." ]]
|
||||||
[[ "Use" "\"use\" cons@" ]]
|
[[ "Use" "use+" ]]
|
||||||
[[ "In" "\"in\" set" ]]
|
[[ "In" "\"in\" set" ]]
|
||||||
] ;
|
] ;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ USE: lists
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: test
|
USE: test
|
||||||
|
|
||||||
|
: cons@ [ cons ] change ;
|
||||||
|
: unique@ [ unique ] change ;
|
||||||
|
|
||||||
[ [ 1 ] ] [ 1 f "x" set "x" cons@ "x" get ] unit-test
|
[ [ 1 ] ] [ 1 f "x" set "x" cons@ "x" get ] unit-test
|
||||||
[ [[ 1 2 ]] ] [ 1 2 "x" set "x" cons@ "x" get ] unit-test
|
[ [[ 1 2 ]] ] [ 1 2 "x" set "x" cons@ "x" get ] unit-test
|
||||||
[ [ 1 2 ] ] [ 1 [ 2 ] "x" set "x" cons@ "x" get ] unit-test
|
[ [ 1 2 ] ] [ 1 [ 2 ] "x" set "x" cons@ "x" get ] unit-test
|
||||||
|
|
|
@ -41,14 +41,10 @@ prettyprint sequences stdio strings unparser vectors words ;
|
||||||
|
|
||||||
SYMBOL: failures
|
SYMBOL: failures
|
||||||
|
|
||||||
|
: failure failures [ cons ] change ;
|
||||||
|
|
||||||
: test-handler ( name quot -- ? )
|
: test-handler ( name quot -- ? )
|
||||||
[
|
[ [ dup error. cons failure f ] [ t ] ifte* ] catch ;
|
||||||
[
|
|
||||||
dup error. cons failures cons@ f
|
|
||||||
] [
|
|
||||||
t
|
|
||||||
] ifte*
|
|
||||||
] catch ;
|
|
||||||
|
|
||||||
: test-path ( name -- path )
|
: test-path ( name -- path )
|
||||||
"/library/test/" swap ".factor" cat3 ;
|
"/library/test/" swap ".factor" cat3 ;
|
||||||
|
@ -80,7 +76,7 @@ SYMBOL: failures
|
||||||
"inference" "dataflow" "interpreter" "alien"
|
"inference" "dataflow" "interpreter" "alien"
|
||||||
"line-editor" "gadgets" "memory" "redefine"
|
"line-editor" "gadgets" "memory" "redefine"
|
||||||
"annotate"
|
"annotate"
|
||||||
] append,
|
] %
|
||||||
|
|
||||||
os "win32" = [
|
os "win32" = [
|
||||||
"buffer" ,
|
"buffer" ,
|
||||||
|
@ -93,7 +89,7 @@ SYMBOL: failures
|
||||||
"compiler/stack" "compiler/ifte"
|
"compiler/stack" "compiler/ifte"
|
||||||
"compiler/generic" "compiler/bail-out"
|
"compiler/generic" "compiler/bail-out"
|
||||||
"compiler/linearizer"
|
"compiler/linearizer"
|
||||||
] append,
|
] %
|
||||||
] unless
|
] unless
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -102,7 +98,7 @@ SYMBOL: failures
|
||||||
"benchmark/continuations" "benchmark/ack"
|
"benchmark/continuations" "benchmark/ack"
|
||||||
"benchmark/hashtables" "benchmark/strings"
|
"benchmark/hashtables" "benchmark/strings"
|
||||||
"benchmark/vectors"
|
"benchmark/vectors"
|
||||||
] append,
|
] %
|
||||||
] make-list ;
|
] make-list ;
|
||||||
|
|
||||||
: passed.
|
: passed.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
IN: temporary
|
IN: temporary
|
||||||
USING: kernel kernel-internals math namespaces random sequences
|
USING: kernel kernel-internals lists math namespaces random
|
||||||
strings test vectors ;
|
sequences strings test vectors ;
|
||||||
|
|
||||||
[ 3 ] [ [ t f t ] length ] unit-test
|
[ 3 ] [ [ t f t ] length ] unit-test
|
||||||
[ 3 ] [ { t f t } length ] unit-test
|
[ 3 ] [ { t f t } length ] unit-test
|
||||||
|
@ -91,3 +91,9 @@ unit-test
|
||||||
|
|
||||||
[ -1 ] [ 5 { } index ] unit-test
|
[ -1 ] [ 5 { } index ] unit-test
|
||||||
[ 4 ] [ 5 { 1 2 3 4 5 } index ] unit-test
|
[ 4 ] [ 5 { 1 2 3 4 5 } index ] unit-test
|
||||||
|
|
||||||
|
[ { "c" "b" "a" } ] [ { "a" "b" "c" } clone dup 0 2 exchange ] unit-test
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
100 count dup list>vector dup nreverse >list >r reverse r> =
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -21,7 +21,7 @@ SYMBOL: vocabularies
|
||||||
vocab dup [ hash-values [ ] subset word-sort ] when ;
|
vocab dup [ hash-values [ ] subset word-sort ] when ;
|
||||||
|
|
||||||
: all-words ( -- list )
|
: all-words ( -- list )
|
||||||
[ vocabs [ words append, ] each ] make-list ;
|
[ vocabs [ words % ] each ] make-list ;
|
||||||
|
|
||||||
: each-word ( quot -- )
|
: each-word ( quot -- )
|
||||||
#! Apply a quotation to each word in the image.
|
#! Apply a quotation to each word in the image.
|
||||||
|
|
Loading…
Reference in New Issue