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 ;
: (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 )
>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" } ":"
{ $subsection key? }
{ $subsection at }
{ $subsection value-at }
{ $subsection assoc-empty? }
{ $subsection keys }
{ $subsection values }
{ $subsection assoc-stack }
{ $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"
"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? }
@ -111,6 +117,7 @@ $nl
{ $subsection "assocs-protocol" }
"A large set of utility words work on any object whose class implements the associative mapping protocol."
{ $subsection "assocs-lookup" }
{ $subsection "assocs-values" }
{ $subsection "assocs-mutation" }
{ $subsection "assocs-combinators" }
{ $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 } "." }
{ $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
{ $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 } "." }
{ $notes "This word runs in linear time, proportional to the number of entries in the assoc." } ;
{ $description "Looks up the key associated with a value. No distinction is made between a missing key and a key set to " { $link f } "." } ;
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*
{ $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 )
[ [ 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 )
swap [ = nip ] curry assoc-find 2drop ;
M: assoc value-at* swap [ = nip ] curry assoc-find nip ;
: value-at ( value assoc -- key/f ) value-at* drop ;
: value? ( value assoc -- ? ) value-at* nip ;
: push-at ( value key assoc -- )
[ ?push ] change-at ;

View File

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

View File

@ -51,7 +51,7 @@ must-fail-with
[ error>> unexpected-eof? ]
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? ]
must-fail-with

View File

@ -40,6 +40,12 @@ big-endian off
ds-reg [] arg0 MOV ! store literal on datastack
] 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
arg1 stack-reg MOV ! pass callstack pointer as arg 2

View File

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

View File

