[m-rev.] for review: add infrastructure for Erlang backend

Peter Wang wangp at students.csse.unimelb.edu.au
Mon May 7 12:53:00 AEST 2007


Estimated hours take: 4
Branches: main

Add some preliminary infrastructure for an HLDS->Erlang code generator.

compiler/globals.m:
compiler/options.m:
        Recognise "erlang" as a valid compilation target.

        Add new options: `--erlang' and `--erlang-only' as synonyms
        for `--target erlang' and `--target erlang --target-code-only'.
        XXX the new options are currently undocumented.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
	Recognise "Erlang" as a valid language for foreign code.

compiler/add_pragma.m:
compiler/add_type.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/foreign.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_gen.m:
compiler/ml_optimize.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/modules.m:
compiler/pragma_c_gen.m:
compiler/prog_foreign.m:
compiler/simplify.m:
	Conform to the above changes.

Index: compiler/add_pragma.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_pragma.m,v
retrieving revision 1.62
diff -u -r1.62 add_pragma.m
--- compiler/add_pragma.m	4 Mar 2007 23:37:55 -0000	1.62
+++ compiler/add_pragma.m	7 May 2007 02:39:03 -0000
@@ -406,6 +406,7 @@
                     ( Lang = lang_java
                     ; Lang = lang_csharp
                     ; Lang = lang_managed_cplusplus
+                    ; Lang = lang_erlang
                     ),
                     Pieces = [words("Warning:"),
                         fixed("`:- pragma foreign_export' declarations"),
Index: compiler/add_type.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_type.m,v
retrieving revision 1.26
diff -u -r1.26 add_type.m
--- compiler/add_type.m	2 May 2007 06:16:33 -0000	1.26
+++ compiler/add_type.m	7 May 2007 02:39:03 -0000
@@ -447,6 +447,7 @@
         ; Target = target_java, LangStr = "Java"
         ; Target = target_asm, LangStr = "C"
         ; Target = target_x86_64, LangStr = "C"
+        ; Target = target_erlang, LangStr = "Erlang"
         ),
         MainPieces = [words("Error: no"), fixed(LangStr),
             fixed("`pragma foreign_type'"), words("declaration for"),
@@ -479,7 +480,7 @@
         MaybeForeignTypeBody1 = yes(ForeignTypeBody1)
     ;
         MaybeForeignTypeBody1 = no,
-        ForeignTypeBody1 = foreign_type_body(no, no, no)
+        ForeignTypeBody1 = foreign_type_body(no, no, no, no)
     ),
     merge_foreign_type_bodies_2(ForeignTypeBody0, ForeignTypeBody1,
         ForeignTypeBody),
@@ -502,12 +503,14 @@
 :- pred merge_foreign_type_bodies_2(foreign_type_body::in,
     foreign_type_body::in, foreign_type_body::out) is semidet.
 
-merge_foreign_type_bodies_2(foreign_type_body(MaybeILA, MaybeCA, MaybeJavaA),
-        foreign_type_body(MaybeILB, MaybeCB, MaybeJavaB),
-        foreign_type_body(MaybeIL, MaybeC, MaybeJava)) :-
+merge_foreign_type_bodies_2(
+        foreign_type_body(MaybeILA, MaybeCA, MaybeJavaA, MaybeErlangA),
+        foreign_type_body(MaybeILB, MaybeCB, MaybeJavaB, MaybeErlangB),
+        foreign_type_body(MaybeIL, MaybeC, MaybeJava, MaybeErlang)) :-
     merge_maybe(MaybeILA, MaybeILB, MaybeIL),
     merge_maybe(MaybeCA, MaybeCB, MaybeC),
-    merge_maybe(MaybeJavaA, MaybeJavaB, MaybeJava).
+    merge_maybe(MaybeJavaA, MaybeJavaB, MaybeJava),
+    merge_maybe(MaybeErlangA, MaybeErlangB, MaybeErlang).
 
 :- pred merge_maybe(maybe(T)::in, maybe(T)::in, maybe(T)::out) is semidet.
 
@@ -623,17 +626,22 @@
         ForeignType = il(ILForeignType),
         Data = foreign_type_lang_data(ILForeignType, MaybeUserEqComp,
             Assertions),
-        Body = foreign_type_body(yes(Data), no, no)
+        Body = foreign_type_body(yes(Data), no, no, no)
     ;
         ForeignType = c(CForeignType),
         Data = foreign_type_lang_data(CForeignType, MaybeUserEqComp,
             Assertions),
-        Body = foreign_type_body(no, yes(Data), no)
+        Body = foreign_type_body(no, yes(Data), no, no)
     ;
         ForeignType = java(JavaForeignType),
         Data = foreign_type_lang_data(JavaForeignType, MaybeUserEqComp,
             Assertions),
-        Body = foreign_type_body(no, no, yes(Data))
+        Body = foreign_type_body(no, no, yes(Data), no)
+    ;
+        ForeignType = erlang(ErlangForeignType),
+        Data = foreign_type_lang_data(ErlangForeignType, MaybeUserEqComp,
+            Assertions),
+        Body = foreign_type_body(no, no, no, yes(Data))
     ).
 
 :- pred ctors_add(list(constructor)::in, type_ctor::in, tvarset::in,
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.169
diff -u -r1.169 code_gen.m
--- compiler/code_gen.m	6 Jan 2007 09:23:25 -0000	1.169
+++ compiler/code_gen.m	7 May 2007 02:39:03 -0000
@@ -258,6 +258,7 @@
             ; Lang = lang_csharp
             ; Lang = lang_managed_cplusplus
             ; Lang = lang_il
+            ; Lang = lang_erlang
             ),
             unexpected(this_file,
                 "generate_goal_2: foreign code other than C unexpected")
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.106
diff -u -r1.106 compile_target_code.m
--- compiler/compile_target_code.m	11 Apr 2007 04:21:59 -0000	1.106
+++ compiler/compile_target_code.m	7 May 2007 02:39:03 -0000
@@ -80,6 +80,11 @@
 :- pred compile_csharp_file(io.output_stream::in, module_imports::in,
     file_name::in, file_name::in, bool::out, io::di, io::uo) is det.
 
