Files
mercury/compiler/static_term.m
Zoltan Somogyi 3ce3b14c84 Make procedure bodies available to the declarative debugger.
Estimated hours taken: 20

Make procedure bodies available to the declarative debugger.

browser/program_representation.m:
	Add _rep suffixes to the function symbols, to make iit easier to
	distinguish HLDS goals and goal representations.

compiler/static_layout.m:
	If --trace-decl is specified, include a representation of the procedure
	body in the procedure's layout structure.

compiler/prog_rep.m:
	A new module, containing the code that converts goals from HLDS
	to a term in the format we want to put in the layout structure.

compiler/static_term.m:
	A new module, containing the code that converts Mercury terms
	to the LLDS rval we need to give to llds_out.m.

compiler/code_gen.m:
compiler/continuation_info.m:
	Preserve the information needed by prog_rep

compiler/Mmakefile:
	Extend the search path to the browser directory, since the new file
	prog_rep.m imports one of the submodules of mdb.m stored there.

compiler/notes/compiler_desigm.html:
	Document the new modules.

library/std_util.m:
	Add a mechanism for static_term.m to use in converting terms into
	rvals. This mechanism uses RTTI information to deconstruct terms,
	and return not only their arguments, but also information about how
	the term can be constructed from its arguments.

runtime/mercury_type_info.h:
	Add a couple of macros to make construction and deconstruction of univs
	easier, for use in std_util.m.

trace/mercury_trace_internal.c:
	Add a new command, "proc_body", that prints out the representation
	of the body of the current procedure. This is meant only for developers
	to use to check that the procedure body representation is OK; it is
	deliberately not documented.

	Also fix a bug: make sure that we do not pass a NULL pointer to fputs
	when echoing a line of input that isn't there (because we got EOF).
2000-09-25 04:37:26 +00:00

95 lines
3.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% Copyright (C) 2000 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: static_term.m.
% Author: zs.
%
% This module handles the conversion of Mercury terms in the compiler
% into rvals we can give to llds_out.m in order to make those terms available
% at runtime in the program being compiled.
%
%---------------------------------------------------------------------------%
:- module static_term.
:- interface.
:- import_module llds.
:- import_module counter, std_util.
:- pred static_term__term_to_rval(univ::in, maybe(rval)::out,
counter::in, counter::out) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module builtin_ops.
:- import_module list, require.
static_term__term_to_rval(Univ, Rval, CellCounter0, CellCounter) :-
( std_util__get_functor_info(Univ, FunctorInfo) ->
static_term__functor_info_to_rval(FunctorInfo, Rval,
CellCounter0, CellCounter)
;
error("static_term__term_to_rval: unexpected kind of term")
).
:- pred static_term__functor_info_to_rval(functor_tag_info::in,
maybe(rval)::out, counter::in, counter::out) is det.
static_term__functor_info_to_rval(FunctorInfo, MaybeRval,
CellCounter0, CellCounter) :-
(
FunctorInfo = functor_integer(Int),
MaybeRval = yes(const(int_const(Int))),
CellCounter = CellCounter0
;
FunctorInfo = functor_float(Float),
MaybeRval = yes(const(float_const(Float))),
CellCounter = CellCounter0
;
FunctorInfo = functor_string(String),
MaybeRval = yes(const(string_const(String))),
CellCounter = CellCounter0
;
FunctorInfo = functor_enum(Enum),
MaybeRval = yes(const(int_const(Enum))),
CellCounter = CellCounter0
;
FunctorInfo = functor_local(Ptag, Sectag),
MaybeRval = yes(mkword(Ptag,
unop(mkbody, const(int_const(Sectag))))),
CellCounter = CellCounter0
;
FunctorInfo = functor_remote(Ptag, Sectag, Args),
MaybeSectagRval = yes(const(int_const(Sectag))),
list__map_foldl(static_term__term_to_rval,
Args, MaybeArgRvals, CellCounter0, CellCounter1),
counter__allocate(CNum, CellCounter1, CellCounter),
Reuse = no,
MaybeRval = yes(create(Ptag, [MaybeSectagRval | MaybeArgRvals],
uniform(no), must_be_static, CNum,
"static_term", Reuse))
;
FunctorInfo = functor_unshared(Ptag, Args),
list__map_foldl(static_term__term_to_rval,
Args, MaybeArgRvals, CellCounter0, CellCounter1),
counter__allocate(CNum, CellCounter1, CellCounter),
Reuse = no,
MaybeRval = yes(create(Ptag, MaybeArgRvals,
uniform(no), must_be_static, CNum,
"static_term", Reuse))
;
FunctorInfo = functor_notag(Univ),
static_term__term_to_rval(Univ, MaybeRval,
CellCounter0, CellCounter)
;
FunctorInfo = functor_equiv(Univ),
static_term__term_to_rval(Univ, MaybeRval,
CellCounter0, CellCounter)
).