mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-27 23:34:52 +00:00
Branches: main
Improve the C# backend.
C# foreign types remain commented out so as not to force an upgrade of the
bootstrap compiler yet.
compiler/handle_options.m:
Enable static ground cells for C# backend.
compiler/ml_global_data.m:
Make fields of static vector structures have `public' access.
Local access doesn't make sense.
Use structs to hold vector common data in C#.
Conform to changes.
compiler/ml_proc_gen.m:
Enable use_common_cells on C#.
Conform to changes.
compiler/mlds.m:
Rename `finality' to `overridability'. The `final' keyword in Java
has multiple meanings, so avoid that word. Use the word `sealed'
to describe classes or virtual methods which cannot be overridden,
which is the keyword in C#.
compiler/ml_switch_gen.m:
Remember the types of mlconst_foreign constants. In the C# backend a
foreign enum value needs to be cast to the right type. For some
reason, there was a field already which could be used for this purpose
but was only ever set to mlds_native_int_type.
compiler/ml_type_gen.m:
Replace ml_gen_final_member_decl_flags with
ml_gen_const_member_decl_flags. Return flags with the `sealed' flag
unset, as that wouldn't make sense for member variables.
Remember the type in mlconst_foreign.
compiler/ml_unify_gen.m:
Remember the type in mlconst_foreign.
compiler/mlds_to_cs.m:
Support static data in C#.
Support foreign enumerations.
Use the `default(T)' operator to initialise certain types of variables,
particularly user-defined types, which the Mercury compiler may not
know enumeration defined in another module, i.e. a value type, which
cannot be initialised with `null'.
Remove the requirement to add mark foreign types which are of value
types with the "valuetype" prefix.
compiler/mlds_to_java.m:
Write out the `final' keyword when either the `sealed' or `const' flags
are set.
Conform to changes.
compiler/rtti_to_mlds.m:
RTTI data doesn't need the `sealed' flag set.
compiler/ml_code_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/ml_elim_nested.m:
Conform to changes.
library/builtin.m:
Export `comparison_result' to C# foreign code.
Fix `deep_copy' for arrays.
library/bitmap.m:
library/pretty_printer.m:
library/store.m:
library/version_array.m:
library/version_hash_table.m:
Implement these modules for C#.
library/io.m:
library/dir.m:
Implement `dir.current_directory' for C#.
library/exception.m:
Implement `catch_impl' for multi and nondet predicates.
library/rtti_implementation.m:
Implement `get_typeclass_info_from_term' for C#.
library/string.m:
Fix `string.set_char' for C#.
library/time.m:
Delete now-unnecessary "valuetype" prefix on foreign type.
library/type_desc.m:
Implement `make_type' for C#.
runtime/mercury_dotnet.cs.in:
Collapse equivalences when comparing TypeInfo_Structs for equality.
tests/hard_coded/Mmakefile:
Disable some tests in C# grade.
tests/hard_coded/ee_dummy.m:
tests/hard_coded/ee_valid_test.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/exported_foreign_enum.m:
tests/hard_coded/export_test.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/float_gv.m:
tests/hard_coded/foreign_enum_dummy.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_name_mutable.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/impure_init_and_final.m:
tests/hard_coded/intermod_poly_mode_2.m:
tests/hard_coded/loop_inv_test1.m:
tests/hard_coded/loop_inv_test.m:
tests/hard_coded/multimode.m:
tests/hard_coded/pragma_export.m:
tests/hard_coded/pragma_foreign_export.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/trace_goal_4.m:
tests/hard_coded/uc_export_enum.m:
tests/hard_coded/user_compare.m:
tests/hard_coded/write_xml.m:
Make these test cases work on C#.
tests/hard_coded/deep_copy.exp3:
tests/hard_coded/expand.exp3:
tests/hard_coded/float_reg.exp3:
Add expected results for C#.
tests/hard_coded/string_strip.exp2:
Update this result, which was not updated when the test case changed
previously.
234 lines
4.7 KiB
Mathematica
234 lines
4.7 KiB
Mathematica
% vim: ft=mercury sw=4 ts=4 expandtab
|
|
%
|
|
% This regression test is an expanded version of the program files by Greg Duck
|
|
% in a bug report on Feb 22 2006.
|
|
|
|
:- module float_gv.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di,io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module float.
|
|
|
|
:- type c ---> c(int, int).
|
|
|
|
:- type coord.
|
|
:- pragma foreign_type(c, coord, "coord *").
|
|
:- pragma foreign_type("C#", coord, "Coord").
|
|
:- pragma foreign_type("Java", coord, "Coord").
|
|
:- pragma foreign_type("Erlang", coord, "").
|
|
|
|
:- pragma foreign_decl(c, "
|
|
typedef struct {
|
|
int x, y;
|
|
} coord;
|
|
").
|
|
|
|
:- pragma foreign_decl("C#", "
|
|
class Coord {
|
|
public int x, y;
|
|
}
|
|
").
|
|
|
|
:- pragma foreign_decl("Java", "
|
|
class Coord {
|
|
public int x, y;
|
|
}
|
|
").
|
|
|
|
:- func new_coord(int, int) = coord.
|
|
|
|
:- func x(coord) = int.
|
|
:- func y(coord) = int.
|
|
|
|
:- pragma foreign_proc(c,
|
|
new_coord(X::in, Y::in) = (C::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
C = MR_GC_NEW(coord);
|
|
C->x = X;
|
|
C->y = Y;
|
|
").
|
|
|
|
:- pragma foreign_proc(c,
|
|
x(C::in) = (X::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
X = C->x;
|
|
").
|
|
|
|
:- pragma foreign_proc(c,
|
|
y(C::in) = (Y::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
Y = C->y;
|
|
").
|
|
|
|
:- pragma foreign_proc("C#",
|
|
new_coord(X::in, Y::in) = (C::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
C = new Coord();
|
|
C.x = X;
|
|
C.y = Y;
|
|
").
|
|
|
|
:- pragma foreign_proc("C#",
|
|
x(C::in) = (X::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
X = C.x;
|
|
").
|
|
|
|
:- pragma foreign_proc("C#",
|
|
y(C::in) = (Y::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
Y = C.y;
|
|
").
|
|
|
|
:- pragma foreign_proc("Java",
|
|
new_coord(X::in, Y::in) = (C::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
C = new Coord();
|
|
C.x = X;
|
|
C.y = Y;
|
|
").
|
|
|
|
:- pragma foreign_proc("Java",
|
|
x(C::in) = (X::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
X = C.x;
|
|
").
|
|
|
|
:- pragma foreign_proc("Java",
|
|
y(C::in) = (Y::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
Y = C.y;
|
|
").
|
|
|
|
:- pragma foreign_proc("Erlang",
|
|
new_coord(X::in, Y::in) = (C::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
C = {X, Y}
|
|
").
|
|
|
|
:- pragma foreign_proc("Erlang",
|
|
x(C::in) = (X::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
{X, _} = C
|
|
").
|
|
|
|
:- pragma foreign_proc("Erlang",
|
|
y(C::in) = (Y::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
{_, Y} = C
|
|
").
|
|
|
|
:- mutable(gv1,float,0.0,ground,[untrailed]).
|
|
:- mutable(gv2,float,2.3,ground,[untrailed]).
|
|
:- mutable(gv3,string,"",ground,[untrailed]).
|
|
:- mutable(gv4,string,"def",ground,[untrailed]).
|
|
:- mutable(gv5,coord,new_coord(0, 0),ground,[untrailed]).
|
|
:- mutable(gv6,coord,new_coord(2, 3),ground,[untrailed]).
|
|
|
|
:- pragma promise_pure(main/2).
|
|
main(!IO) :-
|
|
% Check whether we get back the same value as we set.
|
|
GV1Init = 1.2,
|
|
write(GV1Init,!IO),
|
|
nl(!IO),
|
|
impure set_gv1(GV1Init),
|
|
semipure get_gv1(GV1Final),
|
|
write(GV1Final,!IO),
|
|
nl(!IO),
|
|
( GV1Init = GV1Final ->
|
|
true
|
|
;
|
|
write_string("GV1 NOT SAME!\n",!IO)
|
|
),
|
|
|
|
% Check whether we get back the same value as the initialization.
|
|
GV2Init = 2.3,
|
|
write(GV2Init,!IO),
|
|
nl(!IO),
|
|
semipure get_gv2(GV2Final),
|
|
write(GV2Final,!IO),
|
|
nl(!IO),
|
|
( GV2Init = GV2Final ->
|
|
true
|
|
;
|
|
write_string("GV2 NOT SAME!\n",!IO)
|
|
),
|
|
|
|
% Check whether we get back the same value as we set.
|
|
GV3Init = "abc",
|
|
write(GV3Init,!IO),
|
|
nl(!IO),
|
|
impure set_gv3(GV3Init),
|
|
semipure get_gv3(GV3Final),
|
|
write(GV3Final,!IO),
|
|
nl(!IO),
|
|
( GV3Init = GV3Final ->
|
|
true
|
|
;
|
|
write_string("GV3 NOT SAME!\n",!IO)
|
|
),
|
|
|
|
% Check whether we get back the same value as the initialization.
|
|
GV4Init = "def",
|
|
write(GV4Init,!IO),
|
|
nl(!IO),
|
|
semipure get_gv4(GV4Final),
|
|
write(GV4Final,!IO),
|
|
nl(!IO),
|
|
( GV4Init = GV4Final ->
|
|
true
|
|
;
|
|
write_string("GV4 NOT SAME!\n",!IO)
|
|
),
|
|
|
|
% Check whether we get back the same value as we set.
|
|
GV5Init = new_coord(1, 2),
|
|
write(c(x(GV5Init), y(GV5Init)),!IO),
|
|
nl(!IO),
|
|
impure set_gv5(GV5Init),
|
|
semipure get_gv5(GV5Final),
|
|
write(c(x(GV5Final), y(GV5Final)),!IO),
|
|
nl(!IO),
|
|
(
|
|
x(GV5Init) = x(GV5Final),
|
|
y(GV5Init) = y(GV5Final)
|
|
->
|
|
true
|
|
;
|
|
write_string("GV5 NOT SAME!\n",!IO)
|
|
),
|
|
|
|
% Check whether we get back the same value as the initialization.
|
|
GV6Init = new_coord(2, 3),
|
|
write(c(x(GV6Init), y(GV6Init)),!IO),
|
|
nl(!IO),
|
|
semipure get_gv6(GV6Final),
|
|
write(c(x(GV6Final), y(GV6Final)),!IO),
|
|
nl(!IO),
|
|
(
|
|
x(GV6Init) = x(GV6Final),
|
|
y(GV6Init) = y(GV6Final)
|
|
->
|
|
true
|
|
;
|
|
write_string("GV6 NOT SAME!\n",!IO)
|
|
).
|