+    % compile_erlang_file(ErrorStream, ErlangFile, BeamFile, Succeeded)
+    %
+:- pred compile_erlang_file(io.output_stream::in,
+    file_name::in, file_name::in, bool::out, io::di, io::uo) is det.
+
     % make_init_file(ErrorStream, MainModuleName, ModuleNames, Succeeded):
     %
     % Make the `.init' file for a library containing the given modules.
@@ -900,6 +905,11 @@
 
 %-----------------------------------------------------------------------------%
 
+compile_erlang_file(_ErrorStream, _ErlangFile, _BeamFile, _Succeeded, !IO) :-
+    sorry(this_file, "compile_erlang_file").
+
+%-----------------------------------------------------------------------------%
+
 make_init_file(ErrorStream, MainModuleName, AllModules, Succeeded, !IO) :-
     module_name_to_file_name(MainModuleName, ".init.tmp", yes, TmpInitFileName,
         !IO),
@@ -1029,6 +1039,7 @@
         ; Target = target_java
         ; Target = target_il
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         join_module_list(Modules, Obj, ObjectsList, !IO)
     ),
Index: compiler/export.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.109
diff -u -r1.109 export.m
--- compiler/export.m	4 Mar 2007 23:37:56 -0000	1.109
+++ compiler/export.m	7 May 2007 02:39:03 -0000
@@ -146,6 +146,7 @@
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_java
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         sorry(this_file,  ":- pragma foreign_export for non-C backends.")
     ),
@@ -722,6 +723,7 @@
         ; Lang = lang_java
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         sorry(this_file, "foreign languages other than C unimplemented")
     ),
Index: compiler/foreign.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/foreign.m,v
retrieving revision 1.70
diff -u -r1.70 foreign.m
--- compiler/foreign.m	19 Jan 2007 07:04:12 -0000	1.70
+++ compiler/foreign.m	7 May 2007 02:39:03 -0000
@@ -263,6 +263,7 @@
             ; ForeignLanguage = lang_csharp
             ; ForeignLanguage = lang_il
             ; ForeignLanguage = lang_java
+            ; ForeignLanguage = lang_erlang
             ),
             unimplemented_combination(TargetLanguage, ForeignLanguage)
         )
@@ -278,6 +279,7 @@
             ( ForeignLanguage = lang_csharp
             ; ForeignLanguage = lang_il
             ; ForeignLanguage = lang_java
+            ; ForeignLanguage = lang_erlang
             ),
             unimplemented_combination(TargetLanguage, ForeignLanguage)
         )
@@ -290,6 +292,7 @@
             ; ForeignLanguage = lang_managed_cplusplus
             ; ForeignLanguage = lang_il
             ; ForeignLanguage = lang_java
+            ; ForeignLanguage = lang_erlang
             ),
             unimplemented_combination(TargetLanguage, ForeignLanguage)
         )
@@ -302,6 +305,7 @@
             ; ForeignLanguage = lang_managed_cplusplus
             ; ForeignLanguage = lang_csharp
             ; ForeignLanguage = lang_java
+            ; ForeignLanguage = lang_erlang
             ),
             unimplemented_combination(TargetLanguage, ForeignLanguage)
         )
@@ -314,6 +318,20 @@
             ; ForeignLanguage = lang_managed_cplusplus
             ; ForeignLanguage = lang_csharp
             ; ForeignLanguage = lang_il
+            ; ForeignLanguage = lang_erlang
+            ),
+            unimplemented_combination(TargetLanguage, ForeignLanguage)
+        )
+    ;
+        TargetLanguage = lang_erlang,
+        (
+            ForeignLanguage = lang_erlang
+        ;
+            ( ForeignLanguage = lang_c
+            ; ForeignLanguage = lang_managed_cplusplus
+            ; ForeignLanguage = lang_csharp
+            ; ForeignLanguage = lang_il
+            ; ForeignLanguage = lang_java
             ),
             unimplemented_combination(TargetLanguage, ForeignLanguage)
         )
@@ -345,6 +363,7 @@
 make_pred_name_rest(lang_csharp, _SymName) = "some_csharp_name".
 make_pred_name_rest(lang_il, _SymName) = "some_il_name".
 make_pred_name_rest(lang_java, _SymName) = "some_java_name".
+make_pred_name_rest(lang_erlang, _SymName) = "some_erlang_name".
 
 make_pragma_import(PredInfo, ProcInfo, C_Function, Context, PragmaImpl, VarSet,
         PragmaVars, ArgTypes, Arity, PredOrFunc, !ModuleInfo, !Specs) :-
@@ -525,6 +544,8 @@
         ( ForeignTypeBody ^ il = yes(_) -> yes ; no )).
 have_foreign_type_for_backend(target_java, ForeignTypeBody,
         ( ForeignTypeBody ^ java = yes(_) -> yes ; no )).
+have_foreign_type_for_backend(target_erlang, ForeignTypeBody,
+        ( ForeignTypeBody ^ erlang = yes(_) -> yes ; no )).
 have_foreign_type_for_backend(target_asm, ForeignTypeBody, Result) :-
     have_foreign_type_for_backend(target_c, ForeignTypeBody, Result).
 have_foreign_type_for_backend(target_x86_64, ForeignTypeBody, Result) :-
@@ -566,7 +587,8 @@
 
 foreign_type_body_to_exported_type(ModuleInfo, ForeignTypeBody, Name,
         MaybeUserEqComp, Assertions) :-
-    ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC, MaybeJava),
+    ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC, MaybeJava,
+        MaybeErlang),
     module_info_get_globals(ModuleInfo, Globals),
     globals.get_target(Globals, Target),
     (
@@ -602,6 +624,17 @@
             unexpected(this_file, "to_exported_type: no Java type")
         )
     ;
+        Target = target_erlang,
+        (
+            MaybeErlang = yes(Data),
+            Data = foreign_type_lang_data(erlang_type, MaybeUserEqComp,
+                Assertions),
+            Name = unqualified("")
+        ;
+            MaybeErlang = no,
+            unexpected(this_file, "to_exported_type: no Erlang type")
+        )
+    ;
         Target = target_asm,
         (
             MaybeC = yes(Data),
@@ -645,6 +678,8 @@
         sym_name_to_string(ForeignType).
 to_type_string(lang_java, foreign(ForeignType, _)) =
         sym_name_to_string(ForeignType).
+to_type_string(lang_erlang, foreign(ForeignType, _)) =
+        sym_name_to_string(ForeignType).
 
     % XXX does this do the right thing for high level data?
 to_type_string(lang_c, mercury(Type)) = Result :-
@@ -693,6 +728,8 @@
     ;
         Result = "java.lang.Object"
     ).
+to_type_string(lang_erlang, mercury(_Type)) = _ :-
+    sorry(this_file, "to_type_string for erlang").
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.81
diff -u -r1.81 globals.m
--- compiler/globals.m	13 Feb 2007 00:16:54 -0000	1.81
+++ compiler/globals.m	7 May 2007 02:39:03 -0000
@@ -46,8 +46,10 @@
                             % back-end. Do not go via C, instead generate GCC's
                             % internal `tree' data structure.
                             % (Work in progress.)
-    ;       target_x86_64.  % Compile directly to x86_64 assembler.
+    ;       target_x86_64   % Compile directly to x86_64 assembler.
                             % (Work in progress.)
+    ;       target_erlang.  % Generate Erlang.
+                            % (Work in progress)
 
 :- type foreign_language
     --->    lang_c
@@ -55,7 +57,8 @@
     ;       lang_csharp
     ;       lang_managed_cplusplus
     ;       lang_java
-    ;       lang_il.
+    ;       lang_il
+    ;       lang_erlang.
 
     % A string representation of the compilation target suitable
     % for use in human-readable error messages.
