stepping over a word
parent
a2717958f0
commit
9c0d7f23d2
|
@ -14,7 +14,6 @@
|
||||||
+ linearizer/generator:
|
+ linearizer/generator:
|
||||||
|
|
||||||
- peephole optimizer
|
- peephole optimizer
|
||||||
- tail call optimization
|
|
||||||
- getenv/setenv: if literal arg, compile as a load/store
|
- getenv/setenv: if literal arg, compile as a load/store
|
||||||
- compiler: drop literal peephole optimization
|
- compiler: drop literal peephole optimization
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@
|
||||||
|
|
||||||
+ ffi:
|
+ ffi:
|
||||||
|
|
||||||
- port ffi to new compiler
|
|
||||||
- is signed -vs- unsigned pointers an issue?
|
- is signed -vs- unsigned pointers an issue?
|
||||||
- bitfields in C structs
|
- bitfields in C structs
|
||||||
- SDL_Rect** type
|
- SDL_Rect** type
|
||||||
|
@ -68,7 +66,6 @@
|
||||||
|
|
||||||
+ misc:
|
+ misc:
|
||||||
|
|
||||||
- some way to step over a word in the stepper
|
|
||||||
- step: print NEXT word to execute, not word that JUST executed
|
- step: print NEXT word to execute, not word that JUST executed
|
||||||
- perhaps /i should work with all numbers
|
- perhaps /i should work with all numbers
|
||||||
- unit test weirdness: 2 lines appears at end
|
- unit test weirdness: 2 lines appears at end
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
!
|
!
|
||||||
! ./f factor.image -libraries:sdl=libSDL.so -libraries:sdl-gfx=libSDL_gfx.so
|
! ./f factor.image -libraries:sdl=libSDL.so -libraries:sdl-gfx=libSDL_gfx.so
|
||||||
!
|
!
|
||||||
! "examples/oop.factor" run-file
|
|
||||||
! "examples/factoroids.factor" run-file
|
! "examples/factoroids.factor" run-file
|
||||||
|
|
||||||
IN: factoroids
|
IN: factoroids
|
||||||
|
@ -16,7 +15,7 @@ USE: lists
|
||||||
USE: logic
|
USE: logic
|
||||||
USE: math
|
USE: math
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: oop
|
USE: generic
|
||||||
USE: random
|
USE: random
|
||||||
USE: sdl
|
USE: sdl
|
||||||
USE: sdl-event
|
USE: sdl-event
|
||||||
|
@ -116,18 +115,18 @@ M: ship draw ( actor -- )
|
||||||
[
|
[
|
||||||
surface get screen-xy radius get color get
|
surface get screen-xy radius get color get
|
||||||
filledCircleColor
|
filledCircleColor
|
||||||
] bind ;M
|
] bind ;
|
||||||
|
|
||||||
M: ship tick ( actor -- ? ) dup [ move ] bind active? ;M
|
M: ship tick ( actor -- ? ) dup [ move ] bind active? ;
|
||||||
|
|
||||||
: make-ship ( -- ship )
|
C: ship ( -- ship )
|
||||||
<ship> [
|
[
|
||||||
width get 2 /i height get 50 - rect> position set
|
width get 2 /i height get 50 - rect> position set
|
||||||
white color set
|
white color set
|
||||||
10 radius set
|
10 radius set
|
||||||
0 velocity set
|
0 velocity set
|
||||||
active on
|
active on
|
||||||
] extend unit ;
|
] extend ;
|
||||||
|
|
||||||
! Projectiles
|
! Projectiles
|
||||||
TRAITS: plasma
|
TRAITS: plasma
|
||||||
|
@ -135,17 +134,17 @@ M: plasma draw ( actor -- )
|
||||||
[
|
[
|
||||||
surface get screen-xy dup len get + color get
|
surface get screen-xy dup len get + color get
|
||||||
vlineColor
|
vlineColor
|
||||||
] bind ;M
|
] bind ;
|
||||||
|
|
||||||
M: plasma tick ( actor -- ? )
|
M: plasma tick ( actor -- ? )
|
||||||
dup [ move ] bind dup in-screen? swap active? and ;M
|
dup [ move ] bind dup in-screen? swap active? and ;
|
||||||
|
|
||||||
M: plasma collide ( actor1 actor2 -- )
|
M: plasma collide ( actor1 actor2 -- )
|
||||||
#! Remove the other actor.
|
#! Remove the other actor.
|
||||||
deactivate deactivate ;M
|
deactivate deactivate ;
|
||||||
|
|
||||||
: make-plasma ( actor dy -- plasma )
|
C: plasma ( actor dy -- plasma )
|
||||||
<plasma> [
|
[
|
||||||
velocity set
|
velocity set
|
||||||
actor-xy
|
actor-xy
|
||||||
blue color set
|
blue color set
|
||||||
|
@ -157,17 +156,17 @@ M: plasma collide ( actor1 actor2 -- )
|
||||||
: player-fire ( -- )
|
: player-fire ( -- )
|
||||||
#! Do nothing if player is dead.
|
#! Do nothing if player is dead.
|
||||||
player-actor [
|
player-actor [
|
||||||
#{ 0 -6 } make-plasma player-shots cons@
|
#{ 0 -6 } <plasma> player-shots cons@
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
: enemy-fire ( actor -- )
|
: enemy-fire ( actor -- )
|
||||||
#{ 0 5 } make-plasma enemy-shots cons@ ;
|
#{ 0 5 } <plasma> enemy-shots cons@ ;
|
||||||
|
|
||||||
! Background of stars
|
! Background of stars
|
||||||
TRAITS: particle
|
TRAITS: particle
|
||||||
|
|
||||||
M: particle draw ( actor -- )
|
M: particle draw ( actor -- )
|
||||||
[ surface get screen-xy color get pixelColor ] bind ;M
|
[ surface get screen-xy color get pixelColor ] bind ;
|
||||||
|
|
||||||
: wrap ( -- )
|
: wrap ( -- )
|
||||||
#! If current actor has gone beyond screen bounds, move it
|
#! If current actor has gone beyond screen bounds, move it
|
||||||
|
@ -178,7 +177,9 @@ M: particle draw ( actor -- )
|
||||||
rect> position set ;
|
rect> position set ;
|
||||||
|
|
||||||
M: particle tick ( actor -- )
|
M: particle tick ( actor -- )
|
||||||
[ move wrap t ] bind ;M
|
[ move wrap t ] bind ;
|
||||||
|
|
||||||
|
C: particle ;
|
||||||
|
|
||||||
SYMBOL: stars
|
SYMBOL: stars
|
||||||
: star-count 100 ;
|
: star-count 100 ;
|
||||||
|
@ -216,7 +217,7 @@ M: enemy draw ( actor -- )
|
||||||
[
|
[
|
||||||
surface get screen-xy radius get color get
|
surface get screen-xy radius get color get
|
||||||
filledCircleColor
|
filledCircleColor
|
||||||
] bind ;M
|
] bind ;
|
||||||
|
|
||||||
: attack-chance 30 ;
|
: attack-chance 30 ;
|
||||||
|
|
||||||
|
@ -239,7 +240,9 @@ SYMBOL: wiggle-x
|
||||||
M: enemy tick ( actor -- )
|
M: enemy tick ( actor -- )
|
||||||
dup attack
|
dup attack
|
||||||
dup [ wiggle move position get imaginary ] bind
|
dup [ wiggle move position get imaginary ] bind
|
||||||
y-in-screen? swap active? and ;M
|
y-in-screen? swap active? and ;
|
||||||
|
|
||||||
|
C: enemy ;
|
||||||
|
|
||||||
: spawn-enemy ( -- )
|
: spawn-enemy ( -- )
|
||||||
<enemy> [
|
<enemy> [
|
||||||
|
@ -289,7 +292,7 @@ SYMBOL: event
|
||||||
: init-game ( -- )
|
: init-game ( -- )
|
||||||
#! Init game objects.
|
#! Init game objects.
|
||||||
init-stars
|
init-stars
|
||||||
make-ship player set
|
<ship> unit player set
|
||||||
<event> event set ;
|
<event> event set ;
|
||||||
|
|
||||||
: each-layer ( quot -- )
|
: each-layer ( quot -- )
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
! "examples/mandel.factor" run-file
|
! "examples/mandel.factor" run-file
|
||||||
|
|
||||||
IN: mandel
|
IN: mandel
|
||||||
|
USE: compiler
|
||||||
USE: alien
|
USE: alien
|
||||||
USE: errors
|
USE: errors
|
||||||
USE: kernel
|
USE: kernel
|
||||||
|
@ -43,14 +43,14 @@ USE: test
|
||||||
] times*
|
] times*
|
||||||
] make-list list>vector nip ;
|
] make-list list>vector nip ;
|
||||||
|
|
||||||
: absq >rect swap sq swap sq + ;
|
: absq >rect swap sq swap sq + ; inline
|
||||||
|
|
||||||
: iter ( c z nb-iter -- x )
|
: iter ( c z nb-iter -- x )
|
||||||
over absq 4 >= over 0 = or [
|
over absq 4 >= over 0 = or [
|
||||||
nip nip
|
nip nip
|
||||||
] [
|
] [
|
||||||
pred >r sq dupd + r> iter
|
pred >r sq dupd + r> iter
|
||||||
] ifte ;
|
] ifte ; compiled
|
||||||
|
|
||||||
: max-color 360 ;
|
: max-color 360 ;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ SYMBOL: center
|
||||||
x-inc get * center get real x-inc get width get 2 / * - + >float
|
x-inc get * center get real x-inc get width get 2 / * - + >float
|
||||||
r>
|
r>
|
||||||
y-inc get * center get imaginary y-inc get height get 2 / * - + >float
|
y-inc get * center get imaginary y-inc get height get 2 / * - + >float
|
||||||
rect> ;
|
rect> ; compiled
|
||||||
|
|
||||||
: render ( -- )
|
: render ( -- )
|
||||||
init-mandel
|
init-mandel
|
||||||
|
|
|
@ -34,7 +34,12 @@ USE: stdio
|
||||||
"Cold boot in progress..." print
|
"Cold boot in progress..." print
|
||||||
|
|
||||||
[
|
[
|
||||||
"/version.factor"
|
"/library/generic/generic.factor"
|
||||||
|
"/library/generic/object.factor"
|
||||||
|
"/library/generic/builtin.factor"
|
||||||
|
"/library/generic/predicate.factor"
|
||||||
|
"/library/generic/traits.factor"
|
||||||
|
|
||||||
"/version.factor"
|
"/version.factor"
|
||||||
"/library/stack.factor"
|
"/library/stack.factor"
|
||||||
"/library/combinators.factor"
|
"/library/combinators.factor"
|
||||||
|
@ -57,11 +62,6 @@ USE: stdio
|
||||||
"/library/errors.factor"
|
"/library/errors.factor"
|
||||||
"/library/continuations.factor"
|
"/library/continuations.factor"
|
||||||
"/library/threads.factor"
|
"/library/threads.factor"
|
||||||
"/library/generic/generic.factor"
|
|
||||||
"/library/generic/object.factor"
|
|
||||||
"/library/generic/builtin.factor"
|
|
||||||
"/library/generic/predicate.factor"
|
|
||||||
"/library/generic/traits.factor"
|
|
||||||
"/library/io/stream.factor"
|
"/library/io/stream.factor"
|
||||||
"/library/io/stdio.factor"
|
"/library/io/stdio.factor"
|
||||||
"/library/io/io-internals.factor"
|
"/library/io/io-internals.factor"
|
||||||
|
@ -71,7 +71,7 @@ USE: stdio
|
||||||
"/library/syntax/parser.factor"
|
"/library/syntax/parser.factor"
|
||||||
"/library/syntax/parse-stream.factor"
|
"/library/syntax/parse-stream.factor"
|
||||||
"/library/bootstrap/init.factor"
|
"/library/bootstrap/init.factor"
|
||||||
"/library/syntax/parse-syntax.factor"
|
! "/library/syntax/parse-syntax.factor"
|
||||||
|
|
||||||
"/library/format.factor"
|
"/library/format.factor"
|
||||||
"/library/syntax/unparser.factor"
|
"/library/syntax/unparser.factor"
|
||||||
|
|
|
@ -25,12 +25,12 @@
|
||||||
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
IN: init
|
IN: kernel
|
||||||
USE: ansi
|
USE: ansi
|
||||||
USE: compiler
|
USE: compiler
|
||||||
USE: errors
|
USE: errors
|
||||||
USE: inference
|
USE: inference
|
||||||
USE: kernel
|
USE: command-line
|
||||||
USE: listener
|
USE: listener
|
||||||
USE: lists
|
USE: lists
|
||||||
USE: math
|
USE: math
|
||||||
|
@ -75,7 +75,7 @@ USE: unparser
|
||||||
warm-boot
|
warm-boot
|
||||||
garbage-collection
|
garbage-collection
|
||||||
"interactive" get [ print-banner listener ] when
|
"interactive" get [ print-banner listener ] when
|
||||||
0 exit*
|
0 exit*
|
||||||
] set-boot
|
] set-boot
|
||||||
|
|
||||||
init-error-handler
|
init-error-handler
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
IN: init
|
IN: kernel
|
||||||
USE: kernel
|
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: parser
|
USE: parser
|
||||||
USE: stdio
|
USE: stdio
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
IN: init
|
IN: command-line
|
||||||
USE: compiler
|
USE: compiler
|
||||||
USE: errors
|
USE: errors
|
||||||
USE: files
|
USE: files
|
||||||
|
|
|
@ -41,7 +41,16 @@ USE: unparser
|
||||||
USE: vectors
|
USE: vectors
|
||||||
USE: words
|
USE: words
|
||||||
|
|
||||||
|
: supported-cpu? ( -- ? )
|
||||||
|
cpu "unknown" = not ;
|
||||||
|
|
||||||
|
: check-architecture ( -- )
|
||||||
|
supported-cpu? [
|
||||||
|
"Unsupported CPU; compiler disabled" throw
|
||||||
|
] unless ;
|
||||||
|
|
||||||
: compiling ( word -- definition )
|
: compiling ( word -- definition )
|
||||||
|
check-architecture
|
||||||
"verbose-compile" get [
|
"verbose-compile" get [
|
||||||
"Compiling " write dup . flush
|
"Compiling " write dup . flush
|
||||||
] when
|
] when
|
||||||
|
@ -67,7 +76,7 @@ USE: words
|
||||||
|
|
||||||
: compiled ( -- )
|
: compiled ( -- )
|
||||||
#! Compile the most recently defined word.
|
#! Compile the most recently defined word.
|
||||||
word compile ; parsing
|
"compile" get [ word compile ] when ; parsing
|
||||||
|
|
||||||
: cannot-compile ( word -- )
|
: cannot-compile ( word -- )
|
||||||
"verbose-compile" get [
|
"verbose-compile" get [
|
||||||
|
@ -81,10 +90,4 @@ USE: words
|
||||||
|
|
||||||
: compile-all ( -- )
|
: compile-all ( -- )
|
||||||
#! Compile all words.
|
#! Compile all words.
|
||||||
[
|
[ try-compile ] each-word ;
|
||||||
! dup "infer-effect" word-property [
|
|
||||||
try-compile
|
|
||||||
! ] [
|
|
||||||
! drop
|
|
||||||
! ] ifte
|
|
||||||
] each-word ;
|
|
||||||
|
|
|
@ -61,13 +61,20 @@ PREDICATE: vector hashtable ( obj -- ? )
|
||||||
#! undefined value, or a value set to f.
|
#! undefined value, or a value set to f.
|
||||||
hash* dup [ cdr ] when ;
|
hash* dup [ cdr ] when ;
|
||||||
|
|
||||||
: set-hash ( value key table -- )
|
: set-hash* ( key table quot -- )
|
||||||
|
#! Apply the quotation to yield a new association list.
|
||||||
|
over >r -rot dupd (hashcode) r> vector-nth swap call ;
|
||||||
|
inline
|
||||||
|
|
||||||
|
! : set-hash ( value key table -- )
|
||||||
#! Store the value in the hashtable. Either replaces an
|
#! Store the value in the hashtable. Either replaces an
|
||||||
#! existing value in the appropriate bucket, or adds a new
|
#! existing value in the appropriate bucket, or adds a new
|
||||||
#! key/value pair,
|
#! key/value pair.
|
||||||
dup >r 2dup (hashcode) dup >r swap
|
! [ set-assoc ] set-hash* ;
|
||||||
vector-nth set-assoc
|
|
||||||
r> r> set-vector-nth ;
|
: remove-hash ( key table -- )
|
||||||
|
#! Remove a value from a hashtable.
|
||||||
|
[ remove-assoc ] set-hash* ;
|
||||||
|
|
||||||
: hash-each ( hash code -- )
|
: hash-each ( hash code -- )
|
||||||
#! Apply the code to each key/value pair of the hashtable.
|
#! Apply the code to each key/value pair of the hashtable.
|
||||||
|
|
|
@ -4,5 +4,9 @@ USE: kernel
|
||||||
USE: math
|
USE: math
|
||||||
USE: random
|
USE: random
|
||||||
USE: test
|
USE: test
|
||||||
|
USE: compiler
|
||||||
|
|
||||||
[ ] [ [ 100000 [ 0 10000 random-int , ] times ] make-list [ > ] sort drop ] unit-test
|
: sort-benchmark
|
||||||
|
[ 100000 [ 0 10000 random-int , ] times ] make-list [ > ] sort drop ; compiled
|
||||||
|
|
||||||
|
[ ] [ sort-benchmark ] unit-test
|
||||||
|
|
|
@ -46,3 +46,15 @@ f 100 fac "testhash" get set-hash
|
||||||
[ t ] [ #{ 2 3 } "testhash" get hash ] unit-test
|
[ t ] [ #{ 2 3 } "testhash" get hash ] unit-test
|
||||||
[ f ] [ 100 fac "testhash" get hash* cdr ] unit-test
|
[ f ] [ 100 fac "testhash" get hash* cdr ] unit-test
|
||||||
[ { } ] [ { [ { } ] } vector-clone "testhash" get hash* cdr ] unit-test
|
[ { } ] [ { [ { } ] } vector-clone "testhash" get hash* cdr ] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
[ "salmon" | "fish" ]
|
||||||
|
[ "crocodile" | "reptile" ]
|
||||||
|
[ "cow" | "mammal" ]
|
||||||
|
[ "visual basic" | "language" ]
|
||||||
|
] alist>hash "testhash" set
|
||||||
|
|
||||||
|
[ f ] [
|
||||||
|
"visual basic" "testhash" get remove-hash
|
||||||
|
"visual basic" "testhash" get hash*
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
IN: scratchpad
|
IN: scratchpad
|
||||||
USE: init
|
USE: command-line
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: test
|
USE: test
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,16 @@ SYMBOL: meta-cf
|
||||||
: do ( obj -- )
|
: do ( obj -- )
|
||||||
dup word? [ meta-word ] [ push-d ] ifte ;
|
dup word? [ meta-word ] [ push-d ] ifte ;
|
||||||
|
|
||||||
|
: meta-word-1 ( word -- )
|
||||||
|
dup "meta-word" word-property dup [
|
||||||
|
nip call
|
||||||
|
] [
|
||||||
|
drop host-word
|
||||||
|
] ifte ;
|
||||||
|
|
||||||
|
: do-1 ( obj -- )
|
||||||
|
dup word? [ meta-word-1 ] [ push-d ] ifte ;
|
||||||
|
|
||||||
: (interpret) ( quot -- )
|
: (interpret) ( quot -- )
|
||||||
#! The quotation is called with each word as its executed.
|
#! The quotation is called with each word as its executed.
|
||||||
done? [ drop ] [ [ next swap call ] keep (interpret) ] ifte ;
|
done? [ drop ] [ [ next swap call ] keep (interpret) ] ifte ;
|
||||||
|
@ -182,6 +192,10 @@ SYMBOL: meta-cf
|
||||||
done? [ "Stepper is done." print drop ] [ call ] ifte ;
|
done? [ "Stepper is done." print drop ] [ call ] ifte ;
|
||||||
|
|
||||||
: step
|
: step
|
||||||
|
#! Step into current word.
|
||||||
|
[ next dup report do-1 ] not-done ;
|
||||||
|
|
||||||
|
: into
|
||||||
#! Step into current word.
|
#! Step into current word.
|
||||||
[ next dup report do ] not-done ;
|
[ next dup report do ] not-done ;
|
||||||
|
|
||||||
|
@ -191,7 +205,8 @@ SYMBOL: meta-cf
|
||||||
"show stepper stacks." print
|
"show stepper stacks." print
|
||||||
\ &get prettyprint-1
|
\ &get prettyprint-1
|
||||||
" ( var -- value ) inspects the stepper namestack." print
|
" ( var -- value ) inspects the stepper namestack." print
|
||||||
\ step prettyprint-1 " -- single step" print
|
\ step prettyprint-1 " -- single step over" print
|
||||||
|
\ into prettyprint-1 " -- single step into" print
|
||||||
\ (trace) prettyprint-1 " -- trace until end" print
|
\ (trace) prettyprint-1 " -- trace until end" print
|
||||||
\ (run) prettyprint-1 " -- run until end" print
|
\ (run) prettyprint-1 " -- run until end" print
|
||||||
\ exit prettyprint-1 " -- exit single-stepper" print ;
|
\ exit prettyprint-1 " -- exit single-stepper" print ;
|
||||||
|
|
Loading…
Reference in New Issue