[m-rev.] for review: erlang external procs and mmc --make support

Peter Ross pro at missioncriticalit.com
Wed May 30 14:15:54 AEST 2007


On Wed, May 30, 2007 at 01:03:59PM +1000, Peter Wang wrote:
> Estimated hours taken: 25
> Branches: main
> 
> Add support for :- external procedures to the Erlang backend.
> 
> Add Erlang support to mmc --make.
> 
> compiler/elds.m:
> 	Extend the ELDS for definitions of external procedures.
> 
> compiler/elds_to_erlang.m:
> 	Move the logic for mapping a module name to a file name into
> 	module_name_to_file_name, as it is needed for mmc --make as well.
> 
> 	Similarly move erlang_module_name to modules.m.
> 
> 	Output export annotations for :- external procedures which are
> 	exported.
> 
> 	Conform to changes in the ELDS.
> 
> compiler/erl_call_gen.m:
> 	Don't generate assignment statements between variables of dummy types.
> 
> compiler/erl_code_gen.m:
> 	Generate skeleton ELDS definitions for external procedures.
> 
> 	Fix more cases where success expressions could be inserted after
> 	`erroneous' goals.  The Erlang compiler would complain about unbound
> 	variables appearing in success expressions following erroneous goals,
> 	because it doesn't know that the erroneous goal would throw an
> 	exception.
> 
> 	Handle some special cases with `erroneous' and `failure' goals where we
> 	used to generate code that the Erlang compiler would complain about
> 	references to unbound variables, or variables being bound in one branch
> 	of a conditional statement but not another, etc.
> 
> 	- handle a special case where the goal inside a commit scope has
> 	determinism `failure', i.e. it would never actually commit;
> 	
> 	- handle a special case where the condition of an if-then-else is
> 	`erroneous', so the Then branch can't be reached;
> 
> 	- handle a special case where a disjunct has determinism `failure',
> 	so later disjuncts will always be evaluated.
> 
> 	Generate code for promise_solutions and exist_quant scopes.
> 
> 	Wrap large success expressions in closures instead of duplicating them
> 	into each disjunct, in the same way that we do for switches.
> 
> 	Disable duplicating of small success expressions into branches of
> 	switches and disjunctions for now, as the implmentation is buggy.
> 
> compiler/handle_options.m:
> 	Remove the LLDS and MLDS options from the grade_component_table entry
> 	for the "erlang" grade.  They caused compute_grade to return "none" if
> 	only --target erlang was used (because --target erlang didn't imply the
> 	same set of meaningless options).
> 
> compiler/hlds_pred.m:
> 	Fix the implementations of `status_is_exported' and
> 	`status_defined_in_this_module' for external procedures.
> 
> compiler/compile_target_code.m:
> compiler/make.dependencies.m:
> compiler/make.m:
> compiler/make.module_target.m:
> compiler/make.program_target.m:
> compiler/make.util.m:
> compiler/modules.m:
> 	Add Erlang support to mmc --make.  It can build "libraries" (we just
> 	use directories called libFOO.beams containing Erlang .beam bytecode
> 	files), install them and executables (which are just shell scripts
> 	which invoke the Erlang runtime system).
> 
> 	Refactor some code and fix a few assumptions in places that we were
> 	building for the C backends.
> 
> 	Replace some calls to io.remove_file by io.remove_file_recursively as
> 	our Erlang "libraries" are actually directories.
> 
> 	Unrelated bugfix: for mmc --make --use-grade-subdirs foo.realclean,
> 	remove the symlink created for foo.init in the current directory.
> 
> 	Delete module_name_to_file_name_sep as it is no longer used.
> 
> compiler/options.m:
> 	Add options --erlang-interpreter, --erlang-object-file-extension
> 	adn --install-command-dir-option.
> 
> doc/user_guide.texi:
> 	Document --install-command-dir-option.
> 
> tests/mmc_make/Mmakefile:
> 	Generate TEST_FLAGS *after* start_runtests_local as
> 	start_runtests_local runs make realclean_local, which deletes
> 	TEST_FLAGS.
> 
> library/io.m:
> 	Add io.remove_file_recursively which can remove non-empty directories.
> 
> 	Fix the fallback implmentation io.buffer_to_string which was calling a
> 	non-existent `from_char_list_semidet' predicate.
> 
> NEWS:
> 	Mention io.remove_file_recursively.
> 
> 
Looks fine, just some minor comments below.