@@ -282,6 +285,7 @@
 convert_target_2("il", target_il).
 convert_target_2("c", target_c).
 convert_target_2("x86_64", target_x86_64).
+convert_target_2("erlang", target_erlang).
 
 convert_foreign_language(String, ForeignLanguage) :-
     convert_foreign_language_2(string.to_lower(String), ForeignLanguage).
@@ -298,6 +302,7 @@
 convert_foreign_language_2("c sharp", lang_csharp).
 convert_foreign_language_2("il", lang_il).
 convert_foreign_language_2("java", lang_java).
+convert_foreign_language_2("erlang", lang_erlang).
 
 convert_gc_method("none", gc_none).
 convert_gc_method("conservative", gc_boehm).
@@ -324,12 +329,14 @@
 compilation_target_string(target_java) = "Java".
 compilation_target_string(target_asm)  = "asm".
 compilation_target_string(target_x86_64) = "x86_64".
+compilation_target_string(target_erlang) = "Erlang".
 
 foreign_language_string(lang_c) = "C".
 foreign_language_string(lang_managed_cplusplus) = "Managed C++".
 foreign_language_string(lang_csharp) = "C#".
 foreign_language_string(lang_il) = "IL".
 foreign_language_string(lang_java) = "Java".
+foreign_language_string(lang_erlang) = "Erlang".
 
 simple_foreign_language_string(lang_c) = "c".
 simple_foreign_language_string(lang_managed_cplusplus) = "cpp".
@@ -337,6 +344,7 @@
 simple_foreign_language_string(lang_csharp) = "csharp".
 simple_foreign_language_string(lang_il) = "il".
 simple_foreign_language_string(lang_java) = "java".
+simple_foreign_language_string(lang_erlang) = "erlang".
 
 gc_is_conservative(gc_boehm) = yes.
 gc_is_conservative(gc_boehm_debug) = yes.
Index: compiler/granularity.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/granularity.m,v
retrieving revision 1.7
diff -u -r1.7 granularity.m
--- compiler/granularity.m	19 Jan 2007 07:04:12 -0000	1.7
+++ compiler/granularity.m	7 May 2007 02:39:03 -0000
@@ -155,6 +155,7 @@
             ; Target = target_java
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             ),
             % This should have caught by mercury_compile.m.
             unexpected(this_file, "runtime_granularity_test_in_goal: " ++
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.297
diff -u -r1.297 handle_options.m
--- compiler/handle_options.m	13 Apr 2007 04:56:39 -0000	1.297
+++ compiler/handle_options.m	7 May 2007 02:39:04 -0000
@@ -536,6 +536,7 @@
             ; Target = target_java
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             )
         ),
 
@@ -625,6 +626,7 @@
             ; Target = target_il
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             )
         ),
         % Generating assembler via the gcc back-end requires
@@ -637,6 +639,7 @@
             ; Target = target_il
             ; Target = target_java
             ; Target = target_x86_64
+            ; Target = target_erlang
             )
         ),
 
@@ -664,6 +667,7 @@
             ; Target = target_c
             ; Target = target_il
             ; Target = target_java
+            ; Target = target_erlang
             )
         ),
 
@@ -1160,6 +1164,7 @@
                     ; Target = target_java
                     ; Target = target_asm
                     ; Target = target_x86_64
+                    ; Target = target_erlang
                     )
                 )
             ;
@@ -1827,6 +1832,9 @@
         ;
             Target = target_x86_64,
             BackendForeignLanguages = ["c"]
+        ;
+            Target = target_erlang,
+            BackendForeignLanguages = ["erlang"]
         ),
 
         % Only set the backend foreign languages if they are unset.
@@ -2353,6 +2361,14 @@
         highlevel_code          - bool(yes),
         highlevel_data          - bool(yes)],
         yes([string("java")]), yes).
+grade_component_table("erlang", comp_gcc_ext, [
+        asm_labels              - bool(no),
+        gcc_non_local_gotos     - bool(no),
+        gcc_global_registers    - bool(no),
+        gcc_nested_functions    - bool(no),
+        highlevel_code          - bool(yes),    % XXX ?
+        highlevel_data          - bool(yes)],
+        yes([string("erlang")]), yes).
 
     % Parallelism/multithreading components.
 grade_component_table("par", comp_par, [parallel - bool(yes)], no, yes).
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.112
diff -u -r1.112 hlds_data.m
--- compiler/hlds_data.m	6 Jan 2007 10:56:12 -0000	1.112
+++ compiler/hlds_data.m	7 May 2007 02:39:04 -0000
@@ -191,7 +191,8 @@
     --->    foreign_type_body(
                 il      :: foreign_type_lang_body(il_foreign_type),
                 c       :: foreign_type_lang_body(c_foreign_type),
-                java    :: foreign_type_lang_body(java_foreign_type)
+                java    :: foreign_type_lang_body(java_foreign_type),
+                erlang  :: foreign_type_lang_body(erlang_foreign_type)
             ).
 
 :- type foreign_type_lang_body(T) == maybe(foreign_type_lang_data(T)).
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.218
diff -u -r1.218 intermod.m
--- compiler/intermod.m	19 Jan 2007 07:04:16 -0000	1.218
+++ compiler/intermod.m	7 May 2007 02:39:04 -0000
@@ -1033,8 +1033,9 @@
     intermod_info::in, intermod_info::out) is det.
 
 resolve_foreign_type_body_overloading(ModuleInfo, TypeCtor,
-        foreign_type_body(MaybeIL0, MaybeC0, MaybeJava0),
-        foreign_type_body(MaybeIL, MaybeC, MaybeJava), !Info) :-
+        foreign_type_body(MaybeIL0, MaybeC0, MaybeJava0, MaybeErlang0),
+        foreign_type_body(MaybeIL, MaybeC, MaybeJava, MaybeErlang),
+        !Info) :-
     module_info_get_globals(ModuleInfo, Globals),
     globals.get_target(Globals, Target),
 
@@ -1050,6 +1051,7 @@
         ( Target = target_c
         ; Target = target_asm
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         resolve_foreign_type_body_overloading_2(ModuleInfo, TypeCtor,
             MaybeC0, MaybeC, !Info)
@@ -1068,6 +1070,7 @@
         ; Target = target_asm
         ; Target = target_java
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         MaybeIL = MaybeIL0
     ),
@@ -1080,8 +1083,22 @@
         ; Target = target_asm
         ; Target = target_il
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         MaybeJava = MaybeJava0
+    ),
+    (
+        Target = target_erlang,
+        resolve_foreign_type_body_overloading_2(ModuleInfo, TypeCtor,
+            MaybeErlang0, MaybeErlang, !Info)
+    ;
+        ( Target = target_c
+        ; Target = target_asm
+        ; Target = target_il
+        ; Target = target_x86_64
+        ; Target = target_java
+        ),
+        MaybeErlang = MaybeErlang0
     ).
 
 :- pred resolve_foreign_type_body_overloading_2(module_info::in, type_ctor::in,
@@ -1274,7 +1291,8 @@
         ( Body = hlds_foreign_type(ForeignTypeBody)
         ; Body ^ du_type_is_foreign_type = yes(ForeignTypeBody)
         ),
-        ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC, MaybeJava)
+        ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC, MaybeJava,
+            MaybeErlang)
     ->
         (
             MaybeIL = yes(DataIL),
@@ -1314,6 +1332,19 @@
                 Context, !IO)
         ;
             MaybeJava = no
