Commit Graph

15 Commits

Author SHA1 Message Date
Peter Ross
77a1261d3b 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.
2001-10-24 13:34:41 +00:00
Fergus Henderson
7a0205f617 Fix a place in mlds_to_il.m where we were assuming that the
Branches: main
Estimated hours taken: 2

compiler/mlds_to_il.m:
compiler/mlds.m:
	Fix a place in mlds_to_il.m where we were assuming that the
	arguments always included a secondary tag; this assumption is
	not robust and will be broken by my change to represent
	constants in discriminated union types using reserved addresses.
	This fix required adding a new boolean field to the `new_object'
	instruction to record whether or not the arguments include a
	secondary tag.

compiler/ml_elim_nested.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Update to handle the new field of `new_object'.
2001-10-24 05:44:05 +00:00
Tyson Dowd
416ca83320 Merge changes to add attributes to the HLDS, MLDS and ILDS from the
Estimated hours taken: 2
Branches: main

Merge changes to add attributes to the HLDS, MLDS and ILDS from the
dotnet-foreign branch.  We don't merge the changes to add syntax for
attributes, as the syntax is still very experimental.

compiler/hlds_pred.m:
compiler/prog_data.m:
	Add attributes to the pred_info (they are a bit like markers,
	but are more than just boolean flags).

compiler/ilasm.m:
	Add custom attributes to appropriate positions (on assemblies,
	IL types and methods).

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_util.m:
compiler/mlds.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:
	Add mlds__attributes, which are the MLDS version of custom attributes.
	Convert hlds_pred__attributes into mlds__attributes.
	Add a list of mlds__attributes to the mlds__function defn.

compiler/mlds_to_il.m:
	Convert MLDS attributes to IL custom attributes.
2001-08-24 15:44:57 +00:00
Fergus Henderson
d6fc3d4ccf Delete some incorrect XXX comments that were added in Tyson's last change.
Estimated hours taken: 0.25
Branches: main

compiler/mlds_to_java.m:
	Delete some incorrect XXX comments that were added in Tyson's last change.
2001-08-05 06:17:02 +00:00
Tyson Dowd
d4965acd72 Implement arrays in the .NET backend.
Estimated hours taken: 15
Branches: main

Implement arrays in the .NET backend.

Arrays are implemented in an unusual way.
array(T) is mapped to the .NET type T[] for all concrete types T.
However, if T is a type variable, we map array(T) to System.Array.

System.Array is the superclass of all array types, so we can always
pass T[] where System.Array is expected.

This mapping allows us to use the Mercury array library module to
operate on arrays that may be exposed by other .NET components (for
example Byte[] or int[]).

In some cases the Mercury compiler will know the value of T, but it may
be calling code that operates on array(T) in a generic fashion.
If the callee returns an array(T), the Mercury compiler can be sure
that this is really T[], but the .NET backend is not that clever.

In that case we have to cast from System.Array to T[] after the call.
(This is very similar to how we unbox return values with type T where T is
known in the caller but not the callee).
We also insert casts from T[] to System.Array -- although they are not
strictly necessary.

compiler/ml_call_gen.m:
	Implement the cast to the known instance of array(T) for return
	values of array.

compiler/mlds.m:
	Add a new MLDS type mlds__mercury_array_type to represent the
	Mercury array/1 type.
	Turn the Mercury type array/1 into mlds__mercury_array_type.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
	Use MR_Word to represent mlds__mercury_array_type, unless we are
	using --high-level-data, in which case we use the appropriately
	named high-level-data type.

compiler/mlds_to_il.m:
	Draw a distinction between the il_object_array_type (object[])
	and the il_generic_array_type (class System.Array).
	Map mlds__mercury_array_type(ElemType) to class System.Array if
	ElemType is a type variable, or ElemType[] otherwise.

compiler/mlds_to_java.m:
	Map mlds__mercury_array_type(ElemType) to class Object[] if
	ElemType is a type variable, or ElemType[] otherwise.
	(type variables are mapped to Object anyway, so this falls
	out of the code anyway).
	(This is untested).
2001-08-03 12:07:28 +00:00
Tyson Dowd
bf0ed70782 Use a new mlds__function_body type to represent function bodies, as the old
Estimated hours taken: 0.75
Branches: main

Use a new mlds__function_body type to represent function bodies, as the old
usage of maybe/1 was error prone ("no" meant the function had been declared
using :- pragma external, not merely that the body was missing).

compiler/mlds.m:
	Add mlds__function_body type.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Handle this change.
2001-07-12 15:44:58 +00:00
Peter Ross
a6d5d61cb5 Refactor the top level of mlds_to_il so that we only do one pass over
Estimated hours taken: 40
Branches: main

Refactor the top level of mlds_to_il so that we only do one pass over
the MLDS to generate the ILDS.  As a side effect of this change nondet
code now works again.

