Zoltan Somogyi 985ef93c1c Add a string builder that tracks line numbers.
I would like to change mlds_to_c_*.m from writing stuff out directly
to using a string builder. However, the existing string.builder.m
won't work, because when writing out .c/.mh/.mih files with --line-numbers,
we need to generate #line directives before and after the MLDS statements
generated for foreign_procs.

The #line directive before is no problem: the context it writes is
the context of the pragma foreign_proc. The #line directive after, however,
wants to output the line number *in the file we are writing the C code to*.
The usual string builder has no way to peek into the component strings
accumulated so far without destroying its uniqueness. We *could* use
unsafe promises of uniqueness to get around this, but I don't think
that would be a good idea. This is because counting the newline chars
in the component strings so far once for *every* foreign_proc would have
0.5 N*M complexity, where N and M are the number of foreign_procs
and the total length of the generate C file respectively, and for
the kinds of programs we use as stress tests, both can be huge.

It would be better to do in a string builder what the Mercury stream
implementation already does: count the newlines in each string
as it is being written out, and update the current line number
accordingly. This is better because its complexity is linear,
*and* because it has better locality. This diff does that.

compiler/lines_builder.m:
    This new module is a near-copy of string.builder.m. It differs in

    - keeping the (unchanging) filename and the (continually updated)
      line number in the string builder state,

    - adding a filename and an initial line number (usually 1)
      as parameters of the state init function,

    - having a predicate that returns the filename and the line number
      in a given state,

    - to make that predicate possible, threading the state through
      all operations as in/out pairs, not di/uo pairs, and

    - due to that change in modes, NOT having this kind of string builder
      be an instance of the stream typeclasses that the existing
      string builder type is an instance of.

compiler/libs.m:
    Include the new module in this package.

compiler/notes/compiler_design.html:
    Document the new module.
2024-09-02 10:11:02 +02:00
2023-06-25 03:10:12 +10:00
2023-01-23 13:09:02 +11:00
2024-03-13 16:50:00 +11:00
2024-08-14 12:39:13 +02:00
2023-06-26 20:05:24 +10:00
2024-08-26 17:34:40 +02:00
2023-06-26 20:05:24 +10:00
2024-01-03 17:02:19 +11:00
2024-02-29 06:48:35 +11:00
2023-01-22 23:56:54 +11:00
2023-01-23 17:11:45 +11:00
2023-01-23 04:11:07 +11:00
2023-01-23 02:13:54 +11:00
2023-09-13 16:49:23 +10:00
2023-01-22 19:35:40 +11:00
2024-01-14 17:11:17 +11:00
2023-01-23 13:09:02 +11:00

Mercury

Mercury is a logic/functional programming language which combines the clarity and the expressiveness of declarative programming with advanced static analysis and error detection features.

More information is available on the website's about pages, in other README files in the source code repository, and in the documentation.

Small sample programs written in Mercury can be found in the samples and extras directories of the source code repository.

README files

The Mercury compiler has two different backends and works on different operating systems. Specific information is contained in individual README files:

Other information

See the current release notes for the latest stable release. The news file lists any recent changes. The history file is relevant if you want to find out more about the past development of Mercury. The limitations file lists some ways in which the Mercury implementation does not yet meet its goals.

Information for developers

If you are considering contributing to the Mercury project, the website contains some documents that may be helpful. These include a document about contributions in general and specific information about contributing such as coding styles.

Contact

See our contact page.

Description
No description provided
Readme MIT 145 MiB
Languages
Mercury 85.4%
C 8.7%
Shell 1.4%
Makefile 1%
JavaScript 1%
Other 2%