+        ),
+        (
+            MaybeErlang = yes(DataErlang),
+            DataErlang = foreign_type_lang_data(ErlangForeignType,
+                ErlangMaybeUserEqComp, AssertionsErlang),
+            mercury_output_item(
+                item_type_defn(VarSet, Name, Args,
+                    parse_tree_foreign_type(erlang(ErlangForeignType),
+                        ErlangMaybeUserEqComp, AssertionsErlang),
+                    cond_true),
+                Context, !IO)
+        ;
+            MaybeErlang = no
         )
     ;
         true
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.305
diff -u -r1.305 llds_out.m
--- compiler/llds_out.m	18 Mar 2007 23:34:53 -0000	1.305
+++ compiler/llds_out.m	7 May 2007 02:39:04 -0000
@@ -1293,6 +1293,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         unexpected(this_file, "output_user_foreign_code: unimplemented: " ++
             "foreign code other than C")
@@ -1339,6 +1340,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         unexpected(this_file, "output_user_foreign_code: unexpected: " ++
             "foreign decl code other than C")
Index: compiler/make.module_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.53
diff -u -r1.53 make.module_target.m
--- compiler/make.module_target.m	2 May 2007 04:45:04 -0000	1.53
+++ compiler/make.module_target.m	7 May 2007 02:39:04 -0000
@@ -473,6 +473,9 @@
 build_object_code(_ModuleName, target_x86_64, _, _ErrorStream, _Imports,
         _Succeeded, _, _) :-
     sorry(this_file, "NYI mmc --make and target x86_64").
+build_object_code(_ModuleName, target_erlang, _, _ErrorStream, _Imports,
+        _Succeeded, _, _) :-
+    sorry(this_file, "NYI mmc --make and target erlang").
 
 :- pred compile_foreign_code_file(io.output_stream::in, pic::in,
     module_imports::in, foreign_code_file::in, bool::out,
@@ -500,6 +503,10 @@
         Succeeded, !IO) :-
     compile_target_code.compile_csharp_file(ErrorStream, Imports,
         CSharpFile, DLLFile, Succeeded, !IO).
+compile_foreign_code_file(ErrorStream, _, _Imports,
+        foreign_code_file(lang_erlang, ErlFile, BeamFile), Succeeded, !IO) :-
+    compile_target_code.compile_erlang_file(ErrorStream, ErlFile, BeamFile,
+        Succeeded, !IO).
 
 :- func forkable_module_compilation_task_type(module_compilation_task_type)
     = bool.
@@ -564,6 +571,9 @@
     ;
         CompilationTarget = target_x86_64,
         sorry(this_file, "mmc --make NYI and target x86_64")
+    ;
+        CompilationTarget = target_erlang,
+        sorry(this_file, "mmc --make NYI and target erlang")
     ).
 
 %-----------------------------------------------------------------------------%
@@ -837,6 +847,9 @@
         ;
             CompilationTarget = target_x86_64,
             sorry(this_file, "NYI mmc --make and target x86_64")
+        ;
+            CompilationTarget = target_erlang,
+            sorry(this_file, "NYI mmc --make and target erlang")
         ),
 
         (
@@ -963,6 +976,7 @@
         ( CompilationTarget = target_java
         ; CompilationTarget = target_il
         ; CompilationTarget = target_x86_64
+        ; CompilationTarget = target_erlang
         ),
         ForeignFiles = ForeignFiles0
     ).
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.69
diff -u -r1.69 make.program_target.m
--- compiler/make.program_target.m	2 May 2007 04:45:04 -0000	1.69
+++ compiler/make.program_target.m	7 May 2007 02:39:04 -0000
@@ -145,6 +145,9 @@
         ;
             CompilationTarget = target_x86_64,
             sorry(this_file, "mmc --make and target x86_64")
+        ;
+            CompilationTarget = target_erlang,
+            sorry(this_file, "mmc --make and target erlang")
         ),
 
         AllModulesList = set.to_sorted_list(AllModules),
@@ -304,6 +307,7 @@
         ( CompilationTarget = target_java
         ; CompilationTarget = target_il
         ; CompilationTarget = target_x86_64
+        ; CompilationTarget = target_erlang
         ),
         ObjectTargets = ForeignObjectTargets
     ).
@@ -480,6 +484,9 @@
             CompilationTarget = target_x86_64,
             sorry(this_file, "mmc --make and target x86_64")
         ;
+            CompilationTarget = target_erlang,
+            sorry(this_file, "mmc --make and target erlang")
+        ;
             CompilationTarget = target_il,
             Succeeded = yes
         ;
Index: compiler/make_hlds_passes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.66
diff -u -r1.66 make_hlds_passes.m
--- compiler/make_hlds_passes.m	4 Mar 2007 23:38:00 -0000	1.66
+++ compiler/make_hlds_passes.m	7 May 2007 02:39:04 -0000
@@ -748,6 +748,7 @@
             ; CompilationTarget = target_java
             ; CompilationTarget = target_asm
             ; CompilationTarget = target_x86_64
+            ; CompilationTarget = target_erlang
             ),
             Pieces = [words("Error: foreign_name mutable attribute not yet"),
                 words("implemented for the"),
@@ -990,6 +991,7 @@
             ; Target = target_il
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             ),
             add_pragma_type_spec(Pragma, Context, !ModuleInfo, !QualInfo,
                 !Specs)
@@ -1409,6 +1411,7 @@
         ; CompilationTarget = target_java
         ; CompilationTarget = target_asm
         ; CompilationTarget = target_x86_64
+        ; CompilationTarget = target_erlang
         ),
         true
     ).
@@ -1873,6 +1876,7 @@
         ; Backend = target_java
         ; Backend = target_asm
         ; Backend = target_x86_64
+        ; Backend = target_erlang
         ),
         sorry(this_file, "we don't yet support mutables for non-C backends")
     ).
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.432
diff -u -r1.432 mercury_compile.m
--- compiler/mercury_compile.m	12 Apr 2007 06:40:09 -0000	1.432
+++ compiler/mercury_compile.m	7 May 2007 02:39:05 -0000
@@ -424,6 +424,7 @@
         (
             ( Target = target_il
             ; Target = target_java
+            ; Target = target_erlang
             ),
             NYIMsg = [
                 words("Sorry,"),
@@ -468,6 +469,7 @@
                     ; Target = target_il
                     ; Target = target_asm
                     ; Target = target_x86_64
+                    ; Target = target_erlang
                     ),
                     compile_with_module_options(MainModuleName,
                         OptionVariables, OptionArgs,
@@ -1356,6 +1358,7 @@
     ; CompilationTarget = target_java, TargetSuffix = ".java"
     ; CompilationTarget = target_asm, TargetSuffix = ".s"
     ; CompilationTarget = target_x86_64, TargetSuffix = ".s"
+    ; CompilationTarget = target_erlang, TargetSuffix = ".erl"
     ),
     FindTargetFiles = usual_find_target_files(CompilationTarget,
         TargetSuffix, TopLevelModuleName).
@@ -1400,6 +1403,9 @@
     ;
         CompilationTarget = target_x86_64,
         TimestampSuffix = ".s_date"
+    ;
+        CompilationTarget = target_erlang,
+        TimestampSuffix = ".erl_date"
     ),
     FindTimestampFiles = find_timestamp_files_2(CompilationTarget,
         TimestampSuffix, TopLevelModuleName).