compiler/mlds_to_il.m:
    Do a MLDS to MLDS transformation which places all the procedures and
    data into the mercury_code class.  Then modify all the qualifiers to
    take account of this change to the code.
    Rewrite the top level so that it only does one pass over the MLDS
    data structure.
    Examine the flags when deciding which attributes to place on a
    method, field or class.

compiler/mlds.m:
    Add a new field to mlds__class_defn which is the list of
    defns which are constructors for this class.
    Add the functions mlds__append_mercury_code and mlds__append_name
    which append either "mercury_code" or an arbitary string to the
    module qualifier of a name.

compiler/ml_elim_nested.m:
    Rather then hardcoding the generation of the constructor for the
    environment class, we generate it here as an MLDS method.
    On the IL backend the mercury code is placed in a seperate class to
    the environment data, so the env_type decls must be public so as to
    be accessible from the code.

compiler/ml_code_util.m:
    Wrapper functions should be static methods not instance methods.
    Fix ml_gen_label_func_decl_flags to make this true.

compiler/rtti_to_mlds.m:
    Rtti data structures should be one_copy (ie static) not per_instance.

compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
    Misc changes to handle the additon of a list of constructors to the
    mlds__class_defn.

compiler/mlds_to_csharp.m:
compiler/mlds_to_mcpp.m:
    Use the function class_name rather then mercury_module_name_to_mlds.
2001-07-09 15:55:07 +00:00
Fergus Henderson
befb329aaf Add type information to the array_index operator.
Estimated hours taken: 8
Branches: main

Add type information to the array_index operator.
This is needed for both the GCC back-end and the IL back-end.

compiler/builtin_ops.m:
	In the array_index constructor for the unary_op type,
	add the array element type as a field.

compiler/ml_string_switch.m:
compiler/string_switch.m:
compiler/mlds_to_java.m:
	When generating array_index operators, generate the new field.

compiler/bytecode.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
	When consuming array_index operators, ignore the new field.

compiler/mlds_to_gcc.m:
	When consuming array_index operators, use the array element type,
	rather than wrongly assuming the element type is always 'MR_Integer'.

compiler/mlds_to_il.m:
	Add code to handle the array_index operator,
	rather than calling `throw_unimplemented'.

compiler/bytecode.m:
	Delete the reverse mode of binop_code.  This was not used,
	it was just there to get the compiler to check that we didn't
	map two different binary operators to the same code.  This
	mode no longer works, since we map array_index operators to
	the same code regardless of the the array element type.

compiler/rtti_to_mlds.m:
compiler/ml_string_switch.m:
compiler/ml_code_util.m:
	To avoid code duplication, move ml_string_type, which was defined in
	both rtti_to_mlds.m and ml_string_switch.m, into ml_code_util.m.

compiler/ml_string_switch.m:
	Minor changes to avoid some code duplication.

compiler/mlds_to_java.m:
	Fix a bug where it was using the wrong type for the `args' variable.
	Add an XXX comment about what looks to me like another bug.
2001-07-08 16:40:11 +00:00
Peter Ross
5c2103005e The .NET backend requires that names are not only qualified with their
Estimated hours taken: 4
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
back out a previous solution to this problem and implement a much
neater solution where we hide the package name in the abstract type
mlds_module_name.

This solution is neater because the package name shouldn't change once
the name is defined.  All that we may have to change is the qualifiers
to the name.

compiler/mlds.m:
    Add the package name to the abstract type mlds_module_name.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Back out previous solution.
2001-06-22 09:14:39 +00:00
Peter Ross
bdad224cf7 Add the self rval (ie this pointer in C++) for use on OO backends.
Estimated hours taken: 0.5
Branches: main

Add the self rval (ie this pointer in C++) for use on OO backends.

compiler/mlds.m:
    Add the self rval.

compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
    Code to handle the new rval.
2001-06-21 10:33:55 +00:00
Peter Ross
f092670758 The .NET backend requires that names are not only qualified with their
Estimated hours taken: 16
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
add to the name type the name of the source package which this name is
defined in.  This change will be needed for implementing foreign_class
in the .NET backend where it will no longer be possible to determine
the package name from the fully qualified name.

compiler/mlds.m:
    Add the new field to the mlds__fully_qualified_name type.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Propogate the changes around.
2001-06-08 09:13:45 +00:00
Tyson Dowd
cbdd5a68d5 Minimize the amount of procedure name mangling done by the .NET backend.
Estimated hours taken: 5
Branches: main, dotnet-foreign

Minimize the amount of procedure name mangling done by the .NET backend.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/rtti_to_mlds.m:
	Add the code_model and a boolean indicating whether this
	function (if it is a function) *doesn't* have a return value
	(i.e. it has a non-default mode).

	Also move is_output_det_function into ml_code_util.m and rename it
	ml_is_output_det_function.

compiler/mlds_to_il.m:
	Mangle much more carefully.  We still mangle in a predictable,
	context-insensitive manner, however we take advantage of the
	overloading available in the .NET backend to avoid name clashes
	in most cases.
2001-05-10 15:07:59 +00:00
Tyson Dowd
76ac44335d Implement a C# interface for the .NET backend.
Estimated hours taken: 45
Branches: main

