Merge branch 'master' of factorcode.org:/git/factor

db4
Eduardo Cavazos 2008-05-31 07:30:45 -05:00
commit ef9a59c51f
22 changed files with 246 additions and 143 deletions

View File

@ -7,7 +7,7 @@ math.parser classes alien.arrays alien.c-types alien.strings
alien.structs alien.syntax cpu.architecture alien inspector alien.structs alien.syntax cpu.architecture alien inspector
quotations assocs kernel.private threads continuations.private quotations assocs kernel.private threads continuations.private
libc combinators compiler.errors continuations layouts accessors libc combinators compiler.errors continuations layouts accessors
; init ;
IN: alien.compiler IN: alien.compiler
TUPLE: #alien-node < node return parameters abi ; TUPLE: #alien-node < node return parameters abi ;
@ -336,7 +336,7 @@ M: #alien-indirect generate-node
! this hashtable, they will all be blown away by code GC, beware ! this hashtable, they will all be blown away by code GC, beware
SYMBOL: callbacks SYMBOL: callbacks
callbacks global [ H{ } assoc-like ] change-at [ H{ } clone callbacks set-global ] "alien.compiler" add-init-hook
: register-callback ( word -- ) dup callbacks get set-at ; : register-callback ( word -- ) dup callbacks get set-at ;
@ -344,7 +344,7 @@ M: alien-callback-error summary
drop "Words calling ``alien-callback'' must be compiled with the optimizing compiler." ; drop "Words calling ``alien-callback'' must be compiled with the optimizing compiler." ;
: callback-bottom ( node -- ) : callback-bottom ( node -- )
xt>> [ word-xt drop <alien> ] curry xt>> [ [ register-callback ] [ word-xt drop <alien> ] bi ] curry
recursive-state get infer-quot ; recursive-state get infer-quot ;
\ alien-callback [ \ alien-callback [
@ -354,7 +354,7 @@ M: alien-callback-error summary
pop-literal nip >>abi pop-literal nip >>abi
pop-parameters >>parameters pop-parameters >>parameters
pop-literal nip >>return pop-literal nip >>return
gensym dup register-callback >>xt gensym >>xt
callback-bottom callback-bottom
] "infer" set-word-prop ] "infer" set-word-prop

View File

@ -91,6 +91,6 @@ $nl
ARTICLE: "c-unions" "C unions" ARTICLE: "c-unions" "C unions"
"A " { $snippet "union" } " in C defines a type large enough to hold its largest member. This is usually used to allocate a block of memory which can hold one of several types of values." "A " { $snippet "union" } " in C defines a type large enough to hold its largest member. This is usually used to allocate a block of memory which can hold one of several types of values."
{ $subsection POSTPONE: C-UNION: } { $subsection POSTPONE: C-UNION: }
"C structure objects can be allocated by calling " { $link <c-object> } " or " { $link malloc-object } "." "C union objects can be allocated by calling " { $link <c-object> } " or " { $link malloc-object } "."
$nl $nl
"Arrays of C unions can be created by calling " { $link <c-array> } " or " { $link malloc-array } ". Elements can be read and written using words named " { $snippet { $emphasis "type" } "-nth" } " and " { $snippet "set-" { $emphasis "type" } "-nth" } "; these words are automatically generated by " { $link POSTPONE: C-UNION: } "." ; "Arrays of C unions can be created by calling " { $link <c-array> } " or " { $link malloc-array } ". Elements can be read and written using words named " { $snippet { $emphasis "type" } "-nth" } " and " { $snippet "set-" { $emphasis "type" } "-nth" } "; these words are automatically generated by " { $link POSTPONE: C-UNION: } "." ;

View File

@ -1,5 +1,6 @@
USING: help.syntax help.markup generator.fixup math kernel USING: help.syntax help.markup math kernel
words strings alien byte-array ; words strings alien ;
IN: generator.fixup
HELP: frame-required HELP: frame-required
{ $values { "n" "a non-negative integer" } } { $values { "n" "a non-negative integer" } }

View File

@ -35,10 +35,8 @@ IN: bunny.model
[ normalize ] map ; [ normalize ] map ;
: read-model ( stream -- model ) : read-model ( stream -- model )
"Reading model" print flush [ ascii [ parse-model ] with-file-reader
ascii [ parse-model ] with-file-reader [ normals ] 2keep 3array ;
[ normals ] 2keep 3array
] time ;
: model-path "bun_zipper.ply" temp-file ; : model-path "bun_zipper.ply" temp-file ;

View File

@ -0,0 +1,11 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel ;
IN: db.errors
ERROR: db-error ;
ERROR: sql-error ;
ERROR: table-exists ;
ERROR: bad-schema ;

View File