@@ -1587,6 +1593,7 @@
         ;
             ( Target = target_java
             ; Target = target_il
+            ; Target = target_erlang
             )
         ),
         (
@@ -1684,6 +1691,9 @@
             io.stdout_stream(Stdout, !IO),
             output_x86_64_asm(Stdout, X86_64_Asm, !IO),
             FactTableBaseFiles = []
+        ;
+            Target = target_erlang,
+            sorry(this_file, "mercury_compile_after_front_end: target erlang")
         ),
         recompilation.usage.write_usage_file(!.HLDS, NestedSubModules,
             MaybeTimestamps, !IO),
@@ -3398,6 +3408,7 @@
             ; Target = target_java
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             ),
             GenerateInline = no
         ),
@@ -3973,6 +3984,7 @@
                 ; Target = target_java
                 ; Target = target_asm
                 ; Target = target_x86_64
+                ; Target = target_erlang
                 )
                 % Leave the HLDS alone. We cannot implement parallelism.
             )
@@ -4016,6 +4028,7 @@
             ; Target = target_java
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             )
             % Leave the HLDS alone. We cannot implement parallelism,
             % so there is not point in controlling its granularity.
@@ -4060,6 +4073,7 @@
             ; Target = target_java
             ; Target = target_asm
             ; Target = target_x86_64
+            ; Target = target_erlang
             )
             % Leave the HLDS alone. We cannot implement parallelism,
             % so there is not point in controlling its granularity.
@@ -4645,6 +4659,10 @@
         Lang = lang_java,
         sorry(this_file, ":- import_module not yet implemented: " ++
             "`:- pragma foreign_import_module' for Java")
+    ;
+        Lang = lang_erlang,
+        sorry(this_file, ":- import_module not yet implemented: " ++
+            "`:- pragma foreign_import_module' for Erlang")
     ).
 
 :- pred get_c_body_code(foreign_body_info::in, list(user_foreign_code)::out)
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.315
diff -u -r1.315 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m	22 Feb 2007 03:50:35 -0000	1.315
+++ compiler/mercury_to_mercury.m	7 May 2007 02:39:05 -0000
@@ -1771,6 +1771,9 @@
     ;
         ForeignType = java(_),
         io.write_string("java, ", !IO)
+    ;
+        ForeignType = erlang(_),
+        io.write_string("erlang, ", !IO)
     ),
     Args = list.map((func(V) = term.variable(V, context_init)), TParams),
     construct_qualified_term(Name, Args, MercuryType),
@@ -1791,6 +1794,9 @@
         ForeignType = c(c_type(ForeignTypeStr))
     ;
         ForeignType = java(java_type(ForeignTypeStr))
