]> gitweb.factorcode.org Git - factor.git/commitdiff
stepping over a word
authorSlava Pestov <slava@factorcode.org>
Sat, 18 Dec 2004 02:46:19 +0000 (02:46 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 18 Dec 2004 02:46:19 +0000 (02:46 +0000)
13 files changed:
TODO.FACTOR.txt
examples/factoroids.factor
examples/mandel.factor
library/bootstrap/boot-stage2.factor
library/bootstrap/init-stage2.factor
library/bootstrap/init.factor
library/cli.factor
library/compiler/compiler.factor
library/hashtables.factor
library/test/benchmark/sort.factor
library/test/hashtables.factor
library/test/init.factor
library/tools/interpreter.factor

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