Implement a C# interface for the .NET backend.

To use it, you currently need to set
	--backend-foreign-language csharp --use-foreign-language csharp
in your MCFLAGS.

The C# foreign language interface works by introducing a new sort of
MLDS statement called outline_foreign_proc.  outline_foreign_proc is expected
to be turned into a separate procedure in a separate file.  This is
quite different to normal foreign code which has been renamed as inline
target code, as it is really intended to be generated inline, inside the
generated code.

Because outline_foreign_proc is expected to be generated outside the
normal code, we don't need to generate variable renamings,
initializations, casts and other complicated interfacing code.

Any marshalling is done by the backend, which knows how to marshall
arguments across the boundary into the outline code and back.  In the
case of marshalling to C# from the .NET backend, we currently don't do
anything special (part of the point of .NET is that data
representation don't have to change very often just because you are
using different languages, so this is a property we should try to
preserve).

The actual implementation of the foreign code is therefore very simple.
Simply generate an appropriate procedure, and insert the user's code in
the middle.

The bulk of this change to delay the mangling of MLDS var names, so we
can still use the original user's var name when we output the outline
procedure (since the user's foreign code will refer to these var names,
it's important to keep them around).

compiler/foreign.m:
	Handle the csharp foreign language.

compiler/globals.m:
	Fix an XXX about converting to lowercase to do language name
	comparisons.
	Add new predicates to make conversion of foreign languages
	to strings more uniform.

compiler/handle_options.m:
	Don't set backend_foreign_language to the default if it has
	already been set by hand.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Delay the mangling of MLDS var names by keeping the variable
	number around until the output phase.

	Slightly generalize the handling of foreign language interfacing.
	Handle C# foreign language interfacing.

	Add value_output_vars to the ml_gen_info, which are the variables
	returned rather than passed by reference.  We need to know
	these variables for C# interfacing so that we can handle the return
	value of the forwarding function.

	Mark the beginning and end of the MLDS foreign language processing as
	a "sub-module" (in comments at least).  Later I may put this code
	into a separate module.

	Rename some predicates from c_code to foreign_code.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds.m:
	Add outline_foreign_proc which is handled differently to the old
	target_code (which has been renamed inline_target_code).

	Change the definiton for mlds__var_name.

compiler/mlds_to_c.m:
	Factor out mlds_output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_csharp.m:
	A new module to generate C# code suitable for foreign language
	interfacing.  This is largely lifted from the MC++ code, with a few
	changes to the output syntax.

compiler/mlds_to_il.m:
	Return the set of foreign languages processed instead of a bool
	saying wither MC++ was present.  This is so we can generate the
	appropriate output .cs or .cpp files, and because we need to keep
	track of all the external assembly references we need to put in the
	.il file.

	Handle the inline_target_code and mlds__var_name changes.

compiler/mlds_to_ilasm.m:
	Output .cpp and .cs files conditionally.
	Factor out output_to_file.
	Move MC++ output code to mlds_to_mcpp.m

compiler/mlds_to_java.m:
	Factor out output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_mcpp.m:
	New file to handle generating MC++ code suitable for foreign language
	interfacing.

compiler/options.m:
	Add a way of setting the backend-foreign-language option.

compiler/passes_aux.m:
	Add output_to_file which is used by the MLDS backend to generate
	output files.

compiler/prog_data.m:
	Uncomment csharp as a foreign language.
2001-05-02 11:36:41 +00:00
Julien Fischer
efe77ccbb0 Converts MLDS to Java source code. The following features
Estimated hours taken: 200

Converts MLDS to Java source code.  The following features
do not work/have not yet been implemented:
	* RTTI
	* foreign language interface
	* multidet and nondet predicates
	* higher order predicates
	* enforced usage of Java coding conventions

compiler/mlds_to_java.m:
	Replaces existing file.
compiler/java_util.m:
	New file.  Contains utility predicates that are used
	by the Java backend.
compiler/c_util.m:
	Added comment about Java backend.
2001-03-01 15:52:35 +00:00
Julien Fischer
9602919bbe Added new compiler options to support the Java backend and
Estimated hours taken: 4

Added new compiler options to support the Java backend and
updated documentation to reflect this.

compiler/globals.m:
	Removed comment about Java backend not being implemented.
	Replaced it by one say that it is work in progress.

compiler/mercury_compile.m:
	If Target = java then call the Java backend.

compiler/options.m:
	Added new options for compiling Java files:
	`--java'
	`--java-only'
	`--java-compiler' ('--javac')
	`--java-flags'
	`--java-classpath'
	`--java-object-file-extension'

compiler/handle_options.m:
	If compiling to Java then don't link.
	Added "java" grade.

compiler/mlds_to_java.m
	New file.
	XXX Currently just prints an error message about
	    the Java backend not being implemented.

doc/user_guide.texi:
	Documented new options for compiling Java files.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
	Added support for "java" grade.
2001-01-29 01:55:08 +00:00