@ -2,10 +2,14 @@ USING: help.markup help.syntax sequences strings ;
IN: grouping
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:"
{ $subsection groups }
{ $subsection <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:"
{ $subsection clumps }
{ $subsection <clumps> }

View File

@ -1,9 +1,9 @@
! Copyright (C) 2006, 2008 Slava Pestov.
! 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
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 ;

View File

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

View File

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

View File

@ -2,10 +2,10 @@
! See http://factorcode.org/license.txt for BSD license.
USING: effects alien alien.accessors arrays generic hashtables
kernel assocs math math.libm math.private kernel.private
sequences words parser inference.class inference.dataflow
vectors strings sbufs io namespaces assocs quotations
math.intervals sequences.private combinators splitting layouts
math.parser classes classes.algebra generic.math
sequences words parser vectors strings sbufs io namespaces
assocs quotations math.intervals sequences.private combinators
splitting layouts math.parser classes classes.algebra
generic.math inference.class inference.dataflow
optimizer.pattern-match optimizer.backend optimizer.def-use
optimizer.inlining optimizer.math.partial generic.standard
system accessors ;
@ -444,7 +444,10 @@ most-negative-fixnum most-positive-fixnum [a,b]
{ /f < > <= >= }
[ { 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
{

View File

@ -1,8 +1,9 @@
! Copyright (C) 2007 Slava Pestov.
! 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
USING: kernel sequences inference namespaces generic
combinators classes classes.algebra inference.dataflow ;
! Funny pattern matching
SYMBOL: @

View File

@ -38,6 +38,18 @@ HELP: adjoin
}
{ $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
{ $values { "seq" "a sequence" } { "assoc" "an assoc" } }
{ $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
random math.parser math fry ;
random math.parser math fry ;
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 -- )
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
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: 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 ;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,16 +28,10 @@ VAR: gravity
! node
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! TUPLE: node mass elas pos vel force ;
TUPLE: node < vel mass elas force ;
C: <node> node
! : >>pos ( node pos -- node ) over set-node-pos ;
! : >>vel ( node vel -- node ) over set-node-vel ;
: node-vel ( node -- vel ) vel>> ;
: 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-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 ;
@ -67,12 +61,12 @@ TUPLE: spring rest-length k damp node-a node-b ;
C: <spring> spring
: 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 ;
: stretch-length ( spring -- length )
[ spring-length ] [ spring-rest-length ] bi - ;
[ spring-length ] [ rest-length>> ] bi - ;
: 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-forces ( spring -- a b ) hooke-force dup vneg ;
: 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 ;
@ -118,37 +112,37 @@ C: <spring> spring
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: 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 )
[ 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-a ] [ unit-vec-b->a ] bi vector-projection ;
: 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 )
[ spring-node-b vel>> ] [ spring-node-a vel>> ] bi v- ;
[ node-b>> vel>> ] [ node-a>> vel>> ] bi v- ;
: 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-b ] [ unit-vec-a->b ] bi vector-projection ;
: 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 -- )
dup
[ spring-node-a ] [ damping-force-a ] bi apply-force
[ spring-node-b ] [ damping-force-b ] bi apply-force ;
[ node-a>> ] [ damping-force-a ] bi apply-force
[ node-b>> ] [ damping-force-b ] bi apply-force ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -164,22 +158,22 @@ C: <spring> spring
: bounce-top ( node -- )
world-height 1- >>pos-y
dup [ vel-y ] [ node-elas ] bi * neg >>vel-y
dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
drop ;
: bounce-bottom ( node -- )
0 >>pos-y
dup [ vel-y ] [ node-elas ] bi * neg >>vel-y
dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
drop ;
: bounce-left ( node -- )
0 >>pos-x
dup [ vel-x ] [ node-elas ] bi * neg >>vel-x
dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
drop ;
: bounce-right ( node -- )
world-width 1- >>pos-x
dup [ vel-x ] [ node-elas ] bi * neg >>vel-x
dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -213,7 +207,7 @@ C: <spring> spring
! 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 )
[ vel>> ] [ calc-acceleration time-slice> v*n ] bi v+ ;
@ -223,7 +217,7 @@ C: <spring> spring
: iterate-node ( node -- )
dup new-pos >>pos
dup new-vel >>vel
dup reset-force
reset-force
handle-bounce ;
: 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 ;
TUPLE: gadget < rect
pref-dim parent children orientation focus
visible? root? clipped? layout-state graft-state graft-node
interior boundary
model ;
pref-dim parent children orientation focus
visible? root? clipped? layout-state graft-state graft-node
interior boundary
model ;
M: gadget equal? 2drop f ;
@ -23,9 +23,9 @@ M: gadget hashcode* drop gadget hashcode* ;
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
@ -37,7 +37,7 @@ M: gadget model-changed 2drop ;
gadget new-gadget ;
: activate-control ( gadget -- )
dup gadget-model dup [
dup model>> dup [
2dup add-connection
swap model-changed
] [
@ -45,20 +45,20 @@ M: gadget model-changed 2drop ;
] if ;
: deactivate-control ( gadget -- )
dup gadget-model dup [ 2dup remove-connection ] when 2drop ;
dup model>> dup [ 2dup remove-connection ] when 2drop ;
: control-value ( control -- value )
gadget-model model-value ;
model>> model-value ;
: set-control-value ( value control -- )
gadget-model set-model ;
model>> set-model ;
: relative-loc ( fromgadget togadget -- loc )
2dup eq? [
2drop { 0 0 }
] [
over rect-loc >r
>r gadget-parent r> relative-loc
>r parent>> r> relative-loc
r> v+
] if ;
@ -68,22 +68,18 @@ M: gadget user-input* 2drop t ;
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 )
swapd [ rect-loc v- over v. 0 <=> ] binsearch nip ;
: fast-children-on ( rect axis children -- from to )
3dup
>r >r dup rect-loc swap rect-dim v+
r> r> (fast-children-on) ?1+
>r
>r >r rect-loc
r> r> (fast-children-on) 0 or
r> ;
[ >r >r rect-loc r> r> (fast-children-on) 0 or ]
[ >r >r dup rect-loc swap rect-dim v+ r> r> (fast-children-on) ?1+ ]
3bi ;
: inside? ( bounds gadget -- ? )
dup gadget-visible? [ intersects? ] [ 2drop f ] if ;
dup visible?>> [ intersects? ] [ 2drop f ] if ;
: (pick-up) ( point gadget -- gadget )
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 ;
: 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 -- )
>r gadget-children r> each ; inline
>r children>> r> each ; inline
! Selection protocol
GENERIC: gadget-selection? ( gadget -- ? )
@ -117,14 +113,14 @@ GENERIC: gadget-text* ( gadget -- )
GENERIC: gadget-text-separator ( gadget -- str )
M: gadget gadget-text-separator
gadget-orientation { 0 1 } = "\n" "" ? ;
orientation>> { 0 1 } = "\n" "" ? ;
: gadget-seq-text ( seq gadget -- )
gadget-text-separator swap
[ dup % ] [ gadget-text* ] interleave drop ;
M: gadget gadget-text*
dup gadget-children swap gadget-seq-text ;
dup children>> swap gadget-seq-text ;
M: array gadget-text*
[ gadget-text* ] each ;
@ -132,9 +128,9 @@ M: array gadget-text*
: gadget-text ( gadget -- string ) [ gadget-text* ] "" make ;
: 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 ;
@ -147,22 +143,22 @@ M: array gadget-text*
DEFER: relayout
: invalidate* ( gadget -- )
\ invalidate* over set-gadget-layout-state
\ invalidate* over (>>layout-state)
dup forget-pref-dim
dup gadget-root?
[ layout-later ] [ gadget-parent [ relayout ] when* ] if ;
[ layout-later ] [ parent>> [ relayout ] when* ] if ;
: relayout ( gadget -- )
dup gadget-layout-state \ invalidate* eq?
dup layout-state>> \ invalidate* eq?
[ drop ] [ invalidate* ] if ;
: relayout-1 ( gadget -- )
dup gadget-layout-state
dup layout-state>>
[ 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 -- )
>r 2dup rect-dim =
@ -178,11 +174,11 @@ DEFER: relayout
GENERIC: pref-dim* ( gadget -- dim )
: ?set-gadget-pref-dim ( dim gadget -- )
dup gadget-layout-state
[ 2drop ] [ set-gadget-pref-dim ] if ;
dup layout-state>>
[ 2drop ] [ (>>pref-dim) ] if ;
: pref-dim ( gadget -- dim )
dup gadget-pref-dim [ ] [
dup pref-dim>> [ ] [
[ pref-dim* dup ] keep ?set-gadget-pref-dim
] ?if ;
@ -196,10 +192,10 @@ M: gadget layout* drop ;
: 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 -- )
dup gadget-layout-state [
dup layout-state>> [
dup validate
dup layout*
dup [ layout ] each-child
@ -223,7 +219,7 @@ M: gadget layout* drop ;
{ t f } (queue-graft) ;
: graft-later ( gadget -- )
dup gadget-graft-state {
dup graft-state>> {
{ { f t } [ drop ] }
{ { t t } [ drop ] }
{ { t f } [ unqueue-graft ] }
@ -231,7 +227,7 @@ M: gadget layout* drop ;
} case ;
: ungraft-later ( gadget -- )
dup gadget-graft-state {
dup graft-state>> {
{ { f f } [ drop ] }
{ { t f } [ drop ] }
{ { f t } [ unqueue-graft ] }
@ -255,11 +251,11 @@ M: gadget ungraft* drop ;
: (unparent) ( gadget -- )
dup ungraft
dup forget-pref-dim
f swap set-gadget-parent ;
f swap (>>parent) ;
: unfocus-gadget ( child gadget -- )
tuck gadget-focus eq?
[ f swap set-gadget-focus ] [ drop ] if ;
tuck focus>> eq?
[ f swap (>>focus) ] [ drop ] if ;
SYMBOL: in-layout?
@ -270,10 +266,10 @@ SYMBOL: in-layout?
: unparent ( gadget -- )
not-in-layout
[
dup gadget-parent dup [
dup parent>> dup [
over (unparent)
[ unfocus-gadget ] 2keep
[ gadget-children delete ] keep
[ children>> delete ] keep
relayout
] [
2drop
@ -282,21 +278,21 @@ SYMBOL: in-layout?
: (clear-gadget) ( gadget -- )
dup [ (unparent) ] each-child
f over set-gadget-focus
f swap set-gadget-children ;
f over (>>focus)
f swap (>>children) ;
: clear-gadget ( gadget -- )
not-in-layout
dup (clear-gadget) relayout ;
: ((add-gadget)) ( gadget box -- )
[ gadget-children ?push ] keep set-gadget-children ;
[ children>> ?push ] keep (>>children) ;
: (add-gadget) ( gadget box -- )
over unparent
dup pick set-gadget-parent
dup pick (>>parent)
[ ((add-gadget)) ] 2keep
gadget-graft-state second [ graft ] [ drop ] if ;
graft-state>> second [ graft ] [ drop ] if ;
: add-gadget ( gadget parent -- )
not-in-layout
@ -307,7 +303,7 @@ SYMBOL: in-layout?
swap [ over (add-gadget) ] each relayout ;
: parents ( gadget -- seq )
[ gadget-parent ] follow ;
[ parent>> ] follow ;
: each-parent ( gadget quot -- ? )
>r parents r> all? ; inline
@ -319,7 +315,7 @@ SYMBOL: in-layout?
parents { 0 0 } [ rect-loc v+ ] reduce ;
: (screen-rect) ( gadget -- loc ext )
dup gadget-parent [
dup parent>> [
>r rect-extent r> (screen-rect)
>r tuck v+ r> vmin >r v+ r>
] [
@ -333,7 +329,7 @@ SYMBOL: in-layout?
{
{ [ 2dup eq? ] [ 2drop t ] }
{ [ dup not ] [ 2drop f ] }
[ gadget-parent child? ]
[ parent>> child? ]
} cond ;
GENERIC: focusable-child* ( gadget -- child/t )
@ -346,7 +342,7 @@ M: gadget focusable-child* drop t ;
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 ;
@ -354,7 +350,7 @@ M: f request-focus-on 2drop ;
[ focusable-child ] keep request-focus-on ;
: focus-path ( world -- seq )
[ gadget-focus ] follow ;
[ focus>> ] follow ;
: gadget, ( gadget -- ) gadget get add-gadget ;
@ -371,7 +367,7 @@ M: f request-focus-on 2drop ;
! Deprecated
: set-gadget-delegate ( gadget tuple -- )
over [
dup pick [ set-gadget-parent ] with each-child
dup pick [ (>>parent) ] with each-child
] when set-delegate ;
: 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);
case RT_LITERAL:
return CREF(literals_start,REL_ARGUMENT(rel));
case RT_IMMEDIATE:
return get(CREF(literals_start,REL_ARGUMENT(rel)));
case RT_XT:
return (CELL)untag_word(get(CREF(literals_start,REL_ARGUMENT(rel))))->xt;
case RT_HERE:

View File

@ -12,7 +12,9 @@ typedef enum {
/* current offset */
RT_HERE,
/* a local label */
RT_LABEL
RT_LABEL,
/* immeditae literal */
RT_IMMEDIATE
} F_RELTYPE;
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
includes stack shufflers, some fixnum arithmetic words, and words such as tag,
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)
{
return (i + 2) == array_capacity(array)
@ -253,7 +252,7 @@ void jit_compile(CELL quot, bool relocate)
}
default:
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;
}
}

View File

@ -47,29 +47,9 @@ typedef enum {
JIT_EPILOG,
JIT_RETURN,
JIT_PROFILING,
JIT_TAG,
JIT_TAG_WORD,
JIT_EQP,
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,
JIT_PUSH_IMMEDIATE,
JIT_DECLARE_WORD = 42,
STACK_TRACES_ENV = 59,