Skip to content

Commit

Permalink
Merge branch 'master' of git://factorcode.org/git/factor
Browse files Browse the repository at this point in the history
  • Loading branch information
slavapestov committed May 13, 2009
2 parents 608f140 + 73f61c1 commit cbbc972
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 71 deletions.
34 changes: 11 additions & 23 deletions basis/tools/annotations/annotations.factor
Expand Up @@ -43,29 +43,17 @@ PRIVATE>

<PRIVATE

: word-inputs ( word -- seq )
stack-effect [
[ datastack ] dip in>> length tail*
] [
datastack
] if* ;

: entering ( str -- )
"/-- Entering: " write dup .
word-inputs stack.
"\\--" print flush ;

: word-outputs ( word -- seq )
stack-effect [
[ datastack ] dip out>> length tail*
] [
datastack
] if* ;

: leaving ( str -- )
"/-- Leaving: " write dup .
word-outputs stack.
"\\--" print flush ;
: stack-values ( names -- alist )
[ datastack ] dip [ nip ] [ length tail* ] 2bi zip ;

: trace-message ( word quot str -- )
"--- " write write bl over .
[ stack-effect ] dip '[ @ stack-values ] [ f ] if*
[ simple-table. ] unless-empty flush ; inline

: entering ( str -- ) [ in>> ] "Entering" trace-message ;

: leaving ( str -- ) [ out>> ] "Leaving" trace-message ;

: (watch) ( word def -- def )
over '[ _ entering @ _ leaving ] ;
Expand Down
19 changes: 16 additions & 3 deletions core/classes/predicate/predicate-tests.factor
@@ -1,5 +1,6 @@
USING: math tools.test classes.algebra words kernel sequences assocs ;
IN: classes.predicate
USING: math tools.test classes.algebra words kernel sequences assocs
accessors eval definitions compiler.units generic ;
IN: classes.predicate.tests

PREDICATE: negative < integer 0 < ;
PREDICATE: positive < integer 0 > ;
Expand All @@ -18,4 +19,16 @@ M: positive abs ;

[ 10 ] [ -10 abs ] unit-test
[ 10 ] [ 10 abs ] unit-test
[ 0 ] [ 0 abs ] unit-test
[ 0 ] [ 0 abs ] unit-test

! Bug report from Bruno Deferrari
TUPLE: tuple-a slot ;
TUPLE: tuple-b < tuple-a ;

PREDICATE: tuple-c < tuple-b slot>> ;

GENERIC: ptest ( tuple -- )
M: tuple-a ptest drop ;
IN: classes.predicate.tests USING: kernel ; M: tuple-c ptest drop ;

[ ] [ tuple-b new ptest ] unit-test
32 changes: 24 additions & 8 deletions core/generic/single/single.factor
Expand Up @@ -58,13 +58,13 @@ M: single-combination make-default-method
] unless ;

! 1. Flatten methods
TUPLE: predicate-engine methods ;
TUPLE: predicate-engine class methods ;

: <predicate-engine> ( methods -- engine ) predicate-engine boa ;
C: <predicate-engine> predicate-engine

: push-method ( method specializer atomic assoc -- )
[
[ H{ } clone <predicate-engine> ] unless*
dupd [
[ ] [ H{ } clone <predicate-engine> ] ?if
[ methods>> set-at ] keep
] change-at ;

Expand Down Expand Up @@ -182,14 +182,27 @@ M: tuple-dispatch-engine compile-engine
[ <enum> swap update ] keep
] with-variable ;

PREDICATE: predicate-engine-word < word "owner-generic" word-prop ;

SYMBOL: predicate-engines

