Paste: idea for -unsafe words/validators

Author: erg
Mode: factor
Date: Tue, 13 Sep 2011 18:20:53
Plain Text |
HOOK: (send) io-backend ( packet addrspec datagram -- )

M: unix (send)
    [ make-sockaddr/size ] [ [ handle>> ] keep ] bi* do-send ;

ERROR: invalid-port object ;

: check-port ( packet addrspec port -- packet addrspec port )
    2dup addr>> [ class ] bi@ assert=
    pick class byte-array assert= ;

: check-connectionless-port ( port -- port )
    dup { [ datagram-port? ] [ raw-port? ] } 1|| [ invalid-port ] unless ;

: check-send ( packet addrspec port -- packet addrspec port )
    check-connectionless-port dup check-disposed check-port ;

: send ( packet addrspec datagram -- ) check-send (send) ;


---------------------

V: send ( packet addrspec datagram -- )
    check-connectionless-port dup check-disposed check-port ;

: send ( packet addrspec datagram -- ) (send) ;

or 


V: send check-connectionless-port ;

V: send dup check-disposed ;

V: send check-port ;

: send ( packet addrspec datagram -- ) (send) ;

Calling send would call all of the V: validators as before-methods (in random order).  Calling send-unsafe would call (send) directly.

V: could require leaving all the arguments on the stack or dropping them.

You could also do more things with static type declarations and multimethods.

New Annotation

Summary:
Author:
Mode:
Body: