[m-rev.] for review: module initialisation for erlang

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jun 7 17:55:21 AEST 2007


On Thu, 7 Jun 2007, Peter Wang wrote:

> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ util/mkinit_common.c	7 Jun 2007 05:31:27 -0000

...

> +/*---------------------------------------------------------------------------*/
> +
> +/*
> +** Add the directory name to the end of the ** search path for `.init' files.
> +*/

Delete '**' from the middle of that comment.

...

> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ util/mkinit_common.h	7 Jun 2007 05:31:27 -0000
> @@ -0,0 +1,45 @@
> +#ifndef MKINIT_COMMON_H
> +#define MKINIT_COMMON_H
> +
> +#include    <stdio.h>
> +
> +/*
> +** mercury_array_macros.h uses the MR_NEW_ARRAY and MR_RESIZE_ARRAY macros.
> +*/
> +
> +#define MR_NEW_ARRAY(type, num) \
> +        ((type *) malloc((num) * sizeof(type)))
> +
> +#define MR_RESIZE_ARRAY(ptr, type, num) \
> +        ((type *) realloc((ptr), (num) * sizeof(type)))
> +
> +/* --- adjustable limits --- */
> +#define MAXLINE     256 /* maximum number of characters per line */
> +                        /* (characters after this limit are ignored) */
> +
> +/* --- used to collect a list of strings --- */
> +
> +typedef struct String_List_struct {
> +    char                        *data;
> +    struct String_List_struct   *next;
> +} String_List;
> +
> +/* --- global variables --- */
> +
> +extern const char *MR_progname;
> +extern int         num_errors;
> +
> +extern  void    set_output_file(const char *output_file_name);
> +extern	void	add_init_file_dir(const char *dir_name);
> +extern	void	do_path_search(char **files, int num_files);

Fix the indentation there.

> +extern  char    *read_line(const char *filename, FILE *fp, int max);
> +extern  int     get_line(FILE *file, char *line, int line_max);
> +extern  void    *checked_malloc(size_t size);
> +extern  char    *checked_strdup(const char *str);
> +extern  char    *checked_strdupcat(const char *str, const char *suffix);

...

> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ util/mkinit_erl.c	7 Jun 2007 05:31:27 -0000
> @@ -0,0 +1,609 @@
> +/*
> +** vim:sw=4 ts=4 expandtab
> +*/
> +/*
> +** Copyright (C) 2007 The University of Melbourne.
> +** This file may only be copied under the terms of the GNU General
> +** Public License - see the file COPYING in the Mercury distribution.
> +*/
> +
> +/*
> +** File: mkinit_erl.c
> +** Main authors: zs, fjh, wangp
> +**
> +** Given a list of .erl or .init files on the command line, this program
> +** produces the initialization file (usually called *_init.erl) on stdout.
> +** The initialization file is a small program that calls the initialization
> +** functions for all the modules in a Mercury program.
> +**
> +** Alternatively, if invoked with the -k option, this program produces a
> +** list of intialization directives on stdout.  This mode of operation is
> +** is used when building .init files for libraries.
> +**
> +** If invoked with the -s option, this program produces a standalone
> +** runtime interface on stdout.  This mode of operation is used when
> +** using Mercury libraries from applications written in foreign languages.

That last sentence is true for the C version, for the Erlang backend
it's (probably) only so that you can call Mercury libraries from Erlang
applications - does that particular mode of usage work for the Erlang
backend (yet)?

> +/*
> +** List of names of the modules to call all the usual initialization
> +** functions for: "init", "init_type_tables", "init_debugger" and (with
> +** the right #defines) "init_complexity_procs" and "write_out_proc_statics".
> +*/

Delete the C backend specific stuff in these comments.

> +
> +static const char   **std_modules = NULL;
> +static int          std_module_max = 0;
> +static int          std_module_next = 0;
> +#define MR_INIT_STD_MODULE_SIZE     100
> +
> +/*
> +** List of names of handwritten modules, for which we call a limited set
> +** of initialization functions: "init", "init_type_tables" and (with
> +** the right #defines) "write_out_proc_statics". We don't call
> +** "init_debugger" functions since handwritten modules don't have module
> +** layouts, and we don't generate "init_complexity_procs" since they have
> +** no Mercury code to measure the complexity of.
> +*/
> +

...

> +static void
> +process_init_file(const char *filename, const char *prefix_str)
> +{
> +    /*
> +    ** The strings that are supposed to be followed by other information
> +    ** (INIT, REQUIRED_INIT, and REQUIRED_FINAL) should end with
> +    ** the space that separates the keyword from the following data.
> +    ** The string that is not supposed to be following by other information
> +    ** (ENDINIT) should not have a following space, since llds_out.m and
> +    ** mlds_to_c.m do not add that space.
> +    */

Fix that comment: llds_out.m and mlds_to_c.m don't generate Erlang.
Does the Erlang code generator have the same behaviour?

> +
> +    const char * const  init_str = "INIT ";
> +    const char * const  reqinit_str = "REQUIRED_INIT ";
> +    const char * const  reqfinal_str = "REQUIRED_FINAL ";
> +    const char * const  envvar_str = "ENVVAR ";
> +    const char * const  endinit_str = "ENDINIT";
> +    const int           prefix_strlen = strlen(prefix_str);
> +    const int           init_strlen = strlen(init_str);
> +    const int           reqinit_strlen = strlen(reqinit_str);
> +    const int           reqfinal_strlen = strlen(reqfinal_str);
> +    const int           envvar_strlen = strlen(envvar_str);
> +    const int           endinit_strlen = strlen(endinit_str);
> +    char                line0[MAXLINE];
> +    char *              line;
> +    int                 len;
> +    FILE                *cfile;
> +
> +    cfile = fopen(filename, "r");

s/cfile/erl_file/

The rest looks okay.

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