@ -175,7 +175,7 @@ M: postgresql-db create-sql-statement ( class -- seq )
: drop-table-sql ( table -- statement ) : drop-table-sql ( table -- statement )
[ [
"drop table " 0% 0% ";" 0% drop "drop table " 0% 0% drop
] query-make ; ] query-make ;
M: postgresql-db drop-sql-statement ( class -- seq ) M: postgresql-db drop-sql-statement ( class -- seq )

View File

@ -1,9 +1,8 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel math namespaces sequences random USING: accessors kernel math namespaces sequences random
strings strings math.parser math.intervals combinators
math.bitfields.lib namespaces.lib db db.tuples db.types math.bitfields.lib namespaces.lib db db.tuples db.types ;
math.intervals ;
IN: db.queries IN: db.queries
GENERIC: where ( specs obj -- ) GENERIC: where ( specs obj -- )
@ -15,7 +14,7 @@ GENERIC: where ( specs obj -- )
: query-make ( class quot -- ) : query-make ( class quot -- )
>r sql-props r> >r sql-props r>
[ 0 sql-counter rot with-variable ";" 0% ] { "" { } { } } nmake [ 0 sql-counter rot with-variable ] { "" { } { } } nmake
<simple-statement> maybe-make-retryable ; inline <simple-statement> maybe-make-retryable ; inline
M: db begin-transaction ( -- ) "BEGIN" sql-command ; M: db begin-transaction ( -- ) "BEGIN" sql-command ;
@ -127,3 +126,36 @@ M: db <select-by-slots-statement> ( tuple class -- statement )
" from " 0% 0% " from " 0% 0%
where-clause where-clause
] query-make ; ] query-make ;
: do-group ( tuple groups -- )
[
", " join " group by " prepend append
] curry change-sql drop ;
: do-order ( tuple order -- )
[
", " join " order by " prepend append
] curry change-sql drop ;
: do-offset ( tuple n -- )
[
number>string " offset " prepend append
] curry change-sql drop ;
: do-limit ( tuple n -- )
[
number>string " limit " prepend append
] curry change-sql drop ;
: make-advanced-statement ( tuple advanced -- tuple' )
dupd
{
[ group>> [ do-group ] [ drop ] if* ]
[ order>> [ do-order ] [ drop ] if* ]
[ limit>> [ do-limit ] [ drop ] if* ]
[ offset>> [ do-offset ] [ drop ] if* ]
} 2cleave ;
M: db <advanced-select-statement> ( tuple class group order limit offset -- tuple )
advanced-statement boa
[ <select-by-slots-statement> ] dip make-advanced-statement ;

View File

@ -4,9 +4,11 @@ IN: db.sql.tests
! TUPLE: person name age ; ! TUPLE: person name age ;
: insert-1 : insert-1
{ insert { insert
{ table "person" } {
{ columns "name" "age" } { table "person" }
{ values "erg" 26 } { columns "name" "age" }
{ values "erg" 26 }
}
} ; } ;
: update-1 : update-1

View File

@ -4,24 +4,25 @@ USING: alien.c-types arrays assocs kernel math math.parser
namespaces sequences db.sqlite.ffi db combinators namespaces sequences db.sqlite.ffi db combinators
continuations db.types calendar.format serialize continuations db.types calendar.format serialize
io.streams.byte-array byte-arrays io.encodings.binary io.streams.byte-array byte-arrays io.encodings.binary
io.backend ; io.backend db.errors ;
IN: db.sqlite.lib IN: db.sqlite.lib
: sqlite-error ( n -- * ) ERROR: sqlite-error < db-error n string ;
sqlite-error-messages nth throw ; ERROR: sqlite-sql-error < sql-error n string ;
: sqlite-statement-error-string ( -- str ) : throw-sqlite-error ( n -- * )
db get db-handle sqlite3_errmsg ; dup sqlite-error-messages nth sqlite-error ;
: sqlite-statement-error ( -- * ) : sqlite-statement-error ( -- * )
sqlite-statement-error-string throw ; SQLITE_ERROR
db get db-handle sqlite3_errmsg sqlite-sql-error ;
: sqlite-check-result ( n -- ) : sqlite-check-result ( n -- )
{ {
{ [ dup SQLITE_OK = ] [ drop ] } { SQLITE_OK [ ] }
{ [ dup SQLITE_ERROR = ] [ sqlite-statement-error ] } { SQLITE_ERROR [ sqlite-statement-error ] }
[ sqlite-error ] [ throw-sqlite-error ]
} cond ; } case ;
: sqlite-open ( path -- db ) : sqlite-open ( path -- db )
normalize-path normalize-path
@ -158,12 +159,11 @@ IN: db.sqlite.lib
dup sqlite-#columns [ sqlite-column ] with map ; dup sqlite-#columns [ sqlite-column ] with map ;
: sqlite-step-has-more-rows? ( prepared -- bool ) : sqlite-step-has-more-rows? ( prepared -- bool )
dup SQLITE_ROW = [ {
drop t { SQLITE_ROW [ t ] }
] [ { SQLITE_DONE [ f ] }
dup SQLITE_DONE = [ sqlite-check-result f ]
[ drop ] [ sqlite-check-result ] if f } case ;
] if ;
: sqlite-next ( prepared -- ? ) : sqlite-next ( prepared -- ? )
sqlite3_step sqlite-step-has-more-rows? ; sqlite3_step sqlite-step-has-more-rows? ;

View File

@ -16,7 +16,7 @@ M: sqlite-db make-db* ( path db -- db )
swap >>path ; swap >>path ;
M: sqlite-db db-open ( db -- db ) M: sqlite-db db-open ( db -- db )
[ path>> sqlite-open ] [ swap >>handle ] bi ; dup path>> sqlite-open >>handle ;
M: sqlite-db db-close ( handle -- ) sqlite-close ; M: sqlite-db db-close ( handle -- ) sqlite-close ;
M: sqlite-db dispose ( db -- ) dispose-db ; M: sqlite-db dispose ( db -- ) dispose-db ;
@ -197,4 +197,3 @@ M: sqlite-db compound ( str seq -- str' )
{ "default" [ first number>string join-space ] } { "default" [ first number>string join-space ] }
[ 2drop ] [ 2drop ]
} case ; } case ;

