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

db4
Doug Coleman 2008-07-12 22:59:34 -05:00
commit ca3e39714d
34 changed files with 319 additions and 203 deletions

View File

@ -151,7 +151,8 @@ M: byte-array byte-length length ;
swap dup length memcpy ; swap dup length memcpy ;
: (define-nth) ( word type quot -- ) : (define-nth) ( word type quot -- )
>r heap-size [ rot * ] swap prefix r> append define-inline ; >r heap-size [ rot * >fixnum ] swap prefix
r> append define-inline ;
: nth-word ( name vocab -- word ) : nth-word ( name vocab -- word )
>r "-nth" append r> create ; >r "-nth" append r> create ;

View File

@ -57,13 +57,19 @@ ARTICLE: "assocs-lookup" "Lookup and querying of assocs"
"Utility operations built up from the " { $link "assocs-protocol" } ":" "Utility operations built up from the " { $link "assocs-protocol" } ":"
{ $subsection key? } { $subsection key? }
{ $subsection at } { $subsection at }
{ $subsection value-at }
{ $subsection assoc-empty? } { $subsection assoc-empty? }
{ $subsection keys } { $subsection keys }
{ $subsection values } { $subsection values }
{ $subsection assoc-stack } { $subsection assoc-stack }
{ $see-also at* assoc-size } ; { $see-also at* assoc-size } ;
ARTICLE: "assocs-values" "Transposed assoc operations"
"Most assoc words take a key and find the corresponding value. The following words take a value and find the corresponding key:"
{ $subsection value-at }
{ $subsection value-at* }
{ $subsection value? }
"With most assoc implementations, these words runs in linear time, proportional to the number of entries in the assoc. For fast value lookups, use " { $vocab-link "biassocs" } "." ;
ARTICLE: "assocs-sets" "Set-theoretic operations on assocs" ARTICLE: "assocs-sets" "Set-theoretic operations on assocs"
"It is often useful to use the keys of an associative mapping as a set, exploiting the constant or logarithmic lookup time of most implementations (" { $link "alists" } " being a notable exception)." "It is often useful to use the keys of an associative mapping as a set, exploiting the constant or logarithmic lookup time of most implementations (" { $link "alists" } " being a notable exception)."
{ $subsection assoc-subset? } { $subsection assoc-subset? }
@ -111,6 +117,7 @@ $nl
{ $subsection "assocs-protocol" } { $subsection "assocs-protocol" }
"A large set of utility words work on any object whose class implements the associative mapping protocol." "A large set of utility words work on any object whose class implements the associative mapping protocol."
{ $subsection "assocs-lookup" } { $subsection "assocs-lookup" }
{ $subsection "assocs-values" }
{ $subsection "assocs-mutation" } { $subsection "assocs-mutation" }
{ $subsection "assocs-combinators" } { $subsection "assocs-combinators" }
{ $subsection "assocs-sets" } ; { $subsection "assocs-sets" } ;
@ -231,10 +238,17 @@ HELP: assoc-stack
{ $description "Searches for the key in successive elements of the sequence, starting from the end. If an assoc containing the key is found, the associated value is output. If no assoc contains the key, outputs " { $link f } "." } { $description "Searches for the key in successive elements of the sequence, starting from the end. If an assoc containing the key is found, the associated value is output. If no assoc contains the key, outputs " { $link f } "." }
{ $notes "This word is used to implement abstractions such as nested scopes; if the sequence is a stack represented by a vector, then the most recently pushed assoc -- the innermost scope -- will be searched first." } ; { $notes "This word is used to implement abstractions such as nested scopes; if the sequence is a stack represented by a vector, then the most recently pushed assoc -- the innermost scope -- will be searched first." } ;
HELP: value-at*
{ $values { "value" "an object" } { "assoc" assoc } { "key/f" "the key associated to the value, or " { $link f } } { "?" "a boolean" } }
{ $description "Looks up the key associated with a value. The boolean flag can decide beteen the case of a missing key, and a key of " { $link f } "." } ;
HELP: value-at HELP: value-at
{ $values { "value" "an object" } { "assoc" assoc } { "key/f" "the key associated to the value, or " { $link f } } } { $values { "value" "an object" } { "assoc" assoc } { "key/f" "the key associated to the value, or " { $link f } } }
{ $description "Looks up the key associated with a value. No distinction is made between a missing key and a key set to " { $link f } "." } { $description "Looks up the key associated with a value. No distinction is made between a missing key and a key set to " { $link f } "." } ;
{ $notes "This word runs in linear time, proportional to the number of entries in the assoc." } ;
HELP: value?
{ $values { "value" "an object" } { "assoc" assoc } { "?" "a boolean" } }
{ $description "Tests if an assoc contains at least one key with the given value." } ;
HELP: delete-at* HELP: delete-at*
{ $values { "key" "a key" } { "assoc" assoc } { "old" "the previous value or " { $link f } } { "?" "a boolean" } } { $values { "key" "a key" } { "assoc" assoc } { "old" "the previous value or " { $link f } } { "?" "a boolean" } }

View File

@ -144,10 +144,13 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
: extract-keys ( seq assoc -- subassoc ) : extract-keys ( seq assoc -- subassoc )
[ [ dupd at ] curry ] keep map>assoc ; [ [ dupd at ] curry ] keep map>assoc ;
! M: assoc >alist [ 2array ] { } assoc>map ; GENERIC: value-at* ( value assoc -- key/f ? )
: value-at ( value assoc -- key/f ) M: assoc value-at* swap [ = nip ] curry assoc-find nip ;
swap [ = nip ] curry assoc-find 2drop ;
: value-at ( value assoc -- key/f ) value-at* drop ;
: value? ( value assoc -- ? ) value-at* nip ;
: push-at ( value key assoc -- ) : push-at ( value key assoc -- )
[ ?push ] change-at ; [ ?push ] change-at ;

View File

@ -119,6 +119,7 @@ SYMBOL: jit-primitive
SYMBOL: jit-word-jump SYMBOL: jit-word-jump
SYMBOL: jit-word-call SYMBOL: jit-word-call
SYMBOL: jit-push-literal SYMBOL: jit-push-literal
SYMBOL: jit-push-immediate
SYMBOL: jit-if-word SYMBOL: jit-if-word
SYMBOL: jit-if-jump SYMBOL: jit-if-jump
SYMBOL: jit-dispatch-word SYMBOL: jit-dispatch-word
@ -149,6 +150,7 @@ SYMBOL: undefined-quot
{ jit-epilog 33 } { jit-epilog 33 }
{ jit-return 34 } { jit-return 34 }
{ jit-profiling 35 } { jit-profiling 35 }
{ jit-push-immediate 36 }
{ jit-declare-word 42 } { jit-declare-word 42 }
{ undefined-quot 60 } { undefined-quot 60 }
} at header-size + ; } at header-size + ;
@ -438,6 +440,7 @@ M: quotation '
jit-word-jump jit-word-jump
jit-word-call jit-word-call
jit-push-literal jit-push-literal
jit-push-immediate
jit-if-word jit-if-word
jit-if-jump jit-if-jump
jit-dispatch-word jit-dispatch-word

