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

db4
Slava Pestov 2008-02-27 16:32:19 -06:00
commit fd54bbc4b3
7 changed files with 180 additions and 6 deletions

View File

@ -4,7 +4,7 @@ USING: kernel words namespaces classes parser continuations
math math.parser
combinators sequences splitting quotations arrays strings tools.time
parser-combinators new-slots accessors assocs.lib
combinators.cleave bake calendar ;
combinators.cleave bake calendar calendar.format ;
IN: builder.util

View File

@ -8,7 +8,9 @@ words combinators.lib db.types combinators tools.walker ;
IN: db.sqlite
TUPLE: sqlite-db path ;
C: <sqlite-db> sqlite-db
M: sqlite-db make-db* ( path db -- db )
[ set-sqlite-db-path ] keep ;
M: sqlite-db db-open ( db -- )
dup sqlite-db-path sqlite-open <db>
@ -19,9 +21,6 @@ M: sqlite-db db-close ( handle -- )
M: sqlite-db dispose ( db -- ) dispose-db ;
: with-sqlite ( path quot -- )
>r <sqlite-db> r> with-db ; inline
TUPLE: sqlite-statement ;
TUPLE: sqlite-result-set has-more? ;
@ -47,7 +46,6 @@ M: sqlite-result-set dispose ( result-set -- )
f swap set-result-set-handle ;
: sqlite-bind ( specs handle -- )
break
swap [ sqlite-bind-type ] with each ;
M: sqlite-statement bind-statement* ( obj statement -- )

View File

@ -0,0 +1,46 @@
USING: kernel namespaces sequences
io io.files io.launcher bake builder.util
accessors vars ;
IN: size-of
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
VAR: headers
: include-headers ( -- seq )
headers> [ { "#include <" , ">" } bake to-string ] map ;
: size-of-c-program ( type -- lines )
{
"#include <stdio.h>"
include-headers
{ "main() { printf( \"%i\\n\" , sizeof( " , " ) ) ; }" }
}
bake to-strings ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: c-file ( -- path ) "size-of.c" temp-file ;
: exe ( -- path ) "size-of" temp-file ;
: answer ( -- path ) "size-of-answer" temp-file ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: size-of ( type -- n )
c-file
[ size-of-c-program [ print ] each ]
with-file-writer
{ "gcc" c-file "-o" exe } to-strings
[ "Error compiling generated C program" print ] run-or-bail
<process*>
{ exe } to-strings >>arguments
answer >>stdout
>desc run-process drop
answer eval-file ;

View File

@ -0,0 +1,54 @@
USING: kernel alien.syntax math ;
IN: unix.stat
! Ubuntu 8.04 32-bit
C-STRUCT: stat
{ "dev_t" "st_dev" }
{ "ushort" "__pad1" }
{ "ino_t" "st_ino" }
{ "mode_t" "st_mode" }
{ "nlink_t" "st_nlink" }
{ "uid_t" "st_uid" }
{ "gid_t" "st_gid" }
{ "dev_t" "st_rdev" }
{ "ushort" "__pad2" }
{ "off_t" "st_size" }
{ "blksize_t" "st_blksize" }
{ "blkcnt_t" "st_blocks" }
{ "timespec" "st_atim" }
{ "timespec" "st_mtim" }
{ "timespec" "st_ctim" }
{ "ulong" "unused4" }
{ "ulong" "unused5" } ;
FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ;
FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ;
: stat ( pathname buf -- int ) 3 -rot __xstat ;
: lstat ( pathname buf -- int ) 3 -rot __lxstat ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: S_IFMT OCT: 170000 ; ! These bits determine file type.
: S_IFDIR OCT: 40000 ; ! Directory.
: S_IFCHR OCT: 20000 ; ! Character device.
: S_IFBLK OCT: 60000 ; ! Block device.
: S_IFREG OCT: 100000 ; ! Regular file.
: S_IFIFO OCT: 010000 ; ! FIFO.
: S_IFLNK OCT: 120000 ; ! Symbolic link.
: S_IFSOCK OCT: 140000 ; ! Socket.
: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ;
: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ;
: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ;
: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ;
: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ;
: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ;
: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ;
: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ;

View File

@ -0,0 +1,54 @@
USING: kernel alien.syntax math ;
IN: unix.stat
! Ubuntu 7.10 64-bit
C-STRUCT: stat
{ "dev_t" "st_dev" }
{ "ino_t" "st_ino" }
{ "nlink_t" "st_nlink" }
{ "mode_t" "st_mode" }
{ "uid_t" "st_uid" }
{ "gid_t" "st_gid" }
{ "int" "pad0" }
{ "dev_t" "st_rdev" }
{ "off_t" "st_size" }
{ "blksize_t" "st_blksize" }
{ "blkcnt_t" "st_blocks" }
{ "timespec" "st_atim" }
{ "timespec" "st_mtim" }
{ "timespec" "st_ctim" }
{ "long" "__unused0" }
{ "long" "__unused1" }
{ "long" "__unused2" } ;
FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ;
FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ;
: stat ( pathname buf -- int ) 3 -rot __xstat ;
: lstat ( pathname buf -- int ) 3 -rot __lxstat ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: S_IFMT OCT: 170000 ; ! These bits determine file type.
: S_IFDIR OCT: 40000 ; ! Directory.
: S_IFCHR OCT: 20000 ; ! Character device.
: S_IFBLK OCT: 60000 ; ! Block device.
: S_IFREG OCT: 100000 ; ! Regular file.
: S_IFIFO OCT: 010000 ; ! FIFO.
: S_IFLNK OCT: 120000 ; ! Symbolic link.
: S_IFSOCK OCT: 140000 ; ! Socket.
: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ;
: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ;
: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ;
: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ;
: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ;
: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ;
: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ;
: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ;

View File

@ -0,0 +1,11 @@
USING: system combinators vocabs.loader ;
IN: unix.stat
cell-bits
{
{ 32 [ "unix.stat.linux.32" require ] }
{ 64 [ "unix.stat.linux.64" require ] }
}
case

View File

@ -0,0 +1,11 @@
USING: system combinators vocabs.loader ;
IN: unix.stat
{
{ [ linux? ] [ "unix.stat.linux" require ] }
{ [ t ] [ ] }
}
cond