+    ;
+        ForeignType = erlang(erlang_type),
+        ForeignTypeStr = ""
     ),
     io.write_string(ForeignTypeStr, !IO),
     io.write_string("\"", !IO),
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.198
diff -u -r1.198 ml_code_gen.m
--- compiler/ml_code_gen.m	4 Mar 2007 23:38:01 -0000	1.198
+++ compiler/ml_code_gen.m	7 May 2007 02:39:05 -0000
@@ -885,7 +885,7 @@
     hlds_data.get_type_defn_body(TypeDefn, Body),
     (
         Body = hlds_foreign_type(
-            foreign_type_body(MaybeIL, _MaybeC, _MaybeJava))
+            foreign_type_body(MaybeIL, _MaybeC, _MaybeJava, _MaybeErlang))
     ->
         (
             MaybeIL = yes(Data),
@@ -904,6 +904,8 @@
 foreign_type_required_imports(target_asm, _) = [].
 foreign_type_required_imports(target_x86_64, _) = _ :-
     unexpected(this_file, "target x86_64 and --high-level-code").
+foreign_type_required_imports(target_erlang, _) = _ :-
+    unexpected(this_file, "foreign_type_required_imports: target erlang").
 
 :- pred ml_gen_defns(module_info::in, mlds_defns::out, io::di, io::uo) is det.
 
@@ -2420,10 +2422,14 @@
             Target = target_x86_64,
             unexpected(this_file,
                 "target x86_64 with --high-level-code")
+        ;
+            Target = target_erlang,
+            unexpected(this_file,
+                "ml_gen_nondet_pragma_foreign_proc: target erlang")
         )
     ;
         unexpected(this_file,
-            "ml_gen_nondet_pragma_c_code: unexpected code model")
+            "ml_gen_nondet_pragma_foreign_proc: unexpected code model")
     ),
     Ending_C_Code = [
         raw_target_code("\t\t}\n", []),
@@ -2556,6 +2562,10 @@
         ml_gen_ordinary_pragma_java_proc(CodeModel, Attributes,
             PredId, ProcId, Args, ExtraArgs,
             Foreign_Code, Context, Decls, Statements, !Info)
+    ;
+        Lang = lang_erlang,
+        unexpected(this_file,
+            "ml_gen_ordinary_pragma_foreign_proc: unexpected language Erlang")
     ).
 
 :- pred ml_gen_ordinary_pragma_java_proc(code_model::in,
Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.49
diff -u -r1.49 ml_optimize.m
--- compiler/ml_optimize.m	19 Jan 2007 07:04:20 -0000	1.49
+++ compiler/ml_optimize.m	7 May 2007 02:39:05 -0000
@@ -457,6 +457,7 @@
 % target_supports_break_and_continue_2(target_c_sharp) = yes.
 target_supports_break_and_continue_2(target_x86_64) = _ :-
     unexpected(this_file, "target x86_64 with --high-level-code").
+target_supports_break_and_continue_2(target_erlang) = no.
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/ml_switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
retrieving revision 1.29
diff -u -r1.29 ml_switch_gen.m
--- compiler/ml_switch_gen.m	8 Jan 2007 03:03:12 -0000	1.29
+++ compiler/ml_switch_gen.m	7 May 2007 02:39:05 -0000
@@ -275,6 +275,7 @@
 % target_supports_int_switch_2(c_sharp) = yes.
 target_supports_int_switch_2(target_x86_64) =
     unexpected(this_file, "target x86_64 with --high-level code").
+target_supports_int_switch_2(target_erlang) = yes.
 
 target_supports_string_switch_2(target_c) = no.
 target_supports_string_switch_2(target_asm) = no.
@@ -283,6 +284,8 @@
 % target_supports_string_switch_2(c_sharp) = yes.
 target_supports_string_switch_2(target_x86_64) =
     unexpected(this_file, "target x86_64 with --high-level code").
+target_supports_string_switch_2(target_erlang) =
+    unexpected(this_file, "target erlang").
 
 target_supports_computed_goto_2(target_c) = yes.
 target_supports_computed_goto_2(target_asm) = no.
@@ -293,6 +296,7 @@
 % target_supports_computed_goto_2(c_sharp) = no.
 target_supports_computed_goto_2(target_x86_64) =
     unexpected(this_file, "target x86_64 with --high-level code").
+target_supports_computed_goto_2(target_erlang) = no.
 
 target_supports_goto_2(target_c) = yes.
 target_supports_goto_2(target_asm) = yes.
@@ -301,6 +305,7 @@
 % target_supports_goto_2(c_sharp) = yes.
 target_supports_goto_2(target_x86_64) =
     unexpected(this_file, "target x86_64 with --high-level code").
+target_supports_goto_2(target_erlang) = no.
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/ml_type_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.64
diff -u -r1.64 ml_type_gen.m
--- compiler/ml_type_gen.m	8 Jan 2007 03:03:12 -0000	1.64
+++ compiler/ml_type_gen.m	7 May 2007 02:39:05 -0000
@@ -727,6 +727,8 @@
 target_uses_constructors(target_asm) = no.
 target_uses_constructors(target_x86_64) =
     unexpected(this_file, "target_x86_64 and --high-level-code").
+target_uses_constructors(target_erlang) =
+    unexpected(this_file, "target erlang").
 
 :- func target_uses_empty_base_classes(compilation_target) = bool.
 
@@ -736,6 +738,8 @@
 target_uses_empty_base_classes(target_asm) = no.
 target_uses_empty_base_classes(target_x86_64) = 
     unexpected(this_file, "target_x86_64 and --high-level-code").
+target_uses_empty_base_classes(target_erlang) = 
+    unexpected(this_file, "target erlang").
 
     % This should return yes if references to function parameters in
     % constructor functions must be qualified with the module name,
@@ -753,6 +757,7 @@
 target_requires_module_qualified_params(target_asm) = no.
 target_requires_module_qualified_params(target_x86_64) = 
     unexpected(this_file, "target_x86_64 with --high-level-code").
+target_requires_module_qualified_params(target_erlang) = no.
 
 :- func gen_constructor_function(globals, mlds_class_id,
     mlds_type, mlds_module_name, mlds_class_id, maybe(int), mlds_defns,
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.110
diff -u -r1.110 ml_unify_gen.m
--- compiler/ml_unify_gen.m	8 Jan 2007 03:03:12 -0000	1.110
+++ compiler/ml_unify_gen.m	7 May 2007 02:39:05 -0000
@@ -529,6 +529,8 @@
 target_supports_inheritence(target_asm) = no.
 target_supports_inheritence(target_x86_64) =
     unexpected(this_file, "target_x86_64 and --high-level-code").
+target_supports_inheritence(target_erlang) =
+    unexpected(this_file, "target erlang").
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.148
diff -u -r1.148 mlds.m
--- compiler/mlds.m	18 Mar 2007 23:34:54 -0000	1.148
+++ compiler/mlds.m	7 May 2007 02:39:05 -0000
@@ -1778,7 +1778,8 @@
         module_info_get_type_table(ModuleInfo, Types),
         map.search(Types, TypeCtor, TypeDefn),
         hlds_data.get_type_defn_body(TypeDefn, Body),
-        Body = hlds_foreign_type(foreign_type_body(MaybeIL, MaybeC, MaybeJava))
+        Body = hlds_foreign_type(foreign_type_body(MaybeIL, MaybeC, MaybeJava,
+            _MaybeErlang))
     ->
         module_info_get_globals(ModuleInfo, Globals),
         globals.get_target(Globals, Target),
@@ -1834,6 +1835,9 @@
         ;
             Target = target_x86_64,
             unexpected(this_file, "target x86_64 with --high-level-code")
+        ;
+            Target = target_erlang,
+            unexpected(this_file, "mercury_type_to_mlds_type: target erlang")
         ),
         MLDSType = mlds_foreign_type(ForeignType)
     ;
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.213
diff -u -r1.213 mlds_to_c.m
--- compiler/mlds_to_c.m	18 Mar 2007 23:34:54 -0000	1.213
+++ compiler/mlds_to_c.m	7 May 2007 02:39:06 -0000
@@ -216,6 +216,7 @@
         ( Target = target_java
         ; Target = target_il
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         unexpected(this_file, "expected target asm or target c")
     ).
@@ -380,6 +381,7 @@
         ; Target = target_java
         ; Target = target_asm
         ; Target = target_x86_64
+        ; Target = target_erlang
         )
     ),
     mlds_indent(Indent, !IO),
@@ -490,6 +492,7 @@
         ; Target = target_java
         ; Target = target_asm
         ; Target = target_x86_64
+        ; Target = target_erlang
         )
     ),
     mlds_indent(Indent, !IO),
@@ -805,6 +808,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         sorry(this_file, "foreign code other than C")
     ).
@@ -848,6 +852,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_java
+        ; Lang = lang_erlang
         ),
         sorry(this_file, "foreign code other than C")
     ).
@@ -867,6 +872,8 @@
     sorry(this_file, "foreign code other than C").
 mlds_output_c_defn(_Indent, user_foreign_code(lang_java, _, _), !IO) :-
     sorry(this_file, "foreign code other than C").
+mlds_output_c_defn(_Indent, user_foreign_code(lang_erlang, _, _), !IO) :-
+    sorry(this_file, "foreign code other than C").
 
 :- pred mlds_output_pragma_export_defn(mlds_module_name::in, indent::in,
     mlds_pragma_export::in, io::di, io::uo) is det.
@@ -943,6 +950,9 @@
     ;
         ForeignType = java(_),
         unexpected(this_file, "mlds_output_type_prefix: java foreign_type")
+    ;
+        ForeignType = erlang(_),
+        unexpected(this_file, "mlds_output_type_prefix: erlang foreign_type")
     ).
 mlds_output_pragma_export_type(prefix, mlds_class_type(_, _, _), !IO) :-
     io.write_string("MR_Word", !IO).
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.179
diff -u -r1.179 mlds_to_il.m
--- compiler/mlds_to_il.m	18 Mar 2007 23:34:55 -0000	1.179
+++ compiler/mlds_to_il.m	7 May 2007 02:39:06 -0000
@@ -3133,6 +3133,9 @@
     ;
         ForeignType = java(_),
         unexpected(this_file, "java foreign type")
+    ;
+        ForeignType = erlang(_),
+        unexpected(this_file, "erlang foreign type")
     ).
 
 mlds_type_to_ilds_type(ILDataRep, mlds_ptr_type(MLDSType)) =
