- icons\r
- use incremental strategy for all pack layouts where possible\r
- multiline editing in listener\r
-- sort out clipping off-by-one flaw when filling rectangles\r
- better menu positioning\r
- only redraw dirty gadgets\r
- get stuff in examples dir running in the ui\r
: library-abi ( library -- abi )
library [ [ "abi" get ] bind ] [ "cdecl" ] ifte* ;
+: DLL" skip-blank parse-string dlopen swons ; parsing
+
: ALIEN: scan-word <alien> swons ; parsing
IN: alien
USING: assembler compiler compiler-backend compiler-frontend
errors generic hashtables inference io kernel lists math
-namespaces prettyprint sequences strings words ;
+namespaces prettyprint sequences strings words parser ;
! ! ! WARNING ! ! !
! Reloading this file into a running Factor instance on Win32
[ dup parameters stack-space %cleanup , ] unless
linearize-return ;
+: unpair ( seq -- odds evens )
+ 2 swap group flip dup empty?
+ [ drop { } { } ] [ 2unseq ] ifte ;
+
+: parse-arglist ( lst -- types stack effect )
+ unpair [
+ " " % [ "," ?tail drop % " " % ] each "-- " %
+ ] make-string ;
+
+: (define-c-word) ( type lib func types stack-effect -- )
+ >r over create-in >r
+ [ alien-invoke ] cons cons cons cons r> swap define-compound
+ word r> "stack-effect" set-word-prop ;
+
+: define-c-word ( type lib func function-args -- )
+ [ "()" subseq? not ] subset parse-arglist (define-c-word) ;
+
\ alien-invoke [ [ string object string general-list ] [ ] ]
"infer-effect" set-word-prop
+++ /dev/null
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: alien
-USING: kernel lists math parser words ;
-
-: BEGIN-ENUM:
- #! C-style enumerations. Their use is not encouraged unless
- #! it is for C library interfaces. Used like this:
- #!
- #! BEGIN-ENUM 0
- #! ENUM: x
- #! ENUM: y
- #! ENUM: z
- #! END-ENUM
- #!
- #! This is the same as : x 0 ; : y 1 ; : z 2 ;.
- scan string>number ; parsing
-
-: ENUM:
- dup CREATE swap unit define-compound 1 + ; parsing
-
-: END-ENUM
- drop ; parsing
]
"struct-name" get define-c-type
"struct-name" get "in" get init-c-type ;
-
-: BEGIN-STRUCT: ( -- offset )
- scan "struct-name" set 0 ; parsing
-
-: FIELD: ( offset -- offset )
- scan scan define-field ; parsing
-
-: END-STRUCT ( length -- )
- define-struct-type ; parsing
-
-: BEGIN-UNION: ( -- max )
- scan "struct-name" set 0 ; parsing
-
-: MEMBER: ( max -- max )
- scan define-member ; parsing
-
-: END-UNION ( max -- )
- define-struct-type ; parsing
! Copyright (C) 2005 Alex Chapman.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
-USING: compiler kernel lists namespaces parser sequences words ;
+USING: compiler kernel lists math namespaces parser
+sequences words ;
! usage of 'LIBRARY:' and 'FUNCTION:' :
!
: LIBRARY: scan "c-library" set ; parsing
-: unpair ( seq -- odds evens )
- 2 swap group flip dup empty?
- [ drop { } { } ] [ 2unseq ] ifte ;
-
-: parse-arglist ( lst -- types stack effect )
- unpair [
- " " % [ "," ?tail drop % " " % ] each "-- " %
- ] make-string ;
-
-: (define-c-word) ( type lib func types stack-effect -- )
- >r over create-in >r
- [ alien-invoke ] cons cons cons cons r> swap define-compound
- word r> "stack-effect" set-word-prop ;
-
-: define-c-word ( type lib func function-args -- )
- [ "()" subseq? not ] subset parse-arglist (define-c-word) ;
-
: FUNCTION:
scan "c-library" get scan string-mode on
[ string-mode off define-c-word ] [ ] ; parsing
#! TYPEDEF: old new
scan scan typedef ; parsing
-: DLL" skip-blank parse-string dlopen swons ; parsing
+: BEGIN-STRUCT: ( -- offset )
+ scan "struct-name" set 0 ; parsing
+
+: FIELD: ( offset -- offset )
+ scan scan define-field ; parsing
+
+: END-STRUCT ( length -- )
+ define-struct-type ; parsing
+
+: BEGIN-UNION: ( -- max )
+ scan "struct-name" set 0 ; parsing
+
+: MEMBER: ( max -- max )
+ scan define-member ; parsing
+
+: END-UNION ( max -- )
+ define-struct-type ; parsing
+
+: BEGIN-ENUM:
+ #! C-style enumerations. Their use is not encouraged unless
+ #! it is for C library interfaces. Used like this:
+ #!
+ #! BEGIN-ENUM 0
+ #! ENUM: x
+ #! ENUM: y
+ #! ENUM: z
+ #! END-ENUM
+ #!
+ #! This is the same as : x 0 ; : y 1 ; : z 2 ;.
+ scan string>number ; parsing
+
+: ENUM:
+ dup CREATE swap unit define-compound 1 + ; parsing
+
+: END-ENUM
+ drop ; parsing
"/library/compiler/compiler.factor"
"/library/alien/c-types.factor"
- "/library/alien/enums.factor"
"/library/alien/structs.factor"
"/library/alien/compiler.factor"
"/library/alien/syntax.factor"
math namespaces parser prettyprint sequences sequences io
strings vectors words ;
+! If true in current namespace, we are bootstrapping.
+SYMBOL: bootstrapping?
+
! The image being constructed; a vector of word-size integers
SYMBOL: image
"Writing image to " write dup write "..." print
<file-writer> [ (write-image) ] with-stream ;
-: with-minimal-image ( quot -- image )
+: with-image ( quot -- image )
[
+ bootstrapping? on
800000 <vector> image set
20000 <hashtable> objects set
call
image get
] with-scope ;
-: with-image ( quot -- image )
- #! The quotation leaves a boot quotation on the stack.
- [ begin call end ] with-minimal-image ;
-
: make-image ( name -- )
#! Make a bootstrap image.
[
+ begin
"/library/bootstrap/boot-stage1.factor" run-resource
namespace global [ "foobar" set ] bind
+ end
] with-image
swap write-image ;
: sort ( seq quot -- seq | quot: elt elt -- -1/0/1 )
swap [ swap nsort ] immutable ; inline
+: number-sort ( seq -- seq ) [ - ] sort ;
+
+: string-sort ( seq -- seq ) [ lexi ] sort ;
+
: binsearch ( elt seq quot -- i | quot: elt elt -- -1/0/1 )
swap dup empty?
[ 3drop -1 ] [ binsearch-slice (binsearch) ] ifte ;
M: generic definer drop \ G: ;
: lookup-union ( typelist -- class )
- [ - ] sort typemap get hash [ object ] unless* ;
+ number-sort typemap get hash [ object ] unless* ;
: class-or ( class class -- class )
#! Return a class that both classes are subclasses of.
: define-class ( class metaclass -- )
dupd "metaclass" set-word-prop
- dup types [ - ] sort typemap get set-hash ;
+ dup types number-sort typemap get set-hash ;
--- /dev/null
+USING: kernel parser sequences io ;
+[
+ "/library/httpd/http-common.factor"
+ "/library/httpd/mime.factor"
+ "/library/httpd/html-tags.factor"
+ "/library/httpd/html.factor"
+ "/library/httpd/responder.factor"
+ "/library/httpd/httpd.factor"
+ "/library/httpd/file-responder.factor"
+ "/library/httpd/test-responder.factor"
+ "/library/httpd/resource-responder.factor"
+ "/library/httpd/cont-responder.factor"
+ "/library/httpd/browser-responder.factor"
+ "/library/httpd/default-responders.factor"
+ "/library/httpd/http-client.factor"
+] [
+ dup print run-resource
+] each
: path+ ( path path -- path ) "/" swap append3 ;
: exists? ( file -- ? ) stat >boolean ;
: directory? ( file -- ? ) stat car ;
-: directory ( dir -- list ) (directory) [ lexi ] sort ;
+: directory ( dir -- list ) (directory) string-sort ;
: file-length ( file -- length ) stat third ;
: file-extension ( filename -- extension )
"." split cdr dup [ peek ] when ;
[ "surface*" "short" "short" "short" "short" "uint" ]
alien-invoke ;
-: pieColor ( surface x y rad start end color -- )
- "void" "sdl-gfx" "pieColor"
- [ "surface*" "short" "short" "short" "short" "short" "uint" ]
- alien-invoke ;
-
-: filledPieColor ( surface x y rad start end color -- )
- "void" "sdl-gfx" "filledPieColor"
- [ "surface*" "short" "short" "short" "short" "short" "uint" ]
- alien-invoke ;
-
: trigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
"void" "sdl-gfx" "trigonColor"
[ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
: must-lock-surface? ( surface -- ? )
#! This is a macro in SDL_video.h.
- dup sdl-surface-offset 0 = [
- sdl-surface-flags
+ dup surface-offset 0 = [
+ surface-flags
SDL_HWSURFACE SDL_ASYNCBLIT bitor SDL_RLEACCEL bitor
bitand 0 = not
] [
] ifte SDL_Flip drop
] with-scope ; inline
-: sdl-surface-rect ( x y surface -- rect )
- dup sdl-surface-w swap sdl-surface-h make-rect ;
+: surface-rect ( x y surface -- rect )
+ dup surface-w swap surface-h make-rect ;
FIELD: uchar alpha
END-STRUCT
-BEGIN-STRUCT: sdl-surface
+BEGIN-STRUCT: surface
FIELD: uint flags
FIELD: sdl-format* format
FIELD: int w
"void" "sdl" "SDL_UnlockSurface" [ "surface*" ] alien-invoke ;
: SDL_SetClipRect ( surface rect -- ? )
- "bool" "sdl" "SDL_SetClipRect" [ "surface*" "rect*" ] alien-invoke ;
+ "bool" "sdl" "SDL_SetClipRect" [ "surface*" "sdl-rect*" ] alien-invoke ;
: SDL_FreeSurface ( surface -- )
"void" "sdl" "SDL_FreeSurface" [ "surface*" ] alien-invoke ;
#! The blit function should not be called on a locked
#! surface.
"int" "sdl" "SDL_UpperBlit" [
- "surface*" "rect*"
- "surface*" "rect*"
+ "surface*" "sdl-rect*"
+ "surface*" "sdl-rect*"
] alien-invoke ;
: SDL_FillRect ( surface rect color -- n )
#! If rect is null, fills entire surface.
"bool" "sdl" "SDL_FillRect"
- [ "surface*" "rect*" "uint" ] alien-invoke ;
+ [ "surface*" "sdl-rect*" "uint" ] alien-invoke ;
: SDL_WM_SetCaption ( title icon -- )
"void" "sdl" "SDL_WM_SetCaption"
USING: compiler kernel math sequences test ;
: sort-benchmark
- 100000 [ drop 0 10000 random-int ] map [ - ] sort drop ; compiled
+ 100000 [ drop 0 10000 random-int ] map number-sort drop ; compiled
[ ] [ sort-benchmark ] unit-test
sorter-seq >vector nip
] unit-test
-[ [ ] ] [ [ ] [ - ] sort ] unit-test
+[ [ ] ] [ [ ] number-sort ] unit-test
: pairs ( seq quot -- )
swap dup length 1 - [
[ t ] [
100 [
drop
- 1000 [ drop 0 1000 random-int ] map [ - ] sort [ - ] sorted?
+ 1000 [ drop 0 1000 random-int ] map number-sort [ - ] sorted?
] all?
] unit-test
: rect-extent ( rect -- loc dim )
dup rect-loc dup rot rect-dim v+ ;
-: screen-loc ( rect -- loc )
- rect-loc origin get v+ ;
-
-: screen-bounds ( rect -- rect )
- dup screen-loc swap rect-dim <rect> ;
+: >absolute ( rect -- rect )
+ dup rect-loc origin get v+ dup rot rect-dim v+ <rect> ;
M: rect inside? ( loc rect -- ? )
- screen-bounds rect-bounds { 1 1 1 } v- { 0 0 0 } vmax
+ >absolute rect-bounds { 1 1 1 } v- { 0 0 0 } vmax
>r v- { 0 0 0 } r> vbetween? conjunction ;
: intersect ( rect rect -- rect )
#! in any subgadget. If not, see if it is contained in the
#! box delegate.
dup gadget-visible? >r 2dup inside? r> drop [
- [ rect-loc v- ] keep 2dup
pick-up* [ pick-up ] [ nip ] ?ifte
] [
2drop f
M: pack layout* ( pack -- ) dup pref-dims packed-layout ;
+: pack-comparator rect-loc origin get v+ v- over v. ;
+
: pick-up-fast ( axis point gadgets -- gadget )
- [ rect-loc v- over v. ] binsearch* nip ;
+ [ pack-comparator ] binsearch* nip ;
M: pack pick-up* ( point pack -- gadget )
dup pack-vector pick rot gadget-children
pick-up-fast tuck inside? [ drop f ] unless ;
-! M: pack visible-children* ( rect pack -- list )
-! dup pack-vector -rot gadget-children >r rect-extent r>
-! [ rect-loc origin get v+ v- over v. ] binsearch-slice nip ;
+M: pack visible-children* ( rect pack -- list )
+ dup pack-vector -rot gadget-children >r rect-extent r>
+ [ pack-comparator ] binsearch-slice nip ;
TUPLE: stack ;
GENERIC: visible-children* ( rect gadget -- list )
M: gadget visible-children* ( rect gadget -- list )
- gadget-children [ screen-bounds intersects? ] subset-with ;
+ gadget-children [ >absolute intersects? ] subset-with ;
: visible-children ( gadget -- list )
clip get swap visible-children* ;
GENERIC: draw-gadget* ( gadget -- )
: translate&clip ( gadget -- )
- screen-bounds dup rect-loc origin set
+ >absolute dup rect-loc origin set
clip [ intersect dup ] change set-clip ;
: draw-gadget ( gadget -- )
: draw-surface ( x y surface -- )
surface get SDL_UnlockSurface
[
- [ sdl-surface-rect ] keep swap surface get 0 0
- ] keep sdl-surface-rect swap rot SDL_UpperBlit drop
+ [ surface-rect ] keep swap surface get 0 0
+ ] keep surface-rect swap rot SDL_UpperBlit drop
surface get dup must-lock-surface? [
SDL_LockSurface
] when drop ;
: vocabs ( -- list )
#! Push a list of vocabularies.
- vocabularies get hash-keys [ lexi ] sort ;
+ vocabularies get hash-keys string-sort ;
: vocab ( name -- vocab )
#! Get a vocabulary.