Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_ffi_c_more.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 in "C header" `{
18 #include <stdio.h>
19 `}
20
21 in "C" `{
22 void f( char *str ) {
23 printf( "%s\n", str );
24 }
25 `}
26
27 `{
28 void g() {
29 printf( "from C\n" );
30 }
31 `}
32
33 extern class A
34 new is extern `{ return malloc(1); `}
35 new new_implicit `{ return malloc(1); `}
36 new new_in_language is extern in "C" `{ return malloc(1); `}
37 new new_in_language_implicit in "C" `{ return malloc(1); `}
38
39 fun m : Int is extern `{ return 10; `}
40
41 fun n : String is extern import CString.to_s `{
42 return CString_to_s( "allo" );
43 `}
44
45 fun o ( str : String ) is extern import String.to_cstring `{
46 f( String_to_cstring( str ) );
47 `}
48
49 fun p : Int import m `{
50 return A_m( self ) + 5;
51 `}
52
53 fun in_language : Int is extern in "C" `{
54 return 4;
55 `}
56 fun in_language_implicit : Int in "C" `{
57 return 4;
58 `}
59 fun simple_implicit `{
60 g();
61 `}
62 fun inline_implicit : Int `{ return 7; `}
63 end
64
65 extern class B
66 super A
67 end
68
69 extern class C `{int*`}
70 end
71
72 extern class D
73 super C
74 end
75
76 extern class E
77 super C
78 end
79
80 var a = new A
81 print a.m
82 print a.n
83 a.o( "hello" )
84 print a.p