View File

@ -3,7 +3,8 @@
USING: io.files kernel tools.test db db.tuples classes USING: io.files kernel tools.test db db.tuples classes
db.types continuations namespaces math math.ranges db.types continuations namespaces math math.ranges
prettyprint calendar sequences db.sqlite math.intervals prettyprint calendar sequences db.sqlite math.intervals
db.postgresql accessors random math.bitfields.lib ; db.postgresql accessors random math.bitfields.lib
math.ranges strings sequences.lib ;
IN: db.tuples.tests IN: db.tuples.tests
TUPLE: person the-id the-name the-number the-real TUPLE: person the-id the-name the-number the-real
@ -198,9 +199,10 @@ TUPLE: annotation n paste-id summary author mode contents ;
: test-sqlite ( quot -- ) : test-sqlite ( quot -- )
>r "tuples-test.db" temp-file sqlite-db r> with-db ; >r "tuples-test.db" temp-file sqlite-db r> with-db ;
: test-postgresql ( -- ) ! : test-postgresql ( quot -- )
>r { "localhost" "postgres" "foob" "factor-test" } postgresql-db r> with-db ; ! >r { "localhost" "postgres" "foob" "factor-test" } postgresql-db r> with-db ;
: test-postgresql drop ;
: test-repeated-insert : test-repeated-insert
[ ] [ person ensure-table ] unit-test [ ] [ person ensure-table ] unit-test
[ ] [ person1 get insert-tuple ] unit-test [ ] [ person1 get insert-tuple ] unit-test
@ -224,6 +226,12 @@ TUPLE: serialize-me id data ;
TUPLE: exam id name score ; TUPLE: exam id name score ;
: random-exam ( -- exam )
f
6 [ CHAR: a CHAR: b [a,b] random ] replicate >string
100 random
exam boa ;
: test-intervals ( -- ) : test-intervals ( -- )
exam "EXAM" exam "EXAM"
{ {
@ -415,7 +423,7 @@ TUPLE: does-not-persist ;
] test-postgresql ] test-postgresql
TUPLE: suparclass a ; TUPLE: suparclass id a ;
suparclass f { suparclass f {
{ "id" "ID" +db-assigned-id+ } { "id" "ID" +db-assigned-id+ }
@ -428,8 +436,26 @@ subbclass "SUBCLASS" {
{ "b" "B" TEXT } { "b" "B" TEXT }
} define-persistent } define-persistent
TUPLE: fubbclass < subbclass ;
fubbclass "FUBCLASS" { } define-persistent
: test-db-inheritance ( -- ) : test-db-inheritance ( -- )
[ ] [ subbclass ensure-table ] unit-test ; [ ] [ subbclass ensure-table ] unit-test
[ ] [ fubbclass ensure-table ] unit-test
[ ] [
subbclass new 5 >>a "hi" >>b dup insert-tuple id>> "id" set
] unit-test
[ t "hi" 5 ] [
subbclass new "id" get >>id select-tuple
[ subbclass? ] [ b>> ] [ a>> ] tri
] unit-test
[ ] [ fubbclass new 0 >>a "hi" >>b insert-tuple ] unit-test
[ t ] [ fubbclass new select-tuples [ fubbclass? ] all? ] unit-test ;
[ test-db-inheritance ] test-sqlite [ test-db-inheritance ] test-sqlite

View File

@ -13,10 +13,10 @@ IN: db.tuples
"db-columns" set-word-prop "db-columns" set-word-prop
"db-relations" set-word-prop ; "db-relations" set-word-prop ;
ERROR: not-persistent ; ERROR: not-persistent class ;
: db-table ( class -- obj ) : db-table ( class -- obj )
"db-table" word-prop [ not-persistent ] unless* ; dup "db-table" word-prop [ ] [ not-persistent ] ?if ;
: db-columns ( class -- obj ) : db-columns ( class -- obj )
superclasses [ "db-columns" word-prop ] map concat ; superclasses [ "db-columns" word-prop ] map concat ;
@ -42,6 +42,8 @@ HOOK: <insert-user-assigned-statement> db ( class -- obj )
HOOK: <update-tuple-statement> db ( class -- obj ) HOOK: <update-tuple-statement> db ( class -- obj )
HOOK: <delete-tuples-statement> db ( tuple class -- obj ) HOOK: <delete-tuples-statement> db ( tuple class -- obj )
HOOK: <select-by-slots-statement> db ( tuple class -- tuple ) HOOK: <select-by-slots-statement> db ( tuple class -- tuple )
TUPLE: advanced-statement group order offset limit ;
HOOK: <advanced-select-statement> db ( tuple class group order offset limit -- tuple )
HOOK: insert-tuple* db ( tuple statement -- ) HOOK: insert-tuple* db ( tuple statement -- )
@ -74,16 +76,16 @@ M: retryable execute-statement* ( statement type -- )
[ regenerate-params bind-statement* f ] cleanup [ regenerate-params bind-statement* f ] cleanup
] curry 10 retry drop ; ] curry 10 retry drop ;
: resulting-tuple ( row out-params -- tuple ) : resulting-tuple ( class row out-params -- tuple )
dup first class>> new [ rot class new [
[ [
>r slot-name>> r> set-slot-named >r slot-name>> r> set-slot-named
] curry 2each ] curry 2each
] keep ; ] keep ;
: query-tuples ( statement -- seq ) : query-tuples ( exemplar-tuple statement -- seq )
[ out-params>> ] keep query-results [ [ out-params>> ] keep query-results [
[ sql-row-typed swap resulting-tuple ] with query-map [ sql-row-typed swap resulting-tuple ] with with query-map
] with-disposal ; ] with-disposal ;
: query-modify-tuple ( tuple statement -- ) : query-modify-tuple ( tuple statement -- )
@ -141,9 +143,12 @@ M: retryable execute-statement* ( statement type -- )
[ bind-tuple ] keep execute-statement [ bind-tuple ] keep execute-statement
] with-disposal ; ] with-disposal ;
: select-tuples ( tuple -- tuples ) : do-select ( exemplar-tuple statement -- tuples )
dup dup class <select-by-slots-statement> [ [ [ bind-tuple ] [ query-tuples ] 2bi ] with-disposal ;
[ bind-tuple ] keep query-tuples
] with-disposal ;
: select-tuple ( tuple -- tuple/f ) select-tuples ?first ; : select-tuples ( tuple -- tuples )
dup dup class <select-by-slots-statement> do-select ;
: select-tuple ( tuple -- tuple/f )
dup dup class f f f 1 <advanced-select-statement>
do-select ?first ;