Index: compiler/mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.36
diff -u -r1.36 mlds_to_ilasm.m
--- compiler/mlds_to_ilasm.m	1 Dec 2006 15:04:10 -0000	1.36
+++ compiler/mlds_to_ilasm.m	7 May 2007 02:39:06 -0000
@@ -101,6 +101,8 @@
     sorry(this_file, "language IL foreign code not supported").
 handle_foreign_lang(lang_java, _) :-
     sorry(this_file, "language Java foreign code not supported").
+handle_foreign_lang(lang_erlang, _) :-
+    sorry(this_file, "language Erlang foreign code not supported").
 
     % Generate the `.il' file.
     % Returns the set of foreign language
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.91
diff -u -r1.91 mlds_to_java.m
--- compiler/mlds_to_java.m	18 Mar 2007 23:34:55 -0000	1.91
+++ compiler/mlds_to_java.m	7 May 2007 02:39:06 -0000
@@ -474,6 +474,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         sorry(this_file, "foreign decl other than Java")
     ).
@@ -493,6 +494,7 @@
         ; Lang = lang_csharp
         ; Lang = lang_managed_cplusplus
         ; Lang = lang_il
+        ; Lang = lang_erlang
         ),
         sorry(this_file, "foreign code other than Java")
     ).
@@ -1859,6 +1861,9 @@
     ;
         ForeignType = il(_),
         unexpected(this_file, "output_type: il foreign_type")
+    ;
+        ForeignType = erlang(_),
+        unexpected(this_file, "output_type: erlang foreign_type")
     ).
 output_type(mlds_class_type(Name, Arity, _ClassKind), !IO) :-
     % We used to treat enumerations specially here, outputting
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.421
diff -u -r1.421 modules.m
--- compiler/modules.m	4 Mar 2007 23:38:03 -0000	1.421
+++ compiler/modules.m	7 May 2007 02:39:06 -0000
@@ -3413,6 +3413,7 @@
 
         module_name_to_file_name(ModuleName, ".dll", no, DllFileName, !IO),
         module_name_to_file_name(ModuleName, ".class", no, ClassFileName, !IO),
+        module_name_to_file_name(ModuleName, ".beam", no, BeamFileName, !IO),
         SubModules = submodules(ModuleName, AllDeps),
         (
             Target = target_il,
@@ -3473,6 +3474,11 @@
                 ForeignImportTargets = [ClassFileName],
                 ForeignImportExt = ".java"
             ;
+                Target = target_erlang,
+                ForeignImportTargets = [BeamFileName],
+                % XXX not sure about this
+                ForeignImportExt = ".erl"
+            ;
                 Target = target_c,
                 % NOTE: for C (and asm) the possible targets might be a .o
                 % file _or_ a .pic_o file.  We need to include dependencies
@@ -3762,6 +3768,7 @@
             ; ForeignLang = lang_managed_cplusplus
             ; ForeignLang = lang_java
             ; ForeignLang = lang_il
+            ; ForeignLang = lang_erlang
             )
         )
     ;
@@ -4307,6 +4314,7 @@
         ; Target = target_java, Lang = lang_java
         ; Target = target_il, Lang = lang_il
         ; Target = target_x86_64, Lang = lang_c
+        ; Target = target_erlang, Lang = lang_erlang
         ),
         % Assume we need the `.mh' files for all imported modules
         % (we will if they define foreign types).
@@ -4698,6 +4706,7 @@
         ; Target = target_java
         ; Target = target_asm
         ; Target = target_x86_64
+        ; Target = target_erlang
         ),
         ForeignModulesAndExts = []
     ),
