diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 698c3a1766..f29dec128c 100644 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -10,6 +10,7 @@ IN: bootstrap.x86 : shift-arg ( -- reg ) ECX ; : div-arg ( -- reg ) EAX ; : mod-arg ( -- reg ) EDX ; +: arg ( -- reg ) EAX ; : temp0 ( -- reg ) EAX ; : temp1 ( -- reg ) EDX ; : temp2 ( -- reg ) ECX ; diff --git a/basis/cpu/x86/64/unix/bootstrap.factor b/basis/cpu/x86/64/unix/bootstrap.factor index a21c4534d2..20a953b6d5 100644 --- a/basis/cpu/x86/64/unix/bootstrap.factor +++ b/basis/cpu/x86/64/unix/bootstrap.factor @@ -5,6 +5,7 @@ cpu.x86.assembler layouts vocabs parser ; IN: bootstrap.x86 : stack-frame-size ( -- n ) 4 bootstrap-cells ; +: arg ( -- reg ) RDI ; << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >> call diff --git a/basis/cpu/x86/64/winnt/bootstrap.factor b/basis/cpu/x86/64/winnt/bootstrap.factor index 709f138463..3accca400f 100644 --- a/basis/cpu/x86/64/winnt/bootstrap.factor +++ b/basis/cpu/x86/64/winnt/bootstrap.factor @@ -5,6 +5,7 @@ cpu.x86.assembler layouts vocabs parser ; IN: bootstrap.x86 : stack-frame-size ( -- n ) 8 bootstrap-cells ; +: arg ( -- reg ) RCX ; << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >> call diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index 3451da78e1..42fcfaa6a2 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -162,11 +162,11 @@ big-endian off ! Quotations and words [ ! load from stack - temp0 ds-reg [] MOV + arg ds-reg [] MOV ! pop stack ds-reg bootstrap-cell SUB ! call quotation - temp0 quot-xt-offset [+] JMP + arg quot-xt-offset [+] JMP ] f f f \ (call) define-sub-primitive [ diff --git a/basis/io/unix/epoll/epoll.factor b/basis/io/unix/epoll/epoll.factor index 05a9bcfa8d..e8d33787f3 100644 --- a/basis/io/unix/epoll/epoll.factor +++ b/basis/io/unix/epoll/epoll.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types kernel io.ports io.unix.backend -bit-arrays sequences assocs unix unix.linux.epoll math -namespaces unix.time ; +USING: accessors alien.c-types kernel io.ports io.unix.backend +bit-arrays sequences assocs struct-arrays math namespaces locals +fry unix unix.linux.epoll unix.time ; IN: io.unix.epoll TUPLE: epoll-mx < mx events ; @@ -14,47 +14,50 @@ TUPLE: epoll-mx < mx events ; : ( -- mx ) epoll-mx new-mx - max-events epoll_create dup io-error over set-mx-fd - max-events "epoll-event" over set-epoll-mx-events ; + max-events epoll_create dup io-error >>fd + max-events "epoll-event" >>events ; -GENERIC: io-task-events ( task -- n ) - -M: input-task io-task-events drop EPOLLIN ; - -M: output-task io-task-events drop EPOLLOUT ; - -: make-event ( task -- event ) +: make-event ( fd events -- event ) "epoll-event" - over io-task-events over set-epoll-event-events - swap io-task-fd over set-epoll-event-fd ; + [ set-epoll-event-events ] keep + [ set-epoll-event-fd ] keep ; -: do-epoll-ctl ( task mx what -- ) - >r mx-fd r> rot dup io-task-fd swap make-event - epoll_ctl io-error ; +:: do-epoll-ctl ( fd mx what events -- ) + mx fd>> what fd fd events make-event epoll_ctl io-error ; -M: epoll-mx register-io-task ( task mx -- ) - [ EPOLL_CTL_ADD do-epoll-ctl ] [ call-next-method ] 2bi ; +: do-epoll-add ( fd mx events -- ) + EPOLL_CTL_ADD swap EPOLLONESHOT bitor do-epoll-ctl ; -M: epoll-mx unregister-io-task ( task mx -- ) - [ call-next-method ] [ EPOLL_CTL_DEL do-epoll-ctl ] 2bi ; +: do-epoll-del ( fd mx events -- ) + EPOLL_CTL_DEL swap do-epoll-ctl ; -: wait-event ( mx timeout -- n ) - >r { mx-fd epoll-mx-events } get-slots max-events - r> epoll_wait dup multiplexer-error ; +M: epoll-mx add-input-callback ( thread fd mx -- ) + [ EPOLLIN do-epoll-add ] [ call-next-method ] 2bi ; -: epoll-read-task ( mx fd -- ) - over mx-reads at* [ perform-io-task ] [ 2drop ] if ; +M: epoll-mx add-output-callback ( thread fd mx -- ) + [ EPOLLOUT do-epoll-add ] [ call-next-method ] 2bi ; -: epoll-write-task ( mx fd -- ) - over mx-writes at* [ perform-io-task ] [ 2drop ] if ; +M: epoll-mx remove-input-callbacks ( fd mx -- seq ) + 2dup reads>> key? [ + [ call-next-method ] [ EPOLLIN do-epoll-del ] 2bi + ] [ 2drop f ] if ; -: handle-event ( mx kevent -- ) - epoll-event-fd 2dup epoll-read-task epoll-write-task ; +M: epoll-mx remove-output-callbacks ( fd mx -- seq ) + 2dup writes>> key? [ + [ EPOLLOUT do-epoll-del ] [ call-next-method ] 2bi + ] [ 2drop f ] if ; + +: wait-event ( mx us -- n ) + [ [ fd>> ] [ events>> ] bi [ underlying>> ] [ length ] bi ] [ 1000 /i ] bi* + epoll_wait dup multiplexer-error ; + +: handle-event ( event mx -- ) + [ epoll-event-fd ] dip + [ EPOLLIN EPOLLOUT bitor do-epoll-del ] + [ input-available ] [ output-available ] 2tri ; : handle-events ( mx n -- ) - [ - over epoll-mx-events epoll-event-nth handle-event - ] with each ; + [ dup events>> ] dip head-slice swap '[ _ handle-event ] each ; -M: epoll-mx wait-for-events ( ms mx -- ) - dup rot wait-event handle-events ; +M: epoll-mx wait-for-events ( us mx -- ) + swap 60000000 or dupd wait-event handle-events ; diff --git a/basis/io/unix/linux/linux.factor b/basis/io/unix/linux/linux.factor index e75f4c5f6b..be5b83f1b0 100644 --- a/basis/io/unix/linux/linux.factor +++ b/basis/io/unix/linux/linux.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel io.backend io.monitors io.unix.backend -io.unix.select io.unix.linux.monitors system namespaces ; +io.unix.epoll io.unix.linux.monitors system namespaces ; IN: io.unix.linux M: linux init-io ( -- ) - mx set-global ; + mx set-global ; linux set-io-backend diff --git a/basis/tools/files/files.factor b/basis/tools/files/files.factor index ab9ce01c3e..7968639d47 100755 --- a/basis/tools/files/files.factor +++ b/basis/tools/files/files.factor @@ -41,9 +41,9 @@ percent-used percent-free ; : file-system-spec ( file-system-info obj -- str ) { - { device-name [ device-name>> ] } - { mount-point [ mount-point>> ] } - { type [ type>> ] } + { device-name [ device-name>> [ "" ] unless* ] } + { mount-point [ mount-point>> [ "" ] unless* ] } + { type [ type>> [ "" ] unless* ] } { available-space [ available-space>> [ 0 ] unless* ] } { free-space [ free-space>> [ 0 ] unless* ] } { used-space [ used-space>> [ 0 ] unless* ] } @@ -63,7 +63,7 @@ percent-used percent-free ; [ [ unparse ] map ] bi prefix simple-table. ; : file-systems. ( -- ) - { device-name free-space used-space total-space percent-used } + { device-name free-space used-space total-space percent-used mount-point } print-file-systems ; { diff --git a/basis/unix/linux/epoll/epoll.factor b/basis/unix/linux/epoll/epoll.factor index c18fa2ee6c..72935807c3 100644 --- a/basis/unix/linux/epoll/epoll.factor +++ b/basis/unix/linux/epoll/epoll.factor @@ -18,14 +18,15 @@ FUNCTION: int epoll_wait ( int epfd, epoll_event* events, int maxevents, int tim : EPOLL_CTL_DEL 2 ; inline ! Remove a file decriptor from the interface. : EPOLL_CTL_MOD 3 ; inline ! Change file decriptor epoll_event structure. -: EPOLLIN HEX: 001 ; inline -: EPOLLPRI HEX: 002 ; inline -: EPOLLOUT HEX: 004 ; inline -: EPOLLRDNORM HEX: 040 ; inline -: EPOLLRDBAND HEX: 080 ; inline -: EPOLLWRNORM HEX: 100 ; inline -: EPOLLWRBAND HEX: 200 ; inline -: EPOLLMSG HEX: 400 ; inline -: EPOLLERR HEX: 008 ; inline -: EPOLLHUP HEX: 010 ; inline -: EPOLLET 31 2^ ; inline +: EPOLLIN HEX: 001 ; inline +: EPOLLPRI HEX: 002 ; inline +: EPOLLOUT HEX: 004 ; inline +: EPOLLRDNORM HEX: 040 ; inline +: EPOLLRDBAND HEX: 080 ; inline +: EPOLLWRNORM HEX: 100 ; inline +: EPOLLWRBAND HEX: 200 ; inline +: EPOLLMSG HEX: 400 ; inline +: EPOLLERR HEX: 008 ; inline +: EPOLLHUP HEX: 010 ; inline +: EPOLLONESHOT 30 2^ ; inline +: EPOLLET 31 2^ ; inline diff --git a/core/byte-arrays/byte-arrays-tests.factor b/core/byte-arrays/byte-arrays-tests.factor index 07b82f6111..edaea108a1 100644 --- a/core/byte-arrays/byte-arrays-tests.factor +++ b/core/byte-arrays/byte-arrays-tests.factor @@ -1,7 +1,10 @@ IN: byte-arrays.tests -USING: tools.test byte-arrays ; +USING: tools.test byte-arrays sequences kernel ; -[ B{ 1 2 3 0 0 0 } ] [ 6 B{ 1 2 3 } resize-byte-array ] unit-test +[ 6 B{ 1 2 3 } ] [ + 6 B{ 1 2 3 } resize-byte-array + [ length ] [ 3 head ] bi +] unit-test [ B{ 1 2 } ] [ 2 B{ 1 2 3 4 5 6 7 8 9 } resize-byte-array ] unit-test diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 8c9eff94f5..e364359928 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -845,9 +845,10 @@ PRIVATE> USE: arrays : array-length ( array -- len ) - { array } declare length>> ; + { array } declare length>> ; inline : array-flip ( matrix -- newmatrix ) + { array } declare [ dup first array-length [ array-length min ] reduce ] keep [ [ array-nth ] with { } map-as ] curry { } map-as ; diff --git a/extra/benchmark/benchmark.factor b/extra/benchmark/benchmark.factor index a1e892229a..9afd211876 100755 --- a/extra/benchmark/benchmark.factor +++ b/extra/benchmark/benchmark.factor @@ -6,8 +6,10 @@ continuations debugger math ; IN: benchmark : run-benchmark ( vocab -- result ) - [ [ require ] [ [ run ] benchmark ] bi ] curry - [ error. f ] recover ; + [ "=== " write vocab-name print flush ] [ + [ [ require ] [ [ run ] benchmark ] bi ] curry + [ error. f ] recover + ] bi ; : run-benchmarks ( -- assoc ) "benchmark" all-child-vocabs-seq