Merge branch 'master' of git://factorcode.org/git/factor
commit
cacd5f4849
|
@ -0,0 +1,12 @@
|
|||
|
||||
USING: kernel parser lexer locals.private ;
|
||||
|
||||
IN: bind-in
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: ->
|
||||
"[" parse-tokens make-locals dup push-locals
|
||||
\ ] (parse-lambda) <lambda>
|
||||
parsed-lambda
|
||||
\ call parsed ; parsing
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
USING: kernel assocs locals combinators
|
||||
math math.functions system unicode.case ;
|
||||
|
||||
IN: dns.cache.nx
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: nx-cache ( -- table ) H{ } ;
|
||||
|
||||
: nx-cache-at ( name -- time ) >lower nx-cache at ;
|
||||
: nx-cache-delete-at ( name -- ) >lower nx-cache delete-at ;
|
||||
: nx-cache-set-at ( time name -- ) >lower nx-cache set-at ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: now ( -- seconds ) millis 1000.0 / round >integer ;
|
||||
|
||||
:: non-existent-name? ( NAME -- ? )
|
||||
[let | TIME [ NAME nx-cache-at ] |
|
||||
{
|
||||
{ [ TIME f = ] [ f ] }
|
||||
{ [ TIME now <= ] [ NAME nx-cache-delete-at f ] }
|
||||
{ [ t ] [ t ] }
|
||||
}
|
||||
cond
|
||||
] ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
:: cache-non-existent-name ( NAME TTL -- )
|
||||
[let | TIME [ TTL now + ] | TIME NAME nx-cache-set-at ] ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
USING: kernel sequences assocs sets locals combinators
|
||||
accessors system math math.functions unicode.case prettyprint
|
||||
combinators.cleave dns ;
|
||||
|
||||
IN: dns.cache.rr
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
TUPLE: <entry> time data ;
|
||||
|
||||
: now ( -- seconds ) millis 1000.0 / round >integer ;
|
||||
|
||||
: expired? ( <entry> -- ? ) time>> now <= ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: make-cache-key ( obj -- key )
|
||||
{ [ name>> >lower ] [ type>> unparse ] [ class>> unparse ] } 1arr " " join ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: cache ( -- table ) H{ } ;
|
||||
|
||||
: cache-at ( obj -- ent ) make-cache-key cache at ;
|
||||
: cache-delete ( obj -- ) make-cache-key cache delete-at ;
|
||||
: cache-set-at ( ent obj -- ) make-cache-key cache set-at ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
:: cache-get ( OBJ -- rrs/f )
|
||||
[let | ENT [ OBJ cache-at ] |
|
||||
{
|
||||
{ [ ENT f = ] [ f ] }
|
||||
{ [ ENT expired? ] [ OBJ cache-delete f ] }
|
||||
{
|
||||
[ t ]
|
||||
[
|
||||
[let | NAME [ OBJ name>> ]
|
||||
TYPE [ OBJ type>> ]
|
||||
CLASS [ OBJ class>> ]
|
||||
TTL [ now ENT time>> - ] |
|
||||
ENT data>>
|
||||
[| RDATA | T{ rr f NAME TYPE CLASS TTL RDATA } ]
|
||||
map
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
cond
|
||||
] ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
:: cache-add ( RR -- )
|
||||
[let | ENT [ RR cache-at ]
|
||||
TIME [ RR ttl>> now + ]
|
||||
RDATA [ RR rdata>> ] |
|
||||
{
|
||||
{ [ ENT f = ] [ T{ <entry> f TIME V{ RDATA } } RR cache-set-at ] }
|
||||
{ [ ENT expired? ] [ RR cache-delete RR cache-add ] }
|
||||
{ [ t ] [ TIME ENT (>>time) RDATA ENT data>> adjoin ] }
|
||||
}
|
||||
cond
|
||||
] ;
|
Loading…
Reference in New Issue