2 USING: kernel namespaces sequences
3 io io.files io.launcher io.encodings.ascii
10 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 : include-headers ( -- seq )
15 headers> [ `{ "#include <" , ">" } to-string ] map ;
17 : size-of-c-program ( type -- lines )
21 { "main() { printf( \"%i\" , sizeof( " , " ) ) ; }" }
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 : c-file ( -- path ) "size-of.c" temp-file ;
29 : exe ( -- path ) "size-of" temp-file ;
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 : size-of ( type -- n )
34 size-of-c-program c-file ascii set-file-lines
36 { "gcc" c-file "-o" exe } to-strings
37 [ "Error compiling generated C program" print ] run-or-bail
39 exe ascii <process-reader> contents string>number ;