From: Alexis Laferrière Date: Thu, 18 Aug 2011 18:15:58 +0000 (-0400) Subject: tests: adds native interface tests X-Git-Tag: v0.5~31^2~16 X-Git-Url: http://nitlanguage.org tests: adds native interface tests Signed-off-by: Alexis Laferrière --- diff --git a/tests/sav/test_ni_accessor.sav b/tests/sav/test_ni_accessor.sav new file mode 100644 index 0000000..06a4146 --- /dev/null +++ b/tests/sav/test_ni_accessor.sav @@ -0,0 +1,4 @@ +r rw +r rw set from native +rw set from native +set from native diff --git a/tests/sav/test_ni_cast_simple.sav b/tests/sav/test_ni_cast_simple.sav new file mode 100644 index 0000000..86e041d --- /dev/null +++ b/tests/sav/test_ni_cast_simple.sav @@ -0,0 +1,3 @@ +foo +bar +baz diff --git a/tests/sav/test_ni_fibonacci.sav b/tests/sav/test_ni_fibonacci.sav new file mode 100644 index 0000000..310b228 --- /dev/null +++ b/tests/sav/test_ni_fibonacci.sav @@ -0,0 +1,8 @@ +0 +1 +5 +144 +0 +1 +5 +144 diff --git a/tests/sav/test_ni_import_init.sav b/tests/sav/test_ni_import_init.sav new file mode 100644 index 0000000..0d8f9dd --- /dev/null +++ b/tests/sav/test_ni_import_init.sav @@ -0,0 +1,2 @@ +100==100 +33==33 diff --git a/tests/sav/test_ni_import_meth.sav b/tests/sav/test_ni_import_meth.sav new file mode 100644 index 0000000..def9538 --- /dev/null +++ b/tests/sav/test_ni_import_meth.sav @@ -0,0 +1,4 @@ +nity +nity +nity1 3 +nity2 7 13 diff --git a/tests/sav/test_ni_new.sav b/tests/sav/test_ni_new.sav new file mode 100644 index 0000000..5979542 --- /dev/null +++ b/tests/sav/test_ni_new.sav @@ -0,0 +1,7 @@ +a +a +allo from 1234 +allo from 2345 +allo from 3456 +allo from 1234 +allo from 1234 diff --git a/tests/sav/test_ni_null.sav b/tests/sav/test_ni_null.sav new file mode 100644 index 0000000..2cd94a1 --- /dev/null +++ b/tests/sav/test_ni_null.sav @@ -0,0 +1,7 @@ +true -? true +false -? false +false -? false +true -? true +false -? false +is null, ok +something diff --git a/tests/sav/test_ni_operators.sav b/tests/sav/test_ni_operators.sav new file mode 100644 index 0000000..ad8f392 --- /dev/null +++ b/tests/sav/test_ni_operators.sav @@ -0,0 +1,25 @@ +11 +9 +22 +3 +false +false +false +false +true +3 +4096 +true +false +false +false +false +true +true +true +false +false +true +true +52 +456 diff --git a/tests/sav/test_ni_out.sav b/tests/sav/test_ni_out.sav new file mode 100644 index 0000000..f67ecaf --- /dev/null +++ b/tests/sav/test_ni_out.sav @@ -0,0 +1,5 @@ +1 +2 +3 +3 +hello world diff --git a/tests/sav/test_ni_pointer.sav b/tests/sav/test_ni_pointer.sav new file mode 100644 index 0000000..190a180 --- /dev/null +++ b/tests/sav/test_ni_pointer.sav @@ -0,0 +1 @@ +123 diff --git a/tests/sav/test_ni_primitives.sav b/tests/sav/test_ni_primitives.sav new file mode 100644 index 0000000..c68bddc --- /dev/null +++ b/tests/sav/test_ni_primitives.sav @@ -0,0 +1,6 @@ +false +true +k +2234 +12345.0 +hello world diff --git a/tests/sav/test_ni_special_all_native.sav b/tests/sav/test_ni_special_all_native.sav new file mode 100644 index 0000000..35d242b --- /dev/null +++ b/tests/sav/test_ni_special_all_native.sav @@ -0,0 +1,2 @@ +A +B diff --git a/tests/sav/test_ni_special_from_native.sav b/tests/sav/test_ni_special_from_native.sav new file mode 100644 index 0000000..6fa5513 --- /dev/null +++ b/tests/sav/test_ni_special_from_native.sav @@ -0,0 +1,8 @@ +a from nit +A +a from extern +A +a from nit +B +a from extern +B diff --git a/tests/sav/test_ni_special_pointer.sav b/tests/sav/test_ni_special_pointer.sav new file mode 100644 index 0000000..3697126 --- /dev/null +++ b/tests/sav/test_ni_special_pointer.sav @@ -0,0 +1,4 @@ +0 +1 +2 +1234 diff --git a/tests/sav/test_ni_special_to_native.sav b/tests/sav/test_ni_special_to_native.sav new file mode 100644 index 0000000..c03e006 --- /dev/null +++ b/tests/sav/test_ni_special_to_native.sav @@ -0,0 +1,6 @@ +A +A from native +B +B from native +B +B from native diff --git a/tests/sav/test_ni_strings.sav b/tests/sav/test_ni_strings.sav new file mode 100644 index 0000000..4dad352 --- /dev/null +++ b/tests/sav/test_ni_strings.sav @@ -0,0 +1,5 @@ +hello world... +hello world? +hello world! +something +9 diff --git a/tests/sav/test_ni_super.sav b/tests/sav/test_ni_super.sav new file mode 100644 index 0000000..71acf9f --- /dev/null +++ b/tests/sav/test_ni_super.sav @@ -0,0 +1,2 @@ +A +B special A diff --git a/tests/test_ni_accessor.nit b/tests/test_ni_accessor.nit new file mode 100644 index 0000000..6f2a5d3 --- /dev/null +++ b/tests/test_ni_accessor.nit @@ -0,0 +1,36 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + readable var _r : String = "r" + writable var _w : String = "w" + readable writable var _rw : String = "rw" + + fun print_all is extern import String::to_cstring, r, rw + fun modify is extern import String::from_cstring, w=, rw= +end + +class B + fun print_and_modify( a : A ) is extern import A::rw, A::rw=, String::to_cstring, String::from_cstring +end + +var a = new A +a.print_all +a.modify +a.print_all + +var b = new B +b.print_and_modify( a ) diff --git a/tests/test_ni_accessor.nit.c b/tests/test_ni_accessor.nit.c new file mode 100644 index 0000000..e41a6a7 --- /dev/null +++ b/tests/test_ni_accessor.nit.c @@ -0,0 +1,59 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_accessor.nit.h" + +/* +C implementation of test_ni_accessor::A::print_all + +Imported methods signatures: + char * String_to_cstring( String recv ) for string::String::to_cstring + String A_r( A recv ) for test_ni_accessor::A::r + String A_rw( A recv ) for test_ni_accessor::A::rw +*/ +void A_print_all___impl( A recv ) +{ + printf( "%s %s\n", + String_to_cstring( A_r( recv ) ), + String_to_cstring( A_rw( recv ) ) ); +} + +/* +C implementation of test_ni_accessor::A::modify + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring + void A_w__eq( A recv, String w ) for test_ni_accessor::A::w= + void A_rw__eq( A recv, String rw ) for test_ni_accessor::A::rw= +*/ +void A_modify___impl( A recv ) +{ + A_w__assign( recv, new_String_from_cstring( "w set from native" ) ); + A_rw__assign( recv, new_String_from_cstring( "rw set from native" ) ); +} + +/* +C implementation of test_ni_accessor::B::print_and_modify + +Imported methods signatures: + String A_rw( A recv ) for test_ni_accessor::A::rw + void A_rw__assign( A recv, String value ) for test_ni_accessor::A::rw= + char * String_to_cstring( String recv ) for string::String::to_cstring + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +void B_print_and_modify___impl( B recv, A a ) +{ + printf( "%s\n", String_to_cstring( A_rw( a ) ) ); + A_rw__assign( a, new_String_from_cstring( "set from native" ) ); + printf( "%s\n", String_to_cstring( A_rw( a ) ) ); +} diff --git a/tests/test_ni_accessor.nit.h b/tests/test_ni_accessor.nit.h new file mode 100644 index 0000000..02c81e8 --- /dev/null +++ b/tests/test_ni_accessor.nit.h @@ -0,0 +1,23 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_accessor_IMPL_NIT_H +#define test_ni_accessor_IMPL_NIT_H + +#include + +void A_print_all___impl( A recv ); +void A_modify___impl( A recv ); +void B_print_and_modify___impl( B recv, A a ); + +#endif diff --git a/tests/test_ni_cast_extra.nit b/tests/test_ni_cast_extra.nit new file mode 100644 index 0000000..b8f0274 --- /dev/null +++ b/tests/test_ni_cast_extra.nit @@ -0,0 +1,52 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun isa_b : Bool is extern import A as(B) + fun as_b : nullable B is extern import A as(B), A as(nullable B) +end + +class B +end + +class C +special A + fun isa_a : Bool is extern import C as(A) +end + +class D # triangle +special A +special B + init do end + fun as_a : A is extern import D as(A) +end + +# isa +var a = new A +var c = new C +var d = new D + +print "a isa b {a.isa_b} (expected: false)" +print "c isa a {c.isa_a} (expected: true)" +print "d isa b {d.isa_b} (expected: true)" + +var da = d.as_a +var db = d.as_b +var ab = a.as_b + +print "da is null? {da==null} (expected: false)" +print "db is null? {db==null} (expected: false)" +print "ab is null? {ab==null} (expected: true)" diff --git a/tests/test_ni_cast_extra.nit.c b/tests/test_ni_cast_extra.nit.c new file mode 100644 index 0000000..31a736c --- /dev/null +++ b/tests/test_ni_cast_extra.nit.c @@ -0,0 +1,67 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_cast_extra.nit.h" + +/* +C implementation of test_ni_cast_extra::A::isa_b + +Imported methods signatures: + int A_is_a_B( A value ) to check if a A is a B + B A_as_B( A value ) to cast from A to B +*/ +int A_isa_b___impl( A recv ) +{ + return A_is_a_B( recv ); +} + +/* +C implementation of test_ni_cast_extra::A::as_b + +Imported methods signatures: + int A_is_a_B( A value ) to check if a A is a B + B A_as_B( A value ) to cast from A to B + int A_is_a_nullable_B( A value ) to check if a A is a nullable B + nullable_B A_as_nullable_B( A value ) to cast from A to nullable B +*/ +nullable_B A_as_b___impl( A recv ) +{ + if ( A_is_a_nullable_B( recv ) ) + return A_as_nullable_B( recv ); + else + return null_B(); +} + +/* +C implementation of test_ni_cast_extra::C::isa_a + +Imported methods signatures: + int C_is_a_A( C value ) to check if a C is a A + A C_as_A( C value ) to cast from C to A +*/ +int C_isa_a___impl( C recv ) +{ + return C_is_a_A( recv ); +} + +/* +C implementation of test_ni_cast_extra::D::as_a + +Imported methods signatures: + int D_is_a_A( D value ) to check if a D is a A + A D_as_A( D value ) to cast from D to A +*/ +A D_as_a___impl( D recv ) +{ + return D_as_A( recv ); +} diff --git a/tests/test_ni_cast_extra.nit.h b/tests/test_ni_cast_extra.nit.h new file mode 100644 index 0000000..dfc7cff --- /dev/null +++ b/tests/test_ni_cast_extra.nit.h @@ -0,0 +1,24 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_cast_extra_IMPL_NIT_H +#define test_ni_cast_extra_IMPL_NIT_H + +#include + +int A_isa_b___impl( A recv ); +nullable_B A_as_b___impl( A recv ); +int C_isa_a___impl( C recv ); +A D_as_a___impl( D recv ); + +#endif diff --git a/tests/test_ni_cast_simple.nit b/tests/test_ni_cast_simple.nit new file mode 100644 index 0000000..f6c5824 --- /dev/null +++ b/tests/test_ni_cast_simple.nit @@ -0,0 +1,35 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +fun s_to_o( s : String ) : Object is extern import String as ( Object ) + +fun n_to_nn( s : String ) : nullable String is extern import String as nullable +fun nn_to_n( s : nullable String ) : String is extern import nullable String as not nullable + +var o = s_to_o( "foo" ) +var nn = n_to_nn( "bar" ) +var n = nn_to_n( "baz" ) + +print o + +if nn == null +then + print "null (not good)" +else + print nn +end + +print n diff --git a/tests/test_ni_cast_simple.nit.c b/tests/test_ni_cast_simple.nit.c new file mode 100644 index 0000000..633f40a --- /dev/null +++ b/tests/test_ni_cast_simple.nit.c @@ -0,0 +1,49 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_cast_simple.nit.h" + +/* +C implementation of test_ni_cast_simple::Object::s_to_o + +Imported methods signatures: + int String_is_a_Object( String value ) to check if a String is a Object + Object String_as_Object( String value ) to cast from String to Object +*/ +Object Object_s_to_o___impl( Object recv, String s ) +{ + return String_as_Object( s ); +} + +/* +C implementation of test_ni_cast_simple::Object::n_to_nn + +Imported methods signatures: + nullable_String String_as_nullable( String value ) to cast from String to nullable String +*/ +nullable_String Object_n_to_nn___impl( Object recv, String s ) +{ + return String_as_nullable( s ); +} + +/* +C implementation of test_ni_cast_simple::Object::nn_to_n + +Imported methods signatures: + int String_is_null( nullable_String value ) to check if a nullable String is a String + String nullable_String_as_not_null( nullable_String value ) to cast from nullable String to String +*/ +String Object_nn_to_n___impl( Object recv, nullable_String s ) +{ + return String_as_not_null( s ); +} diff --git a/tests/test_ni_cast_simple.nit.h b/tests/test_ni_cast_simple.nit.h new file mode 100644 index 0000000..42793ea --- /dev/null +++ b/tests/test_ni_cast_simple.nit.h @@ -0,0 +1,23 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_cast_simple_IMPL_NIT_H +#define test_ni_cast_simple_IMPL_NIT_H + +#include + +Object Object_s_to_o___impl( Object recv, String s ); +nullable_String Object_n_to_nn___impl( Object recv, String s ); +String Object_nn_to_n___impl( Object recv, nullable_String s ); + +#endif diff --git a/tests/test_ni_casts.nit.c b/tests/test_ni_casts.nit.c new file mode 100644 index 0000000..084c6cf --- /dev/null +++ b/tests/test_ni_casts.nit.c @@ -0,0 +1,49 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_casts.nit.h" + +/* +C implementation of test_ni_casts::Object::a + +Imported methods signatures: + int String_is_a_Object( String value ) to check if a String is a Object + Object String_as_Object( String value ) to cast from String to Object +*/ +Object Object_a___impl( Object recv, String s ) +{ + return String_as_Object( s ); +} + +/* +C implementation of test_ni_casts::Object::b + +Imported methods signatures: + nullable_String String_as_nullable( String value ) to cast from String to nullable String +*/ +nullable_String Object_b___impl( Object recv, String s ) +{ + return String_as_nullable( s ); +} + +/* +C implementation of test_ni_casts::Object::c + +Imported methods signatures: + int nullable_String_is_null( nullable_String value ) to check if a nullable String is a String + String nullable_String_as_not_null( nullable_String value ) to cast from nullable String to String +*/ +String Object_c___impl( Object recv, nullable_String s ) +{ + return nullable_String_as_not_null( s ); +} diff --git a/tests/test_ni_casts.nit.h b/tests/test_ni_casts.nit.h new file mode 100644 index 0000000..0592b25 --- /dev/null +++ b/tests/test_ni_casts.nit.h @@ -0,0 +1,23 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_casts_IMPL_NIT_H +#define test_ni_casts_IMPL_NIT_H + +#include + +Object Object_a___impl( Object recv, String s ); +nullable_String Object_b___impl( Object recv, String s ); +String Object_c___impl( Object recv, nullable_String s ); + +#endif diff --git a/tests/test_ni_extern_inheritance.nit b/tests/test_ni_extern_inheritance.nit new file mode 100644 index 0000000..1909004 --- /dev/null +++ b/tests/test_ni_extern_inheritance.nit @@ -0,0 +1,55 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +extern A + fun f is extern +end + +extern B + super A + + redef fun f is extern +end + +extern C + super B + + redef fun f is extern +end + +extern D + super A + super B + + redef fun f is extern +end + +extern E + super B + super D + + redef fun f is extern +end + +extern F +end + +extern G + super B + super F + + redef fun f is extern +end diff --git a/tests/test_ni_extern_inheritance.nit.c b/tests/test_ni_extern_inheritance.nit.c new file mode 100644 index 0000000..31a8296 --- /dev/null +++ b/tests/test_ni_extern_inheritance.nit.c @@ -0,0 +1,44 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_extern_inheritance.nit.h" + +/* +C implementation of test_ni_extern_inheritance::A::f +*/ +void A_f___impl( void* recv ) {} + +/* +C implementation of test_ni_extern_inheritance::B::(test_ni_extern_inheritance::A::f) +*/ +void B_f___impl( void* recv ) {} + +/* +C implementation of test_ni_extern_inheritance::C::(test_ni_extern_inheritance::A::f) +*/ +void C_f___impl( void* recv ) {} + +/* +C implementation of test_ni_extern_inheritance::D::(test_ni_extern_inheritance::A::f) +*/ +void D_f___impl( void* recv ) {} + +/* +C implementation of test_ni_extern_inheritance::E::(test_ni_extern_inheritance::A::f) +*/ +void E_f___impl( void* recv ) {} + +/* +C implementation of test_ni_extern_inheritance::G::(test_ni_extern_inheritance::A::f) +*/ +void G_f___impl( void* recv ) {} diff --git a/tests/test_ni_extern_inheritance.nit.h b/tests/test_ni_extern_inheritance.nit.h new file mode 100644 index 0000000..b7b8d57 --- /dev/null +++ b/tests/test_ni_extern_inheritance.nit.h @@ -0,0 +1,25 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef TEST_NI_EXTERN_INHERITANCE_NIT_H +#define TEST_NI_EXTERN_INHERITANCE_NIT_H + +#include + +void A_f___impl( void* recv ); +void B_f___impl( void* recv ); +void C_f___impl( void* recv ); +void D_f___impl( void* recv ); +void E_f___impl( void* recv ); +void G_f___impl( void* recv ); +#endif diff --git a/tests/test_ni_fibonacci.nit b/tests/test_ni_fibonacci.nit new file mode 100644 index 0000000..155add3 --- /dev/null +++ b/tests/test_ni_fibonacci.nit @@ -0,0 +1,36 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class FibonacciEngine + fun fibonacci( n : Int ) : Int is extern import fibonacci +end + +redef class Int + fun fibonacci : Int is extern import fibonacci +end + +var engine = new FibonacciEngine +print engine.fibonacci( 0 ) +print engine.fibonacci( 1 ) +print engine.fibonacci( 5 ) +print engine.fibonacci( 12 ) +# print engine.fibonacci( 123 ) + +print 0.fibonacci +print 1.fibonacci +print 5.fibonacci +print 12.fibonacci +# print 123.fibonacci diff --git a/tests/test_ni_fibonacci.nit.c b/tests/test_ni_fibonacci.nit.c new file mode 100644 index 0000000..c0141a9 --- /dev/null +++ b/tests/test_ni_fibonacci.nit.c @@ -0,0 +1,47 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_fibonacci.nit.h" + + +/* +C implementation of fibonacci::FibonacciEngine::fibonacci + +Imported methods signatures: + bigint FibonacciEngine_fibonacci( FibonacciEngine recv, bigint n ) for fibonacci::FibonacciEngine::fibonacci +*/ +bigint FibonacciEngine_fibonacci___impl( FibonacciEngine recv, bigint n ) +{ + if ( n == 0 ) + return 0; + if ( n == 1 ) + return 1; + else + return FibonacciEngine_fibonacci( recv, n-1 ) + FibonacciEngine_fibonacci( recv, n-2 ); +} + +/* +C implementation of fibonacci::Int::fibonacci + +Imported methods signatures: + bigint Int_fibonacci( bigint recv ) for fibonacci::Int::fibonacci +*/ +bigint Int_fibonacci___impl( bigint recv ) +{ + if ( recv == 0 ) + return 0; + else if ( recv == 1 ) + return 1; + else + return Int_fibonacci( recv-1 ) + Int_fibonacci( recv-2 ); +} diff --git a/tests/test_ni_fibonacci.nit.h b/tests/test_ni_fibonacci.nit.h new file mode 100644 index 0000000..a834646 --- /dev/null +++ b/tests/test_ni_fibonacci.nit.h @@ -0,0 +1,22 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef fibonacci_NIT_H +#define fibonacci_NIT_H + +#include + +bigint FibonacciEngine_fibonacci___impl( FibonacciEngine recv, bigint n ); +bigint Int_fibonacci___impl( bigint recv ); + +#endif diff --git a/tests/test_ni_import_init.nit b/tests/test_ni_import_init.nit new file mode 100644 index 0000000..f7ecbc9 --- /dev/null +++ b/tests/test_ni_import_init.nit @@ -0,0 +1,40 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class B + var _i : Int = 0 + + init do end + + init from( i : Int ) + do + _i = i + end + + fun i : Int do return _i end +end + +class A + fun ex_sees_b_attr( b : B ) : Int is extern import B::i + + fun ex_sees_b_init( i : Int ) : B is extern import B, B::from +end + +var a = new A +var b100 = new B.from( 100 ) + +print "100=={a.ex_sees_b_attr( b100 )}" +print "33=={a.ex_sees_b_init( 33 ).i}" diff --git a/tests/test_ni_import_init.nit.c b/tests/test_ni_import_init.nit.c new file mode 100644 index 0000000..2aba0b1 --- /dev/null +++ b/tests/test_ni_import_init.nit.c @@ -0,0 +1,37 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_import_init.nit.h" + +/* +C implementation of acces::A::ex_sees_b_attr + +Imported methods signatures: + bigint B_i( B recv ) for acces::B::i +*/ +bigint A_ex_sees_b_attr___impl( A recv, B b ) +{ + return B_i( b ); +} + +/* +C implementation of acces::A::ex_sees_b_init + +Imported methods signatures: + void new_B( ) for acces::B::init + void new_B_from( bigint i ) for acces::B::from +*/ +B A_ex_sees_b_init___impl( A recv, bigint i ) +{ + return new_B_from( i ); +} diff --git a/tests/test_ni_import_init.nit.h b/tests/test_ni_import_init.nit.h new file mode 100644 index 0000000..bce9903 --- /dev/null +++ b/tests/test_ni_import_init.nit.h @@ -0,0 +1,22 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef acces_NIT_H +#define acces_NIT_H + +#include + +bigint A_ex_sees_b_attr___impl( A recv, B b ); +B A_ex_sees_b_init___impl( A recv, bigint i ); + +#endif diff --git a/tests/test_ni_import_meth.nit b/tests/test_ni_import_meth.nit new file mode 100644 index 0000000..db9a014 --- /dev/null +++ b/tests/test_ni_import_meth.nit @@ -0,0 +1,29 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun nity do print "nity" + fun nity1 ( x : Int ) do print "nity1 {x}" + fun nity2 ( x : Int, y : Int ) do print "nity2 {x} {y}" + + fun ex_sees_nity is extern import nity + + fun ex_sees_nities is extern import nity1, nity2 +end + +var a = new A +a.ex_sees_nity +a.ex_sees_nities diff --git a/tests/test_ni_import_meth.nit.c b/tests/test_ni_import_meth.nit.c new file mode 100644 index 0000000..5d54fc2 --- /dev/null +++ b/tests/test_ni_import_meth.nit.c @@ -0,0 +1,39 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_import_meth.nit.h" + +/* +C implementation of simple::A::ex_sees_nity + +Imported methods signatures: + void A_nity( A recv ) for simple::A::nity +*/ +void A_ex_sees_nity___impl( A recv ) +{ + A_nity( recv ); +} + +/* +C implementation of simple::A::ex_sees_nities + +Imported methods signatures: + void A_nity1( A recv, bigint x ) for simple::A::nity1 + void A_nity2( A recv, bigint x, bigint y ) for simple::A::nity2 +*/ +void A_ex_sees_nities___impl( A recv ) +{ + A_nity( recv ); + A_nity1( recv, 3 ); + A_nity2( recv, 7, 13 ); +} diff --git a/tests/test_ni_import_meth.nit.h b/tests/test_ni_import_meth.nit.h new file mode 100644 index 0000000..e4bd6c4 --- /dev/null +++ b/tests/test_ni_import_meth.nit.h @@ -0,0 +1,22 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef simple_NIT_H +#define simple_NIT_H + +#include + +void A_ex_sees_nity___impl( A recv ); +void A_ex_sees_nities___impl( A recv ); + +#endif diff --git a/tests/test_ni_inits.nit.c b/tests/test_ni_inits.nit.c new file mode 100644 index 0000000..f3ea67c --- /dev/null +++ b/tests/test_ni_inits.nit.c @@ -0,0 +1,56 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_inits.nit.h" + +/* +C implementation of test_ni_inits::A::with_b +*/ +A new_A_with_b___impl( ) +{ + A a = malloc( sizeof(char) ); + *a = 'b'; + return a; +} + +/* +C implementation of test_ni_inits::A::alloc +*/ +A new_A_alloc___impl( ) +{ + A a = malloc( sizeof(char) ); + return a; +} + +/* +C implementation of test_ni_inits::A::set +*/ +void A_set___impl( A recv, char v ) +{ + *recv = 'v'; +} + +/* +C implementation of test_ni_inits::A::(string::Object::to_s) + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +String A_to_s___impl( A recv ) +{ + char *str = malloc( 2 * sizeof(char) ); + str[0] = *recv; + str[1] = 0; + + return new_String_from_cstring( str ); +} diff --git a/tests/test_ni_inits.nit.h b/tests/test_ni_inits.nit.h new file mode 100644 index 0000000..9d0b8aa --- /dev/null +++ b/tests/test_ni_inits.nit.h @@ -0,0 +1,26 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_inits_IMPL_NIT_H +#define test_ni_inits_IMPL_NIT_H + +#define A char* + +#include + +A new_A_with_b___impl( ); +A new_A_alloc___impl( ); +void A_set___impl( A recv, char v ); +String A_to_s___impl( A recv ); + +#endif diff --git a/tests/test_ni_new.nit b/tests/test_ni_new.nit new file mode 100644 index 0000000..55b5d76 --- /dev/null +++ b/tests/test_ni_new.nit @@ -0,0 +1,42 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +extern A special Pointer + new is extern import p + new with_args( x : Int, a : A ) is extern + + fun a do print "a" + fun p is extern + fun d : A is extern import d, A +end + +class B + init do end +end + +var a = new A +var b = new A.with_args( 2345, a ) +a.a +b.a + +a.p # 1234 +b.p # 2345 +new A.with_args( 3456, b ).p # 3456 + +a.d.p # +b.d.p # + +var c = new B diff --git a/tests/test_ni_new.nit.c b/tests/test_ni_new.nit.c new file mode 100644 index 0000000..7d7c6c0 --- /dev/null +++ b/tests/test_ni_new.nit.c @@ -0,0 +1,59 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_new.nit.h" + +#include + + +/* +C implementation of extern_new::A::init + +Imported methods signatures: + void A_p( A recv ) for extern_new::A::p +*/ +int dv = 1234; +A new_A___impl( ) +{ + return &dv; +} + +/* +C implementation of extern_new::A::with_args +*/ +A new_A_with_args___impl( bigint x, A a ) +{ + int* v = (int*)malloc( sizeof(int) ); + (*v) = (int)x; + return v; +} + +/* +C implementation of extern_new::A::p +*/ +void A_p___impl( A recv ) +{ + printf( "allo from %i\n", *recv ); +} + +/* +C implementation of extern_new::A::d + +Imported methods signatures: + A A_d( A recv ) for extern_new::A::d + A new_A( ) for extern_new::A::init +*/ +A A_d___impl( A recv ) +{ + return new_A(); +} diff --git a/tests/test_ni_new.nit.h b/tests/test_ni_new.nit.h new file mode 100644 index 0000000..c666a98 --- /dev/null +++ b/tests/test_ni_new.nit.h @@ -0,0 +1,28 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_new_IMPL_NIT_H +#define test_ni_new_IMPL_NIT_H + +#define A int* + +#include + +#include + +A new_A___impl( ); +A new_A_with_args___impl( bigint x, A a ); +void A_p___impl( A recv ); +A A_d___impl( A recv ); + +#endif diff --git a/tests/test_ni_null.nit b/tests/test_ni_null.nit new file mode 100644 index 0000000..ea2b78a --- /dev/null +++ b/tests/test_ni_null.nit @@ -0,0 +1,37 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun is_int_null( ni : nullable Int ) : Bool is extern import Int as not nullable + fun is_a_null( na : nullable A ) : Bool is extern import A as not nullable + + fun get_nullable_string( get_nulled : Bool ) : nullable String is extern import String::from_cstring, String as nullable +end + +var a = new A + +print "true -? {a.is_int_null( null )}" +print "false -? {a.is_int_null( 0 )}" +print "false -? {a.is_int_null( 1234 )}" + +print "true -? {a.is_a_null( null )}" +print "false -? {a.is_a_null( a )}" + +var nstr = a.get_nullable_string( true ) +if nstr == null then print "is null, ok" else print nstr # expects "is null" + +nstr = a.get_nullable_string( false ) +if nstr == null then print "is null, error" else print nstr # expects "something" diff --git a/tests/test_ni_null.nit.c b/tests/test_ni_null.nit.c new file mode 100644 index 0000000..9a42abe --- /dev/null +++ b/tests/test_ni_null.nit.c @@ -0,0 +1,57 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_null.nit.h" + +/* +C implementation of test_ni_null::A::is_int_null + +Imported methods signatures: + int Int_is_null( nullable_Int value ) to check if a nullable Int is a Int + bigint bigint_as_not_null( nullable_Int value ) to cast from nullable Int to Int +*/ +int A_is_int_null___impl( A recv, nullable_Int ni ) +{ + return Int_is_null( ni ); +} + +/* +C implementation of test_ni_null::A::is_a_null + +Imported methods signatures: + int A_is_null( nullable_A value ) to check if a nullable A is a A + A A_as_not_null( nullable_A value ) to cast from nullable A to A +*/ +int A_is_a_null___impl( A recv, nullable_A na ) +{ + return A_is_null( na ); +} + +/* +C implementation of test_ni_null::A::get_nullable_string + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring + nullable_String String_as_nullable( String value ) to cast from String to nullable String +*/ +nullable_String A_get_nullable_string___impl( A recv, int get_nulled ) +{ + if ( get_nulled ) + { + return null_String(); + } + else + { + return String_as_nullable( new_String_from_cstring( "something" ) ); + } +} diff --git a/tests/test_ni_null.nit.h b/tests/test_ni_null.nit.h new file mode 100644 index 0000000..a5a5d34 --- /dev/null +++ b/tests/test_ni_null.nit.h @@ -0,0 +1,23 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_null_IMPL_NIT_H +#define test_ni_null_IMPL_NIT_H + +#include + +int A_is_int_null___impl( A recv, nullable_Int ni ); +int A_is_a_null___impl( A recv, nullable_A na ); +nullable_String A_get_nullable_string___impl( A recv, int get_nulled ); + +#endif diff --git a/tests/test_ni_operators.nit b/tests/test_ni_operators.nit new file mode 100644 index 0000000..e1b33f2 --- /dev/null +++ b/tests/test_ni_operators.nit @@ -0,0 +1,114 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class A + var value : Int + + init ( value : Int ) do self.value = value + + fun +( other : A ) : A is extern import value, A + + fun -( other : A ) : A is extern import value, A + + fun *( by : Int ) : A is extern import value, A + + fun /( by : Int ) : A is extern import value, A + + redef fun ==( other ) is extern import value, nullable Object as(A) + + fun %( other : A ) : A is extern import value, A + +# fun +=( other : A ) : A is extern import value, value=, A `{ +# int new_val = A_value( recv ) + A_value( other ); +# A_value__assign( recv, new_val ); +# return new_A( new_val ); +# `} + +# fun -=( other : A ) : A is extern import +=, A, value `{ +# A inv_other = new_A( -1*A_value( other ) ); +# return A__plus_equal( recv, int_other ); +# `} + + fun <=>( other : A ) : A is extern import value, A + +# fun @( other : A ) : A is extern import value, A `{ +# return new_A( A_value( recv )* 1000 ); +# `} + + fun >( other : A ) : Bool is extern import value + + fun <( other : A ) : Bool is extern import value + + fun >=( other : A ) : Bool is extern import value + + fun <=( other : A ) : Bool is extern import value + + fun >>( other : A ) is extern import value, value=, A + + fun <<( other : A ) is extern import value, A + + fun []( index : Int ) : A is extern import A + + fun []=( index : Int, value : A ) : A is extern import A + + redef fun to_s do return value.to_s +end + +print new A( 1 ) + new A( 10 ) # 11 +print new A( 10 ) - new A( 1 ) # 9 + +print new A( 2 ) * 11 # 22 +print new A( 33 ) / 11 # 3 + +print new A( 44 ) == null # false +print new A( 55 ) == 55 # false +print new A( 33 ) == new A( 11 ) # false +print new A( 22 ) == new A( 77 ) # false +print new A( 11 ) == new A( 11 ) # true + +print new A( 147 ) % new A( 12 ) # 3 +print new A( 4 ) <=> new A( 123 ) # 4096 + +print new A( 1 ) < new A( 100 ) # true +print new A( 100 ) < new A( 100 ) # false +print new A( 100 ) < new A( 1 ) # false + +print new A( 1 ) > new A( 100 ) # false +print new A( 100 ) > new A( 100 ) # false +print new A( 100 ) > new A( 1 ) # true + +print new A( 1 ) <= new A( 100 ) # true +print new A( 100 ) <= new A( 100 ) # true +print new A( 100 ) <= new A( 1 ) # false + +print new A( 1 ) >= new A( 100 ) # false +print new A( 100 ) >= new A( 100 ) # true +print new A( 100 ) >= new A( 1 ) # true + +#var x = new A( 1 ) +#x << new A( 5 ) +#print x # 16 + +#var y = new A( 32 ) +#y >> new A( 2 ) +#print y # 8 + +var a = new A( 456 ) +print a[ 52 ] # 52 + +a[ 74 ] = new A( 96 ) +print a # 96 diff --git a/tests/test_ni_operators.nit.c b/tests/test_ni_operators.nit.c new file mode 100644 index 0000000..54e4948 --- /dev/null +++ b/tests/test_ni_operators.nit.c @@ -0,0 +1,236 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_operators.nit.h" + +/* +C implementation of test_ni_operators::A::+ + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__plus___impl( A recv, A other ) +{ + + int s = A_value( recv ); + int o = A_value( other ); + + return new_A( s + o ); + +} + +/* +C implementation of test_ni_operators::A::- + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__minus___impl( A recv, A other ) +{ + + int s = A_value( recv ); + int o = A_value( other ); + + return new_A( s - o ); + +} + +/* +C implementation of test_ni_operators::A::* + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__star___impl( A recv, bigint by ) +{ + + int s = A_value( recv ); + + return new_A( s * by ); + +} + +/* +C implementation of test_ni_operators::A::/ + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__slash___impl( A recv, bigint by ) +{ + + int s = A_value( recv ); + + return new_A( s / by ); + +} + +/* +C implementation of test_ni_operators::A::(kernel::Object::==) + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + int nullable_Object_is_a_A( nullable_Object value ) to check if a nullable Object is a A + A nullable_Object_as_A( nullable_Object value ) to cast from nullable Object to A +*/ +int A__equal___impl( A recv, nullable_Object other ) +{ + + if ( nullable_Object_is_a_A( other ) && + A_value( nullable_Object_as_A(other) ) == A_value( recv ) ) + return 1; + else + return 0; + +} + +/* +C implementation of test_ni_operators::A::% + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__percent___impl( A recv, A other ) +{ + + return new_A( A_value( recv ) % A_value( other ) ); + +} + +/* +C implementation of test_ni_operators::A::<=> + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__starship___impl( A recv, A other ) +{ + + return new_A( A_value( recv )* 1024 ); + +} + +/* +C implementation of test_ni_operators::A::> + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value +*/ +int A__greater___impl( A recv, A other ) +{ + + return A_value( recv ) > A_value( other ); + +} + +/* +C implementation of test_ni_operators::A::< + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value +*/ +int A__less___impl( A recv, A other ) +{ + + return A_value( recv ) < A_value( other ); + +} + +/* +C implementation of test_ni_operators::A::>= + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value +*/ +int A__ge___impl( A recv, A other ) +{ + + return A_value( recv ) >= A_value( other ); + +} + +/* +C implementation of test_ni_operators::A::<= + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value +*/ +int A__less_or_equal___impl( A recv, A other ) +{ + + return A_value( recv ) <= A_value( other ); + +} + +/* +C implementation of test_ni_operators::A::>> + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + void A_value__assign( A recv, bigint value ) for test_ni_operators::A::value= + A new_A( bigint value ) for test_ni_operators::A::init +*/ +void A__right___impl( A recv, A other ) +{ + + int new_val = A_value( recv ) >> A_value( other ); + A_value__assign( recv, new_val ); + +} + +/* +C implementation of test_ni_operators::A::<< + +Imported methods signatures: + bigint A_value( A recv ) for test_ni_operators::A::value + A new_A( bigint value ) for test_ni_operators::A::init +*/ +void A__left___impl( A recv, A other ) +{ + + int new_val = A_value( recv ) << A_value( other ); + A_value__assign( recv, new_val ); + +} + +/* +C implementation of test_ni_operators::A::[] + +Imported methods signatures: + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__index___impl( A recv, bigint index ) +{ + + return new_A( index ); + +} + +/* +C implementation of test_ni_operators::A::[]= + +Imported methods signatures: + A new_A( bigint value ) for test_ni_operators::A::init +*/ +A A__index_assign___impl( A recv, bigint index, A value ) +{ + + return new_A( index + A_value( value ) ); + +} \ No newline at end of file diff --git a/tests/test_ni_operators.nit.h b/tests/test_ni_operators.nit.h new file mode 100644 index 0000000..7964db9 --- /dev/null +++ b/tests/test_ni_operators.nit.h @@ -0,0 +1,35 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_operators_IMPL_NIT_H +#define test_ni_operators_IMPL_NIT_H + +#include + +A A__plus___impl( A recv, A other ); +A A__minus___impl( A recv, A other ); +A A__star___impl( A recv, bigint by ); +A A__slash___impl( A recv, bigint by ); +int A__equal___impl( A recv, nullable_Object other ); +A A__percent___impl( A recv, A other ); +A A__starship___impl( A recv, A other ); +int A__greater___impl( A recv, A other ); +int A__less___impl( A recv, A other ); +int A__ge___impl( A recv, A other ); +int A__less_or_equal___impl( A recv, A other ); +void A__right___impl( A recv, A other ); +void A__left___impl( A recv, A other ); +A A__index___impl( A recv, bigint index ); +A A__index_assign___impl( A recv, bigint index, A value ); + +#endif diff --git a/tests/test_ni_out.nit b/tests/test_ni_out.nit new file mode 100644 index 0000000..83a80c3 --- /dev/null +++ b/tests/test_ni_out.nit @@ -0,0 +1,37 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + init do end + + fun is_not_extern do end + + fun proc is extern + fun function : Int is extern + + fun one( x : Int ) : Int is extern + fun two( x : Int, y : Int ) : Int is extern + fun three( x : Int, y : Int, z : Int ) : Int is extern +end + +fun in_object( o : Object ) : Object is extern + +var a = new A +print a.function +print a.one( 2 ) +print a.two( 1, 2 ) +print a.three( 2, 4, 3 ) +print in_object( "hello world" ) diff --git a/tests/test_ni_out.nit.c b/tests/test_ni_out.nit.c new file mode 100644 index 0000000..11c6d1c --- /dev/null +++ b/tests/test_ni_out.nit.c @@ -0,0 +1,62 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_out.nit.h" + +/* +C implementation of simple::A::proc +*/ +void A_proc___impl( A recv ) +{ + printf( "proc\n" ); +} + +/* +C implementation of simple::A::function +*/ +bigint A_function___impl( A recv ) +{ + return 1; +} + +/* +C implementation of simple::A::one +*/ +bigint A_one___impl( A recv, bigint x ) +{ + return x; +} + +/* +C implementation of simple::A::two +*/ +bigint A_two___impl( A recv, bigint x, bigint y ) +{ + return x + y; +} + +/* +C implementation of simple::A::three +*/ +bigint A_three___impl( A recv, bigint x, bigint y, bigint z ) +{ + return x + y - z; +} + +/* +C implementation of simple::Object::in_object +*/ +Object Object_in_object___impl( Object recv, Object o ) +{ + return o; +} diff --git a/tests/test_ni_out.nit.h b/tests/test_ni_out.nit.h new file mode 100644 index 0000000..83924a5 --- /dev/null +++ b/tests/test_ni_out.nit.h @@ -0,0 +1,26 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef simple_NIT_H +#define simple_NIT_H + +#include + +void A_proc___impl( A recv ); +bigint A_function___impl( A recv ); +bigint A_one___impl( A recv, bigint x ); +bigint A_two___impl( A recv, bigint x, bigint y ); +bigint A_three___impl( A recv, bigint x, bigint y, bigint z ); +Object Object_in_object___impl( Object recv, Object o ); + +#endif diff --git a/tests/test_ni_pointer.nit b/tests/test_ni_pointer.nit new file mode 100644 index 0000000..b248ec1 --- /dev/null +++ b/tests/test_ni_pointer.nit @@ -0,0 +1,25 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +extern A +special Pointer + new is extern + + redef fun to_s : String is extern import String::from_cstring +end + +var a = new A +print a diff --git a/tests/test_ni_pointer.nit.c b/tests/test_ni_pointer.nit.c new file mode 100644 index 0000000..ae916ce --- /dev/null +++ b/tests/test_ni_pointer.nit.c @@ -0,0 +1,37 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_pointer.nit.h" + +/* +C implementation of test_ni_pointer::A::init +*/ +A new_A___impl( ) +{ + int* v = (int*)malloc( sizeof(int) ); + (*v) = 123; + return (A)v; +} + +/* +C implementation of test_ni_pointer::A::(string::Object::to_s) + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +String A_to_s___impl( A recv ) +{ + char* s = calloc( 256, sizeof(char) ); + sprintf( s, "%d", *((int*)recv) ); + return new_String_from_cstring( s ); +} diff --git a/tests/test_ni_pointer.nit.h b/tests/test_ni_pointer.nit.h new file mode 100644 index 0000000..2fcf8a7 --- /dev/null +++ b/tests/test_ni_pointer.nit.h @@ -0,0 +1,27 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_pointer_IMPL_NIT_H +#define test_ni_pointer_IMPL_NIT_H + +#define A void* + +#include + +#include + +A new_A___impl( ); +void A_native_init___impl( A recv ); +String A_to_s___impl( A recv ); + +#endif diff --git a/tests/test_ni_primitives.nit b/tests/test_ni_primitives.nit new file mode 100644 index 0000000..88fd001 --- /dev/null +++ b/tests/test_ni_primitives.nit @@ -0,0 +1,32 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +fun opposite( v : Bool ) : Bool is extern +fun plus_10( v : Char ) : Char is extern +fun plus_1000( v : Int ) : Int is extern +fun multiply_by_100( v : Float ) : Float is extern +fun print_ns( s : NativeString ) is extern + +print opposite( true ) +print opposite( false ) + +print plus_10( 'a' ) + +print plus_1000( 1234 ) + +print multiply_by_100( 123.45 ) + +print_ns( "hello world".to_cstring ) diff --git a/tests/test_ni_primitives.nit.c b/tests/test_ni_primitives.nit.c new file mode 100644 index 0000000..519578f --- /dev/null +++ b/tests/test_ni_primitives.nit.c @@ -0,0 +1,56 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_primitives.nit.h" + +#include + +/* +C implementation of test_ni_primitives::Object::opposite +*/ +int Object_opposite___impl( Object recv, int v ) +{ + return v == 0; +} + +/* +C implementation of test_ni_primitives::Object::plus_10 +*/ +char Object_plus_10___impl( Object recv, char v ) +{ + return v + 10; +} + +/* +C implementation of test_ni_primitives::Object::plus_1000 +*/ +bigint Object_plus_1000___impl( Object recv, bigint v ) +{ + return v + 1000; +} + +/* +C implementation of test_ni_primitives::Object::multiply_by_100 +*/ +float Object_multiply_by_100___impl( Object recv, float v ) +{ + return v * 100; +} + +/* +C implementation of test_ni_primitives::Object::print_ns +*/ +void Object_print_ns___impl( Object recv, char * s ) +{ + printf( "%s\n", s ); +} diff --git a/tests/test_ni_primitives.nit.h b/tests/test_ni_primitives.nit.h new file mode 100644 index 0000000..1866e66 --- /dev/null +++ b/tests/test_ni_primitives.nit.h @@ -0,0 +1,27 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_primitives_IMPL_NIT_H +#define test_ni_primitives_IMPL_NIT_H + +#include + +#include + +int Object_opposite___impl( Object recv, int v ); +char Object_plus_10___impl( Object recv, char v ); +bigint Object_plus_1000___impl( Object recv, bigint v ); +float Object_multiply_by_100___impl( Object recv, float v ); +void Object_print_ns___impl( Object recv, char * s ); + +#endif diff --git a/tests/test_ni_special_all_native.nit b/tests/test_ni_special_all_native.nit new file mode 100644 index 0000000..38062f3 --- /dev/null +++ b/tests/test_ni_special_all_native.nit @@ -0,0 +1,31 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun work is extern + fun call is extern import work +end + +class B +special A + redef fun work is extern +end + +var a = new A +var b = new B + +a.call +b.call diff --git a/tests/test_ni_special_all_native.nit.c b/tests/test_ni_special_all_native.nit.c new file mode 100644 index 0000000..fa9ca8f --- /dev/null +++ b/tests/test_ni_special_all_native.nit.c @@ -0,0 +1,41 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_special_all_native.nit.h" + +/* +C implementation of test_ni_special_all_native::A::work +*/ +void A_work___impl( A recv ) +{ + printf( "A\n" ); +} + +/* +C implementation of test_ni_special_all_native::A::call + +Imported methods signatures: + void A_work( A recv ) for test_ni_special_all_native::A::work +*/ +void A_call___impl( A recv ) +{ + A_work( recv ); +} + +/* +C implementation of test_ni_special_all_native::B::(test_ni_special_all_native::A::work) +*/ +void B_work___impl( B recv ) +{ + printf( "B\n" ); +} diff --git a/tests/test_ni_special_all_native.nit.h b/tests/test_ni_special_all_native.nit.h new file mode 100644 index 0000000..e33fea0 --- /dev/null +++ b/tests/test_ni_special_all_native.nit.h @@ -0,0 +1,25 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_special_all_native_IMPL_NIT_H +#define test_ni_special_all_native_IMPL_NIT_H + +#include + +#include + +void A_work___impl( A recv ); +void A_call___impl( A recv ); +void B_work___impl( B recv ); + +#endif diff --git a/tests/test_ni_special_from_native.nit b/tests/test_ni_special_from_native.nit new file mode 100644 index 0000000..8d0cda9 --- /dev/null +++ b/tests/test_ni_special_from_native.nit @@ -0,0 +1,37 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun nity do print "A" + fun exy is extern import nity +end + +class B +special A + redef fun nity do print "B" +end + +var a = new A +print "a from nit" +a.nity +print "a from extern" +a.exy + +var b = new B +print "a from nit" +b.nity +print "a from extern" +b.exy diff --git a/tests/test_ni_special_from_native.nit.c b/tests/test_ni_special_from_native.nit.c new file mode 100644 index 0000000..90eaf62 --- /dev/null +++ b/tests/test_ni_special_from_native.nit.c @@ -0,0 +1,25 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_special_from_native.nit.h" + +/* +C implementation of test_ni_special_from_native::A::exy + +Imported methods signatures: + void A_nity( A recv ) for test_ni_special_from_native::A::nity +*/ +void A_exy___impl( A recv ) +{ + A_nity( recv ); +} diff --git a/tests/test_ni_special_from_native.nit.h b/tests/test_ni_special_from_native.nit.h new file mode 100644 index 0000000..715956d --- /dev/null +++ b/tests/test_ni_special_from_native.nit.h @@ -0,0 +1,23 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_special_from_native_IMPL_NIT_H +#define test_ni_special_from_native_IMPL_NIT_H + +#include + +#include + +void A_exy___impl( A recv ); + +#endif diff --git a/tests/test_ni_special_pointer.nit b/tests/test_ni_special_pointer.nit new file mode 100644 index 0000000..29b2157 --- /dev/null +++ b/tests/test_ni_special_pointer.nit @@ -0,0 +1,40 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +extern ExternInt special Pointer + new as_0 is extern + new as_1 is extern + new as_2 is extern + + redef fun to_s : String is extern import String::from_cstring + fun to_i : Int is extern +end + +redef class Int + fun to_extern_int : ExternInt is extern +end + +var i = new ExternInt.as_0 +print i.to_i + +i = new ExternInt.as_1 +print i.to_i + +i = new ExternInt.as_2 +print i.to_i + +i = 1234 .to_extern_int +print i.to_i diff --git a/tests/test_ni_special_pointer.nit.c b/tests/test_ni_special_pointer.nit.c new file mode 100644 index 0000000..00ccaf2 --- /dev/null +++ b/tests/test_ni_special_pointer.nit.c @@ -0,0 +1,77 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_special_pointer.nit.h" + +/* +C implementation of test_ni_special_pointer::ExternInt::as_0 +*/ +ExternInt new_ExternInt_as_0___impl( ) +{ + ExternInt i0 = (int*)malloc( sizeof(int) ); + (*i0) = 0; + return i0; +} + +/* +C implementation of test_ni_special_pointer::ExternInt::as_1 +*/ +ExternInt new_ExternInt_as_1___impl( ) +{ + ExternInt i0 = (int*)malloc( sizeof(int) ); + (*i0) = 1; + return i0; +} + +/* +C implementation of test_ni_special_pointer::ExternInt::as_2 +*/ +ExternInt new_ExternInt_as_2___impl( ) +{ + ExternInt i0 = (int*)malloc( sizeof(int) ); + (*i0) = 2; + return i0; +} + +/* +C implementation of test_ni_special_pointer::ExternInt::(string::Object::to_s) + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +String ExternInt_to_s___impl( ExternInt recv ) +{ + int v = *recv; + char *vs = (char*)calloc( 256, sizeof(char) ); + + sprintf( vs, "%i", v ); + return new_String_from_cstring( vs ); +} + +/* +C implementation of test_ni_special_pointer::ExternInt::to_i +*/ +bigint ExternInt_to_i___impl( ExternInt recv ) +{ + return *recv; +} + +/* +C implementation of test_ni_special_pointer::Int::to_extern_int +*/ +ExternInt Int_to_extern_int___impl( bigint recv ) +{ + ExternInt i = malloc( sizeof(int) ); + (*i) = recv; + return i; +} diff --git a/tests/test_ni_special_pointer.nit.h b/tests/test_ni_special_pointer.nit.h new file mode 100644 index 0000000..0ae2b79 --- /dev/null +++ b/tests/test_ni_special_pointer.nit.h @@ -0,0 +1,30 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_special_pointer_IMPL_NIT_H +#define test_ni_special_pointer_IMPL_NIT_H + +#define ExternInt int* + +#include + +#include + +ExternInt new_ExternInt_as_0___impl( ); +ExternInt new_ExternInt_as_1___impl( ); +ExternInt new_ExternInt_as_2___impl( ); +String ExternInt_to_s___impl( ExternInt recv ); +bigint ExternInt_to_i___impl( ExternInt recv ); +ExternInt Int_to_extern_int___impl( bigint recv ); + +#endif diff --git a/tests/test_ni_special_to_native.nit b/tests/test_ni_special_to_native.nit new file mode 100644 index 0000000..07a3ef1 --- /dev/null +++ b/tests/test_ni_special_to_native.nit @@ -0,0 +1,38 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun extern_echo is extern + fun echo do print "A" +end + +class B +special A + redef fun extern_echo is extern + redef fun echo do print "B" +end + +var a = new A +a.echo +a.extern_echo + +var b = new B +b.echo +b.extern_echo + +# explicit casts +b.as(A).echo +b.as(A).extern_echo diff --git a/tests/test_ni_special_to_native.nit.c b/tests/test_ni_special_to_native.nit.c new file mode 100644 index 0000000..ba26947 --- /dev/null +++ b/tests/test_ni_special_to_native.nit.c @@ -0,0 +1,32 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_special_to_native.nit.h" + +#include + +/* +C implementation of test_ni_special_to_native::A::extern_echo +*/ +void A_extern_echo___impl( A recv ) +{ + printf( "A from native\n" ); +} + +/* +C implementation of test_ni_special_to_native::B::(test_ni_special_to_native::A::extern_echo) +*/ +void B_extern_echo___impl( B recv ) +{ + printf( "B from native\n" ); +} diff --git a/tests/test_ni_special_to_native.nit.h b/tests/test_ni_special_to_native.nit.h new file mode 100644 index 0000000..aeba40c --- /dev/null +++ b/tests/test_ni_special_to_native.nit.h @@ -0,0 +1,24 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_special_to_native_IMPL_NIT_H +#define test_ni_special_to_native_IMPL_NIT_H + +#include + +#include + +void A_extern_echo___impl( A recv ); +void B_extern_echo___impl( B recv ); + +#endif diff --git a/tests/test_ni_strings.nit b/tests/test_ni_strings.nit new file mode 100644 index 0000000..962db1a --- /dev/null +++ b/tests/test_ni_strings.nit @@ -0,0 +1,34 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun get_str_from_nstr( nstr : NativeString ) : String is extern import String::from_cstring + fun get_str_from_nstr_with_len( nstr : NativeString ) : String is extern import String::with_native, NativeString::cstring_length + + fun get_nstr_from_str( str : String ) : NativeString is extern import String::to_cstring + + fun get_something() : String is extern import String::from_cstring +end + +var a = new A +print a.get_str_from_nstr( "hello world...".to_cstring ) +print a.get_str_from_nstr_with_len( "hello world?".to_cstring ) +print new String.from_cstring( a.get_nstr_from_str( "hello world!" ) ) + + +var something = a.get_something() # expects "something" +print something +print something.length diff --git a/tests/test_ni_strings.nit.c b/tests/test_ni_strings.nit.c new file mode 100644 index 0000000..57dd878 --- /dev/null +++ b/tests/test_ni_strings.nit.c @@ -0,0 +1,61 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_strings.nit.h" + + +/* +C implementation of test_ni_strings::A::get_str_from_nstr + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +String A_get_str_from_nstr___impl( A recv, char * nstr ) +{ + return new_String_from_cstring( nstr ); +} + +/* +C implementation of test_ni_strings::A::get_str_from_nstr_with_len + +Imported methods signatures: + String new_String_with_native( char * nat, bigint size ) for string::String::with_native + bigint NativeString_cstring_length( char * recv ) for string::NativeString::cstring_length +*/ +String A_get_str_from_nstr_with_len___impl( A recv, char * nstr ) +{ + return new_String_with_native( nstr, NativeString_cstring_length( nstr ) ); +} + +/* +C implementation of test_ni_strings::A::get_nstr_from_str + +Imported methods signatures: + char * String_to_cstring( String recv ) for string::String::to_cstring +*/ +char * A_get_nstr_from_str___impl( A recv, String str ) +{ + return String_to_cstring( str ); +} + + +/* +C implementation of test_ni_strings::A::get_something + +Imported methods signatures: + String new_String_from_cstring( char * str ) for string::String::from_cstring +*/ +String A_get_something___impl( A recv ) +{ + return new_String_from_cstring( "something" ); +} diff --git a/tests/test_ni_strings.nit.h b/tests/test_ni_strings.nit.h new file mode 100644 index 0000000..66b189d --- /dev/null +++ b/tests/test_ni_strings.nit.h @@ -0,0 +1,26 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef test_ni_strings_IMPL_NIT_H +#define test_ni_strings_IMPL_NIT_H + +#include + +#include + +String A_get_str_from_nstr___impl( A recv, char * nstr ); +String A_get_str_from_nstr_with_len___impl( A recv, char * nstr ); +char * A_get_nstr_from_str___impl( A recv, String str ); +String A_get_something___impl( A recv ); + +#endif diff --git a/tests/test_ni_super.nit b/tests/test_ni_super.nit new file mode 100644 index 0000000..a76be8e --- /dev/null +++ b/tests/test_ni_super.nit @@ -0,0 +1,30 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + fun id : String do return "A" +end + +class B +special A + redef fun id : String is extern import super, String::from_cstring, String::to_cstring +end + +var a = new A +print a.id + +var b = new B +print b.id diff --git a/tests/test_ni_super.nit.c b/tests/test_ni_super.nit.c new file mode 100644 index 0000000..fc4ca50 --- /dev/null +++ b/tests/test_ni_super.nit.c @@ -0,0 +1,36 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_super.nit.h" + +/* +C implementation of super::B::(super::A::id) + +Imported methods signatures: + void new_String_from_cstring( char * str ) for string::String::from_cstring + char * String_to_cstring( String recv ) for string::String::to_cstring + String B_id___super( B recv ) to call super +*/ +String B_id___impl( B recv ) +{ + char *new_name; + char *prefix = "B special "; + char *super_name = String_to_cstring( B_id___super( recv ) ); + + new_name = calloc( strlen( prefix )+strlen( super_name )+1, sizeof(char) ); + strcpy( new_name, prefix ); + strcpy( new_name+strlen( prefix ), super_name ); + new_name[ strlen( prefix )+strlen( super_name ) ] = '\0'; + + return new_String_from_cstring( new_name ); +} diff --git a/tests/test_ni_super.nit.h b/tests/test_ni_super.nit.h new file mode 100644 index 0000000..441cced --- /dev/null +++ b/tests/test_ni_super.nit.h @@ -0,0 +1,21 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef super_NIT_H +#define super_NIT_H + +#include + +String B_id___impl( B recv ); + +#endif diff --git a/tests/test_ni_virtypes.nit b/tests/test_ni_virtypes.nit new file mode 100644 index 0000000..b6bf656 --- /dev/null +++ b/tests/test_ni_virtypes.nit @@ -0,0 +1,42 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2011 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + type E : Object +end + +class B + super A + redef type E : Int + fun f : E is extern +end + +class C + super A + redef type E : String + fun f( v : E ) is extern +end + +class D + super B + redef fun f is extern +end + +var b = new B +print b.f + +var d = new D +print d.f diff --git a/tests/test_ni_virtypes.nit.c b/tests/test_ni_virtypes.nit.c new file mode 100644 index 0000000..02c93a9 --- /dev/null +++ b/tests/test_ni_virtypes.nit.c @@ -0,0 +1,33 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "test_ni_virtypes.nit.h" + +/* +C implementation of test_ni_virtypes::B::f +*/ +bigint B_f___impl( B recv ) { + return 1; +} + +/* +C implementation of test_ni_virtypes::C::f +*/ +void C_f___impl( C recv, String v ) {} + +/* +C implementation of test_ni_virtypes::D::(test_ni_virtypes::B::f) +*/ +bigint D_f___impl( D recv ) { + return 2; +} diff --git a/tests/test_ni_virtypes.nit.h b/tests/test_ni_virtypes.nit.h new file mode 100644 index 0000000..c378865 --- /dev/null +++ b/tests/test_ni_virtypes.nit.h @@ -0,0 +1,22 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2011 Alexis Laferrière + * + * This file is free software, which comes along with NIT. This software is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#ifndef TEST_NI_VIRTYPES_NIT_H +#define TEST_NI_VIRTYPES_NIT_H + +#include + +bigint B_f___impl( B recv ); +void C_f___impl( C recv, String v ); +bigint D_f___impl( D recv ); +#endif