]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/size-of/size-of.factor
Update 'size-of' and move to extra from unmaintained
[factor.git] / unmaintained / size-of / size-of.factor
1
2 USING: kernel namespaces sequences
3        io io.files io.launcher io.encodings.ascii
4        bake builder.util
5        accessors vars
6        math.parser ;
7
8 IN: size-of
9
10 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11
12 VAR: headers
13
14 : include-headers ( -- seq )
15   headers> [ `{ "#include <" , ">" } to-string ] map ;
16
17 : size-of-c-program ( type -- lines )
18   `{
19     "#include <stdio.h>"
20     include-headers
21     { "main() { printf( \"%i\" , sizeof( " , " ) ) ; }" }
22   }
23   to-strings ;
24
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26
27 : c-file ( -- path ) "size-of.c" temp-file ;
28
29 : exe ( -- path ) "size-of" temp-file ;
30
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32
33 : size-of ( type -- n )
34   size-of-c-program c-file ascii set-file-lines
35
36   { "gcc" c-file "-o" exe } to-strings
37   [ "Error compiling generated C program" print ] run-or-bail
38
39   exe ascii <process-reader> contents string>number ;