tests: do not use program_name for examples/socket_*.nit
[nit.git] / examples / extern_methods.nit.c
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2 *
3 * Copyright 2012 Alexis Laferrière <alexis.laf@xymus.net>
4 *
5 * This file is free software, which comes along with NIT. This software is
6 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 * is kept unaltered, and a notification of the changes is added.
10 * You are allowed to redistribute it and sell it, alone or is a part of
11 * another product.
12 */
13
14 #include "extern_methods.nit.h"
15
16 #include <math.h>
17
18 /*
19 C implementation of extern_methods::Int::fib
20 */
21 bigint Int_fib___impl( bigint recv ) {
22 if ( recv < 2 )
23 return recv;
24 else
25 return Int_fib___impl( recv-1 ) + Int_fib___impl( recv-2 );
26 }
27
28 /*
29 C implementation of extern_methods::Int::sleep
30 */
31 void Int_sleep___impl( bigint recv ) {
32 sleep( recv );
33 }
34
35 /*
36 C implementation of extern_methods::Int::atan_with
37 */
38 float Int_atan_with___impl( bigint recv, bigint x ) {
39 return atan2( recv, x );
40 }
41
42 /*
43 C implementation of extern_methods::Int::foo
44
45 Imported methods signatures:
46 bigint Int_fib( bigint recv ) for extern_methods::Int::fib
47 bigint Int__plus( bigint recv, bigint i ) for kernel::Int::(kernel::Discrete::+)
48 String Int_to_s( bigint recv ) for string::Int::(string::Object::to_s)
49 char * String_to_cstring( String recv ) for string::String::to_cstring
50 */
51 void Int_foo___impl( bigint recv ) {
52 bigint recv_fib = Int_fib( recv );
53 bigint recv_plus_fib = Int__plus( recv, recv_fib );
54
55 String nit_string = Int_to_s( recv_plus_fib );
56 char *c_string = String_to_cstring( nit_string );
57
58 printf( "from C: self + fib(self) = %s\n", c_string );
59 }
60