View File

@ -142,7 +142,8 @@ HOOK: bind% db ( spec -- )
HOOK: bind# db ( spec obj -- ) HOOK: bind# db ( spec obj -- )
: offset-of-slot ( str obj -- n ) : offset-of-slot ( str obj -- n )
class "slots" word-prop slot-named slot-spec-offset ; class superclasses [ "slots" word-prop ] map concat
slot-named slot-spec-offset ;
: get-slot-named ( name obj -- value ) : get-slot-named ( name obj -- value )
tuck offset-of-slot slot ; tuck offset-of-slot slot ;

View File

@ -64,9 +64,11 @@ M: winnt add-completion ( win32-handle -- )
: handle-overlapped ( timeout -- ? ) : handle-overlapped ( timeout -- ? )
wait-for-overlapped [ wait-for-overlapped [
>r drop GetLastError dup [
[ 1array ] [ expected-io-error? ] bi >r drop GetLastError 1array r> resume-callback t
[ r> 2drop f ] [ r> resume-callback t ] if ] [
2drop f
] if
] [ ] [
resume-callback t resume-callback t
] if ; ] if ;

View File

@ -0,0 +1,24 @@
IN: logging.tests
USING: tools.test logging math ;
: input-logging-test ( a b -- c ) + ;
\ input-logging-test NOTICE add-input-logging
: output-logging-test ( a b -- c ) + ;
\ output-logging-test DEBUG add-output-logging
: error-logging-test ( a b -- c ) / ;
\ error-logging-test ERROR add-error-logging
"logging-test" [
[ 4 ] [ 1 3 input-logging-test ] unit-test
[ 4 ] [ 1 3 output-logging-test ] unit-test
[ 4/3 ] [ 4 3 error-logging-test ] unit-test
[ f ] [ 1 0 error-logging-test ] unit-test
] with-logging