View File

@ -51,7 +51,7 @@ must-fail-with
[ error>> unexpected-eof? ] [ error>> unexpected-eof? ]
must-fail-with must-fail-with
[ "IN: classes.tuple.parser.tests USE: generic.standard TUPLE: foo { slot no-method } ;" eval ] [ "IN: classes.tuple.parser.tests USE: alien TUPLE: foo { slot dll } ;" eval ]
[ error>> no-initial-value? ] [ error>> no-initial-value? ]
must-fail-with must-fail-with

View File

@ -40,6 +40,12 @@ big-endian off
ds-reg [] arg0 MOV ! store literal on datastack ds-reg [] arg0 MOV ! store literal on datastack
] rc-absolute-cell rt-literal 1 rex-length + jit-push-literal jit-define ] rc-absolute-cell rt-literal 1 rex-length + jit-push-literal jit-define
[
arg0 0 MOV ! load literal
ds-reg bootstrap-cell ADD ! increment datastack pointer
ds-reg [] arg0 MOV ! store literal on datastack
] rc-absolute-cell rt-immediate 1 rex-length + jit-push-immediate jit-define
[ [
arg0 0 MOV ! load XT arg0 0 MOV ! load XT
arg1 stack-reg MOV ! pass callstack pointer as arg 2 arg1 stack-reg MOV ! pass callstack pointer as arg 2

View File

@ -72,6 +72,7 @@ SYMBOL: label-table
: rt-xt 4 ; : rt-xt 4 ;
: rt-here 5 ; : rt-here 5 ;
: rt-label 6 ; : rt-label 6 ;
: rt-immediate 7 ;
TUPLE: label-fixup label class ; TUPLE: label-fixup label class ;

View File

@ -2,10 +2,14 @@ USING: help.markup help.syntax sequences strings ;
IN: grouping IN: grouping
ARTICLE: "grouping" "Groups and clumps" ARTICLE: "grouping" "Groups and clumps"
"Splitting a sequence into disjoint, fixed-length subsequences:"
{ $subsection group }
"A virtual sequence for splitting a sequence into disjoint, fixed-length subsequences:" "A virtual sequence for splitting a sequence into disjoint, fixed-length subsequences:"
{ $subsection groups } { $subsection groups }
{ $subsection <groups> } { $subsection <groups> }
{ $subsection <sliced-groups> } { $subsection <sliced-groups> }
"Splitting a sequence into overlapping, fixed-length subsequences:"
{ $subsection clump }
"A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:" "A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:"
{ $subsection clumps } { $subsection clumps }
{ $subsection <clumps> } { $subsection <clumps> }

View File

@ -1,9 +1,9 @@
! Copyright (C) 2006, 2008 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel generic sequences prettyprint io words arrays
summary effects debugger assocs accessors inference.backend
inference.dataflow ;
IN: inference.errors IN: inference.errors
USING: inference.backend inference.dataflow kernel generic
sequences prettyprint io words arrays summary effects debugger
assocs accessors ;
M: inference-error error-help error>> error-help ; M: inference-error error-help error>> error-help ;

View File

@ -1,8 +1,7 @@
! Copyright (C) 2004, 2008 Slava Pestov. ! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: namespaces assocs sequences inference.dataflow USING: namespaces assocs sequences kernel generic assocs classes
inference.backend kernel generic assocs classes vectors vectors accessors combinators inference.dataflow inference.backend ;
accessors combinators ;
IN: optimizer.def-use IN: optimizer.def-use
SYMBOL: def-use SYMBOL: def-use

View File

@ -1,15 +1,15 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien arrays generic hashtables definitions USING: accessors alien arrays generic hashtables definitions
inference.dataflow inference.state inference.class kernel assocs kernel assocs math math.order math.private kernel.private
math math.order math.private kernel.private sequences words sequences words parser vectors strings sbufs io namespaces
parser vectors strings sbufs io namespaces assocs quotations assocs quotations sequences.private io.binary io.streams.string
sequences.private io.binary io.streams.string layouts splitting layouts splitting math.intervals math.floats.private
math.intervals math.floats.private classes.tuple classes.predicate classes.tuple classes.predicate classes.tuple.private classes
classes.tuple.private classes classes.algebra optimizer.def-use classes.algebra sequences.private combinators byte-arrays
optimizer.backend optimizer.pattern-match optimizer.inlining byte-vectors slots.private inference.dataflow inference.state
sequences.private combinators byte-arrays byte-vectors inference.class optimizer.def-use optimizer.backend
slots.private ; optimizer.pattern-match optimizer.inlining ;
IN: optimizer.known-words IN: optimizer.known-words
{ <tuple> <tuple-boa> (tuple) } [ { <tuple> <tuple-boa> (tuple) } [

View File

@ -2,10 +2,10 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: effects alien alien.accessors arrays generic hashtables USING: effects alien alien.accessors arrays generic hashtables
kernel assocs math math.libm math.private kernel.private kernel assocs math math.libm math.private kernel.private
sequences words parser inference.class inference.dataflow sequences words parser vectors strings sbufs io namespaces
vectors strings sbufs io namespaces assocs quotations assocs quotations math.intervals sequences.private combinators
math.intervals sequences.private combinators splitting layouts splitting layouts math.parser classes classes.algebra
math.parser classes classes.algebra generic.math generic.math inference.class inference.dataflow
optimizer.pattern-match optimizer.backend optimizer.def-use optimizer.pattern-match optimizer.backend optimizer.def-use
optimizer.inlining optimizer.math.partial generic.standard optimizer.inlining optimizer.math.partial generic.standard
system accessors ; system accessors ;
@ -444,7 +444,10 @@ most-negative-fixnum most-positive-fixnum [a,b]
{ /f < > <= >= } { /f < > <= >= }
[ { real real } "input-classes" set-word-prop ] each [ { real real } "input-classes" set-word-prop ] each
{ /i bitand bitor bitxor bitnot shift } { /i mod /mod }
[ { rational rational } "input-classes" set-word-prop ] each
{ bitand bitor bitxor bitnot shift }
[ { integer integer } "input-classes" set-word-prop ] each [ { integer integer } "input-classes" set-word-prop ] each
{ {

View File

@ -1,8 +1,9 @@
! Copyright (C) 2007 Slava Pestov. ! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences namespaces generic
combinators classes classes.algebra
inference inference.dataflow ;
IN: optimizer.pattern-match IN: optimizer.pattern-match
USING: kernel sequences inference namespaces generic
combinators classes classes.algebra inference.dataflow ;
! Funny pattern matching ! Funny pattern matching
SYMBOL: @ SYMBOL: @

View File

@ -38,6 +38,18 @@ HELP: adjoin
} }
{ $side-effects "seq" } ; { $side-effects "seq" } ;
HELP: conjoin
{ $values { "elt" object } { "assoc" "an assoc" } }
{ $description "Stores a key/value pair, both equal to " { $snippet "elt" } ", into the assoc." }
{ $examples
{ $example
"USING: kernel prettyprint sets ;"
"H{ } clone 1 over conjoin ."
"H{ { 1 1 } }"
}
}
{ $side-effects "assoc" } ;
HELP: unique HELP: unique
{ $values { "seq" "a sequence" } { "assoc" "an assoc" } } { $values { "seq" "a sequence" } { "assoc" "an assoc" } }
{ $description "Outputs a new assoc where the keys and values are equal." } { $description "Outputs a new assoc where the keys and values are equal." }

View File

@ -1,13 +1,8 @@
USING: arrays assocs kernel vectors sequences namespaces USING: arrays assocs kernel vectors sequences namespaces
random math.parser math fry ; random math.parser math fry ;
IN: assocs.lib IN: assocs.lib
: ref-at ( table key -- value ) swap at ;
: put-at* ( table key value -- ) swap rot set-at ;
: put-at ( table key value -- table ) swap pick set-at ;
: set-assoc-stack ( value key seq -- ) : set-assoc-stack ( value key seq -- )
dupd [ key? ] with find-last nip set-at ; dupd [ key? ] with find-last nip set-at ;

View File

@ -32,7 +32,7 @@ dup >rule-number rule-values rule-keys [ rule> set-at ] 2each ;
! step-wrapped-line ! step-wrapped-line
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: pattern>state ( {_a_b_c_} -- state ) >array rule> at ; : pattern>state ( {_a_b_c_} -- state ) rule> at ;
: cap-line ( line -- 0-line-0 ) { 0 } prepend { 0 } append ; : cap-line ( line -- 0-line-0 ) { 0 } prepend { 0 } append ;

View File

@ -14,13 +14,25 @@ USING: kernel namespaces math quotations arrays hashtables sequences threads
ui.gadgets.packs ui.gadgets.packs
ui.gadgets.grids ui.gadgets.grids
ui.gadgets.theme ui.gadgets.theme
accessors
qualified
namespaces.lib assocs.lib vars namespaces.lib assocs.lib vars
rewrite-closures automata math.geometry.rect ; rewrite-closures automata math.geometry.rect newfx ;
IN: automata.ui IN: automata.ui
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
QUALIFIED: ui.gadgets
QUALIFIED: ui.gadgets.grids
: add-gadget ( parent child -- parent ) over ui.gadgets:add-gadget ;
: grid-add ( grid child i j -- grid )
>r >r dupd swap r> r> ui.gadgets.grids:grid-add ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: draw-point ( y x value -- ) 1 = [ swap glVertex2i ] [ 2drop ] if ; : draw-point ( y x value -- ) 1 = [ swap glVertex2i ] [ 2drop ] if ;
: draw-line ( y line -- ) 0 swap [ >r 2dup r> draw-point 1+ ] each 2drop ; : draw-line ( y line -- ) 0 swap [ >r 2dup r> draw-point 1+ ] each 2drop ;
@ -57,29 +69,40 @@ slate> relayout-1 ;
DEFER: automata-window DEFER: automata-window
: automata-window* ( -- ) init-rule set-interesting <frame> : automata-window* ( -- )
init-rule
set-interesting
{ <frame>
[ "1 - Center" [ start-center ] view-button ]
[ "2 - Random" [ start-random ] view-button ]
[ "3 - Continue" [ run-rule ] view-button ]
[ "5 - Random Rule" [ random-rule ] view-button ]
[ "n - New" [ automata-window ] view-button ]
} make*
[ [ gadget, ] curry ] map concat ! Hack
make-shelf over @top grid-add
[ display ] closed-quot <slate> { 400 400 } over set-slate-dim dup >slate <shelf>
over @center grid-add
{ "1 - Center" [ start-center ] view-button add-gadget
{ T{ key-down f f "1" } [ [ start-center ] view-action ] } "2 - Random" [ start-random ] view-button add-gadget
{ T{ key-down f f "2" } [ [ start-random ] view-action ] } "3 - Continue" [ run-rule ] view-button add-gadget
{ T{ key-down f f "3" } [ [ run-rule ] view-action ] } "5 - Random Rule" [ random-rule ] view-button add-gadget
{ T{ key-down f f "5" } [ [ random-rule ] view-action ] } "n - New" [ automata-window ] view-button add-gadget
{ T{ key-down f f "n" } [ [ automata-window ] view-action ] }
} [ make* ] map >hashtable <handler> tuck set-gadget-delegate @top grid-add
"Automata" open-window ;
C[ display ] <slate>
{ 400 400 } >>dim
dup >slate
@center grid-add
H{ }
T{ key-down f f "1" } [ start-center ] view-action is
T{ key-down f f "2" } [ start-random ] view-action is
T{ key-down f f "3" } [ run-rule ] view-action is
T{ key-down f f "5" } [ random-rule ] view-action is
T{ key-down f f "n" } [ automata-window ] view-action is
<handler>
tuck set-gadget-delegate
"Automata" open-window ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,28 @@
IN: biassocs
USING: help.markup help.syntax assocs kernel ;
HELP: biassoc
{ $class-description "The class of bidirectional assocs. Bidirectional assoc are implemented by combining two assocs, with one the transpose of the other." } ;
HELP: <biassoc>
{ $values { "exemplar" assoc } { "biassoc" biassoc } }
{ $description "Creates a new biassoc using a new assoc of the same type as " { $snippet "exemplar" } " for underlying storage." } ;
HELP: <bihash>
{ $values { "biassoc" biassoc } }
{ $description "Creates a new biassoc using a pair of hashtables for underlying storage." } ;
HELP: once-at
{ $values { "value" object } { "key" object } { "assoc" assoc } }
{ $description "If the assoc does not contain the given key, adds the key/value pair to the assoc, otherwise does nothing." } ;
ARTICLE: "biassocs" "Bidirectional assocs"
"A " { $emphasis "bidirectional assoc" } " combines a pair of assocs to form a data structure where both normal assoc opeartions (eg, " { $link at } "), as well as " { $link "assocs-values" } " (eg, " { $link value-at } ") run in sub-linear time."
$nl
"Bidirectional assocs implement the entire assoc protocol with the exception of " { $link delete-at } ". Duplicate values are allowed, however value lookups with " { $link value-at } " only return the first key that a given value was stored with."
{ $subsection biassoc }
{ $subsection biassoc? }
{ $subsection <biassoc> }
{ $subsection <bihash> } ;
ABOUT: "biassocs"

View File

@ -0,0 +1,22 @@
IN: biassocs.tests
USING: biassocs assocs namespaces tools.test ;
<bihash> "h" set
[ 0 ] [ "h" get assoc-size ] unit-test
[ ] [ 1 2 "h" get set-at ] unit-test
[ 1 ] [ 2 "h" get at ] unit-test
[ 2 ] [ 1 "h" get value-at ] unit-test
[ 1 ] [ "h" get assoc-size ] unit-test
[ ] [ 1 3 "h" get set-at ] unit-test
[ 1 ] [ 3 "h" get at ] unit-test
[ 2 ] [ 1 "h" get value-at ] unit-test
[ 2 ] [ "h" get assoc-size ] unit-test

View File

@ -0,0 +1,35 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel assocs accessors ;
IN: biassocs
TUPLE: biassoc from to ;
: <biassoc> ( exemplar -- biassoc )
[ clone ] [ clone ] bi biassoc boa ;
: <bihash> ( -- biassoc )
H{ } <biassoc> ;
M: biassoc assoc-size from>> assoc-size ;
M: biassoc at* from>> at* ;
M: biassoc value-at* to>> at* ;
: once-at ( value key assoc -- )
2dup key? [ 3drop ] [ set-at ] if ;
M: biassoc set-at
[ from>> set-at ] [ swapd to>> once-at ] 3bi ;
M: biassoc delete-at
"biassocs do not support deletion" throw ;
M: biassoc >alist
from>> >alist ;
M: biassoc clear-assoc
[ from>> clear-assoc ] [ to>> clear-assoc ] bi ;
INSTANCE: biassoc assoc

View File

@ -0,0 +1 @@
Bidirectional assocs

1
extra/biassocs/tags.txt Normal file
View File

@ -0,0 +1 @@
collections

View File

@ -1,2 +1 @@
collections
extensions extensions

View File

@ -20,7 +20,8 @@ USING: combinators.short-circuit kernel namespaces
ui.gadgets.grids ui.gadgets.grids
ui.gestures ui.gestures
assocs.lib vars rewrite-closures boids accessors assocs.lib vars rewrite-closures boids accessors
math.geometry.rect ; math.geometry.rect
newfx ;
IN: boids.ui IN: boids.ui
@ -145,20 +146,20 @@ VARS: population-label cohesion-label alignment-label separation-label ;
slate> over @center grid-add slate> over @center grid-add
H{ } clone H{ } clone
T{ key-down f f "1" } C[ drop randomize ] put-at T{ key-down f f "1" } C[ drop randomize ] is
T{ key-down f f "2" } C[ drop sub-10-boids ] put-at T{ key-down f f "2" } C[ drop sub-10-boids ] is
T{ key-down f f "3" } C[ drop add-10-boids ] put-at T{ key-down f f "3" } C[ drop add-10-boids ] is
T{ key-down f f "q" } C[ drop inc-cohesion-weight ] put-at T{ key-down f f "q" } C[ drop inc-cohesion-weight ] is
T{ key-down f f "a" } C[ drop dec-cohesion-weight ] put-at T{ key-down f f "a" } C[ drop dec-cohesion-weight ] is
T{ key-down f f "w" } C[ drop inc-alignment-weight ] put-at T{ key-down f f "w" } C[ drop inc-alignment-weight ] is
T{ key-down f f "s" } C[ drop dec-alignment-weight ] put-at T{ key-down f f "s" } C[ drop dec-alignment-weight ] is
T{ key-down f f "e" } C[ drop inc-separation-weight ] put-at T{ key-down f f "e" } C[ drop inc-separation-weight ] is
T{ key-down f f "d" } C[ drop dec-separation-weight ] put-at T{ key-down f f "d" } C[ drop dec-separation-weight ] is
T{ key-down f f "ESC" } C[ drop toggle-loop ] put-at T{ key-down f f "ESC" } C[ drop toggle-loop ] is
<handler> tuck set-gadget-delegate "Boids" open-window ; <handler> tuck set-gadget-delegate "Boids" open-window ;
: boids-window ( -- ) [ [ boids-window* ] with-scope ] with-ui ; : boids-window ( -- ) [ [ boids-window* ] with-scope ] with-ui ;

View File

@ -9,16 +9,8 @@ TUPLE: float-array
{ length array-capacity read-only } { length array-capacity read-only }
{ underlying byte-array read-only } ; { underlying byte-array read-only } ;
<PRIVATE
: floats>bytes 8 * ; inline
: float-array@ underlying>> swap >fixnum floats>bytes ; inline
PRIVATE>
: <float-array> ( n -- float-array ) : <float-array> ( n -- float-array )
dup floats>bytes <byte-array> float-array boa ; inline dup "double" <c-array> float-array boa ; inline
M: float-array clone M: float-array clone
[ length>> ] [ underlying>> clone ] bi float-array boa ; [ length>> ] [ underlying>> clone ] bi float-array boa ;
@ -26,13 +18,13 @@ M: float-array clone
M: float-array length length>> ; M: float-array length length>> ;
M: float-array nth-unsafe M: float-array nth-unsafe
float-array@ alien-double ; underlying>> double-nth ;
M: float-array set-nth-unsafe M: float-array set-nth-unsafe
[ >float ] 2dip float-array@ set-alien-double ; [ >float ] 2dip underlying>> set-double-nth ;
: >float-array ( seq -- float-array ) : >float-array ( seq -- float-array )
T{ float-array f 0 B{ } } clone-like ; inline T{ float-array } clone-like ; inline
M: float-array like M: float-array like
drop dup float-array? [ >float-array ] unless ; drop dup float-array? [ >float-array ] unless ;
@ -45,7 +37,7 @@ M: float-array equal?
M: float-array resize M: float-array resize
[ drop ] [ [ drop ] [
[ floats>bytes ] [ underlying>> ] bi* [ "double" heap-size * ] [ underlying>> ] bi*
resize-byte-array resize-byte-array
] 2bi ] 2bi
float-array boa ; float-array boa ;
@ -58,13 +50,13 @@ INSTANCE: float-array sequence
1 <float-array> [ set-first ] keep ; flushable 1 <float-array> [ set-first ] keep ; flushable
: 2float-array ( x y -- array ) : 2float-array ( x y -- array )
T{ float-array f 0 B{ } } 2sequence ; flushable T{ float-array } 2sequence ; flushable
: 3float-array ( x y z -- array ) : 3float-array ( x y z -- array )
T{ float-array f 0 B{ } } 3sequence ; flushable T{ float-array } 3sequence ; flushable
: 4float-array ( w x y z -- array ) : 4float-array ( w x y z -- array )
T{ float-array f 0 B{ } } 4sequence ; flushable T{ float-array } 4sequence ; flushable
: F{ ( parsed -- parsed ) : F{ ( parsed -- parsed )
\ } [ >float-array ] parse-literal ; parsing \ } [ >float-array ] parse-literal ; parsing

View File

@ -1,3 +1 @@
cons collections
lists
sequences

View File

@ -1,10 +1,10 @@
! Copyright (C) 2006, 2008 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: classes inference inference.dataflow io kernel USING: classes io kernel kernel.private math.parser namespaces
kernel.private math.parser namespaces optimizer prettyprint optimizer prettyprint prettyprint.backend sequences words arrays
prettyprint.backend sequences words arrays match macros match macros assocs sequences.private generic combinators
assocs sequences.private optimizer.specializers generic sorting math quotations accessors inference inference.dataflow
combinators sorting math quotations accessors ; optimizer.specializers ;
IN: optimizer.debugger IN: optimizer.debugger
! A simple tool for turning dataflow IR into quotations, for ! A simple tool for turning dataflow IR into quotations, for

View File

@ -28,16 +28,10 @@ VAR: gravity
! node ! node
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! TUPLE: node mass elas pos vel force ;
TUPLE: node < vel mass elas force ; TUPLE: node < vel mass elas force ;
C: <node> node C: <node> node
! : >>pos ( node pos -- node ) over set-node-pos ;
! : >>vel ( node vel -- node ) over set-node-vel ;
: node-vel ( node -- vel ) vel>> ; : node-vel ( node -- vel ) vel>> ;
: set-node-vel ( vel node -- ) swap >>vel drop ; : set-node-vel ( vel node -- ) swap >>vel drop ;
@ -52,9 +46,9 @@ C: <node> node
: >>vel-x ( node x -- node ) over vel>> set-first ; : >>vel-x ( node x -- node ) over vel>> set-first ;
: >>vel-y ( node y -- node ) over vel>> set-second ; : >>vel-y ( node y -- node ) over vel>> set-second ;
: apply-force ( node vec -- ) over node-force v+ swap set-node-force ; : apply-force ( node vec -- ) over force>> v+ >>force drop ;
: reset-force ( node -- ) 0 0 2array swap set-node-force ; : reset-force ( node -- node ) 0 0 2array >>force ;
: node-id ( id -- node ) 1- nodes> nth ; : node-id ( id -- node ) 1- nodes> nth ;
@ -67,12 +61,12 @@ TUPLE: spring rest-length k damp node-a node-b ;
C: <spring> spring C: <spring> spring
: end-points ( spring -- b-pos a-pos ) : end-points ( spring -- b-pos a-pos )
[ spring-node-b pos>> ] [ spring-node-a pos>> ] bi ; [ node-b>> pos>> ] [ node-a>> pos>> ] bi ;
: spring-length ( spring -- length ) end-points v- norm ; : spring-length ( spring -- length ) end-points v- norm ;
: stretch-length ( spring -- length ) : stretch-length ( spring -- length )
[ spring-length ] [ spring-rest-length ] bi - ; [ spring-length ] [ rest-length>> ] bi - ;
: dir ( spring -- vec ) end-points v- normalize ; : dir ( spring -- vec ) end-points v- normalize ;
@ -87,14 +81,14 @@ C: <spring> spring
! !
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: hooke-force-mag ( spring -- mag ) [ spring-k ] [ stretch-length ] bi * ; : hooke-force-mag ( spring -- mag ) [ k>> ] [ stretch-length ] bi * ;
: hooke-force ( spring -- force ) [ dir ] [ hooke-force-mag ] bi v*n ; : hooke-force ( spring -- force ) [ dir ] [ hooke-force-mag ] bi v*n ;
: hooke-forces ( spring -- a b ) hooke-force dup vneg ; : hooke-forces ( spring -- a b ) hooke-force dup vneg ;
: act-on-nodes-hooke ( spring -- ) : act-on-nodes-hooke ( spring -- )
[ spring-node-a ] [ spring-node-b ] [ ] tri hooke-forces swapd [ node-a>> ] [ node-b>> ] [ ] tri hooke-forces swapd
apply-force apply-force
apply-force ; apply-force ;
@ -118,37 +112,37 @@ C: <spring> spring
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: relative-velocity-a ( spring -- vel ) : relative-velocity-a ( spring -- vel )
[ spring-node-a vel>> ] [ spring-node-b vel>> ] bi v- ; [ node-a>> vel>> ] [ node-b>> vel>> ] bi v- ;
: unit-vec-b->a ( spring -- vec ) : unit-vec-b->a ( spring -- vec )
[ spring-node-a pos>> ] [ spring-node-b pos>> ] bi v- ; [ node-a>> pos>> ] [ node-b>> pos>> ] bi v- ;
: relative-velocity-along-spring-a ( spring -- vel ) : relative-velocity-along-spring-a ( spring -- vel )
[ relative-velocity-a ] [ unit-vec-b->a ] bi vector-projection ; [ relative-velocity-a ] [ unit-vec-b->a ] bi vector-projection ;
: damping-force-a ( spring -- vec ) : damping-force-a ( spring -- vec )
[ relative-velocity-along-spring-a ] [ spring-damp ] bi v*n vneg ; [ relative-velocity-along-spring-a ] [ damp>> ] bi v*n vneg ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: relative-velocity-b ( spring -- vel ) : relative-velocity-b ( spring -- vel )
[ spring-node-b vel>> ] [ spring-node-a vel>> ] bi v- ; [ node-b>> vel>> ] [ node-a>> vel>> ] bi v- ;
: unit-vec-a->b ( spring -- vec ) : unit-vec-a->b ( spring -- vec )
[ spring-node-b pos>> ] [ spring-node-a pos>> ] bi v- ; [ node-b>> pos>> ] [ node-a>> pos>> ] bi v- ;
: relative-velocity-along-spring-b ( spring -- vel ) : relative-velocity-along-spring-b ( spring -- vel )
[ relative-velocity-b ] [ unit-vec-a->b ] bi vector-projection ; [ relative-velocity-b ] [ unit-vec-a->b ] bi vector-projection ;
: damping-force-b ( spring -- vec ) : damping-force-b ( spring -- vec )
[ relative-velocity-along-spring-b ] [ spring-damp ] bi v*n vneg ; [ relative-velocity-along-spring-b ] [ damp>> ] bi v*n vneg ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: act-on-nodes-damping ( spring -- ) : act-on-nodes-damping ( spring -- )
dup dup
[ spring-node-a ] [ damping-force-a ] bi apply-force [ node-a>> ] [ damping-force-a ] bi apply-force
[ spring-node-b ] [ damping-force-b ] bi apply-force ; [ node-b>> ] [ damping-force-b ] bi apply-force ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -164,22 +158,22 @@ C: <spring> spring
: bounce-top ( node -- ) : bounce-top ( node -- )
world-height 1- >>pos-y world-height 1- >>pos-y
dup [ vel-y ] [ node-elas ] bi * neg >>vel-y dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
drop ; drop ;
: bounce-bottom ( node -- ) : bounce-bottom ( node -- )
0 >>pos-y 0 >>pos-y
dup [ vel-y ] [ node-elas ] bi * neg >>vel-y dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
drop ; drop ;
: bounce-left ( node -- ) : bounce-left ( node -- )
0 >>pos-x 0 >>pos-x
dup [ vel-x ] [ node-elas ] bi * neg >>vel-x dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
drop ; drop ;
: bounce-right ( node -- ) : bounce-right ( node -- )
world-width 1- >>pos-x world-width 1- >>pos-x
dup [ vel-x ] [ node-elas ] bi * neg >>vel-x dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
drop ; drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -213,7 +207,7 @@ C: <spring> spring
! F = ma ! F = ma
: calc-acceleration ( node -- vec ) [ node-force ] [ node-mass ] bi v/n ; : calc-acceleration ( node -- vec ) [ force>> ] [ mass>> ] bi v/n ;
: new-vel ( node -- vel ) : new-vel ( node -- vel )
[ vel>> ] [ calc-acceleration time-slice> v*n ] bi v+ ; [ vel>> ] [ calc-acceleration time-slice> v*n ] bi v+ ;
@ -223,7 +217,7 @@ C: <spring> spring
: iterate-node ( node -- ) : iterate-node ( node -- )
dup new-pos >>pos dup new-pos >>pos
dup new-vel >>vel dup new-vel >>vel
dup reset-force reset-force
handle-bounce ; handle-bounce ;
: iterate-nodes ( -- ) nodes> [ iterate-node ] each ; : iterate-nodes ( -- ) nodes> [ iterate-node ] each ;

View File

@ -12,10 +12,10 @@ SYMBOL: ui-notify-flag
: notify-ui-thread ( -- ) ui-notify-flag get-global raise-flag ; : notify-ui-thread ( -- ) ui-notify-flag get-global raise-flag ;
TUPLE: gadget < rect TUPLE: gadget < rect
pref-dim parent children orientation focus pref-dim parent children orientation focus
visible? root? clipped? layout-state graft-state graft-node visible? root? clipped? layout-state graft-state graft-node
interior boundary interior boundary
model ; model ;
M: gadget equal? 2drop f ; M: gadget equal? 2drop f ;
@ -23,9 +23,9 @@ M: gadget hashcode* drop gadget hashcode* ;
M: gadget model-changed 2drop ; M: gadget model-changed 2drop ;
: gadget-child ( gadget -- child ) gadget-children first ; : gadget-child ( gadget -- child ) children>> first ;
: nth-gadget ( n gadget -- child ) gadget-children nth ; : nth-gadget ( n gadget -- child ) children>> nth ;
: new-gadget ( class -- gadget ) : new-gadget ( class -- gadget )
new new
@ -37,7 +37,7 @@ M: gadget model-changed 2drop ;
gadget new-gadget ; gadget new-gadget ;
: activate-control ( gadget -- ) : activate-control ( gadget -- )
dup gadget-model dup [ dup model>> dup [
2dup add-connection 2dup add-connection
swap model-changed swap model-changed
] [ ] [
@ -45,20 +45,20 @@ M: gadget model-changed 2drop ;
] if ; ] if ;
: deactivate-control ( gadget -- ) : deactivate-control ( gadget -- )
dup gadget-model dup [ 2dup remove-connection ] when 2drop ; dup model>> dup [ 2dup remove-connection ] when 2drop ;
: control-value ( control -- value ) : control-value ( control -- value )
gadget-model model-value ; model>> model-value ;
: set-control-value ( value control -- ) : set-control-value ( value control -- )
gadget-model set-model ; model>> set-model ;
: relative-loc ( fromgadget togadget -- loc ) : relative-loc ( fromgadget togadget -- loc )
2dup eq? [ 2dup eq? [
2drop { 0 0 } 2drop { 0 0 }
] [ ] [
over rect-loc >r over rect-loc >r
>r gadget-parent r> relative-loc >r parent>> r> relative-loc
r> v+ r> v+
] if ; ] if ;
@ -68,22 +68,18 @@ M: gadget user-input* 2drop t ;
GENERIC: children-on ( rect/point gadget -- seq ) GENERIC: children-on ( rect/point gadget -- seq )
M: gadget children-on nip gadget-children ; M: gadget children-on nip children>> ;
: (fast-children-on) ( dim axis gadgets -- i ) : (fast-children-on) ( dim axis gadgets -- i )
swapd [ rect-loc v- over v. 0 <=> ] binsearch nip ; swapd [ rect-loc v- over v. 0 <=> ] binsearch nip ;
: fast-children-on ( rect axis children -- from to ) : fast-children-on ( rect axis children -- from to )
3dup [ >r >r rect-loc r> r> (fast-children-on) 0 or ]
>r >r dup rect-loc swap rect-dim v+ [ >r >r dup rect-loc swap rect-dim v+ r> r> (fast-children-on) ?1+ ]
r> r> (fast-children-on) ?1+ 3bi ;
>r
>r >r rect-loc
r> r> (fast-children-on) 0 or
r> ;
: inside? ( bounds gadget -- ? ) : inside? ( bounds gadget -- ? )
dup gadget-visible? [ intersects? ] [ 2drop f ] if ; dup visible?>> [ intersects? ] [ 2drop f ] if ;
: (pick-up) ( point gadget -- gadget ) : (pick-up) ( point gadget -- gadget )
dupd children-on [ inside? ] with find-last nip ; dupd children-on [ inside? ] with find-last nip ;
@ -97,10 +93,10 @@ M: gadget children-on nip gadget-children ;
: dim-sum ( seq -- dim ) { 0 0 } [ v+ ] reduce ; : dim-sum ( seq -- dim ) { 0 0 } [ v+ ] reduce ;
: orient ( gadget seq1 seq2 -- seq ) : orient ( gadget seq1 seq2 -- seq )
>r >r gadget-orientation r> r> [ pick set-axis ] 2map nip ; >r >r orientation>> r> r> [ pick set-axis ] 2map nip ;
: each-child ( gadget quot -- ) : each-child ( gadget quot -- )
>r gadget-children r> each ; inline >r children>> r> each ; inline
! Selection protocol ! Selection protocol
GENERIC: gadget-selection? ( gadget -- ? ) GENERIC: gadget-selection? ( gadget -- ? )
@ -117,14 +113,14 @@ GENERIC: gadget-text* ( gadget -- )
GENERIC: gadget-text-separator ( gadget -- str ) GENERIC: gadget-text-separator ( gadget -- str )
M: gadget gadget-text-separator M: gadget gadget-text-separator
gadget-orientation { 0 1 } = "\n" "" ? ; orientation>> { 0 1 } = "\n" "" ? ;
: gadget-seq-text ( seq gadget -- ) : gadget-seq-text ( seq gadget -- )
gadget-text-separator swap gadget-text-separator swap
[ dup % ] [ gadget-text* ] interleave drop ; [ dup % ] [ gadget-text* ] interleave drop ;
M: gadget gadget-text* M: gadget gadget-text*
dup gadget-children swap gadget-seq-text ; dup children>> swap gadget-seq-text ;
M: array gadget-text* M: array gadget-text*
[ gadget-text* ] each ; [ gadget-text* ] each ;
@ -132,9 +128,9 @@ M: array gadget-text*
: gadget-text ( gadget -- string ) [ gadget-text* ] "" make ; : gadget-text ( gadget -- string ) [ gadget-text* ] "" make ;
: invalidate ( gadget -- ) : invalidate ( gadget -- )
\ invalidate swap set-gadget-layout-state ; \ invalidate swap (>>layout-state) ;
: forget-pref-dim ( gadget -- ) f swap set-gadget-pref-dim ; : forget-pref-dim ( gadget -- ) f swap (>>pref-dim) ;
: layout-queue ( -- queue ) \ layout-queue get ; : layout-queue ( -- queue ) \ layout-queue get ;
@ -147,22 +143,22 @@ M: array gadget-text*
DEFER: relayout DEFER: relayout
: invalidate* ( gadget -- ) : invalidate* ( gadget -- )
\ invalidate* over set-gadget-layout-state \ invalidate* over (>>layout-state)
dup forget-pref-dim dup forget-pref-dim
dup gadget-root? dup gadget-root?
[ layout-later ] [ gadget-parent [ relayout ] when* ] if ; [ layout-later ] [ parent>> [ relayout ] when* ] if ;
: relayout ( gadget -- ) : relayout ( gadget -- )
dup gadget-layout-state \ invalidate* eq? dup layout-state>> \ invalidate* eq?
[ drop ] [ invalidate* ] if ; [ drop ] [ invalidate* ] if ;
: relayout-1 ( gadget -- ) : relayout-1 ( gadget -- )
dup gadget-layout-state dup layout-state>>
[ drop ] [ dup invalidate layout-later ] if ; [ drop ] [ dup invalidate layout-later ] if ;
: show-gadget ( gadget -- ) t swap set-gadget-visible? ; : show-gadget ( gadget -- ) t swap (>>visible?) ;
: hide-gadget ( gadget -- ) f swap set-gadget-visible? ; : hide-gadget ( gadget -- ) f swap (>>visible?) ;
: (set-rect-dim) ( dim gadget quot -- ) : (set-rect-dim) ( dim gadget quot -- )
>r 2dup rect-dim = >r 2dup rect-dim =
@ -178,11 +174,11 @@ DEFER: relayout
GENERIC: pref-dim* ( gadget -- dim ) GENERIC: pref-dim* ( gadget -- dim )
: ?set-gadget-pref-dim ( dim gadget -- ) : ?set-gadget-pref-dim ( dim gadget -- )
dup gadget-layout-state dup layout-state>>
[ 2drop ] [ set-gadget-pref-dim ] if ; [ 2drop ] [ (>>pref-dim) ] if ;
: pref-dim ( gadget -- dim ) : pref-dim ( gadget -- dim )
dup gadget-pref-dim [ ] [ dup pref-dim>> [ ] [
[ pref-dim* dup ] keep ?set-gadget-pref-dim [ pref-dim* dup ] keep ?set-gadget-pref-dim
] ?if ; ] ?if ;
@ -196,10 +192,10 @@ M: gadget layout* drop ;
: prefer ( gadget -- ) dup pref-dim swap set-layout-dim ; : prefer ( gadget -- ) dup pref-dim swap set-layout-dim ;
: validate ( gadget -- ) f swap set-gadget-layout-state ; : validate ( gadget -- ) f swap (>>layout-state) ;
: layout ( gadget -- ) : layout ( gadget -- )
dup gadget-layout-state [ dup layout-state>> [
dup validate dup validate
dup layout* dup layout*
dup [ layout ] each-child dup [ layout ] each-child
@ -223,7 +219,7 @@ M: gadget layout* drop ;
{ t f } (queue-graft) ; { t f } (queue-graft) ;
: graft-later ( gadget -- ) : graft-later ( gadget -- )
dup gadget-graft-state { dup graft-state>> {
{ { f t } [ drop ] } { { f t } [ drop ] }
{ { t t } [ drop ] } { { t t } [ drop ] }
{ { t f } [ unqueue-graft ] } { { t f } [ unqueue-graft ] }
@ -231,7 +227,7 @@ M: gadget layout* drop ;
} case ; } case ;
: ungraft-later ( gadget -- ) : ungraft-later ( gadget -- )
dup gadget-graft-state { dup graft-state>> {
{ { f f } [ drop ] } { { f f } [ drop ] }
{ { t f } [ drop ] } { { t f } [ drop ] }
{ { f t } [ unqueue-graft ] } { { f t } [ unqueue-graft ] }
@ -255,11 +251,11 @@ M: gadget ungraft* drop ;
: (unparent) ( gadget -- ) : (unparent) ( gadget -- )
dup ungraft dup ungraft
dup forget-pref-dim dup forget-pref-dim
f swap set-gadget-parent ; f swap (>>parent) ;
: unfocus-gadget ( child gadget -- ) : unfocus-gadget ( child gadget -- )
tuck gadget-focus eq? tuck focus>> eq?
[ f swap set-gadget-focus ] [ drop ] if ; [ f swap (>>focus) ] [ drop ] if ;
SYMBOL: in-layout? SYMBOL: in-layout?
@ -270,10 +266,10 @@ SYMBOL: in-layout?
: unparent ( gadget -- ) : unparent ( gadget -- )
not-in-layout not-in-layout
[ [
dup gadget-parent dup [ dup parent>> dup [
over (unparent) over (unparent)
[ unfocus-gadget ] 2keep [ unfocus-gadget ] 2keep
[ gadget-children delete ] keep [ children>> delete ] keep
relayout relayout
] [ ] [
2drop 2drop
@ -282,21 +278,21 @@ SYMBOL: in-layout?
: (clear-gadget) ( gadget -- ) : (clear-gadget) ( gadget -- )
dup [ (unparent) ] each-child dup [ (unparent) ] each-child
f over set-gadget-focus f over (>>focus)
f swap set-gadget-children ; f swap (>>children) ;
: clear-gadget ( gadget -- ) : clear-gadget ( gadget -- )
not-in-layout not-in-layout
dup (clear-gadget) relayout ; dup (clear-gadget) relayout ;
: ((add-gadget)) ( gadget box -- ) : ((add-gadget)) ( gadget box -- )
[ gadget-children ?push ] keep set-gadget-children ; [ children>> ?push ] keep (>>children) ;
: (add-gadget) ( gadget box -- ) : (add-gadget) ( gadget box -- )
over unparent over unparent
dup pick set-gadget-parent dup pick (>>parent)
[ ((add-gadget)) ] 2keep [ ((add-gadget)) ] 2keep
gadget-graft-state second [ graft ] [ drop ] if ; graft-state>> second [ graft ] [ drop ] if ;
: add-gadget ( gadget parent -- ) : add-gadget ( gadget parent -- )
not-in-layout not-in-layout
@ -307,7 +303,7 @@ SYMBOL: in-layout?
swap [ over (add-gadget) ] each relayout ; swap [ over (add-gadget) ] each relayout ;
: parents ( gadget -- seq ) : parents ( gadget -- seq )
[ gadget-parent ] follow ; [ parent>> ] follow ;
: each-parent ( gadget quot -- ? ) : each-parent ( gadget quot -- ? )
>r parents r> all? ; inline >r parents r> all? ; inline
@ -319,7 +315,7 @@ SYMBOL: in-layout?
parents { 0 0 } [ rect-loc v+ ] reduce ; parents { 0 0 } [ rect-loc v+ ] reduce ;
: (screen-rect) ( gadget -- loc ext ) : (screen-rect) ( gadget -- loc ext )
dup gadget-parent [ dup parent>> [
>r rect-extent r> (screen-rect) >r rect-extent r> (screen-rect)
>r tuck v+ r> vmin >r v+ r> >r tuck v+ r> vmin >r v+ r>
] [ ] [
@ -333,7 +329,7 @@ SYMBOL: in-layout?
{ {
{ [ 2dup eq? ] [ 2drop t ] } { [ 2dup eq? ] [ 2drop t ] }
{ [ dup not ] [ 2drop f ] } { [ dup not ] [ 2drop f ] }
[ gadget-parent child? ] [ parent>> child? ]
} cond ; } cond ;
GENERIC: focusable-child* ( gadget -- child/t ) GENERIC: focusable-child* ( gadget -- child/t )
@ -346,7 +342,7 @@ M: gadget focusable-child* drop t ;
GENERIC: request-focus-on ( child gadget -- ) GENERIC: request-focus-on ( child gadget -- )
M: gadget request-focus-on gadget-parent request-focus-on ; M: gadget request-focus-on parent>> request-focus-on ;
M: f request-focus-on 2drop ; M: f request-focus-on 2drop ;
@ -354,7 +350,7 @@ M: f request-focus-on 2drop ;
[ focusable-child ] keep request-focus-on ; [ focusable-child ] keep request-focus-on ;
: focus-path ( world -- seq ) : focus-path ( world -- seq )
[ gadget-focus ] follow ; [ focus>> ] follow ;
: gadget, ( gadget -- ) gadget get add-gadget ; : gadget, ( gadget -- ) gadget get add-gadget ;
@ -371,7 +367,7 @@ M: f request-focus-on 2drop ;
! Deprecated ! Deprecated
: set-gadget-delegate ( gadget tuple -- ) : set-gadget-delegate ( gadget tuple -- )
over [ over [
dup pick [ set-gadget-parent ] with each-child dup pick [ (>>parent) ] with each-child
] when set-delegate ; ] when set-delegate ;
: construct-gadget ( class -- tuple ) : construct-gadget ( class -- tuple )

View File

@ -63,6 +63,8 @@ INLINE CELL compute_code_rel(F_REL *rel,
return (CELL)get_rel_symbol(rel,literals_start); return (CELL)get_rel_symbol(rel,literals_start);
case RT_LITERAL: case RT_LITERAL:
return CREF(literals_start,REL_ARGUMENT(rel)); return CREF(literals_start,REL_ARGUMENT(rel));
case RT_IMMEDIATE:
return get(CREF(literals_start,REL_ARGUMENT(rel)));
case RT_XT: case RT_XT:
return (CELL)untag_word(get(CREF(literals_start,REL_ARGUMENT(rel))))->xt; return (CELL)untag_word(get(CREF(literals_start,REL_ARGUMENT(rel))))->xt;
case RT_HERE: case RT_HERE:

View File

@ -12,7 +12,9 @@ typedef enum {
/* current offset */ /* current offset */
RT_HERE, RT_HERE,
/* a local label */ /* a local label */
RT_LABEL RT_LABEL,
/* immeditae literal */
RT_IMMEDIATE
} F_RELTYPE; } F_RELTYPE;
typedef enum { typedef enum {

View File

@ -30,9 +30,8 @@ push the array and immediately drop it after.
in the VM. They are open-coded and no subroutine call is generated. This in the VM. They are open-coded and no subroutine call is generated. This
includes stack shufflers, some fixnum arithmetic words, and words such as tag, includes stack shufflers, some fixnum arithmetic words, and words such as tag,
slot and eq?. A primitive call is relatively expensive (two subroutine calls) slot and eq?. A primitive call is relatively expensive (two subroutine calls)
so this results in a big speedup for relatively little effort. so this results in a big speedup for relatively little effort. */
*/
bool jit_primitive_call_p(F_ARRAY *array, CELL i) bool jit_primitive_call_p(F_ARRAY *array, CELL i)
{ {
return (i + 2) == array_capacity(array) return (i + 2) == array_capacity(array)
@ -253,7 +252,7 @@ void jit_compile(CELL quot, bool relocate)
} }
default: default:
GROWABLE_ARRAY_ADD(literals,obj); GROWABLE_ARRAY_ADD(literals,obj);
EMIT(userenv[JIT_PUSH_LITERAL],literals_count - 1); EMIT(userenv[immediate_p(obj) ? JIT_PUSH_IMMEDIATE : JIT_PUSH_LITERAL],literals_count - 1);
break; break;
} }
} }

View File

@ -47,29 +47,9 @@ typedef enum {
JIT_EPILOG, JIT_EPILOG,
JIT_RETURN, JIT_RETURN,
JIT_PROFILING, JIT_PROFILING,
JIT_TAG, JIT_PUSH_IMMEDIATE,
JIT_TAG_WORD,
JIT_EQP, JIT_DECLARE_WORD = 42,
JIT_EQP_WORD,
JIT_SLOT,
JIT_SLOT_WORD,
JIT_DECLARE_WORD,
JIT_DROP,
JIT_DROP_WORD,
JIT_DUP,
JIT_DUP_WORD,
JIT_TO_R,
JIT_TO_R_WORD,
JIT_FROM_R,
JIT_FROM_R_WORD,
JIT_SWAP,
JIT_SWAP_WORD,
JIT_OVER,
JIT_OVER_WORD,
JIT_FIXNUM_MINUS,
JIT_FIXNUM_MINUS_WORD,
JIT_FIXNUM_GE,
JIT_FIXNUM_GE_WORD,
STACK_TRACES_ENV = 59, STACK_TRACES_ENV = 59,