@@ -5031,9 +5040,10 @@
             % `.mih' files at all; although perhaps we should...
             ( Target = target_il
             ; Target = target_java
+            ; Target = target_erlang
             )
         ;
-            Target= target_x86_64,
+            Target = target_x86_64,
             unexpected(this_file, "--highlevel-code with --target x86_64")
         )
     ;
@@ -5054,6 +5064,7 @@
     ;
         ( Target = target_il
         ; Target = target_java
+        ; Target = target_erlang
         )
     ),
     io.write_string(DepStream, "\n", !IO),
@@ -5266,6 +5277,10 @@
             Target = target_java,
             Rules = JavaMainRule
         ;
+            Target = target_erlang,
+            % XXX not yet
+            Rules = []
+        ;
             ( Target = target_c
             ; Target = target_asm
             ; Target = target_x86_64    % XXX this is only provisional.
@@ -5360,6 +5375,10 @@
             Target = target_java,
             LibRules = JavaLibRule
         ;
+            Target = target_erlang,
+            % XXX not done yet
+            LibRules = []
+        ;
             ( Target = target_c
             ; Target = target_asm
             ; Target = target_x86_64    % XXX This is only provisional.
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.556
diff -u -r1.556 options.m
--- compiler/options.m	24 Apr 2007 09:23:33 -0000	1.556
+++ compiler/options.m	7 May 2007 02:39:07 -0000
@@ -257,6 +257,8 @@
     % XXX The following options need to be documented.
     ;       x86_64              % target x86_64
     ;       x86_64_only         % target x86_64 + target_code_only
+    ;       erlang              % target erlang
+    ;       erlang_only         % target erlang + target_code_only
 
     % Compilation model options for optional features:
 
@@ -689,6 +691,11 @@
     ;       csharp_flags
     ;       quoted_csharp_flag
 
+    % Erlang
+    ;       erlang_compiler
+    ;       erlang_flags
+    ;       quoted_erlang_flag
+
     % Link options
     ;       output_file_name
     ;       ld_flags
@@ -1038,6 +1045,8 @@
     java_only                           -   special,
     x86_64                              -   special,
     x86_64_only                         -   special,
+    erlang                              -   special,
+    erlang_only                         -   special,
 
     % Optional feature compilation model options:
     % (a) Debuggging
@@ -1431,7 +1440,12 @@
     % C#
     csharp_compiler                     -   string("csc"),
     csharp_flags                        -   accumulating([]),
-    quoted_csharp_flag                  -   string_special
+    quoted_csharp_flag                  -   string_special,
+
+    % Erlang
+    erlang_compiler                     -   string("erlc"),
+    erlang_flags                        -   accumulating([]),
+    quoted_erlang_flag                  -   string_special
 ]).
 option_defaults_2(link_option, [
     % Link Options
@@ -1791,6 +1805,10 @@
 long_option("x86-64",               x86_64).
 long_option("x86_64-only",          x86_64_only).
 long_option("x86-64-only",          x86_64_only).
+long_option("erlang",               erlang).
+long_option("Erlang",               erlang).
+long_option("erlang-only",          erlang_only).
+long_option("Erlang-only",          erlang_only).
 % Optional features compilation model options:
 % (a) debugging
 long_option("debug",                exec_trace).
@@ -2226,6 +2244,10 @@
 long_option("csharp-flags",         csharp_flags).
 long_option("csharp-flag",          quoted_csharp_flag).
 
+long_option("erlang-compiler",      erlang_compiler).
+long_option("erlang-flags",         erlang_flags).
+long_option("erlang-flag",          quoted_erlang_flag).
+
 % link options
 long_option("output-file",          output_file_name).
 long_option("ld-flags",             ld_flags).
@@ -2378,6 +2400,11 @@
 special_handler(x86_64_only, none, OptionTable0, ok(OptionTable)) :-
     map.set(OptionTable0, target, string("x86_64"), OptionTable1),
     map.set(OptionTable1, target_code_only, bool(yes), OptionTable).
+special_handler(erlang, none, OptionTable0, ok(OptionTable)) :-
+    map.set(OptionTable0, target, string("erlang"), OptionTable).
+special_handler(erlang_only, none, OptionTable0, ok(OptionTable)) :-
+    map.set(OptionTable0, target, string("erlang"), OptionTable1),
+    map.set(OptionTable1, target_code_only, bool(yes), OptionTable).
 special_handler(profiling, bool(Value), OptionTable0, ok(OptionTable)) :-
     map.set(OptionTable0, profile_time, bool(Value), OptionTable1),
     map.set(OptionTable1, profile_calls, bool(Value), OptionTable2),
@@ -2518,6 +2545,9 @@
 special_handler(quoted_csharp_flag, string(Flag),
         OptionTable0, ok(OptionTable)) :-
     handle_quoted_flag(csharp_flags, Flag, OptionTable0, OptionTable).
+special_handler(quoted_erlang_flag, string(Flag),
+        OptionTable0, ok(OptionTable)) :-
+    handle_quoted_flag(erlang_flags, Flag, OptionTable0, OptionTable).
 special_handler(quoted_ld_flag, string(Flag),
         OptionTable0, ok(OptionTable)) :-
     handle_quoted_flag(ld_flags, Flag, OptionTable0, OptionTable).
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.104
diff -u -r1.104 pragma_c_gen.m
--- compiler/pragma_c_gen.m	22 Feb 2007 03:50:36 -0000	1.104
+++ compiler/pragma_c_gen.m	7 May 2007 02:39:07 -0000
@@ -1435,7 +1435,7 @@
         map.search(Types, TypeId, Defn),
         hlds_data.get_type_defn_body(Defn, Body),
         Body = hlds_foreign_type(
-            foreign_type_body(_MaybeIL, MaybeC, _MaybeJava))
+            foreign_type_body(_MaybeIL, MaybeC, _MaybeJava, _MaybeErlang))
     ->
         (
             MaybeC = yes(Data),
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.188
diff -u -r1.188 prog_data.m
--- compiler/prog_data.m	22 Feb 2007 03:50:36 -0000	1.188
+++ compiler/prog_data.m	7 May 2007 02:39:07 -0000
@@ -168,7 +168,8 @@
 :- type foreign_language_type
     --->    il(il_foreign_type)
     ;       c(c_foreign_type)
-    ;       java(java_foreign_type).
+    ;       java(java_foreign_type)
+    ;       erlang(erlang_foreign_type).
 
 :- type il_foreign_type
     --->    il_type(
@@ -188,6 +189,9 @@
                 string      % The Java type name
             ).
 
+:- type erlang_foreign_type
+    --->    erlang_type.    % Erlang is untyped.
+
 :- type ref_or_val
     --->    reference
     ;       value.
Index: compiler/prog_foreign.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_foreign.m,v
retrieving revision 1.12
diff -u -r1.12 prog_foreign.m
--- compiler/prog_foreign.m	4 Mar 2007 23:38:05 -0000	1.12
+++ compiler/prog_foreign.m	7 May 2007 02:39:07 -0000
@@ -209,6 +209,9 @@
         Lang = lang_java,
         ModuleName = ForeignImportModule
     ;
+        Lang = lang_erlang,
+        ModuleName = ForeignImportModule
+    ;
         Lang = lang_managed_cplusplus,
         ModuleName = foreign_language_module_name(ForeignImportModule, Lang)
     ;
@@ -240,6 +243,10 @@
         Lang = lang_java,
         ImportedForeignCodeModuleName = handle_std_library(CurrentModule,
             ImportedForeignCodeModuleName1)
+    ;
+        Lang = lang_erlang,
+        ImportedForeignCodeModuleName = handle_std_library(CurrentModule,
+            ImportedForeignCodeModuleName1)
     ).
 
     % On the il backend, we need to refer to the module "mercury" when
@@ -336,6 +343,10 @@
         no
     ).
 
+prefer_foreign_language(_Globals, target_erlang, _Lang1, _Lang2) = no.
+    % Nothing useful to do here, but when we add Erlang as a foreign language,
+    % we should add it here.
+
 %-----------------------------------------------------------------------------%
 
 foreign_language(lang_c).
@@ -343,12 +354,14 @@
 foreign_language(lang_csharp).
 foreign_language(lang_managed_cplusplus).
 foreign_language(lang_il).
+foreign_language(lang_erlang).
 
 %-----------------------------------------------------------------------------%
 
 foreign_type_language(il(_)) = lang_il.
 foreign_type_language(c(_)) = lang_c.
 foreign_type_language(java(_)) = lang_java.
+foreign_type_language(erlang(_)) = lang_erlang.
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/prog_io_pragma.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.123
diff -u -r1.123 prog_io_pragma.m
--- compiler/prog_io_pragma.m	4 Mar 2007 23:38:05 -0000	1.123
+++ compiler/prog_io_pragma.m	7 May 2007 02:39:07 -0000
@@ -940,6 +940,14 @@
             Result = error1(["invalid backend specification term" - InputTerm])
         )
     ;
+        Language = lang_erlang,
+        ( InputTerm = term.functor(term.string(_ErlangTypeName), [], _) ->
+            % XXX should we check if the type is blank?
+            Result = ok1(erlang(erlang_type))
+        ;
+            Result = error1(["invalid backend specification term" - InputTerm])
+        )
+    ;
         ( Language = lang_managed_cplusplus
         ; Language = lang_csharp
         ),
@@ -1647,6 +1655,7 @@
         Res = ok1(Attrs)
     ).
 check_required_attributes(lang_java, Attrs, _Term) = ok1(Attrs).
+check_required_attributes(lang_erlang, Attrs, _Term) = ok1(Attrs).
 
 :- pred parse_pragma_foreign_proc_attributes_term0(varset::in, term::in,
     list(collected_pragma_foreign_proc_attribute)::out) is semidet.
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.208
diff -u -r1.208 simplify.m
--- compiler/simplify.m	26 Apr 2007 09:10:42 -0000	1.208
+++ compiler/simplify.m	7 May 2007 02:39:08 -0000
@@ -1529,6 +1529,7 @@
                             ; Target = target_java
                             ; Target = target_asm
                             ; Target = target_x86_64
+                            ; Target = target_erlang
                             ),
                             sorry(this_file, "NYI: runtime trace conditions "
                                 ++ "in languages other than C")
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list