> Index: compiler/elds_to_erlang.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/elds_to_erlang.m,v
> retrieving revision 1.4
> diff -u -r1.4 elds_to_erlang.m
> --- compiler/elds_to_erlang.m	28 May 2007 03:13:51 -0000	1.4
> +++ compiler/elds_to_erlang.m	30 May 2007 03:00:02 -0000
> @@ -553,9 +553,19 @@
>      RttiProcName = rtti_proc_label(PredOrFunc, ThisModule, PredModule,
>          PredName, PredArity, _ArgTypes, _PredId, _ProcId,
>          _HeadVarsWithNames, _ArgModes, _Detism,
> -        PredIsImported, _PredIsPseudoImported,
> +        PredIsImported0, _PredIsPseudoImported,
>          Origin, _ProcIsExported, _ProcIsImported),
>  
> +    % XXX I think pred_info_is_imported is wrong for status_external
> +    % procedures

I'm afraid I don't know, does someone else?

> +    module_info_pred_info(ModuleInfo, PredId, PredInfo),
> +    pred_info_get_import_status(PredInfo, ImportStatus),
> +    ( ImportStatus = status_external(_) ->
> +        PredIsImported = no
> +    ;
> +        PredIsImported = PredIsImported0
> +    ),
> +
>      ( Origin = origin_special_pred(SpecialPred) ->
>          erlang_special_proc_name(ThisModule, PredName, ProcId, SpecialPred,
>              MaybeExtModule, ProcNameStr)

> Index: compiler/modules.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
> retrieving revision 1.425
> diff -u -r1.425 modules.m
> --- compiler/modules.m	27 May 2007 00:59:32 -0000	1.425
> +++ compiler/modules.m	30 May 2007 03:00:02 -0000
> @@ -844,25 +859,34 @@
>      mercury_std_library_module(ModuleNameStr).
>  
>  module_name_to_search_file_name(ModuleName, Ext, FileName, !IO) :-
> -    module_name_to_file_name_sep(ModuleName, ".", Ext, yes, no, FileName, !IO).
> +    module_name_to_file_name_2(ModuleName, Ext, yes, no, FileName, !IO).
>  
>  module_name_to_file_name(ModuleName, Ext, MkDir, FileName, !IO) :-
> -    module_name_to_file_name_sep(ModuleName, ".", Ext, no, MkDir, FileName,
> +    module_name_to_file_name_2(ModuleName, Ext, no, MkDir, FileName,
>          !IO).
>  
> -module_name_to_file_name_sep(ModuleName, Sep, Ext, MkDir, FileName, !IO) :-
> -    module_name_to_file_name_sep(ModuleName, Sep, Ext, no, MkDir, FileName,
> -        !IO).
> -
> -:- pred module_name_to_file_name_sep(module_name::in, string::in, string::in,
> +:- pred module_name_to_file_name_2(module_name::in, string::in,
>      bool::in, bool::in, file_name::out, io::di, io::uo) is det.
>  
> -module_name_to_file_name_sep(ModuleName, Sep, Ext, Search, MkDir, FileName,
> -        !IO) :-
> +module_name_to_file_name_2(ModuleName0, Ext, Search, MkDir, FileName, !IO) :-
>      ( Ext = ".m" ->
>          % Look up the module in the module->file mapping.
> -        source_file_map.lookup_module_source_file(ModuleName, FileName, !IO)
> +        source_file_map.lookup_module_source_file(ModuleName0, FileName, !IO)
>      ;
> +        (
> +            ( Ext = ".erl" 
> +            ; Ext = ".beam"
> +            )
> +        ->
> +            % Erlang uses `.' as a package separator and expects a module
> +            % `a.b.c' to be in a file `a/b/c.erl'.  Rather than that, we use
> +            % a flat namespace with `__' as module separators.

There could be something to be said for using the package notation
somehow for libraries.  Not sure how to do it though.

> +            Sep = "__",
> +            ModuleName = erlang_module_name(ModuleName0)
> +        ;
> +            Sep = ".",
> +            ModuleName = ModuleName0
> +        ),
>          string.append(sym_name_to_string_sep(ModuleName, Sep), Ext, BaseName),
>          choose_file_name(ModuleName, BaseName, Ext, Search, MkDir, FileName,
>              !IO)

-- 
Software Engineer                                (Work)   +32 2 757 10 15
Mission Critical                                 (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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