io.files.info io.files.temp kernel lexer math math.order
math.ranges multiline namespaces sequences source-files
splitting strings system vocabs.loader vocabs.parser words
- alien.c-types alien.structs make parser ;
+ alien.c-types alien.structs make parser continuations ;
IN: alien.inline
-<PRIVATE
SYMBOL: c-library
SYMBOL: library-is-c++
- SYMBOL: compiler-args
+ SYMBOL: linker-args
SYMBOL: c-strings
-: function-types-effect ( -- function types effect )
- scan scan swap ")" parse-tokens
- [ "(" subseq? not ] filter swap parse-arglist ;
-
+<PRIVATE
+ : cleanup-variables ( -- )
+ { c-library library-is-c++ linker-args c-strings }
+ [ off ] each ;
+
: arg-list ( types -- params )
CHAR: a swap length CHAR: a + [a,b]
[ 1string ] map ;
- : append-function-body ( prototype-str -- str )
- " {\n" append parse-here append "\n}\n" append ;
-: factor-function ( function types effect -- word quot effect )
- annotate-effect [ c-library get ] 3dip
- [ [ factorize-type ] map ] dip
- types-effect>params-return factorize-type -roll
- concat make-function ;
-
-: prototype-string ( function types effect -- str )
- [ [ cify-type ] map ] dip
- types-effect>params-return cify-type -rot
- [ " " join ] map ", " join
- "(" prepend ")" append 3array " " join
- library-is-c++ get [ "extern \"C\" " prepend ] when ;
-
-: prototype-string' ( function types return -- str )
- [ dup arg-list ] <effect> prototype-string ;
-
+ : append-function-body ( prototype-str body -- str )
+ [ swap % " {\n" % % "\n}\n" % ] "" make ;
: compile-library? ( -- ? )
c-library get library-path dup exists? [
: compile-library ( -- )
library-is-c++ get [ C++ ] [ C ] if
- compiler-args get
+ linker-args get
c-strings get "\n" join
c-library get compile-to-library ;
+
+ : c-library-name ( name -- name' )
+ [ current-vocab name>> % "_" % % ] "" make ;
PRIVATE>
- : c-function-string ( function types effect -- str )
+: function-types-effect ( -- function types effect )
+ scan scan swap ")" parse-tokens
+ [ "(" subseq? not ] filter swap parse-arglist ;
+
- library-is-c++ get [ "extern \"C\" " prepend ] when
- append-function-body ;
++: prototype-string ( function types effect -- str )
+ [ [ cify-type ] map ] dip
+ types-effect>params-return cify-type -rot
+ [ " " join ] map ", " join
+ "(" prepend ")" append 3array " " join
- : c-function-string' ( function types return -- str )
- [ dup arg-list ] <effect> c-function-string
- append-function-body ;
++ library-is-c++ get [ "extern \"C\" " prepend ] when ;
+
++: prototype-string' ( function types return -- str )
++ [ dup arg-list ] <effect> c-function-string ;
+
+: factor-function ( function types effect -- word quot effect )
+ annotate-effect [ c-library get ] 3dip
+ [ [ factorize-type ] map ] dip
+ types-effect>params-return factorize-type -roll
+ concat make-function ;
+
: define-c-library ( name -- )
- [ current-vocab name>> % "_" % % ] "" make c-library set
+ c-library-name c-library set
V{ } clone c-strings set
- V{ } clone compiler-args set ;
+ V{ } clone linker-args set ;
: compile-c-library ( -- )
compile-library? [ compile-library ] when