Files
mercury/browser/browser_term.m
Julien Fischer 459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00

85 lines
3.2 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2004-2006 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
% File: browser_term.m.
% This module defines a type to represent both natural and synthetic terms
% for use by the browser.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- module mdb.browser_term.
:- interface.
:- import_module bool.
:- import_module list.
:- import_module maybe.
:- import_module univ.
%---------------------------------------------------------------------------%
:- type browser_term
---> plain_term(
univ % We are browsing a plain term.
)
; synthetic_term(
string, % We are browsing a synthetic term,
% such as a predicate name applied to
% a list of arguments. The string says
% what we should print as the functor.
list(univ), % The arguments.
maybe(univ) % If yes, the synthetic term represents
% a function call, and the argument
% inside the yes() is the return value.
).
% This predicate converts a term represented as univ to a browser term.
%
:- func univ_to_browser_term(univ) = browser_term.
% This predicate converts a plain term from the representation used
% in the trace directory to a browser term.
%
:- func plain_term_to_browser_term(T) = browser_term.
% This predicate converts a synthetic term from the representation used
% in the trace directory (as a list of arguments, the last of which
% represents the return value for function calls) to the representation
% used in the browser directory, in which a function call's return
% value is stored separately from the other arguments.
%
% The reason why the trace directory does not use the latter representation
% is that it would require C code to construct values of type maybe(T).
%
:- func synthetic_term_to_browser_term(string, list(univ), bool)
= browser_term.
:- implementation.
:- pragma export(plain_term_to_browser_term(in) = out,
"ML_BROWSE_plain_term_to_browser_term").
:- pragma export(univ_to_browser_term(in) = out,
"ML_BROWSE_univ_to_browser_term").
:- pragma export(synthetic_term_to_browser_term(in, in, in) = out,
"ML_BROWSE_synthetic_term_to_browser_term").
univ_to_browser_term(Univ) = plain_term(Univ).
plain_term_to_browser_term(Term) = plain_term(univ(Term)).
synthetic_term_to_browser_term(FunctorString, Args, IsFunc) = BrowserTerm :-
(
IsFunc = no,
BrowserTerm = synthetic_term(FunctorString, Args, no)
;
IsFunc = yes,
list.split_last_det(Args, FuncArgs, Return),
BrowserTerm = synthetic_term(FunctorString, FuncArgs, yes(Return))
).