View File

@ -4,33 +4,26 @@ USING: logging.server sequences namespaces concurrency.messaging
words kernel arrays shuffle tools.annotations words kernel arrays shuffle tools.annotations
prettyprint.config prettyprint debugger io.streams.string prettyprint.config prettyprint debugger io.streams.string
splitting continuations effects arrays.lib parser strings splitting continuations effects arrays.lib parser strings
combinators.lib quotations ; combinators.lib quotations fry symbols accessors ;
IN: logging IN: logging
SYMBOL: DEBUG SYMBOLS: DEBUG NOTICE WARNING ERROR CRITICAL ;
SYMBOL: NOTICE
SYMBOL: WARNING
SYMBOL: ERROR
SYMBOL: CRITICAL
: log-levels : log-levels { DEBUG NOTICE NOTICE WARNING ERROR CRITICAL } ;
{ DEBUG NOTICE NOTICE WARNING ERROR CRITICAL } ;
: send-to-log-server ( array string -- ) : send-to-log-server ( array string -- )
prefix "log-server" get send ; prefix "log-server" get send ;
SYMBOL: log-service SYMBOL: log-service
: check-log-message : check-log-message ( msg word level -- msg word level )
pick string? 3dup [ string? ] [ word? ] [ word? ] tri* and and
pick word? [ "Bad parameters to log-message" throw ] unless ; inline
pick word? and and
[ "Bad parameters to log-message" throw ] unless ;
: log-message ( msg word level -- ) : log-message ( msg word level -- )
check-log-message check-log-message
log-service get dup [ log-service get dup [
>r >r >r string-lines r> word-name r> word-name r> [ [ string-lines ] [ word-name ] [ word-name ] tri* ] dip
4array "log-message" send-to-log-server 4array "log-message" send-to-log-server
] [ ] [
4drop 4drop
@ -69,7 +62,7 @@ SYMBOL: log-service
PRIVATE> PRIVATE>
: (define-logging) ( word level quot -- ) : (define-logging) ( word level quot -- )
>r >r dup r> r> 2curry annotate ; [ dup ] 2dip 2curry annotate ;
: call-logging-quot ( quot word level -- quot' ) : call-logging-quot ( quot word level -- quot' )
"called" -rot [ log-message ] 3curry prepose ; "called" -rot [ log-message ] 3curry prepose ;
@ -79,31 +72,30 @@ PRIVATE>
: log-stack ( n word level -- ) : log-stack ( n word level -- )
log-service get [ log-service get [
>r >r [ ndup ] keep narray stack>message [ [ ndup ] keep narray stack>message ] 2dip log-message
r> r> log-message
] [ ] [
3drop 3drop
] if ; inline ] if ; inline
: input# stack-effect effect-in length ; : input# stack-effect in>> length ;
: input-logging-quot ( quot word level -- quot' ) : input-logging-quot ( quot word level -- quot' )
over input# -rot [ log-stack ] 3curry prepose ; rot [ [ input# ] keep ] 2dip '[ , , , log-stack @ ] ;
: add-input-logging ( word level -- ) : add-input-logging ( word level -- )
[ input-logging-quot ] (define-logging) ; [ input-logging-quot ] (define-logging) ;
: output# stack-effect effect-out length ; : output# stack-effect out>> length ;
: output-logging-quot ( quot word level -- quot' ) : output-logging-quot ( quot word level -- quot' )
over output# -rot [ log-stack ] 3curry compose ; [ [ output# ] keep ] dip '[ @ , , , log-stack ] ;
: add-output-logging ( word level -- ) : add-output-logging ( word level -- )
[ output-logging-quot ] (define-logging) ; [ output-logging-quot ] (define-logging) ;
: (log-error) ( object word level -- ) : (log-error) ( object word level -- )
log-service get [ log-service get [
>r >r [ print-error ] with-string-writer r> r> log-message [ [ print-error ] with-string-writer ] 2dip log-message
] [ ] [
2drop rethrow 2drop rethrow
] if ; ] if ;
@ -112,22 +104,21 @@ PRIVATE>
: log-critical ( error word -- ) CRITICAL (log-error) ; : log-critical ( error word -- ) CRITICAL (log-error) ;
: stack-balancer ( effect word -- quot ) : stack-balancer ( effect -- quot )
>r dup effect-in length r> [ over >r ERROR log-stack r> ndrop ] 2curry [ in>> length [ ndrop ] curry ]
swap effect-out length f <repetition> append >quotation ; [ out>> length f <repetition> >quotation ]
bi append ;
: error-logging-quot ( quot word -- quot' ) : error-logging-quot ( quot word -- quot' )
[ [ log-error ] curry ] keep dup stack-effect stack-balancer
[ stack-effect ] keep stack-balancer compose '[ , [ , log-error @ ] recover ] ;
[ recover ] 2curry ;
: add-error-logging ( word level -- ) : add-error-logging ( word level -- )
[ over >r input-logging-quot r> error-logging-quot ] [ [ input-logging-quot ] 2keep drop error-logging-quot ]
(define-logging) ; (define-logging) ;
: LOG: : LOG:
#! Syntax: name level #! Syntax: name level
CREATE-WORD CREATE-WORD dup scan-word
dup scan-word '[ 1array stack>message , , log-message ]
[ >r >r 1array stack>message r> r> log-message ] 2curry
define ; parsing define ; parsing

View File

@ -38,15 +38,15 @@ M: TLSv1 ssl-method drop TLSv1_method ;
OpenSSL_add_all_digests OpenSSL_add_all_digests
OpenSSL_add_all_ciphers ; OpenSSL_add_all_ciphers ;
SYMBOL: ssl-initiazed? SYMBOL: ssl-initialized?
: maybe-init-ssl ( -- ) : maybe-init-ssl ( -- )
ssl-initiazed? get-global [ ssl-initialized? get-global [
init-ssl init-ssl
t ssl-initiazed? set-global t ssl-initialized? set-global
] unless ; ] unless ;
[ f ssl-initiazed? set-global ] "openssl" add-init-hook [ f ssl-initialized? set-global ] "openssl" add-init-hook
TUPLE: openssl-context < secure-context aliens ; TUPLE: openssl-context < secure-context aliens ;

View File

@ -23,7 +23,7 @@ namespaces continuations layouts accessors ;
[ ] [ "sudoku" shake-and-bake ] unit-test [ ] [ "sudoku" shake-and-bake ] unit-test
[ t ] [ [ t ] [
cell 8 = 30 15 ? 100000 * small-enough? cell 8 = 20 10 ? 100000 * small-enough?
] unit-test ] unit-test
[ ] [ "hello-ui" shake-and-bake ] unit-test [ ] [ "hello-ui" shake-and-bake ] unit-test
@ -37,6 +37,12 @@ namespaces continuations layouts accessors ;
cell 8 = 40 20 ? 100000 * small-enough? cell 8 = 40 20 ? 100000 * small-enough?
] unit-test ] unit-test
[ ] [ "maze" shake-and-bake ] unit-test
[ t ] [
cell 8 = 30 15 ? 100000 * small-enough?
] unit-test
[ ] [ "bunny" shake-and-bake ] unit-test [ ] [ "bunny" shake-and-bake ] unit-test
[ t ] [ [ t ] [

View File

@ -108,6 +108,8 @@ IN: tools.deploy.shaker
: stripped-globals ( -- seq ) : stripped-globals ( -- seq )
[ [
"callbacks" "alien.compiler" lookup ,
{ {
bootstrap.stage2:bootstrap-time bootstrap.stage2:bootstrap-time
continuations:error continuations:error
@ -142,6 +144,7 @@ IN: tools.deploy.shaker
{ {
gensym gensym
name>char-hook
classes:class-and-cache classes:class-and-cache
classes:class-not-cache classes:class-not-cache
classes:class-or-cache classes:class-or-cache
@ -167,6 +170,8 @@ IN: tools.deploy.shaker
vocabs:load-vocab-hook vocabs:load-vocab-hook
word word
} % } %
{ } { "optimizer.math.partial" } strip-vocab-globals %
] when ] when
strip-prettyprint? [ strip-prettyprint? [

View File

@ -4,7 +4,7 @@ USING: threads kernel namespaces continuations combinators
sequences math namespaces.private continuations.private sequences math namespaces.private continuations.private
concurrency.messaging quotations kernel.private words concurrency.messaging quotations kernel.private words
sequences.private assocs models arrays accessors sequences.private assocs models arrays accessors
generic generic.standard ; generic generic.standard definitions ;
IN: tools.walker IN: tools.walker
SYMBOL: show-walker-hook ! ( status continuation thread -- ) SYMBOL: show-walker-hook ! ( status continuation thread -- )
@ -73,6 +73,7 @@ M: object add-breakpoint ;
{ [ dup "step-into" word-prop ] [ "step-into" word-prop call ] } { [ dup "step-into" word-prop ] [ "step-into" word-prop call ] }
{ [ dup standard-generic? ] [ effective-method (step-into-execute) ] } { [ dup standard-generic? ] [ effective-method (step-into-execute) ] }
{ [ dup hook-generic? ] [ effective-method (step-into-execute) ] } { [ dup hook-generic? ] [ effective-method (step-into-execute) ] }
{ [ dup uses \ suspend swap member? ] [ execute break ] }
{ [ dup primitive? ] [ execute break ] } { [ dup primitive? ] [ execute break ] }
[ word-def (step-into-quot) ] [ word-def (step-into-quot) ]
} cond ; } cond ;
@ -89,7 +90,6 @@ SYMBOL: step-into
SYMBOL: step-all SYMBOL: step-all
SYMBOL: step-into-all SYMBOL: step-into-all
SYMBOL: step-back SYMBOL: step-back
SYMBOL: detach
SYMBOL: abandon SYMBOL: abandon
SYMBOL: call-in SYMBOL: call-in
@ -137,7 +137,7 @@ SYMBOL: +stopped+
{ {
>n ndrop >c c> >n ndrop >c c>
continue continue-with continue continue-with
stop yield suspend sleep (spawn) stop suspend (spawn)
} [ } [
dup [ execute break ] curry dup [ execute break ] curry
"step-into" set-word-prop "step-into" set-word-prop
@ -168,10 +168,7 @@ SYMBOL: +stopped+
+running+ set-status ; +running+ set-status ;
: walker-stopped ( -- ) : walker-stopped ( -- )
+stopped+ set-status +stopped+ set-status ;
[ status +stopped+ eq? ]
[ [ drop f ] handle-synchronous ]
[ ] while ;
: step-into-all-loop ( -- ) : step-into-all-loop ( -- )
+running+ set-status +running+ set-status

View File

@ -15,18 +15,22 @@ IN: webapps.pastebin
! DOMAIN MODEL ! DOMAIN MODEL
! ! ! ! ! !
TUPLE: paste id summary author mode date contents annotations ; TUPLE: entity id summary author mode date contents ;
\ paste "PASTE" entity f
{ {
{ "id" "ID" INTEGER +db-assigned-id+ } { "id" "ID" INTEGER +db-assigned-id+ }
{ "summary" "SUMMARY" { VARCHAR 256 } +not-null+ } { "summary" "SUMMARY" { VARCHAR 256 } +not-null+ }
{ "author" "AUTHOR" { VARCHAR 256 } +not-null+ } { "author" "AUTHOR" { VARCHAR 256 } +not-null+ }
{ "mode" "MODE" { VARCHAR 256 } +not-null+ } { "mode" "MODE" { VARCHAR 256 } +not-null+ }
{ "date" "DATE" DATETIME +not-null+ , } { "date" "DATE" DATETIME +not-null+ }
{ "contents" "CONTENTS" TEXT +not-null+ } { "contents" "CONTENTS" TEXT +not-null+ }
} define-persistent } define-persistent
TUPLE: paste < entity annotations ;
\ paste "PASTES" { } define-persistent
: <paste> ( id -- paste ) : <paste> ( id -- paste )
\ paste new \ paste new
swap >>id ; swap >>id ;
@ -34,23 +38,17 @@ TUPLE: paste id summary author mode date contents annotations ;
: pastes ( -- pastes ) : pastes ( -- pastes )
f <paste> select-tuples ; f <paste> select-tuples ;
TUPLE: annotation aid id summary author mode contents date ; TUPLE: annotation < entity parent ;
annotation "ANNOTATION" annotation "ANNOTATIONS"
{ {
{ "aid" "AID" INTEGER +db-assigned-id+ } { "parent" "PARENT" INTEGER +not-null+ }
{ "id" "ID" INTEGER +not-null+ }
{ "summary" "SUMMARY" { VARCHAR 256 } +not-null+ }
{ "author" "AUTHOR" { VARCHAR 256 } +not-null+ }
{ "mode" "MODE" { VARCHAR 256 } +not-null+ }
{ "date" "DATE" DATETIME +not-null+ }
{ "contents" "CONTENTS" TEXT +not-null+ }
} define-persistent } define-persistent
: <annotation> ( id aid -- annotation ) : <annotation> ( parent id -- annotation )
annotation new annotation new
swap >>aid swap >>id
swap >>id ; swap >>parent ;
: fetch-annotations ( paste -- paste ) : fetch-annotations ( paste -- paste )
dup annotations>> [ dup annotations>> [
@ -76,8 +74,8 @@ M: paste entity-link
id>> "id" associate "$pastebin/paste" swap link>string ; id>> "id" associate "$pastebin/paste" swap link>string ;
M: annotation entity-link M: annotation entity-link
[ id>> "id" associate "$pastebin/paste" swap link>string ] [ parent>> "parent" associate "$pastebin/paste" swap link>string ]
[ aid>> number>string "#" prepend ] bi [ id>> number>string "#" prepend ] bi
append ; append ;
: pastebin-template ( name -- template ) : pastebin-template ( name -- template )
@ -147,7 +145,7 @@ M: annotation entity-link
[ validate-integer-id ] >>init [ validate-integer-id ] >>init
[ "id" value paste annotations>> paste-feed ] >>feed ; [ "id" value paste annotations>> paste-feed ] >>feed ;
: validate-paste ( -- ) : validate-entity ( -- )
{ {
{ "summary" [ v-one-line ] } { "summary" [ v-one-line ] }
{ "author" [ v-one-line ] } { "author" [ v-one-line ] }
@ -156,7 +154,7 @@ M: annotation entity-link
{ "captcha" [ v-captcha ] } { "captcha" [ v-captcha ] }
} validate-params ; } validate-params ;
: deposit-paste-slots ( tuple -- ) : deposit-entity-slots ( tuple -- )
now >>date now >>date
{ "summary" "author" "mode" "contents" } deposit-slots ; { "summary" "author" "mode" "contents" } deposit-slots ;
@ -170,10 +168,10 @@ M: annotation entity-link
"new-paste" pastebin-template >>template "new-paste" pastebin-template >>template
[ [
validate-paste validate-entity
f <paste> f <paste>
[ deposit-paste-slots ] [ deposit-entity-slots ]
[ insert-tuple ] [ insert-tuple ]
[ id>> "$pastebin/paste" <id-redirect> ] [ id>> "$pastebin/paste" <id-redirect> ]
tri tri
@ -195,31 +193,35 @@ M: annotation entity-link
: <new-annotation-action> ( -- action ) : <new-annotation-action> ( -- action )
<page-action> <page-action>
[ validate-paste ] >>validate [
{ { "id" [ v-integer ] } } validate-params
[ "id" param "$pastebin/paste" <id-redirect> ] >>display "id" value "$pastebin/paste" <id-redirect>
] >>display
[ [
f f <annotation> { { "id" [ v-integer ] } } validate-params
{ validate-entity
[ deposit-paste-slots ] ] >>validate
[ { "id" } deposit-slots ]
[ insert-tuple ] [
[ "id" value f <annotation>
! Add anchor here [ deposit-entity-slots ]
id>> "$pastebin/paste" <id-redirect> [ insert-tuple ]
] [
} cleave ! Add anchor here
parent>> "$pastebin/paste" <id-redirect>
]
tri
] >>submit ; ] >>submit ;
: <delete-annotation-action> ( -- action ) : <delete-annotation-action> ( -- action )
<action> <action>
[ { { "aid" [ v-number ] } } validate-params ] >>validate [ { { "id" [ v-number ] } } validate-params ] >>validate
[ [
f "aid" value <annotation> select-tuple f "id" value <annotation> select-tuple
[ delete-tuples ] [ delete-tuples ]
[ id>> "$pastebin/paste" <id-redirect> ] [ parent>> "$pastebin/paste" <id-redirect> ]
bi bi
] >>submit ; ] >>submit ;

View File

@ -11,11 +11,12 @@ F_COMPILED *compile_profiling_stub(F_WORD *word)
CELL code = array_nth(quadruple,0); CELL code = array_nth(quadruple,0);
REGISTER_ROOT(code); REGISTER_ROOT(code);
CELL rel_type = allot_cell(to_fixnum(array_nth(quadruple,2)) F_REL rel;
| (to_fixnum(array_nth(quadruple,1)) << 8)); rel.type = to_fixnum(array_nth(quadruple,2)) | (to_fixnum(array_nth(quadruple,1)) << 8);
CELL rel_offset = array_nth(quadruple,3) * compiled_code_format(); rel.offset = to_fixnum(array_nth(quadruple,3)) * compiled_code_format();
CELL relocation = allot_array_2(rel_type,rel_offset); F_BYTE_ARRAY *relocation = allot_byte_array(sizeof(F_REL));
memcpy((void *)BREF(relocation,0),&rel,sizeof(F_REL));
UNREGISTER_ROOT(code); UNREGISTER_ROOT(code);
UNREGISTER_ROOT(literals); UNREGISTER_ROOT(literals);
@ -24,7 +25,7 @@ F_COMPILED *compile_profiling_stub(F_WORD *word)
WORD_TYPE, WORD_TYPE,
untag_object(code), untag_object(code),
NULL, /* no labels */ NULL, /* no labels */
untag_object(relocation), tag_object(relocation),
untag_object(literals)); untag_object(literals));
} }