: sort-methods ( assoc -- assoc' )
>alist [ keys sort-classes ] keep extract-keys ;

: quote-methods ( assoc -- assoc' )
[ 1quotation \ drop prefix ] assoc-map ;

: find-predicate-engine ( classes -- word )
predicate-engines get [ at ] curry map-find drop ;

: next-predicate-engine ( engine -- word )
class>> superclasses
find-predicate-engine
default get or ;

: methods-with-default ( engine -- assoc )
methods>> clone default get object bootstrap-word pick set-at ;
[ methods>> clone ] [ next-predicate-engine ] bi
object bootstrap-word pick set-at ;

: keep-going? ( assoc -- ? )
assumed get swap second first class<= ;
Expand All @@ -205,8 +218,6 @@ M: tuple-dispatch-engine compile-engine
: class-predicates ( assoc -- assoc )
[ [ "predicate" word-prop [ dup ] prepend ] dip ] assoc-map ;

PREDICATE: predicate-engine-word < word "owner-generic" word-prop ;

: <predicate-engine-word> ( -- word )
generic-word get name>> "/predicate-engine" append f <word>
dup generic-word get "owner-generic" set-word-prop ;
Expand All @@ -217,14 +228,18 @@ M: predicate-engine-word stack-effect "owner-generic" word-prop stack-effect ;
[ <predicate-engine-word> ] dip
[ define ] [ drop generic-word get "engines" word-prop push ] [ drop ] 2tri ;

M: predicate-engine compile-engine
: compile-predicate-engine ( engine -- word )
methods-with-default
sort-methods
quote-methods
prune-redundant-predicates
class-predicates
[ peek ] [ alist>quot picker prepend define-predicate-engine ] if-empty ;

M: predicate-engine compile-engine
[ compile-predicate-engine ] [ class>> ] bi
[ drop ] [ predicate-engines get set-at ] 2bi ;

M: word compile-engine ;

M: f compile-engine ;
Expand All @@ -251,6 +266,7 @@ HOOK: mega-cache-quot combination ( methods -- quot/f )

M: single-combination perform-combination
[
H{ } clone predicate-engines set
dup generic-word set
dup build-decision-tree
[ "decision-tree" set-word-prop ]
Expand Down
2 changes: 1 addition & 1 deletion extra/irc/client/base/base.factor
Expand Up @@ -19,7 +19,7 @@ SYMBOL: current-irc-client

UNION: to-target privmsg notice ;
UNION: to-channel join part topic kick rpl-channel-modes
rpl-notopic rpl-topic rpl-names rpl-names-end ;
topic rpl-names rpl-names-end ;
UNION: to-one-chat to-target to-channel mode ;
UNION: to-many-chats nick quit ;
UNION: to-all-chats irc-end irc-disconnected irc-connected ;
Expand Down
8 changes: 5 additions & 3 deletions extra/irc/client/chats/chats.factor
Expand Up @@ -33,7 +33,8 @@ TUPLE: irc-profile server port nickname password ;
C: <irc-profile> irc-profile

TUPLE: irc-client profile stream in-messages out-messages
chats is-running nick connect reconnect-time is-ready
chats is-running nick connect is-ready
reconnect-time reconnect-attempts
exceptions ;

: <irc-client> ( profile -- irc-client )
Expand All @@ -43,8 +44,9 @@ TUPLE: irc-client profile stream in-messages out-messages
<mailbox> >>in-messages
<mailbox> >>out-messages
H{ } clone >>chats
15 seconds >>reconnect-time
30 seconds >>reconnect-time
10 >>reconnect-attempts
V{ } clone >>exceptions
[ <inet> latin1 <client> ] >>connect ;
[ <inet> latin1 <client> drop ] >>connect ;

SINGLETONS: irc-chat-end irc-end irc-disconnected irc-connected ;
2 changes: 1 addition & 1 deletion extra/irc/client/internals/internals-tests.factor
Expand Up @@ -76,7 +76,7 @@ M: mb-writer dispose drop ;
! Test connect
{ V{ "NICK factorbot" "USER factorbot hostname servername :irc.factor" } } [
"someserver" irc-port "factorbot" f <irc-profile> <irc-client>
[ 2drop <test-stream> t ] >>connect
[ 2drop <test-stream> ] >>connect
[
(connect-irc)
(do-login)
Expand Down
48 changes: 27 additions & 21 deletions extra/irc/client/internals/internals.factor
Expand Up @@ -3,10 +3,17 @@
USING: accessors assocs arrays concurrency.mailboxes continuations destructors
hashtables io irc.client.base irc.client.chats irc.messages kernel namespaces
strings words.symbol irc.messages.base irc.client.participants fry threads
combinators irc.messages.parser ;
combinators irc.messages.parser math ;
EXCLUDE: sequences => join ;
IN: irc.client.internals

: do-connect ( server port quot: ( host port -- stream ) attempts -- stream/f )
dup 0 > [
[ drop call( host port -- stream ) ]
[ drop 15 sleep 1- do-connect ]
recover
] [ 2drop 2drop f ] if ;

: /NICK ( nick -- ) "NICK " prepend irc-print ;
: /PONG ( text -- ) "PONG " prepend irc-print ;

Expand All @@ -15,18 +22,27 @@ IN: irc.client.internals
"USER " prepend " hostname servername :irc.factor" append irc-print ;

: /CONNECT ( server port -- stream )
irc> connect>> call( host port -- stream local ) drop ;
irc> [ connect>> ] [ reconnect-attempts>> ] bi do-connect ;

: /JOIN ( channel password -- )
[ " :" swap 3append ] when* "JOIN " prepend irc-print ;

: try-connect ( -- stream/f )
irc> profile>> [ server>> ] [ port>> ] bi /CONNECT ;

: (terminate-irc) ( -- )
irc> dup is-running>> [
f >>is-running
[ stream>> dispose ] keep
[ in-messages>> ] [ out-messages>> ] bi 2array
[ irc-end swap mailbox-put ] each
] [ drop ] if ;

: (connect-irc) ( -- )
irc> {
[ profile>> [ server>> ] [ port>> ] bi /CONNECT ]
[ (>>stream) ]
[ t swap (>>is-running) ]
[ in-messages>> [ irc-connected ] dip mailbox-put ]
} cleave ;
try-connect [
[ irc> ] dip >>stream t >>is-running
in-messages>> [ irc-connected ] dip mailbox-put
] [ (terminate-irc) ] if* ;

: (do-login) ( -- ) irc> nick>> /LOGIN ;

Expand All @@ -52,7 +68,7 @@ M: to-all-chats message-forwards drop chats> ;
M: to-many-chats message-forwards sender>> participant-chats ;

GENERIC: process-message ( irc-message -- )
M: object process-message drop ;
M: object process-message drop ;
M: ping process-message trailing>> /PONG ;
M: join process-message [ sender>> ] [ chat> ] bi join-participant ;
M: part process-message [ sender>> ] [ chat> ] bi part-participant ;
Expand Down Expand Up @@ -92,9 +108,7 @@ M: irc-message handle-outgoing-irc irc-message>string irc-print t ;

: (handle-disconnect) ( -- )
irc-disconnected irc> in-messages>> mailbox-put
irc> reconnect-time>> sleep
(connect-irc)
(do-login) ;
(connect-irc) (do-login) ;

: handle-disconnect ( error -- ? )
[ irc> exceptions>> push ] when*
Expand Down Expand Up @@ -155,12 +169,4 @@ M: irc-channel-chat remove-chat
[ part new annotate-message irc-send ]
[ name>> unregister-chat ] bi ;

: (terminate-irc) ( -- )
irc> dup is-running>> [
f >>is-running
[ stream>> dispose ] keep
[ in-messages>> ] [ out-messages>> ] bi 2array
[ irc-end swap mailbox-put ] each
] [ drop ] if ;

: (speak) ( message irc-chat -- ) swap annotate-message irc-send ;
: (speak) ( message irc-chat -- ) swap annotate-message irc-send ;
10 changes: 10 additions & 0 deletions extra/irc/logbot/log-line/log-line.factor
Expand Up @@ -11,6 +11,12 @@ GENERIC: >log-line ( object -- line )

M: irc-message >log-line line>> ;

M: ctcp >log-line
[ "CTCP: " % dup sender>> % " " % text>> % ] "" make ;

M: action >log-line
[ "* " % dup sender>> % " " % text>> % ] "" make ;

M: privmsg >log-line
[ "<" % dup sender>> % "> " % text>> % ] "" make ;

Expand All @@ -35,3 +41,7 @@ M: participant-mode >log-line

M: nick >log-line
[ "* " % dup sender>> % " is now known as " % nickname>> % ] "" make ;

M: topic >log-line
[ "* " % dup sender>> % " has set the topic for " % dup channel>> %
": \"" % topic>> % "\"" % ] "" make ;
4 changes: 2 additions & 2 deletions extra/irc/logbot/logbot.factor
Expand Up @@ -16,7 +16,7 @@ SYMBOL: current-stream
"irc.freenode.org" 6667 "flogger" f <irc-profile> ;

: add-timestamp ( string timestamp -- string )
timestamp>hms "[" prepend "] " append prepend ;
timestamp>hms [ "[" % % "] " % % ] "" make ;

: timestamp-path ( timestamp -- path )
timestamp>ymd ".log" append log-directory prepend-path ;
Expand All @@ -27,7 +27,7 @@ SYMBOL: current-stream
] [
current-stream get [ dispose ] when*
[ day-of-year current-day set ]
[ timestamp-path latin1 <file-writer> ] bi
[ timestamp-path latin1 <file-appender> ] bi
current-stream set
] if current-stream get ;

Expand Down
3 changes: 2 additions & 1 deletion extra/irc/messages/base/base.factor
@@ -1,6 +1,6 @@
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes.parser classes.tuple
USING: accessors arrays assocs calendar classes.parser classes.tuple
combinators fry generic.parser kernel lexer
mirrors namespaces parser sequences splitting strings words ;
IN: irc.messages.base
Expand Down Expand Up @@ -51,6 +51,7 @@ M: irc-message post-process-irc-message drop ;

GENERIC: fill-irc-message-slots ( irc-message -- )
M: irc-message fill-irc-message-slots
gmt >>timestamp
{
[ process-irc-trailing ]
[ process-irc-prefix ]
Expand Down
5 changes: 4 additions & 1 deletion extra/irc/messages/messages-tests.factor
Expand Up @@ -71,4 +71,7 @@ IN: irc.messages.tests
{ name "nickname" }
{ trailing "Nickname is already in use" } } }
[ ":ircserver.net 433 * nickname :Nickname is already in use"
string>irc-message f >>timestamp ] unit-test
string>irc-message f >>timestamp ] unit-test

{ t } [ ":someuser!n=user@some.where PRIVMSG #factortest :ACTION jumps!"
string>irc-message action? ] unit-test
16 changes: 13 additions & 3 deletions extra/irc/messages/messages.factor
@@ -1,7 +1,8 @@
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: kernel fry splitting ascii calendar accessors combinators
arrays classes.tuple math.order words assocs strings irc.messages.base ;
arrays classes.tuple math.order words assocs strings irc.messages.base
combinators.short-circuit math ;
EXCLUDE: sequences => join ;
IN: irc.messages

Expand Down Expand Up @@ -61,8 +62,17 @@ IRC: rpl-names-end "366" nickname channel : comment ;
IRC: rpl-nickname-in-use "433" _ name ;
IRC: rpl-nick-collision "436" nickname : comment ;

PREDICATE: channel-mode < mode name>> first "#&" member? ;
PREDICATE: participant-mode < channel-mode parameter>> ;
PREDICATE: ctcp < privmsg
trailing>> { [ length 1 > ] [ first 1 = ] [ peek 1 = ] } 1&& ;
PREDICATE: action < ctcp trailing>> rest "ACTION" head? ;

M: rpl-names post-process-irc-message ( rpl-names -- )
[ [ blank? ] trim " " split ] change-nicks drop ;

PREDICATE: channel-mode < mode name>> first "#&" member? ;
PREDICATE: participant-mode < channel-mode parameter>> ;
M: ctcp post-process-irc-message ( ctcp -- )
[ rest but-last ] change-text drop ;

M: action post-process-irc-message ( action -- )
[ 7 tail ] change-text call-next-method ;
4 changes: 2 additions & 2 deletions extra/irc/messages/parser/parser.factor
@@ -1,6 +1,6 @@
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: kernel fry splitting ascii calendar accessors combinators
USING: kernel fry splitting ascii accessors combinators
arrays classes.tuple math.order words assocs
irc.messages.base sequences ;
IN: irc.messages.parser
Expand Down Expand Up @@ -32,4 +32,4 @@ PRIVATE>
[ >>trailing ]
tri*
[ (>>prefix) ] [ fill-irc-message-slots ] [ swap >>line ] tri
now >>timestamp dup sender >>sender ;
dup sender >>sender ;

0 comments on commit cbbc972

Please sign in to comment.