]> gitweb.factorcode.org Git - factor.git/commitdiff
use stdcall abi by default on windows, word usage counter
authorSlava Pestov <slava@factorcode.org>
Sat, 18 Dec 2004 04:02:19 +0000 (04:02 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 18 Dec 2004 04:02:19 +0000 (04:02 +0000)
13 files changed:
TODO.FACTOR.txt
examples/oop-test.factor [deleted file]
examples/oop.factor [deleted file]
library/bootstrap/boot.factor
library/bootstrap/init-stage2.factor
library/compiler/alien.factor
library/hashtables.factor
library/sdl/sdl-event.factor
library/sdl/sdl-gfx.factor
library/sdl/sdl-video.factor
library/sdl/sdl.factor
library/tools/word-tools.factor
library/vocabularies.factor

index 9b67f83ce7fe1b89a14383e6f2cb2af23519c918..405b674f307bacad3f84fb35e3e952a0afc2d896 100644 (file)
@@ -42,6 +42,7 @@
 \r
 + listener/plugin:\r
 \r
+- word added >1 \r
 - sidekick: still parsing too much\r
 - errors don't always disappear\r
 - console: wrong history\r
diff --git a/examples/oop-test.factor b/examples/oop-test.factor
deleted file mode 100644 (file)
index 70f62e7..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-IN: scratchpad
-USE: hashtables
-USE: namespaces
-USE: oop
-USE: stack
-USE: test
-
-TRAITS: test-traits
-
-[ t ] [ <test-traits> test-traits? ] unit-test
-[ f ] [ "hello" test-traits? ] unit-test
-[ f ] [ <namespace> test-traits? ] unit-test
-
-GENERIC: foo
-
-M: test-traits foo drop 12 ;M
-
-TRAITS: another-test
-
-M: another-test foo drop 13 ;M
-
-[ 12 ] [ <test-traits> foo ] unit-test
-[ 13 ] [ <another-test> foo ] unit-test
-
-TRAITS: quux
-
-M: quux foo "foo" swap hash ;M
-
-[
-    "Hi"
-] [
-    <quux> [
-        "Hi" "foo" set
-    ] extend foo
-] unit-test
diff --git a/examples/oop.factor b/examples/oop.factor
deleted file mode 100644 (file)
index e5200bb..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-! :sidekick.parser=none:
-IN: oop
-
-USE: combinators
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: stack
-USE: strings
-USE: words
-
-SYMBOL: traits
-
-: traits-map ( type -- hash )
-    #! The method map word property maps selector words to
-    #! definitions.
-    "traits-map" word-property ;
-
-: object-map ( obj -- hash )
-    dup hashtable? [ traits swap hash ] [ drop f ] ifte ;
-
-: init-traits-map ( word -- )
-    <namespace> "traits-map" set-word-property ;
-
-: no-method
-    "No applicable method." throw ;
-
-: method ( traits selector -- quot )
-    #! Execute the method with the traits object on the stack.
-    over object-map hash* [ cdr ] [ [ no-method ] ] ifte* ;
-
-: constructor-word ( word -- word )
-    word-name "<" swap ">" cat3 "in" get create ;
-
-: define-constructor ( word -- )
-    #! <foo> where foo is a traits type creates a new instance
-    #! of foo.
-    [ constructor-word [ <namespace> ] ] keep
-    traits-map [ traits pick set-hash ] cons append
-    define-compound ;
-
-: predicate-word ( word -- word )
-    word-name "?" cat2 "in" get create ;
-
-: define-predicate ( word -- )
-    #! foo? where foo is a traits type tests if the top of stack
-    #! is of this type.
-    dup predicate-word swap
-    [ object-map ] swap traits-map [ eq? ] cons append
-    define-compound ;
-
-: TRAITS:
-    #! TRAITS: foo creates a new traits type. Instances can be
-    #! created with <foo>, and tested with foo?.
-    CREATE
-    dup define-symbol
-    dup init-traits-map
-    dup define-constructor
-    define-predicate ; parsing
-
-: GENERIC:
-    #! GENERIC: bar creates a generic word bar that calls the
-    #! bar method on the traits object, with the traits object
-    #! on the stack.
-    CREATE
-    dup unit [ car method call ] cons
-    define-compound ; parsing
-
-: M: ( -- type generic [ ] )
-    #! M: foo bar begins a definition of the bar generic word
-    #! specialized to the foo type.
-    scan-word scan-word f ; parsing
-
-: ;M ( type generic def -- )
-    #! ;M ends a method definition.
-    rot traits-map [ reverse put ] bind ; parsing
index 5bc37dfbc7648f3ac9199a992a90a3ea9d1b71c8..ab98dcd980cac3aa3409d8f380a35044927613b8 100644 (file)
@@ -86,7 +86,6 @@ vocabularies get [
 
 vocabularies get [
     "!syntax" get "syntax" set
-    "!syntax" off
 
     "syntax" get [
         cdr dup word? [
@@ -96,3 +95,5 @@ vocabularies get [
         ] ifte
     ] hash-each
 ] bind
+
+"!syntax" vocabularies get remove-hash
index 1356dd0487f5a8d313d414774b09fbb51c876d6d..dc89ac815b8e77a5f3c956d63e33cf72d5e8af70 100644 (file)
@@ -71,6 +71,7 @@ USE: unparser
 
     run-user-init ;
 
+: auto-inline-count 5 ;
 [
     warm-boot
     garbage-collection
@@ -82,6 +83,14 @@ init-error-handler
 
 0 [ drop succ ] each-word unparse write " words" print 
 
+! "Counting word usages..." print
+! tally-usages
+! 
+! "Automatically inlining words called " write
+! auto-inline-count unparse write
+! " or less times..." print
+! auto-inline-count auto-inline
+
 "Inferring stack effects..." print
 0 [ unit try-infer [ succ ] when ] each-word
 unparse write " words have a stack effect" print
index 45b5e73bbeda93be3ea781e1fcfcfc7957556550..6e3eb5b3f63273888e048c754e1783b3df12885e 100644 (file)
@@ -135,6 +135,15 @@ SYMBOL: alien-parameters
 
 #std-invoke [ linearize-alien ] "linearizer" set-word-property
 
+: alien-invoke ( ... returns library function parameters -- ... )
+    "alien-invoke cannot be interpreted." throw ;
+
+\ alien-invoke [ 4 | 0 ] "infer-effect" set-word-property
+
+\ alien-invoke [
+    os "win32" = #std-invoke #c-invoke ? infer-alien
+] "infer" set-word-property
+
 global [
     "libraries" get [ <namespace> "libraries" set ] unless
 ] bind
index 2e69bc2472867762376a59e599ae5cfcbf6e0689..e777958c73b61b93017745101ca08f821381e627 100644 (file)
@@ -63,14 +63,19 @@ PREDICATE: vector hashtable ( obj -- ? )
 
 : 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
+    >r
+        2dup (hashcode)
+    r> pick >r
+        over >r
+            >r swap vector-nth r> call
+        r>
+    r> set-vector-nth ; inline
     
-: set-hash ( value key table -- )
+: 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.
-!    [ set-assoc ] set-hash* ;
+    [ set-assoc ] set-hash* ;
 
 : remove-hash ( key table -- )
     #! Remove a value from a hashtable.
index 288cea334aaa5416f346adfed3a4d55fb3c23666..3781d023fa5cc2d4c820b22656fbecc5c6abb03b 100644 (file)
@@ -194,7 +194,7 @@ BEGIN-UNION: event
 END-UNION
 
 : SDL_WaitEvent ( event -- )
-    "int" "sdl" "SDL_WaitEvent" [ "event*" ] c-invoke ;
+    "int" "sdl" "SDL_WaitEvent" [ "event*" ] alien-invoke ;
 
 : SDL_PollEvent ( event -- ? )
-    "bool" "sdl" "SDL_PollEvent" [ "event*" ] c-invoke ;
+    "bool" "sdl" "SDL_PollEvent" [ "event*" ] alien-invoke ;
index b96f4097272efdf27c3dd9cc4e4591c64e5dfc19..822eb34b9fc652a68b1cbc8ee7c9d6adc5b28032 100644 (file)
@@ -31,99 +31,99 @@ USE: alien
 : pixelColor ( surface x y color -- )
     "void" "sdl-gfx" "pixelColor"
     [ "surface*" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : hlineColor ( surface x1 x2 y color -- )
     "void" "sdl-gfx" "hlineColor"
     [ "surface*" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : vlineColor ( surface x y1 y2 color -- )
     "void" "sdl-gfx" "vlineColor"
     [ "surface*" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : rectangleColor ( surface x1 y1 x2 y2 color -- )
     "void" "sdl-gfx" "rectangleColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : boxColor ( surface x1 y1 x2 y2 color -- )
     "void" "sdl-gfx" "boxColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : lineColor ( surface x1 y1 x2 y2 color -- )
     "void" "sdl-gfx" "lineColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : aalineColor ( surface x1 y1 x2 y2 color -- )
     "void" "sdl-gfx" "aalineColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : circleColor ( surface x y r color -- )
     "void" "sdl-gfx" "circleColor"
     [ "surface*" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : aacircleColor ( surface x y r color -- )
     "void" "sdl-gfx" "aacircleColor"
     [ "surface*" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : filledCircleColor ( surface x y r color -- )
     "void" "sdl-gfx" "filledCircleColor"
     [ "surface*" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : ellipseColor ( surface x y rx ry color -- )
     "void" "sdl-gfx" "ellipseColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : aaellipseColor ( surface x y rx ry color -- )
     "void" "sdl-gfx" "aaellipseColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : filledEllipseColor ( surface x y rx ry color -- )
     "void" "sdl-gfx" "filledEllipseColor"
     [ "surface*" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : pieColor ( surface x y rad start end color -- )
     "void" "sdl-gfx" "pieColor"
     [ "surface*" "short" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : filledPieColor ( surface x y rad start end color -- )
     "void" "sdl-gfx" "filledPieColor"
     [ "surface*" "short" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : trigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
     "void" "sdl-gfx" "trigonColor"
     [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : aatrigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
     "void" "sdl-gfx" "aatrigonColor"
     [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : filledTrigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
     "void" "sdl-gfx" "filledTrigonColor"
     [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : characterColor ( surface x y c color -- )
     "void" "sdl-gfx" "characterColor"
     [ "surface*" "short" "short" "char" "uint" ]
-    c-invoke ;
+    alien-invoke ;
 
 : stringColor ( surface x y str color -- )
     "void" "sdl-gfx" "stringColor"
     [ "surface*" "short" "short" "char*" "uint" ]
-    c-invoke ;
+    alien-invoke ;
index f50b0602b63448a8ff54a1eb29502589e249d623..c0322b2aa868f65b4ef50b7f488119eadf60480a 100644 (file)
@@ -119,50 +119,50 @@ END-STRUCT
 
 : SDL_VideoInit ( driver-name flags -- )
     "int" "sdl" "SDL_VideoInit"
-    [ "char*" "int" ] c-invoke ;
+    [ "char*" "int" ] alien-invoke ;
 
 : SDL_VideoQuit ( -- )
-    "void" "sdl" "SDL_VideoQuit" [ ] c-invoke ;
+    "void" "sdl" "SDL_VideoQuit" [ ] alien-invoke ;
 
 ! SDL_VideoDriverName -- needs strings as out params.
 
 : SDL_GetVideoSurface ( -- surface )
-    "surface*" "sdl" "SDL_GetVideoSurface" [ ] c-invoke ;
+    "surface*" "sdl" "SDL_GetVideoSurface" [ ] alien-invoke ;
 
 ! SDL_GetVideoInfo needs C struct bitfield support
 
 : SDL_VideoModeOK ( width height bpp flags -- )
     "int" "sdl" "SDL_VideoModeOK"
-    [ "int" "int" "int" "int" ] c-invoke ;
+    [ "int" "int" "int" "int" ] alien-invoke ;
 
 ! SDL_ListModes needs array of structs support
 
 : SDL_SetVideoMode ( width height bpp flags -- )
     "surface*" "sdl" "SDL_SetVideoMode"
-    [ "int" "int" "int" "int" ] c-invoke ;
+    [ "int" "int" "int" "int" ] alien-invoke ;
 
 ! UpdateRects, UpdateRect
 
 : SDL_Flip ( surface -- )
-    "bool" "sdl" "SDL_Flip" [ "surface*" ] c-invoke ;
+    "bool" "sdl" "SDL_Flip" [ "surface*" ] alien-invoke ;
 
 ! SDL_SetGamma: float types
 
 : SDL_FillRect ( surface rect color -- n )
     #! If rect is null, fills entire surface.
     "bool" "sdl" "SDL_FillRect"
-    [ "surface*" "rect*" "uint" ] c-invoke ;
+    [ "surface*" "rect*" "uint" ] alien-invoke ;
 
 : SDL_LockSurface ( surface -- )
-    "bool" "sdl" "SDL_LockSurface" [ "surface*" ] c-invoke ;
+    "bool" "sdl" "SDL_LockSurface" [ "surface*" ] alien-invoke ;
 
 : SDL_UnlockSurface ( surface -- )
-    "void" "sdl" "SDL_UnlockSurface" [ "surface*" ] c-invoke ;
+    "void" "sdl" "SDL_UnlockSurface" [ "surface*" ] alien-invoke ;
 
 : SDL_MapRGB ( surface r g b -- )
     "uint" "sdl" "SDL_MapRGB"
-    [ "surface*" "uchar" "uchar" "uchar" ] c-invoke ;
+    [ "surface*" "uchar" "uchar" "uchar" ] alien-invoke ;
 
 : SDL_WM_SetCaption ( title icon -- )
     "void" "sdl" "SDL_WM_SetCaption"
-    [ "char*" "char*" ] c-invoke ;
+    [ "char*" "char*" ] alien-invoke ;
index 71e5840fbd7c54fab976855799e8d31bf1982012..7981635ef2a841ecfdebf63c7cf140a881730dc1 100644 (file)
@@ -39,10 +39,10 @@ USE: compiler
 : SDL_INIT_EVERYTHING   HEX: 0000FFFF ;
 
 : SDL_Init ( mode -- )
-    "int" "sdl" "SDL_Init" [ "int" ] c-invoke ;
+    "int" "sdl" "SDL_Init" [ "int" ] alien-invoke ;
 
 : SDL_GetError ( -- error )
-    "char*" "sdl" "SDL_GetError" [ ] c-invoke ;
+    "char*" "sdl" "SDL_GetError" [ ] alien-invoke ;
 
 : SDL_Quit ( -- )
-    "void" "sdl" "SDL_Quit" [ ] c-invoke ;
+    "void" "sdl" "SDL_Quit" [ ] alien-invoke ;
index 6c20e2075070a445da16381fe275c34517361cce..d99757ab6ebc2c052784758839a26dafd2c863df 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: words
+USE: generic
 USE: inspector
 USE: lists
 USE: kernel
@@ -34,6 +35,7 @@ USE: prettyprint
 USE: stdio
 USE: strings
 USE: unparser
+USE: math
 
 : word-uses? ( of in -- ? )
     2dup = [
@@ -100,3 +102,28 @@ USE: unparser
 
 : words. ( vocab -- )
     words . ;
+
+: usage+ ( key -- )
+    dup "usages" word-property
+    [ succ ] [ 1 ] ifte*
+    "usages" set-word-property ;
+
+GENERIC: count-usages ( quot -- )
+M: object count-usages drop ;
+M: word count-usages usage+ ;
+M: cons count-usages unswons count-usages count-usages ;
+
+: tally-usages ( -- )
+    [ f "usages" set-word-property ] each-word
+    [ word-parameter count-usages ] each-word ;
+
+: auto-inline ( count -- )
+    #! Automatically inline all words called less than a count
+    #! number of times.
+    [
+        2dup "usages" word-property dup 0 ? >= [
+            t "inline" set-word-property
+        ] [
+            drop
+        ] ifte
+    ] each-word drop ;
index 405d338cbb448da08b9dfc28316df7a655f5996f..e4d9301beef4942764f9291fc771c11da03c9a3d 100644 (file)
@@ -55,6 +55,7 @@ USE: strings
 : each-word ( quot -- )
     #! Apply a quotation to each word in the image.
     vocabs [ words [ swap dup >r call r> ] each ] each drop ;
+    inline
 
 : (search) ( name vocab -- word )
     vocab dup [ hash ] [ 2drop f ] ifte ;