<commit_before>! Copyright (C) 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators fry generalizations
io.encodings.ascii io.files io.files.temp io.launcher kernel
locals sequences system ;
IN: alien.inline.compiler

SYMBOL: C
SYMBOL: C++

: library-suffix ( -- str )
    os {
        { [ dup macosx? ]  [ drop ".dylib" ] }
        { [ dup unix? ]    [ drop ".so" ] }
        { [ dup windows? ] [ drop ".dll" ] }
    } cond ;

: src-suffix ( lang -- str )
    {
        { C [ ".c" ] }
        { C++ [ ".cpp" ] }
    } case ;

: compiler ( lang -- str )
    {
        { C [ "gcc" ] }
        { C++ [ "g++" ] }
    } case ;

: link-command ( in out lang -- descr )
    compiler os {
        { [ dup linux? ]
          [ drop { "-shared" "-o" } ] }
        { [ dup macosx? ]
          [ drop { "-g" "-prebind" "-dynamiclib" "-o" } ] }
        [ name>> "unimplemented for: " prepend throw ]
    } cond swap prefix prepend prepend ;

:: compile-to-object ( lang contents name -- )
    name ".o" append temp-file
    contents name lang src-suffix append temp-file
    [ ascii set-file-contents ] keep 2array
    { "-fPIC" "-c" "-o" } lang compiler prefix prepend
    try-process ;

:: link-object ( lang args name -- )
    args name [ "lib" prepend library-suffix append ]
    [ ".o" append ] bi [ temp-file ] bi@ 2array
    lang link-command try-process ;

:: compile-to-library ( lang args contents name -- )
    lang contents name compile-to-object
    lang args name link-object ;<commit_msg>alien.inline.compiler: x86_64 check and hook methods<commit_after>! Copyright (C) 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators fry generalizations
io.encodings.ascii io.files io.files.temp io.launcher kernel
locals sequences system words ;
IN: alien.inline.compiler

SYMBOL: C
SYMBOL: C++

: library-suffix ( -- str )
    os {
        { [ dup macosx? ]  [ drop ".dylib" ] }
        { [ dup unix? ]    [ drop ".so" ] }
        { [ dup windows? ] [ drop ".dll" ] }
    } cond ;

: src-suffix ( lang -- str )
    {
        { C [ ".c" ] }
        { C++ [ ".cpp" ] }
    } case ;

: compiler ( lang -- str )
    {
        { C [ "gcc" ] }
        { C++ [ "g++" ] }
    } case ;

HOOK: compiler-descr os ( lang -- descr )

M: word compiler-descr compiler 1array ;
M: macosx compiler-descr
    call-next-method cpu x86.64?
    [ { "-arch" "x86_64" } append ] when ;

HOOK: link-descr os ( -- descr )

M: word link-descr { "-shared" "-o" } ;
M: macosx link-descr
    { "-g" "-prebind" "-dynamiclib" "-o" }
    cpu x86.64? [ { "-arch" "x86_64" } prepend ] when ;

: link-command ( in out lang -- descr )
    compiler-descr link-descr append prepend prepend ;

:: compile-to-object ( lang contents name -- )
    name ".o" append temp-file
    contents name lang src-suffix append temp-file
    [ ascii set-file-contents ] keep 2array
    lang compiler-descr { "-fPIC" "-c" "-o" } append prepend
    try-process ;

:: link-object ( lang args name -- )
    args name [ "lib" prepend library-suffix append ]
    [ ".o" append ] bi [ temp-file ] bi@ 2array
    lang link-command try-process ;

:: compile-to-library ( lang args contents name -- )
    lang contents name compile-to-object
    lang args name link-object ;
{'fraction_non_alphanumeric': 0.1537764350453172, 'fraction_numerical': 0.009969788519637462, 'mean_word_length': 2.195945945945946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7048274', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1118, 'n_words': 327}