Merge branch 'inlinec' into marshall
* inlinec: alien.inline.tests: delete libraries before compilation alien.inline: added C-STRUCTURE: alien.inline: added C-TYPEDEF:db4
commit
5cacaf3524
basis/alien/inline
|
@ -1,23 +1,50 @@
|
|||
! Copyright (C) 2009 Jeremy Hughes.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.inline alien.inline.private io.directories io.files
|
||||
kernel namespaces tools.test ;
|
||||
kernel namespaces tools.test alien.c-types alien.structs ;
|
||||
IN: alien.inline.tests
|
||||
|
||||
C-LIBRARY: const
|
||||
DELETE-C-LIBRARY: test
|
||||
C-LIBRARY: test
|
||||
|
||||
C-FUNCTION: const-int add ( int a, int b )
|
||||
return a + b;
|
||||
;
|
||||
|
||||
C-TYPEDEF: double bigfloat
|
||||
|
||||
C-FUNCTION: bigfloat smaller ( bigfloat a )
|
||||
return a / 10;
|
||||
;
|
||||
|
||||
C-STRUCTURE: rectangle
|
||||
{ "int" "width" }
|
||||
{ "int" "height" } ;
|
||||
|
||||
C-FUNCTION: int area ( rectangle c )
|
||||
return c.width * c.height;
|
||||
;
|
||||
|
||||
;C-LIBRARY
|
||||
|
||||
{ 2 1 } [ add ] must-infer-as
|
||||
[ 5 ] [ 2 3 add ] unit-test
|
||||
|
||||
DELETE-C-LIBRARY: const
|
||||
[ t ] [ "double" "bigfloat" [ resolve-typedef ] bi@ = ] unit-test
|
||||
{ 1 1 } [ smaller ] must-infer-as
|
||||
[ 1.0 ] [ 10 smaller ] unit-test
|
||||
|
||||
[ t ] [ "rectangle" resolve-typedef struct-type? ] unit-test
|
||||
{ 1 1 } [ area ] must-infer-as
|
||||
[ 20 ] [
|
||||
"rectangle" <c-object>
|
||||
4 over set-rectangle-width
|
||||
5 over set-rectangle-height
|
||||
area
|
||||
] unit-test
|
||||
|
||||
|
||||
DELETE-C-LIBRARY: cpplib
|
||||
C-LIBRARY: cpplib
|
||||
|
||||
COMPILE-AS-C++
|
||||
|
@ -34,9 +61,8 @@ C-FUNCTION: const-char* hello ( )
|
|||
{ 0 1 } [ hello ] must-infer-as
|
||||
[ "hello world" ] [ hello ] unit-test
|
||||
|
||||
DELETE-C-LIBRARY: cpplib
|
||||
|
||||
|
||||
DELETE-C-LIBRARY: compile-error
|
||||
C-LIBRARY: compile-error
|
||||
|
||||
C-FUNCTION: char* breakme ( )
|
||||
|
@ -44,5 +70,3 @@ C-FUNCTION: char* breakme ( )
|
|||
;
|
||||
|
||||
<< [ compile-c-library ] must-fail >>
|
||||
|
||||
DELETE-C-LIBRARY: compile-error
|
||||
|
|
|
@ -5,7 +5,8 @@ alien.libraries alien.parser arrays assocs effects fry
|
|||
generalizations grouping io.directories io.files
|
||||
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 ;
|
||||
splitting strings system vocabs.loader vocabs.parser words
|
||||
alien.c-types alien.structs make parser ;
|
||||
IN: alien.inline
|
||||
|
||||
SYMBOL: c-library
|
||||
|
@ -87,6 +88,22 @@ PRIVATE>
|
|||
: define-c-include ( str -- )
|
||||
"#include " prepend c-strings get push ;
|
||||
|
||||
: define-c-typedef ( old new -- )
|
||||
[ typedef ] [
|
||||
[ swap "typedef " % % " " % % ";" % ]
|
||||
"" make c-strings get push
|
||||
] 2bi ;
|
||||
|
||||
: define-c-struct ( name vocab fields -- )
|
||||
[ define-struct ] [
|
||||
nip over
|
||||
[
|
||||
"typedef struct " % "_" % % " {\n" %
|
||||
[ first2 swap % " " % % ";\n" % ] each
|
||||
"} " % % ";\n" %
|
||||
] "" make c-strings get push
|
||||
] 3bi ;
|
||||
|
||||
: delete-inline-library ( str -- )
|
||||
library-path dup exists? [ delete-file ] [ drop ] if ;
|
||||
|
||||
|
@ -105,6 +122,11 @@ SYNTAX: C-INCLUDE: scan define-c-include ;
|
|||
SYNTAX: C-FUNCTION:
|
||||
function-types-effect define-c-function ;
|
||||
|
||||
SYNTAX: C-TYPEDEF: scan scan define-c-typedef ;
|
||||
|
||||
SYNTAX: C-STRUCTURE:
|
||||
scan current-vocab parse-definition define-c-struct ;
|
||||
|
||||
SYNTAX: ;C-LIBRARY compile-c-library ;
|
||||
|
||||
SYNTAX: DELETE-C-LIBRARY: scan delete-inline-library ;
|
||||
|
|
Loading…
Reference in New Issue