mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 04:44:39 +00:00
Merge the foreign_type pragma changes from the dotnet branch to the main
Estimated hours taken: 10
Branches: main
Merge the foreign_type pragma changes from the dotnet branch to the main
branch, plus do some more development work to generalise the change.
compiler/prog_data.m:
Add a type to hold the data from parsing a pragma foreign_type decl.
compiler/prog_io_pragma.m:
Parse the pragma foreign_type. This code is currently commented
out, while we decide on the syntax.
compiler/hlds_data.m:
Add a new alternative to hlds_type_body where the body of the type
is a foreign type.
compiler/make_hlds.m:
Place the foreign_type pragmas into the HLDS.
compiler/foreign.m:
Implement to_type_string which replaces export__type_to_type_string,
unlike export__type_to_type_string foreign__to_type_string takes an
argument specifying which language the representation is meant to be
in. to_type_string also needs to take a module_info to handle
foreign_types correctly. To avoid the need for the module_info to
be passed around the MLDS backend we provide a new type
exported_type which provides enough information for an alternate
version of to_type_string to be called.
compiler/export.m:
Delete export__type_to_type_string.
compiler/llds.m:
Since foreign__to_type_string needs a module_info, we add a new
field to pragma_c_arg_decl which is the result of calling
foreign__to_type_string. This avoids threading the module_info
around various llds passes.
compiler/mlds.m:
Record with in the mercury_type the exported_type, this avoids
passing the module_info around the MLDS backend.
Also add the foreign_type alternative to mlds__type.
Update mercury_type_to_mlds_type so that it handles types which are
foreign types.
compiler/mlds_to_il.m:
Convert a mlds__foreign_type into an ilds__type.
compiler/ilds.m:
The CLR spec requires that System.Object and System.String be
treated specially in the IL assembly so add them as simple types.
compiler/ilasm.m:
Before outputting a class name into the IL assembly check whether it
it can be simplified to a builtin type, and if so output that name
instead as required by the ECMA spec.
Changes for the addition of string and object as simple types.
doc/reference_manual.texi:
Document the new pragma, this is currently commented out because it
refers to syntax that has not yet been finalised.
compiler/fact_table.m:
compiler/llds_out.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/pragma_c_gen.m:
compiler/rtti_to_mlds.m:
Changes to handle using foreign__to_type_string.
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/recompilation_version.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Changes to handle the new hlds_type_body.
compiler/mercury_to_mercury.m:
Output the pragma foreign_type declaration.
compiler/module_qual.m:
Qualify the pragma foreign_type declarations.
compiler/modules.m:
Pragma foreign_type is allowed in the interface.
This commit is contained in:
@@ -70,6 +70,53 @@ parse_pragma_type(_, "source_file", PragmaTerms, ErrorTerm, _VarSet, Result) :-
|
||||
ErrorTerm)
|
||||
).
|
||||
|
||||
/*
|
||||
parse_pragma_type(ModuleName, "foreign_type", PragmaTerms,
|
||||
ErrorTerm, _VarSet, Result) :-
|
||||
( PragmaTerms = [MercuryName, ForeignName, Target] ->
|
||||
(
|
||||
parse_backend(Target, Backend)
|
||||
->
|
||||
parse_implicitly_qualified_term(ModuleName, MercuryName,
|
||||
ErrorTerm, "`:- pragma foreign_type' declaration",
|
||||
MaybeMercuryType),
|
||||
(
|
||||
MaybeMercuryType = ok(MercuryTypeSymName, MercuryArgs),
|
||||
( MercuryArgs = [] ->
|
||||
parse_qualified_term(ForeignName, ErrorTerm,
|
||||
"`:- pragma foreign_type' declaration",
|
||||
MaybeForeignType),
|
||||
(
|
||||
MaybeForeignType = ok(ForeignType, ForeignArgs),
|
||||
( ForeignArgs = [] ->
|
||||
term__coerce(MercuryName, MercuryType),
|
||||
Result = ok(pragma(foreign_type(Backend,
|
||||
MercuryType, MercuryTypeSymName,
|
||||
ForeignType)))
|
||||
;
|
||||
Result = error("foreign type arity not 0", ErrorTerm)
|
||||
)
|
||||
;
|
||||
MaybeForeignType = error(String, Term),
|
||||
Result = error(String, Term)
|
||||
)
|
||||
;
|
||||
Result = error("mercury type arity not 0", ErrorTerm)
|
||||
)
|
||||
;
|
||||
MaybeMercuryType = error(String, Term),
|
||||
Result = error(String, Term)
|
||||
)
|
||||
;
|
||||
Result = error("invalid backend parameter", Target)
|
||||
)
|
||||
;
|
||||
Result = error(
|
||||
"wrong number of arguments in `:- pragma foreign_type' declaration",
|
||||
ErrorTerm)
|
||||
).
|
||||
*/
|
||||
|
||||
parse_pragma_type(ModuleName, "foreign_decl", PragmaTerms,
|
||||
ErrorTerm, VarSet, Result) :-
|
||||
parse_pragma_foreign_decl_pragma(ModuleName, "foreign_decl",
|
||||
@@ -130,6 +177,14 @@ parse_pragma_type(ModuleName, "c_code", PragmaTerms,
|
||||
parse_foreign_language(term__functor(term__string(String), _, _), Lang) :-
|
||||
globals__convert_foreign_language(String, Lang).
|
||||
|
||||
:- pred parse_backend(term, backend).
|
||||
:- mode parse_backend(in, out) is semidet.
|
||||
|
||||
parse_backend(term__functor(Functor, Args, _), Backend) :-
|
||||
Functor = term__atom("il"),
|
||||
Args = [term__functor(term__string(Module), [], _)],
|
||||
Backend = il(Module).
|
||||
|
||||
% This predicate parses both c_header_code and foreign_decl pragmas.
|
||||
:- pred parse_pragma_foreign_decl_pragma(module_name, string,
|
||||
list(term), term, varset, maybe1(item)).
|
||||
|
||||
Reference in New Issue
Block a user