[m-rev.] for review: standalone interfaces

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Feb 8 01:27:40 AEDT 2007


On Wed, 7 Feb 2007, Peter Ross wrote:

...

>> Index: compiler/compile_target_code.m
>> ===================================================================
>> RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
>> retrieving revision 1.103
>> diff -u -r1.103 compile_target_code.m
>> --- compiler/compile_target_code.m	8 Jan 2007 03:03:08 -0000	1.103
>> +++ compiler/compile_target_code.m	5 Feb 2007 06:22:33 -0000
>> @@ -167,6 +167,14 @@
>>      is det.
>>
>>  %-----------------------------------------------------------------------------%
>> +
>> +    % make_standalone_interface(Basename, !IO):
>> +    %
>> +    % Create a standalone interface in the current directory.
>> +    %
>> +:- pred make_standalone_interface(string::in, io::di, io::uo) is det.
>> +
>
> More description of what a stand-alone interface is needed (eg what you
> have in the log message).

The documentation, i.e what a stand-alone interfact is etc, belongs in the 
user's guide, are there are any particular implementation aspects that
you think need documenting here?

...

>> +:- pred make_standalone_int_body(string::in, io::di, io::uo) is det.
>> +
>> +make_standalone_int_body(Basename, !IO) :-
>> +    globals.io_get_globals(Globals, !IO),
>> +    globals.lookup_accumulating_option(Globals, init_files, InitFiles0),
>> +    globals.lookup_accumulating_option(Globals, trace_init_files,
>> +        TraceInitFiles0),
>> +    globals.lookup_maybe_string_option(Globals,
>> +        mercury_standard_library_directory, MaybeStdLibDir),
>> +    grade_directory_component(Globals, GradeDir),
>> +    (
>> +        MaybeStdLibDir = yes(StdLibDir),
>> +        InitFiles1 = [
>> +            StdLibDir / "modules" / GradeDir / "mer_rt.init",
>> +            StdLibDir / "modules" / GradeDir / "mer_std.init" |
>> +            InitFiles0
>> +        ],
>> +        TraceInitFiles = [
>> +            StdLibDir / "modules" / GradeDir / "mer_browser.init",
>> +            StdLibDir / "modules" / GradeDir / "mer_mdbcomp.init" |
>> +            TraceInitFiles0
>> +        ]
>> +    ;
>> +        % Supporting `--no-mercury-standard-library-directory' is necessary
>> +        % in order to use `--generate-standalone-interface' with the
>> +        % the lmc script.
>> +        MaybeStdLibDir = no,
>> +        InitFiles1 = InitFiles0,
>> +        TraceInitFiles = TraceInitFiles0
>> +    ),
>> +    globals.get_trace_level(Globals, TraceLevel),
>> +    ( given_trace_level_is_none(TraceLevel) = no ->
>> +        TraceOpt = "-t",
>> +        InitFiles = InitFiles1 ++ TraceInitFiles
>> +    ;
>> +        TraceOpt = "",
>> +        InitFiles = InitFiles1
>> +    ),
>> +    join_string_list(InitFiles, "", "", " ", InitFilesList),
>> +    globals.lookup_accumulating_option(Globals, runtime_flags,
>> +        RuntimeFlagsList),
>> +    join_quoted_string_list(RuntimeFlagsList, "-r ", "", " ",
>> RuntimeFlags),
>> +    globals.lookup_string_option(Globals, experimental_complexity,
>> +        ExperimentalComplexity),
>> +    ( ExperimentalComplexity = "" ->
>> +        ExperimentalComplexityOpt = ""
>> +    ;
>> +        ExperimentalComplexityOpt = "-X " ++ ExperimentalComplexity
>> +    ),
>> +    compute_grade(Globals, Grade),
>> +    globals.lookup_string_option(Globals, mkinit_command, MkInit),
>> +    CFileName = Basename ++ ".c",
>> +    io.output_stream(ErrorStream, !IO),
>> +    MkInitCmd = string.append_list(
>> +        [   MkInit,
>> +            " -g ", Grade,
>> +            " ", TraceOpt,
>> +            " ", ExperimentalComplexityOpt,
>> +            " ", RuntimeFlags,
>> +            " -o ", quote_arg(CFileName),
>> +            " -s ", InitFilesList
>> +        ]),
>> +    invoke_system_command(ErrorStream, cmd_verbose, MkInitCmd, MkInitCmdOk,
>> +        !IO),
>> +    (
>> +        MkInitCmdOk = yes,
>> +        get_object_code_type(executable, PIC, !IO),
>> +        maybe_pic_object_file_extension(PIC, ObjExt, !IO),
>> +        ObjFileName = Basename ++ ObjExt,
>> +        compile_c_file(ErrorStream, PIC, CFileName, ObjFileName,
>> +            CompileOk, !IO),
>> +        (
>> +            CompileOk = yes
>> +        ;
>> +            CompileOk = no,
>> +            io.set_exit_status(1, !IO),
>> +            io.write_string("mercury_compile: error while compiling ",
>> !IO),
>> +            io.write_string("standalone interface in `", !IO),
>> +            io.write_string(CFileName, !IO),
>> +            io.write_string("'\n", !IO)
>> +        )
>> +    ;
>> +        MkInitCmdOk = no,
>> +        io.set_exit_status(1, !IO),
>> +        io.write_string("mercury_compile: error while creating ", !IO),
>> +        io.write_string("standalone interface in `", !IO),
>> +        io.write_string(CFileName, !IO),
>> +        io.write_string("'\n", !IO)
>> +    ).
>> +
>
> Is it possible to factor out the code which is common to make_init_obj?
> I imagine a lot of it is exactly the same.

Yes, it should be possible to factor quite a bit of it out - I'll do
that as a separate change though.

Julien.
--------------------------------------------------------------------------
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