for review: exposing the table data structure for benchmarking
Zoltan Somogyi
zs at cs.mu.OZ.AU
Tue Nov 24 12:58:02 AEDT 1998
This is for Tyson.
Estimated hours taken: 16
Reorganize the handling of global data structures, and expose the table
pointers for tabled predicates to allow the tables to be reset to empty
by hand-written C code for benchmarking purposes.
compiler/hlds_module.m:
Introduce a new submodule for dealing with global data.
At the moment it deals with (a) layout structures and (b)
tabling pointers.
compiler/continuation_info.m:
Remove the data structures and predicates whose equivalents are now
in hlds_module.
compiler/llds.m:
Introduce a new kind of item, that of compiler-generated variables
whose value is not defined by rvals. At the moment, the only such
item is a tabling pointer variable.
compiler/mercury_compile.m:
Include the new kind of item in the generated LLDS.
compiler/table_gen.m:
Use the new kind of item instead of a static variable declaration
in pragma C code to hold the tabling pointer.
Remove lots of spaces at ends of lines, since many of these screw up
paragraph commands in vi.
compiler/base_type_layout.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_util.m:
compiler/dependency_graph.m:
compiler/hlds_out.m:
compiler/llds_out.m:
compiler/mercury_to_mercury.m:
compiler/switch_gen.m:
compiler/transform_llds.m:
compiler/unify_gen.m:
Handle the changes in the data structures.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/base_type_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_layout.m,v
retrieving revision 1.37
diff -u -u -r1.37 base_type_layout.m
--- base_type_layout.m 1998/11/20 04:06:58 1.37
+++ base_type_layout.m 1998/11/20 11:47:23
@@ -1229,6 +1229,8 @@
unused).
base_type_layout__tag_type_and_value(base_typeclass_info_constant(_, _, _), -1,
unused).
+base_type_layout__tag_type_and_value(tabling_pointer_constant(_, _), -1,
+ unused).
% Get the arguments of this constructor of the current type.
Index: compiler/bytecode_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.39
diff -u -u -r1.39 bytecode_gen.m
--- bytecode_gen.m 1998/11/20 04:07:01 1.39
+++ bytecode_gen.m 1998/11/20 11:47:45
@@ -632,6 +632,9 @@
_, Instance),
ByteConsId = base_typeclass_info_const(ModuleName, ClassId,
Instance)
+ ;
+ ConsId = tabling_pointer_const(_, _),
+ error("bytecode cannot implement tabling")
).
:- pred bytecode_gen__map_cons_tag(cons_tag::in, byte_cons_tag::out) is det.
@@ -655,6 +658,8 @@
error("base_type_info_constant cons tag for non-base_type_info_constant cons id").
bytecode_gen__map_cons_tag(base_typeclass_info_constant(_, _, _), _) :-
error("base_typeclass_info_constant cons tag for non-base_typeclass_info_constant cons id").
+bytecode_gen__map_cons_tag(tabling_pointer_constant(_, _), _) :-
+ error("tabling_pointer_constant cons tag for non-tabling_pointer_constant cons id").
%---------------------------------------------------------------------------%
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.60
diff -u -u -r1.60 code_gen.m
--- code_gen.m 1998/11/20 04:07:08 1.60
+++ code_gen.m 1998/11/20 10:41:29
@@ -31,7 +31,7 @@
:- interface.
:- import_module hlds_module, hlds_pred, hlds_goal, llds, code_info.
-:- import_module continuation_info, globals.
+:- import_module globals.
:- import_module list, io.
% Translate a HLDS module to LLDS.
@@ -46,7 +46,7 @@
:- pred generate_proc_code(pred_info::in, proc_info::in,
proc_id::in, pred_id::in, module_info::in, globals::in,
- continuation_info::in, continuation_info::out, int::in, int::out,
+ global_data::in, global_data::out, int::in, int::out,
c_procedure::out) is det.
% Translate a HLDS goal to LLDS.
@@ -61,7 +61,7 @@
:- import_module call_gen, unify_gen, ite_gen, switch_gen, disj_gen.
:- import_module par_conj_gen, pragma_c_gen, commit_gen.
-:- import_module trace, options, hlds_out.
+:- import_module continuation_info, trace, options, hlds_out.
:- import_module code_aux, middle_rec, passes_aux, llds_out.
:- import_module code_util, type_util, mode_util.
:- import_module prog_data, prog_out, instmap.
@@ -120,34 +120,35 @@
;
[]
),
- { module_info_get_continuation_info(ModuleInfo0, ContInfo0) },
+ { module_info_get_global_data(ModuleInfo0, GlobalData0) },
{ module_info_get_cell_count(ModuleInfo0, CellCount0) },
globals__io_get_globals(Globals),
{ generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
- Globals, ContInfo0, ContInfo, CellCount0, CellCount,
+ Globals, GlobalData0, GlobalData, CellCount0, CellCount,
[], Code) },
{ module_info_set_cell_count(ModuleInfo0, CellCount, ModuleInfo1) },
- { module_info_set_continuation_info(ModuleInfo1, ContInfo,
+ { module_info_set_global_data(ModuleInfo1, GlobalData,
ModuleInfo) }.
% Translate all the procedures of a HLDS predicate to LLDS.
:- pred generate_proc_list_code(list(proc_id)::in, pred_id::in, pred_info::in,
- module_info::in, globals::in,
- continuation_info::in, continuation_info::out, int::in, int::out,
- list(c_procedure)::in, list(c_procedure)::out) is det.
+ module_info::in, globals::in, global_data::in, global_data::out,
+ int::in, int::out, list(c_procedure)::in, list(c_procedure)::out)
+ is det.
generate_proc_list_code([], _PredId, _PredInfo, _ModuleInfo, _Globals,
- ContInfo, ContInfo, CellCount, CellCount, Procs, Procs).
+ GlobalData, GlobalData, CellCount, CellCount, Procs, Procs).
generate_proc_list_code([ProcId | ProcIds], PredId, PredInfo, ModuleInfo0,
- Globals, ContInfo0, ContInfo, CellCount0, CellCount,
+ Globals, GlobalData0, GlobalData, CellCount0, CellCount,
Procs0, Procs) :-
pred_info_procedures(PredInfo, ProcInfos),
map__lookup(ProcInfos, ProcId, ProcInfo),
generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo0,
- Globals, ContInfo0, ContInfo1, CellCount0, CellCount1, Proc),
+ Globals, GlobalData0, GlobalData1, CellCount0, CellCount1,
+ Proc),
generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
- Globals, ContInfo1, ContInfo, CellCount1, CellCount,
+ Globals, GlobalData1, GlobalData, CellCount1, CellCount,
[Proc | Procs0], Procs).
%---------------------------------------------------------------------------%
@@ -170,7 +171,7 @@
%---------------------------------------------------------------------------%
generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo, Globals,
- ContInfo0, ContInfo, CellCount0, CellCount, Proc) :-
+ GlobalData0, GlobalData, CellCount0, CellCount, Proc) :-
proc_info_interface_determinism(ProcInfo, Detism),
proc_info_interface_code_model(ProcInfo, CodeModel),
proc_info_goal(ProcInfo, Goal),
@@ -230,15 +231,16 @@
),
( BasicStackLayout = yes ->
% Create the procedure layout structure.
- code_info__get_layout_info(LayoutInfo, CodeInfo, _),
+ code_info__get_layout_info(InternalMap, CodeInfo, _),
code_util__make_local_entry_label(ModuleInfo, PredId, ProcId,
no, EntryLabel),
- continuation_info__add_proc_info(proc(PredId, ProcId),
- EntryLabel, TotalSlots, Detism, MaybeSuccipSlot,
- MaybeTraceCallLabel, TraceSlotInfo,
- ForceProcId, LayoutInfo, ContInfo0, ContInfo)
+ ProcLayout = proc_layout_info(EntryLabel, Detism, TotalSlots,
+ MaybeSuccipSlot, MaybeTraceCallLabel,
+ TraceSlotInfo, ForceProcId, InternalMap),
+ global_data_add_new_proc_layout(GlobalData0,
+ proc(PredId, ProcId), ProcLayout, GlobalData)
;
- ContInfo = ContInfo0
+ GlobalData = GlobalData0
),
predicate_name(ModuleInfo, PredId, Name),
Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.103
diff -u -u -r1.103 code_util.m
--- code_util.m 1998/11/20 04:07:11 1.103
+++ code_util.m 1998/11/20 11:12:42
@@ -669,6 +669,8 @@
base_type_info_constant(M,T,A)).
code_util__cons_id_to_tag(base_typeclass_info_const(M,C,_,N), _, _,
base_typeclass_info_constant(M,C,N)).
+code_util__cons_id_to_tag(tabling_pointer_const(PredId,ProcId), _, _,
+ tabling_pointer_constant(PredId,ProcId)).
code_util__cons_id_to_tag(cons(Name, Arity), Type, ModuleInfo, Tag) :-
(
% handle the `character' type specially
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.18
diff -u -u -r1.18 continuation_info.m
--- continuation_info.m 1998/11/18 08:11:04 1.18
+++ continuation_info.m 1998/11/20 12:01:16
@@ -8,10 +8,10 @@
% Main author: trd.
% Extensive modifications by zs.
%
-% This file defines the continuation_info data structure, which the code
-% generator uses to collect information that will later be converted into
-% stack_layout tables for accurate garbage collection, for stack tracing,
-% execution tracing and perhaps other purposes.
+% This file defines the data structures the code generator uses to collect
+% information that will later be converted into layout tables for accurate
+% garbage collection, for stack tracing, execution tracing and perhaps
+% other purposes.
%
% Information is collected in several passes.
%
@@ -28,15 +28,18 @@
% all the static information about the procedure (some of which
% is available only after code generation), together with the
% info about internal labels accumulated in the code generator state,
-% in the continuation_info structure (which is part of HLDS).
+% in the global_data structure (which is part of HLDS).
%
% 4 If agc_stack_layouts is set, we make a pass over the
% optimized code recorded in the final LLDS instructions.
% In this pass, we collect information from call instructions
% about the internal labels to which calls can return.
-% This info will also go straight into the continuation_info
+% This info will also go straight into the global_data
% in the HLDS.
%
+% This module is really only concerned with pass 4, although it also defines
+% data structures and some auxiliary predicates for the other passes.
+%
% stack_layout.m converts the information collected in this module into
% stack_layout tables.
@@ -51,14 +54,6 @@
:- import_module set, map, list, std_util, bool.
%
- % Information used by the continuation_info module.
- % This is an abstract data type - when processing is finished
- % use continuation_info__get_all_entries to retrieve the
- % completed proc_layout_infos.
- %
-:- type continuation_info.
-
- %
% Information for any procedure, includes information about the
% procedure itself, and any internal labels within it.
%
@@ -169,50 +164,23 @@
live_value_type % info about the variable
).
- % Return an initialized continuation info structure.
-
-:- pred continuation_info__init(continuation_info::out) is det.
-
- %
- % Add all the information accumulated by the first three passes
- % above for a single procedure.
- %
- % Takes the pred_proc_id, entry label, the number of stack slots,
- % the determinism of the proc, the stack slot of the succip
- % in this proc (if there is one), the label of the call event
- % (if there is such an event), info about the tracing slots of this
- % proc, a flag saying whether we definitely need a procedure id
- % section in the procedure layout, as well as the layouts at all
- % the trace event labels.
- %
-:- pred continuation_info__add_proc_info(pred_proc_id::in, label::in,
- int::in, determinism::in, maybe(int)::in, maybe(label)::in,
- trace_slot_info::in, bool::in, proc_label_layout_info::in,
- continuation_info::in, continuation_info::out) is det.
-
%
% Call continuation_info__maybe_process_proc_llds on the code
% of every procedure in the list.
%
:- pred continuation_info__maybe_process_llds(list(c_procedure)::in,
- module_info::in, continuation_info::in, continuation_info::out) is det.
+ module_info::in, global_data::in, global_data::out) is det.
%
% Check whether this procedure ought to have any layout structures
- % generated for it. If yes, then update the continuation_info to
+ % generated for it. If yes, then update the global_data to
% include all the continuation labels within a proc. Whether or not
% the information about a continuation label includes the variables
% live at that label depends on the values of options.
%
:- pred continuation_info__maybe_process_proc_llds(list(instruction)::in,
pred_proc_id::in, module_info::in,
- continuation_info::in, continuation_info::out) is det.
-
- %
- % Get the finished list of proc_layout_infos.
- %
-:- pred continuation_info__get_all_proc_layouts(continuation_info::in,
- list(proc_layout_info)::out) is det.
+ global_data::in, global_data::out) is det.
%
% Check whether the given procedure should have at least (a) a basic
@@ -230,42 +198,10 @@
:- import_module options, type_util.
:- import_module require.
- % The continuation_info data structure
-:- type continuation_info == map(pred_proc_id, proc_layout_info).
-
%-----------------------------------------------------------------------------%
% Exported predicates.
- %
- % Initialize the continuation_info
- %
-
-continuation_info__init(ContInfo) :-
- map__init(ContInfo).
-
- %
- % Add the info for this proc (a proc_layout_info) to the
- % continuation_info.
- %
-continuation_info__add_proc_info(PredProcId, EntryLabel, StackSize,
- Detism, SuccipLocation, MaybeTraceCallLabel, TraceSlotInfo,
- ForceProcId, InternalMap, ContInfo0, ContInfo) :-
- ( map__contains(ContInfo0, PredProcId) ->
- error("duplicate continuation_info for proc.")
- ;
- LayoutInfo = proc_layout_info(EntryLabel, Detism, StackSize,
- SuccipLocation, MaybeTraceCallLabel,
- TraceSlotInfo, ForceProcId, InternalMap),
- map__det_insert(ContInfo0, PredProcId, LayoutInfo, ContInfo)
- ).
-
- %
- % Get all the proc_layout_infos.
- %
-continuation_info__get_all_proc_layouts(ContInfo, Entries) :-
- map__values(ContInfo, Entries).
-
continuation_info__maybe_process_llds([], _) --> [].
continuation_info__maybe_process_llds([Proc | Procs], ModuleInfo) -->
{ Proc = c_procedure(_, _, PredProcId, Instrs) },
@@ -290,17 +226,17 @@
%
% Process the list of instructions for this proc, adding
- % all internal label information to the continuation_info.
+ % all internal label information to global_data..
%
:- pred continuation_info__process_proc_llds(pred_proc_id::in,
list(instruction)::in, bool::in,
- continuation_info::in, continuation_info::out) is det.
+ global_data::in, global_data::out) is det.
continuation_info__process_proc_llds(PredProcId, Instructions,
- WantReturnInfo, ContInfo0, ContInfo) :-
+ WantReturnInfo, GlobalData0, GlobalData) :-
% Get all the continuation info from the call instructions.
- map__lookup(ContInfo0, PredProcId, ProcLayoutInfo0),
+ global_data_get_proc_layout(GlobalData0, PredProcId, ProcLayoutInfo0),
ProcLayoutInfo0 = proc_layout_info(A, B, C, D, E, F, G, Internals0),
GetCallLivevals = lambda([Instr::in, Pair::out] is semidet, (
Instr = call(_, label(Label), LiveInfo, _) - _Comment,
@@ -313,7 +249,8 @@
Calls, Internals0, Internals),
ProcLayoutInfo = proc_layout_info(A, B, C, D, E, F, G, Internals),
- map__det_update(ContInfo0, PredProcId, ProcLayoutInfo, ContInfo).
+ global_data_update_proc_layout(GlobalData0, PredProcId, ProcLayoutInfo,
+ GlobalData).
%-----------------------------------------------------------------------------%
Index: compiler/dependency_graph.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dependency_graph.m,v
retrieving revision 1.37
diff -u -u -r1.37 dependency_graph.m
--- dependency_graph.m 1998/11/20 04:07:22 1.37
+++ dependency_graph.m 1998/11/20 11:01:01
@@ -326,6 +326,8 @@
DepGraph, DepGraph).
dependency_graph__add_arcs_in_cons(base_typeclass_info_const(_, _, _, _),
_Caller, DepGraph, DepGraph).
+dependency_graph__add_arcs_in_cons(tabling_pointer_const(_, _),
+ _Caller, DepGraph, DepGraph).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.29
diff -u -u -r1.29 hlds_data.m
--- hlds_data.m 1998/11/20 04:07:45 1.29
+++ hlds_data.m 1998/11/20 12:03:54
@@ -45,6 +45,11 @@
% class instance, a string encoding the type
% names and arities of the arguments to the
% instance declaration
+ ; tabling_pointer_const(pred_id, proc_id)
+ % The address of the static variable
+ % that points to the table that implements
+ % memoization, loop checking or the minimal
+ % model semantics for the given procedure.
.
% A cons_defn is the definition of a constructor (i.e. a constant
@@ -127,6 +132,8 @@
error("cons_id_arity: can't get arity of base_type_info_const").
cons_id_arity(base_typeclass_info_const(_, _, _, _), _) :-
error("cons_id_arity: can't get arity of base_typeclass_info_const").
+cons_id_arity(tabling_pointer_const(_, _), _) :-
+ error("cons_id_arity: can't get arity of tabling_pointer_const").
make_functor_cons_id(term__atom(Name), Arity,
cons(unqualified(Name), Arity)).
@@ -268,6 +275,11 @@
% third is the string which uniquely identifies the
% instance declaration (it is made from the type of
% the arguments to the instance decl).
+ ; tabling_pointer_constant(pred_id, proc_id)
+ % This is how we refer to tabling pointer variables
+ % represented as global data. The word just contains
+ % the address of the tabling pointer of the
+ % specified procedure.
; simple_tag(tag_bits)
% This is for constants or functors which only
% require a simple tag. (A "simple" tag is one
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.37
diff -u -u -r1.37 hlds_module.m
--- hlds_module.m 1998/10/28 09:28:01 1.37
+++ hlds_module.m 1998/11/23 03:22:40
@@ -12,6 +12,7 @@
% module_info
% dependency_info
% predicate_table
+% global_data
%
% There is a separate interface section for each of these.
@@ -112,12 +113,12 @@
module_info).
:- mode module_info_set_special_pred_map(in, in, out) is det.
-:- pred module_info_get_continuation_info(module_info, continuation_info).
-:- mode module_info_get_continuation_info(in, out) is det.
+:- pred module_info_get_global_data(module_info, global_data).
+:- mode module_info_get_global_data(in, out) is det.
-:- pred module_info_set_continuation_info(module_info, continuation_info,
+:- pred module_info_set_global_data(module_info, global_data,
module_info).
-:- mode module_info_set_continuation_info(in, in, out) is det.
+:- mode module_info_set_global_data(in, in, out) is det.
:- pred module_info_types(module_info, type_table).
:- mode module_info_types(in, out) is det.
@@ -465,7 +466,7 @@
predicate_table,
proc_requests,
special_pred_map,
- continuation_info,
+ global_data,
type_table,
inst_table,
mode_table,
@@ -518,7 +519,7 @@
map__init(Types),
inst_table_init(Insts),
mode_table_init(Modes),
- continuation_info__init(ContinuationInfo),
+ global_data_init(GlobalData),
map__init(Ctors),
set__init(StratPreds),
map__init(UnusedArgInfo),
@@ -529,7 +530,7 @@
ModuleSubInfo = module_sub(Name, Globals, [], [], no, 0, 0, [],
[], [], StratPreds, UnusedArgInfo, 0, ModuleNames),
ModuleInfo = module(ModuleSubInfo, PredicateTable, Requests,
- UnifyPredMap, ContinuationInfo, Types, Insts, Modes, Ctors,
+ UnifyPredMap, GlobalData, Types, Insts, Modes, Ctors,
ClassTable, SuperClassTable, InstanceTable, 0).
%-----------------------------------------------------------------------------%
@@ -670,7 +671,7 @@
% B predicate_table,
% C proc_requests,
% D special_pred_map,
-% E continuation_info,
+% E global_data,
% F type_table,
% G inst_table,
% H mode_table,
@@ -700,7 +701,7 @@
module_info_get_special_pred_map(MI0, D) :-
MI0 = module(_, _, _, D, _, _, _, _, _, _, _, _, _).
-module_info_get_continuation_info(MI0, E) :-
+module_info_get_global_data(MI0, E) :-
MI0 = module(_, _, _, _, E, _, _, _, _, _, _, _, _).
module_info_types(MI0, F) :-
@@ -747,7 +748,7 @@
MI0 = module(A, B, C, _, E, F, G, H, I, J, K, L, M),
MI = module(A, B, C, D, E, F, G, H, I, J, K, L, M).
-module_info_set_continuation_info(MI0, E, MI) :-
+module_info_set_global_data(MI0, E, MI) :-
MI0 = module(A, B, C, D, _, F, G, H, I, J, K, L, M),
MI = module(A, B, C, D, E, F, G, H, I, J, K, L, M).
@@ -1027,7 +1028,7 @@
predicate_table_optimize(Preds0, Preds),
module_info_set_predicate_table(ModuleInfo0, Preds, ModuleInfo3),
- % XXX Might want to optimize continuation_info here.
+ % XXX Might want to optimize global_data here.
module_info_types(ModuleInfo3, Types0),
map__optimize(Types0, Types),
@@ -1925,5 +1926,107 @@
module_info_preds(ModuleInfo, Preds),
map__lookup(Preds, PredId, PredInfo),
pred_info_arity(PredInfo, Arity).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- interface.
+
+:- type global_data.
+
+:- pred global_data_init(global_data::out) is det.
+
+:- pred global_data_add_new_proc_var(global_data::in,
+ pred_proc_id::in, comp_gen_c_var::in, global_data::out) is det.
+
+:- pred global_data_add_new_proc_layout(global_data::in,
+ pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
+
+:- pred global_data_update_proc_layout(global_data::in,
+ pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
+
+:- pred global_data_get_proc_layout(global_data::in, pred_proc_id::in,
+ proc_layout_info::out) is det.
+
+:- pred global_data_get_all_proc_vars(global_data::in,
+ list(comp_gen_c_var)::out) is det.
+
+:- pred global_data_get_all_proc_layouts(global_data::in,
+ list(proc_layout_info)::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- type proc_var_map == map(pred_proc_id, comp_gen_c_var).
+:- type proc_layout_map == map(pred_proc_id, proc_layout_info).
+
+:- type global_data
+ ---> global_data(
+ proc_var_map,
+ proc_layout_map
+ ).
+
+global_data_init(global_data(EmptyDataMap, EmptyLayoutMap)) :-
+ map__init(EmptyDataMap),
+ map__init(EmptyLayoutMap).
+
+global_data_add_new_proc_var(GlobalData0, PredProcId, ProcVar,
+ GlobalData) :-
+ global_data_get_proc_var_map(GlobalData0, ProcVarMap0),
+ map__det_insert(ProcVarMap0, PredProcId, ProcVar, ProcVarMap),
+ global_data_set_proc_var_map(GlobalData0, ProcVarMap,
+ GlobalData).
+
+global_data_add_new_proc_layout(GlobalData0, PredProcId, ProcLayout,
+ GlobalData) :-
+ global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
+ map__det_insert(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
+ global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
+ GlobalData).
+
+global_data_update_proc_layout(GlobalData0, PredProcId, ProcLayout,
+ GlobalData) :-
+ global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
+ map__det_update(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
+ global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
+ GlobalData).
+
+global_data_get_proc_layout(GlobalData0, PredProcId, ProcLayout) :-
+ global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap),
+ map__lookup(ProcLayoutMap, PredProcId, ProcLayout).
+
+global_data_get_all_proc_vars(GlobalData, ProcVars) :-
+ global_data_get_proc_var_map(GlobalData, ProcVarMap),
+ map__values(ProcVarMap, ProcVars).
+
+global_data_get_all_proc_layouts(GlobalData, ProcLayouts) :-
+ global_data_get_proc_layout_map(GlobalData, ProcLayoutMap),
+ map__values(ProcLayoutMap, ProcLayouts).
+
+%-----------------------------------------------------------------------------%
+
+:- pred global_data_get_proc_var_map(global_data::in, proc_var_map::out)
+ is det.
+:- pred global_data_get_proc_layout_map(global_data::in, proc_layout_map::out)
+ is det.
+:- pred global_data_set_proc_var_map(global_data::in, proc_var_map::in,
+ global_data::out) is det.
+:- pred global_data_set_proc_layout_map(global_data::in, proc_layout_map::in,
+ global_data::out) is det.
+
+global_data_get_proc_var_map(GD, A) :-
+ GD = global_data(A, _).
+
+global_data_get_proc_layout_map(GD, B) :-
+ GD = global_data(_, B).
+
+global_data_set_proc_var_map(GD0, A, GD) :-
+ GD0 = global_data(_, B),
+ GD = global_data(A, B).
+
+global_data_set_proc_layout_map(GD0, B, GD) :-
+ GD0 = global_data(A, _),
+ GD = global_data(A, B).
%-----------------------------------------------------------------------------%
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.210
diff -u -u -r1.210 hlds_out.m
--- hlds_out.m 1998/11/20 04:07:48 1.210
+++ hlds_out.m 1998/11/20 10:58:55
@@ -220,6 +220,8 @@
hlds_out__cons_id_to_string(base_type_info_const(_, _, _), "<base_type_info>").
hlds_out__cons_id_to_string(base_typeclass_info_const(_, _, _, _),
"<base_typeclass_info>").
+hlds_out__cons_id_to_string(tabling_pointer_const(_, _),
+ "<tabling_pointer>").
hlds_out__write_cons_id(cons(SymName, Arity)) -->
prog_out__write_sym_name(SymName),
@@ -241,6 +243,8 @@
io__write_string("<base_type_info>").
hlds_out__write_cons_id(base_typeclass_info_const(_, _, _, _)) -->
io__write_string("<base_typeclass_info>").
+hlds_out__write_cons_id(tabling_pointer_const(_, _)) -->
+ io__write_string("<tabling_pointer>").
% The code of this predicate duplicates the functionality of
% term_errors__describe_one_pred_name. Changes here should be made
@@ -1574,6 +1578,9 @@
io__write_string("), "),
io__write_string(Instance),
io__write_string(")")
+ ;
+ { ConsId = tabling_pointer_const(_, _) },
+ { error("hlds_out__write_functor_cons_id: tabling_pointer_const") }
).
hlds_out__write_var_modes([], [], _, _, _) --> [].
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.233
diff -u -u -r1.233 llds.m
--- llds.m 1998/11/20 04:08:09 1.233
+++ llds.m 1998/11/23 04:23:01
@@ -68,6 +68,7 @@
c_header_info,
list(user_c_code),
list(c_export),
+ list(comp_gen_c_var),
list(comp_gen_c_data),
list(comp_gen_c_module)
).
@@ -80,6 +81,15 @@
term__context % source code location
).
+ % Global variables generated by the compiler.
+:- type comp_gen_c_var
+ ---> tabling_pointer_var(
+ module_name, % The basename of this C file.
+ proc_label % The id of the procedure
+ % whose table this variable
+ % represents.
+ ).
+
% Global data generated by the compiler. Usually readonly,
% with one exception: data containing code addresses must
% be initialized.
@@ -652,10 +662,14 @@
% class name & class arity, names and arities of the
% types
; proc_layout(label)
- % layout structure for the procedure with the given
- % entry label
- ; internal_layout(label).
- % layout structure for the given internal label
+ % Layout structure for the procedure with the given
+ % entry label.
+ ; internal_layout(label)
+ % Layout structure for the given internal label.
+ ; tabling_pointer(proc_label).
+ % A variable that contains a pointer that points to
+ % the table used to implement memoization, loopcheck
+ % or minimal model semantics for the given procedure.
:- type base_data
---> info
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.98
diff -u -u -r1.98 llds_out.m
--- llds_out.m 1998/11/20 04:08:11 1.98
+++ llds_out.m 1998/11/23 05:02:23
@@ -168,7 +168,7 @@
globals__io_lookup_bool_option(split_c_files, SplitFiles),
( { SplitFiles = yes } ->
{ C_File = c_file(ModuleName, C_HeaderInfo,
- UserCCodes, Exports, Datas, Modules) },
+ UserCCodes, Exports, Vars, Datas, Modules) },
module_name_to_file_name(ModuleName, ".dir", yes, ObjDirName),
make_directory(ObjDirName),
output_split_c_file_init(ModuleName, Modules, Datas,
@@ -177,10 +177,12 @@
C_HeaderInfo, StackLayoutLabels, 1, Num1),
output_split_c_exports(Exports, ModuleName,
C_HeaderInfo, StackLayoutLabels, Num1, Num2),
- output_split_comp_gen_c_datas(Datas, ModuleName,
+ output_split_comp_gen_c_vars(Vars, ModuleName,
C_HeaderInfo, StackLayoutLabels, Num2, Num3),
+ output_split_comp_gen_c_datas(Datas, ModuleName,
+ C_HeaderInfo, StackLayoutLabels, Num3, Num4),
output_split_comp_gen_c_modules(Modules, ModuleName,
- C_HeaderInfo, StackLayoutLabels, Num3, _Num)
+ C_HeaderInfo, StackLayoutLabels, Num4, _Num)
;
output_single_c_file(C_File, no, StackLayoutLabels)
).
@@ -192,7 +194,8 @@
output_split_user_c_codes([], _, _, _, Num, Num) --> [].
output_split_user_c_codes([UserCCode | UserCCodes], ModuleName, C_HeaderLines,
StackLayoutLabels, Num0, Num) -->
- { CFile = c_file(ModuleName, C_HeaderLines, [UserCCode], [], [], []) },
+ { CFile = c_file(ModuleName, C_HeaderLines,
+ [UserCCode], [], [], [], []) },
output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
{ Num1 is Num0 + 1 },
output_split_user_c_codes(UserCCodes, ModuleName, C_HeaderLines,
@@ -205,12 +208,26 @@
output_split_c_exports([], _, _, _, Num, Num) --> [].
output_split_c_exports([Export | Exports], ModuleName, C_HeaderLines,
StackLayoutLabels, Num0, Num) -->
- { CFile = c_file(ModuleName, C_HeaderLines, [], [Export], [], []) },
+ { CFile = c_file(ModuleName, C_HeaderLines,
+ [], [Export], [], [], []) },
output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
{ Num1 is Num0 + 1 },
output_split_c_exports(Exports, ModuleName, C_HeaderLines,
StackLayoutLabels, Num1, Num).
+:- pred output_split_comp_gen_c_vars(list(comp_gen_c_var)::in,
+ module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
+ int::in, int::out, io__state::di, io__state::uo) is det.
+
+output_split_comp_gen_c_vars([], _, _, _, Num, Num) --> [].
+output_split_comp_gen_c_vars([Var | Vars], ModuleName, C_HeaderLines,
+ StackLayoutLabels, Num0, Num) -->
+ { CFile = c_file(ModuleName, C_HeaderLines, [], [], [Var], [], []) },
+ output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
+ { Num1 is Num0 + 1 },
+ output_split_comp_gen_c_vars(Vars, ModuleName, C_HeaderLines,
+ StackLayoutLabels, Num1, Num).
+
:- pred output_split_comp_gen_c_datas(list(comp_gen_c_data)::in,
module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
int::in, int::out, io__state::di, io__state::uo) is det.
@@ -218,7 +235,7 @@
output_split_comp_gen_c_datas([], _, _, _, Num, Num) --> [].
output_split_comp_gen_c_datas([Data | Datas], ModuleName, C_HeaderLines,
StackLayoutLabels, Num0, Num) -->
- { CFile = c_file(ModuleName, C_HeaderLines, [], [], [Data], []) },
+ { CFile = c_file(ModuleName, C_HeaderLines, [], [], [], [Data], []) },
output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
{ Num1 is Num0 + 1 },
output_split_comp_gen_c_datas(Datas, ModuleName, C_HeaderLines,
@@ -231,7 +248,8 @@
output_split_comp_gen_c_modules([], _, _, _, Num, Num) --> [].
output_split_comp_gen_c_modules([Module | Modules], ModuleName, C_HeaderLines,
StackLayoutLabels, Num0, Num) -->
- { CFile = c_file(ModuleName, C_HeaderLines, [], [], [], [Module]) },
+ { CFile = c_file(ModuleName, C_HeaderLines,
+ [], [], [], [], [Module]) },
output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
{ Num1 is Num0 + 1 },
output_split_comp_gen_c_modules(Modules, ModuleName, C_HeaderLines,
@@ -296,7 +314,7 @@
output_single_c_file(CFile, SplitFiles, StackLayoutLabels) -->
{ CFile = c_file(ModuleName, C_HeaderLines,
- UserCCode, Exports, Datas, Modules) },
+ UserCCode, Exports, Vars, Datas, Modules) },
( { SplitFiles = yes(Num) } ->
module_name_to_split_c_file_name(ModuleName, Num, ".c",
FileName)
@@ -334,11 +352,11 @@
{ gather_c_file_labels(Modules, Labels) },
{ decl_set_init(DeclSet0) },
output_c_label_decl_list(Labels, DeclSet0, DeclSet1),
- output_c_data_def_list(Datas, DeclSet1, DeclSet2),
-
- output_comp_gen_c_data_list(Datas, DeclSet2, DeclSet3),
+ output_comp_gen_c_var_list(Vars, DeclSet1, DeclSet2),
+ output_c_data_def_list(Datas, DeclSet2, DeclSet3),
+ output_comp_gen_c_data_list(Datas, DeclSet3, DeclSet4),
output_comp_gen_c_module_list(Modules, StackLayoutLabels,
- DeclSet3, _DeclSet),
+ DeclSet4, _DeclSet),
output_user_c_code_list(UserCCode),
output_exported_c_functions(Exports),
@@ -620,6 +638,25 @@
output_c_procedure_list(Procedures, PrintComments, EmitCLoops),
io__write_string("END_MODULE\n").
+:- pred output_comp_gen_c_var_list(list(comp_gen_c_var)::in,
+ decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
+
+output_comp_gen_c_var_list([], DeclSet, DeclSet) --> [].
+output_comp_gen_c_var_list([Var | Vars], DeclSet0, DeclSet) -->
+ output_comp_gen_c_var(Var, DeclSet0, DeclSet1),
+ output_comp_gen_c_var_list(Vars, DeclSet1, DeclSet).
+
+:- pred output_comp_gen_c_var(comp_gen_c_var::in,
+ decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
+
+output_comp_gen_c_var(tabling_pointer_var(ModuleName, ProcLabel),
+ DeclSet0, DeclSet) -->
+ io__write_string("\nWord mercury_var__tabling__"),
+ output_proc_label(ProcLabel),
+ io__write_string(" = 0;\n"),
+ { DataAddr = data_addr(ModuleName, tabling_pointer(ProcLabel)) },
+ { decl_set_insert(DeclSet0, data_addr(DataAddr), DeclSet) }.
+
:- pred output_comp_gen_c_data_list(list(comp_gen_c_data)::in,
decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
@@ -2123,6 +2160,7 @@
data_name_would_include_code_address(base_typeclass_info(_, _), yes).
data_name_would_include_code_address(proc_layout(_), yes).
data_name_would_include_code_address(internal_layout(_), no).
+data_name_would_include_code_address(tabling_pointer(_), no).
:- pred output_decl_id(decl_id, io__state, io__state).
:- mode output_decl_id(in, di, uo) is det.
@@ -2487,6 +2525,7 @@
linkage(base_typeclass_info(_, _), extern).
linkage(proc_layout(_), static).
linkage(internal_layout(_), static).
+linkage(tabling_pointer(_), static).
%-----------------------------------------------------------------------------%
@@ -2711,15 +2750,17 @@
:- mode output_data_addr(in, in, di, uo) is det.
output_data_addr(ModuleName, VarName) -->
- { llds_out__sym_name_mangle(ModuleName, MangledModuleName) },
- io__write_string("mercury_data_"),
(
+ { llds_out__sym_name_mangle(ModuleName, MangledModuleName) },
+ io__write_string("mercury_data_"),
{ VarName = common(N) },
io__write_string(MangledModuleName),
io__write_string("__common_"),
{ string__int_to_string(N, NStr) },
io__write_string(NStr)
;
+ { llds_out__sym_name_mangle(ModuleName, MangledModuleName) },
+ io__write_string("mercury_data_"),
{ VarName = base_type(BaseData, TypeName0, TypeArity) },
io__write_string(MangledModuleName),
{ llds_out__make_base_type_name(BaseData, TypeName0, TypeArity,
@@ -2735,18 +2776,22 @@
{ VarName = base_typeclass_info(ClassId, TypeNames) },
{ llds_out__make_base_typeclass_info_name(ClassId, TypeNames,
Str) },
- io__write_string("__"),
+ io__write_string("mercury_data___"),
io__write_string(Str)
;
% Keep this code in sync with make_stack_layout_name/3.
{ VarName = proc_layout(Label) },
- io__write_string("_layout__"),
+ io__write_string("mercury_data__layout__"),
output_label(Label)
;
% Keep this code in sync with make_stack_layout_name/3.
{ VarName = internal_layout(Label) },
- io__write_string("_layout__"),
+ io__write_string("mercury_data__layout__"),
output_label(Label)
+ ;
+ { VarName = tabling_pointer(ProcLabel) },
+ io__write_string("mercury_var__tabling__"),
+ output_proc_label(ProcLabel)
).
:- pred output_label_as_code_addr(label, io__state, io__state).
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.115
diff -u -u -r1.115 mercury_compile.m
--- mercury_compile.m 1998/11/20 04:08:17 1.115
+++ mercury_compile.m 1998/11/23 04:23:37
@@ -1159,13 +1159,11 @@
write_proc_progress_message(
"% Generating low-level (LLDS) code for ",
PredId, ProcId, ModuleInfo3),
- { module_info_get_continuation_info(ModuleInfo3, ContInfo0) },
+ { module_info_get_global_data(ModuleInfo3, GlobalData0) },
{ module_info_get_cell_count(ModuleInfo3, CellCount0) },
{ generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo3,
- Globals, ContInfo0, ContInfo1, CellCount0, CellCount, Proc0) },
- { module_info_set_continuation_info(ModuleInfo3, ContInfo1,
- ModuleInfo4) },
- { module_info_set_cell_count(ModuleInfo4, CellCount, ModuleInfo5) },
+ Globals, GlobalData0, GlobalData1, CellCount0, CellCount,
+ Proc0) },
{ globals__lookup_bool_option(Globals, optimize, Optimize) },
( { Optimize = yes } ->
optimize__proc(Proc0, Proc)
@@ -1173,14 +1171,13 @@
{ Proc = Proc0 }
),
{ Proc = c_procedure(_, _, PredProcId, Instructions) },
- { module_info_get_continuation_info(ModuleInfo5, ContInfo2) },
write_proc_progress_message(
"% Generating call continuation information for ",
- PredId, ProcId, ModuleInfo5),
+ PredId, ProcId, ModuleInfo3),
{ continuation_info__maybe_process_proc_llds(Instructions, PredProcId,
- ModuleInfo5, ContInfo2, ContInfo3) },
- { module_info_set_continuation_info(ModuleInfo5, ContInfo3,
- ModuleInfo) }.
+ ModuleInfo3, GlobalData1, GlobalData2) },
+ { module_info_set_global_data(ModuleInfo3, GlobalData2, ModuleInfo4) },
+ { module_info_set_cell_count(ModuleInfo4, CellCount, ModuleInfo) }.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -1831,11 +1828,10 @@
maybe_write_string(Verbose,
"% Generating call continuation information..."),
maybe_flush_output(Verbose),
- { module_info_get_continuation_info(ModuleInfo0, ContInfo0) },
+ { module_info_get_global_data(ModuleInfo0, GlobalData0) },
{ continuation_info__maybe_process_llds(LLDS0, ModuleInfo0,
- ContInfo0, ContInfo) },
- { module_info_set_continuation_info(ModuleInfo0, ContInfo,
- ModuleInfo) },
+ GlobalData0, GlobalData) },
+ { module_info_set_global_data(ModuleInfo0, GlobalData, ModuleInfo) },
maybe_write_string(Verbose, " done.\n"),
maybe_report_stats(Stats).
@@ -1875,6 +1871,7 @@
mercury_compile__output_pass(HLDS0, Procs0, ModuleName, CompileErrors) -->
globals__io_lookup_bool_option(verbose, Verbose),
globals__io_lookup_bool_option(statistics, Stats),
+ { get_c_interface_info(HLDS, C_InterfaceInfo) },
{ base_type_info__generate_llds(HLDS0, BaseTypeInfos) },
{ base_type_layout__generate_llds(HLDS0, HLDS1, BaseTypeLayouts) },
{ stack_layout__generate_llds(HLDS1, HLDS,
@@ -1882,10 +1879,10 @@
{ list__append(InternalLayouts, BaseTypeLayouts, StaticData0) },
{ llds_common(Procs0, StaticData0, ModuleName, Procs1, StaticData) },
{ list__condense([BaseTypeInfos, ProcLayouts, StaticData], AllData) },
-
- { get_c_interface_info(HLDS, C_InterfaceInfo) },
- mercury_compile__construct_c_file(C_InterfaceInfo, Procs1, AllData,
- CFile, NumChunks),
+ { module_info_get_global_data(HLDS1, GlobalData) },
+ { global_data_get_all_proc_vars(GlobalData, GlobalVars) },
+ mercury_compile__construct_c_file(C_InterfaceInfo, Procs1, GlobalVars,
+ AllData, CFile, NumChunks),
mercury_compile__output_llds(ModuleName, CFile, LayoutLabels,
Verbose, Stats),
@@ -1903,11 +1900,13 @@
% Split the code up into bite-size chunks for the C compiler.
:- pred mercury_compile__construct_c_file(c_interface_info, list(c_procedure),
- list(comp_gen_c_data), c_file, int, io__state, io__state).
-:- mode mercury_compile__construct_c_file(in, in, in, out, out, di, uo) is det.
+ list(comp_gen_c_var), list(comp_gen_c_data), c_file, int,
+ io__state, io__state).
+:- mode mercury_compile__construct_c_file(in, in, in, in, out, out, di, uo)
+ is det.
-mercury_compile__construct_c_file(C_InterfaceInfo, Procedures, AllData, CFile,
- ComponentCount) -->
+mercury_compile__construct_c_file(C_InterfaceInfo, Procedures, GlobalVars,
+ AllData, CFile, ComponentCount) -->
{ C_InterfaceInfo = c_interface_info(ModuleSymName,
C_HeaderCode0, C_BodyCode0, C_ExportDecls, C_ExportDefns) },
{ llds_out__sym_name_mangle(ModuleSymName, MangledModuleName) },
@@ -1926,14 +1925,15 @@
),
maybe_add_header_file_include(C_ExportDecls, ModuleSymName,
C_HeaderCode0, C_HeaderCode),
- { CFile = c_file(ModuleSymName, C_HeaderCode,
- C_BodyCode, C_ExportDefns, AllData, ChunkedModules) },
+ { CFile = c_file(ModuleSymName, C_HeaderCode, C_BodyCode,
+ C_ExportDefns, GlobalVars, AllData, ChunkedModules) },
{ list__length(C_BodyCode, UserCCodeCount) },
{ list__length(C_ExportDefns, ExportCount) },
+ { list__length(GlobalVars, CompGenVarCount) },
{ list__length(AllData, CompGenDataCount) },
{ list__length(ChunkedModules, CompGenCodeCount) },
{ ComponentCount is UserCCodeCount + ExportCount
- + CompGenDataCount + CompGenCodeCount }.
+ + CompGenVarCount + CompGenDataCount + CompGenCodeCount }.
:- pred maybe_add_header_file_include(c_export_decls, module_name,
c_header_info, c_header_info, io__state, io__state).
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.150
diff -u -u -r1.150 mercury_to_mercury.m
--- mercury_to_mercury.m 1998/11/20 04:08:22 1.150
+++ mercury_to_mercury.m 1998/11/20 11:13:58
@@ -1064,6 +1064,8 @@
io__write(Class),
io__write_strings([" from module ", ModuleString, ", instance number",
InstanceString]).
+mercury_output_cons_id(tabling_pointer_const(_, _), _) -->
+ io__write_string("<tabling pointer>").
mercury_output_mode_defn(VarSet, eqv_mode(Name, Args, Mode), Context) -->
io__write_string(":- mode ("),
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.86
diff -u -u -r1.86 opt_debug.m
--- opt_debug.m 1998/11/12 03:15:43 1.86
+++ opt_debug.m 1998/11/20 11:57:27
@@ -712,6 +712,9 @@
opt_debug__dump_data_name(internal_layout(Label), Str) :-
opt_debug__dump_label(Label, LabelStr),
string__append_list(["internal_layout(", LabelStr, ")"], Str).
+opt_debug__dump_data_name(tabling_pointer(ProcLabel), Str) :-
+ opt_debug__dump_proclabel(ProcLabel, ProcLabelStr),
+ string__append_list(["tabling_pointer(", ProcLabelStr, ")"], Str).
opt_debug__dump_unop(mktag, "mktag").
opt_debug__dump_unop(tag, "tag").
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.25
diff -u -u -r1.25 stack_layout.m
--- stack_layout.m 1998/11/19 06:13:35 1.25
+++ stack_layout.m 1998/11/20 11:58:14
@@ -210,9 +210,8 @@
stack_layout__generate_llds(ModuleInfo0, ModuleInfo,
ProcLayouts, InternalLayouts, LayoutLabels) :-
- module_info_get_continuation_info(ModuleInfo0, ContinuationInfo),
- continuation_info__get_all_proc_layouts(ContinuationInfo,
- ProcLayoutList),
+ module_info_get_global_data(ModuleInfo0, GlobalData),
+ global_data_get_all_proc_layouts(GlobalData, ProcLayoutList),
module_info_name(ModuleInfo0, ModuleName),
module_info_get_cell_count(ModuleInfo0, CellCount),
@@ -230,10 +229,8 @@
list__foldl(stack_layout__construct_layouts, ProcLayoutList,
LayoutInfo0, LayoutInfo),
- stack_layout__get_proc_layout_data(ProcLayouts, LayoutInfo, _),
- stack_layout__get_internal_layout_data(InternalLayouts, LayoutInfo, _),
- stack_layout__get_label_set(LayoutLabels, LayoutInfo, _),
- stack_layout__get_cell_number(FinalCellCount, LayoutInfo, _),
+ LayoutInfo = stack_layout_info(_, FinalCellCount, _,
+ _, _, _, ProcLayouts, InternalLayouts, LayoutLabels),
module_info_set_cell_count(ModuleInfo0, FinalCellCount, ModuleInfo).
%---------------------------------------------------------------------------%
Index: compiler/switch_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/switch_gen.m,v
retrieving revision 1.67
diff -u -u -r1.67 switch_gen.m
--- switch_gen.m 1998/11/20 04:09:17 1.67
+++ switch_gen.m 1998/11/20 12:16:33
@@ -213,6 +213,7 @@
switch_gen__priority(code_addr_constant(_, _), 6). % should never occur
switch_gen__priority(base_type_info_constant(_, _, _), 6).% should never occur
switch_gen__priority(base_typeclass_info_constant(_, _, _), 6).% shouldn't occur
+switch_gen__priority(tabling_pointer_constant(_, _), 6). % shouldn't occur
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.5
diff -u -u -r1.5 table_gen.m
--- table_gen.m 1998/11/20 04:09:18 1.5
+++ table_gen.m 1998/11/23 04:55:20
@@ -7,24 +7,24 @@
% Main author: ohutch
%
% This module transforms HLDS code to a form that allows tabled evaluation,
-% minimal model evaluation and loop detection. The tabling transformation
-% adds calls to several tabling predicates as well as restructuring the
+% minimal model evaluation and loop detection. The tabling transformation
+% adds calls to several tabling predicates as well as restructuring the
% HLDS to implement answer clause resolution, suspension and loop detection.
%
-% The loop detection transformation adds code to a procedure that allows
-% early detection of infinite loops. If such loops are detected the program
+% The loop detection transformation adds code to a procedure that allows
+% early detection of infinite loops. If such loops are detected the program
% will terminate with helpfully error message.
%
-% The memo transformation adds code that allows a procedure to "memo"
-% (remember) answers once they have been generated using program clause
+% The memo transformation adds code that allows a procedure to "memo"
+% (remember) answers once they have been generated using program clause
% resolution.
-%
+%
% The minimal model transformation changes the semantics of the procedure
-% being transformed. See the paper K. Sagonas. `The SLG-WAM: A
-% Search-Efficient Engine for Well-Founded Evaluation of Normal Logic
-% Programs.' PhD thesis, SUNY at Stony Brook, 1996 for a description of
-% the semantics behind the transformation. Currently only SLGd is
-% implemented.
+% being transformed. See the paper K. Sagonas. `The SLG-WAM: A
+% Search-Efficient Engine for Well-Founded Evaluation of Normal Logic
+% Programs.' PhD thesis, SUNY at Stony Brook, 1996 for a description of
+% the semantics behind the transformation. Currently only SLGd is
+% implemented.
%
% XXX the current implementation of minimal_model tabling is buggy;
% e.g. it fails for tests/tabling/coup.m.
@@ -43,12 +43,9 @@
%
% p(A, B) :-
% % Code to get a handle on the table
-% c_code(T0::out, "
-% static Word Table = 0;
-% T0 = &Table;
-% "),
+% T0 = <table pointer for p/2>,
%
-% % Code to lookup input arguments
+% % Code to lookup input arguments
% impure table_lookup_insert_int(T0, A, T1),
% impure table_lookup_insert_int(T1, B, T2),
% (if
@@ -64,7 +61,7 @@
%
% % Mark this subgoal as being evaluated
% impure table_mark_as_working(T2),
-%
+%
% (
% %
% % Original goals
@@ -72,29 +69,27 @@
% )
% then
% impure table_mark_as_succeeded(T2)
-% else
-% impure table_mark_as_failed(T2)
+% else
+% impure table_mark_as_failed(T2)
% )
% ).
%
% Example of transformation for nondet minimal_model :
%
% Given the following code for left recursive transitive closure :
-%
+%
% :- pred p(int, int).
-% :- mode p(in, out) is nondet
+% :- mode p(in, out) is nondet
%
% p(A, B) :- e(A, B).
% p(A, B) :- p(A, C), e(C, B).
-%
+%
% The transformed code would be :
%
% p(A, B) :-
% % Code to get a handle on the table
-% c_code(T0::out, "
-% static Word Table = 0;
-% T0 = &Table;
-% "),
+% T0 = <table pointer for p/2>,
+%
% % Code to lookup input arguments and setup table
% impure table_lookup_insert_int(T0, A, T1),
% impure table_setup(T1, T2),
@@ -112,28 +107,28 @@
% % branch
% impure table_suspend(T2, Ans),
% impure table_restore_int_ans(Ans, 0, B)
-% else
+% else
% ( % Mark that this subgoal is being
% % evaluated
% impure table_mark_have_some_ans(T2),
-%
+%
% (
% %
% % Original goals
-% %
+% %
% ),
-%
+%
% % Code to check for duplicate
% % answers
% impure table_get_ans_table(T2, AT0),
% impure table_lookup_insert_int(AT0, B, AT1),
-%
+%
% % The following pred is semidet
% % it will fail if the answer is
-% % already in the table.
+% % already in the table.
% semipure table_has_not_returned(AT1),
%
-% % Code to save a new ans in the
+% % Code to save a new ans in the
% % table.
% impure table_mark_as_returned(AT1),
% impure table_new_ans_slot(T2, AS),
@@ -150,13 +145,13 @@
% fail
% )
% ).
-%
+%
% The memo and loopcheck transformations are very similar to the above
-% transformations except that for the memo case the code for handing
+% transformations except that for the memo case the code for handing
% loops (fail in the semi_det case, suspend in the nondet case) is changed to
-% a loop check. And in the loop_check case the code for memoing answers is
+% a loop check. And in the loop_check case the code for memoing answers is
% dropped and the loop handling code is modified to call an error predicate.
-%
+%
%-----------------------------------------------------------------------------%
:- module table_gen.
@@ -183,9 +178,8 @@
%-----------------------------------------------------------------------------%
-
- % NOTE : following preds seem to duplicate the code in passes_aux.m.
- % This is not strictly true as the following code saved the value of
+ % NOTE : following preds seem to duplicate the code in passes_aux.m.
+ % This is not strictly true as the following code saved the value of
% the pred_info and passes this value on to the code for handling
% each of the procedures.
table_gen__process_module(Module0, Module) :-
@@ -219,28 +213,34 @@
map__lookup(PredTable, PredId, PredInfo),
pred_info_procedures(PredInfo, ProcTable),
map__lookup(ProcTable, ProcId, ProcInfo),
-
+
proc_info_eval_method(ProcInfo, EvalMethod),
(
EvalMethod \= eval_normal
->
- table_gen__process_proc(EvalMethod, PredId, ProcId, ProcInfo,
- PredInfo, Module0, Module1)
+ table_gen__process_proc(EvalMethod, PredId, ProcId, ProcInfo,
+ PredInfo, Module0, Module1),
+ module_info_get_global_data(Module1, GlobalData0),
+ code_util__make_proc_label(Module1, PredId, ProcId, ProcLabel),
+ module_info_name(Module0, ModuleName),
+ Var = tabling_pointer_var(ModuleName, ProcLabel),
+ global_data_add_new_proc_var(GlobalData0,
+ proc(PredId, ProcId), Var, GlobalData),
+ module_info_set_global_data(Module1, GlobalData, Module2)
;
- Module1 = Module0
+ Module2 = Module0
),
-
- table_gen__process_procs(PredId, ProcIds, Module1, Module).
+ table_gen__process_procs(PredId, ProcIds, Module2, Module).
%---------------------------------------------------------------------------%
-:- pred table_gen__process_proc(eval_method, pred_id, proc_id, proc_info,
+:- pred table_gen__process_proc(eval_method, pred_id, proc_id, proc_info,
pred_info, module_info, module_info).
:- mode table_gen__process_proc(in, in, in, in, in, in, out) is det.
-table_gen__process_proc(EvalMethod, PredId, ProcId, ProcInfo0, PredInfo0,
+table_gen__process_proc(EvalMethod, PredId, ProcId, ProcInfo0, PredInfo0,
Module0, Module) :-
% grab the appropriate fields from the pred_info and proc_info
proc_info_interface_code_model(ProcInfo0, CodeModel),
@@ -252,18 +252,21 @@
(
CodeModel = model_det,
- table_gen__create_new_det_goal(EvalMethod, OrigGoal,
- PredInfo0, Module0, HeadVars, ArgModes, VarTypes0,
+ table_gen__create_new_det_goal(EvalMethod, OrigGoal,
+ PredId, ProcId, PredInfo0, Module0,
+ HeadVars, ArgModes, VarTypes0,
VarTypes, VarSet0, VarSet, Goal)
;
CodeModel = model_semi,
- table_gen__create_new_semi_goal(EvalMethod, OrigGoal,
- PredInfo0, Module0, HeadVars, ArgModes, VarTypes0,
+ table_gen__create_new_semi_goal(EvalMethod, OrigGoal,
+ PredId, ProcId, PredInfo0, Module0,
+ HeadVars, ArgModes, VarTypes0,
VarTypes, VarSet0, VarSet, Goal)
;
CodeModel = model_non,
- table_gen__create_new_non_goal(EvalMethod, OrigGoal,
- PredInfo0, Module0, HeadVars, ArgModes, VarTypes0,
+ table_gen__create_new_non_goal(EvalMethod, OrigGoal,
+ PredId, ProcId, PredInfo0, Module0,
+ HeadVars, ArgModes, VarTypes0,
VarTypes, VarSet0, VarSet, Goal)
),
@@ -280,27 +283,27 @@
map__det_update(PredTable0, PredId, PredInfo, PredTable),
module_info_set_preds(Module0, PredTable, Module).
-
%------------------------------------------------------------------------------%
%
% Transform deterministic procedures.
%
-:- pred table_gen__create_new_det_goal(eval_method, hlds_goal, pred_info,
- module_info, list(prog_var), list(mode), map(prog_var, type),
- map(prog_var, type), prog_varset, prog_varset, hlds_goal).
-:- mode table_gen__create_new_det_goal(in, in, in, in, in, in, in, out, in,
- out, out) is det.
-
-table_gen__create_new_det_goal(EvalMethod, OrigGoal, PredInfo, Module,
- HeadVars, HeadVarModes, VarTypes0, VarTypes, VarSet0,
- VarSet, Goal) :-
- get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
+:- pred table_gen__create_new_det_goal(eval_method, hlds_goal,
+ pred_id, proc_id, pred_info, module_info, list(prog_var), list(mode),
+ map(prog_var, type), map(prog_var, type), prog_varset, prog_varset,
+ hlds_goal).
+:- mode table_gen__create_new_det_goal(in, in, in, in, in, in, in, in,
+ in, out, in, out, out) is det.
+
+table_gen__create_new_det_goal(EvalMethod, OrigGoal, PredId, ProcId,
+ PredInfo, Module, HeadVars, HeadVarModes,
+ VarTypes0, VarTypes, VarSet0, VarSet, Goal) :-
+ get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
OutputVars),
- generate_det_lookup_goal(InputVars, Module, VarTypes0, VarTypes1,
- VarSet0, VarSet1, TableVar, LookUpGoal),
- generate_call("table_have_ans", [TableVar], semidet, semipure,
+ generate_det_lookup_goal(InputVars, Module, PredId, ProcId,
+ VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
+ generate_call("table_have_ans", [TableVar], semidet, semipure,
[], Module, HaveAnsCheckGoal),
generate_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
VarSet1, VarSet2, Module, SaveAnsGoal0),
@@ -309,15 +312,14 @@
generate_call("table_mark_done_working", [TableVar], det, impure,
[], Module, DoneWorkingGoal),
generate_loop_error_goal(PredInfo, Module, VarTypes3, VarTypes,
- VarSet3, VarSet, LoopErrorGoal),
+ VarSet3, VarSet, LoopErrorGoal),
OrigGoal = _ - OrigGoalInfo,
goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
-
+
set__insert(OrigNonLocals, TableVar, GenAnsNonLocals),
-
( EvalMethod = eval_loop_check ->
SaveAnsGoal = DoneWorkingGoal
; EvalMethod = eval_memo ->
@@ -326,7 +328,7 @@
error(
"table_gen__create_new_det_goal: unsupported evaluation model")
),
-
+
generate_call("table_working_on_ans", [TableVar], semidet,
semipure, [], Module, WorkingCheckGoal),
generate_call("table_mark_as_working", [TableVar], det,
@@ -334,7 +336,7 @@
NoLoopGenAnsGoalEx = conj([MarkAsWorkingGoal, OrigGoal,
SaveAnsGoal]),
- create_instmap_delta([MarkAsWorkingGoal, OrigGoal,
+ create_instmap_delta([MarkAsWorkingGoal, OrigGoal,
SaveAnsGoal], NoLoopGenInstMapDelta0),
instmap_delta_restrict(NoLoopGenInstMapDelta0, GenAnsNonLocals,
NoLoopGenInstMapDelta),
@@ -343,26 +345,26 @@
NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
map__init(StoreMap),
- GenAnsGoalEx = if_then_else([], WorkingCheckGoal,
+ GenAnsGoalEx = if_then_else([], WorkingCheckGoal,
LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
create_instmap_delta([WorkingCheckGoal, LoopErrorGoal,
NoLoopGenAnsGoal], GenAnsInstMapDelta0),
- instmap_delta_restrict(GenAnsInstMapDelta0, GenAnsNonLocals,
+ instmap_delta_restrict(GenAnsInstMapDelta0, GenAnsNonLocals,
GenAnsInstMapDelta),
- goal_info_init(GenAnsNonLocals, GenAnsInstMapDelta, det,
+ goal_info_init(GenAnsNonLocals, GenAnsInstMapDelta, det,
GenAnsGoalInfo),
-
+
GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
- ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
+ ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
GenAnsGoal, StoreMap),
create_instmap_delta([HaveAnsCheckGoal, RestoreAnsGoal, GenAnsGoal],
ITEInstMapDelta0),
instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
ITEInstMapDelta),
- goal_info_init(GenAnsNonLocals, ITEInstMapDelta, det,
+ goal_info_init(GenAnsNonLocals, ITEInstMapDelta, det,
ITEGoalInfo),
- ITEGoal = ITEGoalEx - ITEGoalInfo,
+ ITEGoal = ITEGoalEx - ITEGoalInfo,
GoalEx = conj([LookUpGoal, ITEGoal]),
goal_info_init(OrigNonLocals, OrigInstMapDelta, det, GoalInfo),
@@ -370,33 +372,34 @@
Goal = GoalEx - GoalInfo.
%------------------------------------------------------------------------------%
-
+
%
% Transform semi deterministic procedures
%
-:- pred table_gen__create_new_semi_goal(eval_method, hlds_goal, pred_info,
- module_info, list(prog_var), list(mode), map(prog_var, type),
- map(prog_var, type), prog_varset, prog_varset, hlds_goal).
-:- mode table_gen__create_new_semi_goal(in, in, in, in, in, in, in, out, in,
- out, out) is det.
-
-table_gen__create_new_semi_goal(EvalMethod, OrigGoal, PredInfo, Module,
- HeadVars, HeadVarModes, VarTypes0, VarTypes, VarSet0,
- VarSet, Goal) :-
- get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
+:- pred table_gen__create_new_semi_goal(eval_method, hlds_goal,
+ pred_id, proc_id, pred_info, module_info, list(prog_var), list(mode),
+ map(prog_var, type), map(prog_var, type), prog_varset, prog_varset,
+ hlds_goal).
+:- mode table_gen__create_new_semi_goal(in, in, in, in, in, in, in, in,
+ in, out, in, out, out) is det.
+
+table_gen__create_new_semi_goal(EvalMethod, OrigGoal, PredId, ProcId,
+ PredInfo, Module, HeadVars, HeadVarModes,
+ VarTypes0, VarTypes, VarSet0, VarSet, Goal) :-
+ get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
OutputVars),
- generate_det_lookup_goal(InputVars, Module, VarTypes0, VarTypes1,
- VarSet0, VarSet1, TableVar, LookUpGoal),
- generate_call("table_have_ans", [TableVar], semidet, semipure,
+ generate_det_lookup_goal(InputVars, Module, PredId, ProcId,
+ VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
+ generate_call("table_have_ans", [TableVar], semidet, semipure,
[], Module, HaveAnsCheckGoal),
generate_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
VarSet1, VarSet2, Module, SaveAnsGoal0),
generate_restore_goal(OutputVars, TableVar, Module, VarTypes2,
VarTypes3, VarSet2, VarSet3, RestoreTrueAnsGoal),
generate_loop_error_goal(PredInfo, Module, VarTypes3, VarTypes,
- VarSet3, VarSet, LoopErrorGoal),
- generate_call("table_mark_as_failed", [TableVar], failure, impure,
+ VarSet3, VarSet, LoopErrorGoal),
+ generate_call("table_mark_as_failed", [TableVar], failure, impure,
[], Module, MarkAsFailedGoal),
generate_call("table_has_succeeded", [TableVar], semidet, semipure,
[], Module, HasSucceededCheckGoal),
@@ -406,7 +409,7 @@
OrigGoal = _ - OrigGoalInfo,
goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
-
+
set__insert(OrigNonLocals, TableVar, GenAnsNonLocals),
map__init(StoreMap),
@@ -428,9 +431,9 @@
semipure, [], Module, WorkingCheckGoal),
generate_call("table_mark_as_working", [TableVar], det,
impure, [], Module, MarkAsWorkingGoal),
-
+
NoLoopGenAnsGoalEx = conj([MarkAsWorkingGoal, OrigGoal]),
- create_instmap_delta([MarkAsWorkingGoal, OrigGoal],
+ create_instmap_delta([MarkAsWorkingGoal, OrigGoal],
NoLoopGenInstMapDelta0),
instmap_delta_restrict(NoLoopGenInstMapDelta0, GenAnsNonLocals,
NoLoopGenInstMapDelta),
@@ -438,15 +441,15 @@
NoLoopGenGoalInfo),
NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
- GenTrueAnsGoalEx = if_then_else([], WorkingCheckGoal,
+ GenTrueAnsGoalEx = if_then_else([], WorkingCheckGoal,
LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
create_instmap_delta([WorkingCheckGoal, LoopErrorGoal,
NoLoopGenAnsGoal], GenTrueAnsInstMapDelta0),
- instmap_delta_restrict(GenTrueAnsInstMapDelta0,
+ instmap_delta_restrict(GenTrueAnsInstMapDelta0,
GenAnsNonLocals, GenTrueAnsInstMapDelta),
- goal_info_init(GenAnsNonLocals, GenTrueAnsInstMapDelta,
+ goal_info_init(GenAnsNonLocals, GenTrueAnsInstMapDelta,
semidet, GenTrueAnsGoalInfo),
-
+
GenTrueAnsGoal = GenTrueAnsGoalEx - GenTrueAnsGoalInfo
;
EvalMethod = eval_minimal
@@ -455,20 +458,20 @@
generate_call("table_not_working_on_ans", [TableVar], semidet,
semipure, [], Module, NotWorkingCheckGoal),
-
+
generate_call("table_mark_as_working", [TableVar], det,
impure, [], Module, MarkAsWorkingGoal),
-
- GenTrueAnsGoalEx = conj([NotWorkingCheckGoal,
+
+ GenTrueAnsGoalEx = conj([NotWorkingCheckGoal,
MarkAsWorkingGoal, OrigGoal]),
-
- create_instmap_delta([NotWorkingCheckGoal, MarkAsWorkingGoal,
+
+ create_instmap_delta([NotWorkingCheckGoal, MarkAsWorkingGoal,
OrigGoal, SaveAnsGoal], GenTrueAnsInstMapDelta0),
- instmap_delta_restrict(GenTrueAnsInstMapDelta0,
+ instmap_delta_restrict(GenTrueAnsInstMapDelta0,
GenAnsNonLocals, GenTrueAnsInstMapDelta),
- goal_info_init(GenAnsNonLocals, GenTrueAnsInstMapDelta,
+ goal_info_init(GenAnsNonLocals, GenTrueAnsInstMapDelta,
semidet, GenTrueAnsGoalInfo),
-
+
GenTrueAnsGoal = GenTrueAnsGoalEx - GenTrueAnsGoalInfo
;
error(
@@ -478,60 +481,60 @@
RestAnsGoalEx = conj([HasSucceededCheckGoal, RestoreTrueAnsGoal]),
set__singleton_set(RestNonLocals0, TableVar),
set__insert_list(RestNonLocals0, OutputVars, RestNonLocals),
- create_instmap_delta([HasSucceededCheckGoal, RestoreTrueAnsGoal],
+ create_instmap_delta([HasSucceededCheckGoal, RestoreTrueAnsGoal],
RestInstMapDelta0),
instmap_delta_restrict(RestInstMapDelta0, RestNonLocals,
RestInstMapDelta),
- goal_info_init(RestNonLocals, RestInstMapDelta, semidet,
+ goal_info_init(RestNonLocals, RestInstMapDelta, semidet,
RestAnsGoalInfo),
RestoreAnsGoal = RestAnsGoalEx - RestAnsGoalInfo,
- GenAnsGoalEx = if_then_else([], GenTrueAnsGoal, SaveAnsGoal,
+ GenAnsGoalEx = if_then_else([], GenTrueAnsGoal, SaveAnsGoal,
MarkAsFailedGoal, StoreMap),
- create_instmap_delta([GenTrueAnsGoal, SaveAnsGoal, MarkAsFailedGoal],
+ create_instmap_delta([GenTrueAnsGoal, SaveAnsGoal, MarkAsFailedGoal],
GenAnsGoalInstMapDelta0),
instmap_delta_restrict(GenAnsGoalInstMapDelta0, GenAnsNonLocals,
GenAnsGoalInstMapDelta),
goal_info_init(GenAnsNonLocals, GenAnsGoalInstMapDelta, semidet,
GenAnsGoalInfo),
GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
-
- ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
+
+ ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
GenAnsGoal, StoreMap),
create_instmap_delta([HaveAnsCheckGoal, RestoreAnsGoal, GenAnsGoal],
ITEInstMapDelta0),
instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
ITEInstMapDelta),
- goal_info_init(GenAnsNonLocals, ITEInstMapDelta, semidet,
+ goal_info_init(GenAnsNonLocals, ITEInstMapDelta, semidet,
ITEGoalInfo),
- ITEGoal = ITEGoalEx - ITEGoalInfo,
+ ITEGoal = ITEGoalEx - ITEGoalInfo,
GoalEx = conj([LookUpGoal, ITEGoal]),
goal_info_init(OrigNonLocals, OrigInstMapDelta, semidet, GoalInfo),
Goal = GoalEx - GoalInfo.
-
%------------------------------------------------------------------------------%
%
% Transform non deterministic procedures
%
-:- pred table_gen__create_new_non_goal(eval_method, hlds_goal, pred_info,
- module_info, list(prog_var), list(mode), map(prog_var, type),
- map(prog_var, type), prog_varset, prog_varset, hlds_goal).
-:- mode table_gen__create_new_non_goal(in, in, in, in, in, in, in, out, in,
- out, out) is det.
-
-table_gen__create_new_non_goal(EvalMethod, OrigGoal, PredInfo, Module,
- HeadVars, HeadVarModes, VarTypes0, VarTypes, VarSet0,
- VarSet, Goal) :-
- get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
+:- pred table_gen__create_new_non_goal(eval_method, hlds_goal,
+ pred_id, proc_id, pred_info, module_info, list(prog_var), list(mode),
+ map(prog_var, type), map(prog_var, type), prog_varset, prog_varset,
+ hlds_goal).
+:- mode table_gen__create_new_non_goal(in, in, in, in, in, in, in, in,
+ in, out, in, out, out) is det.
+
+table_gen__create_new_non_goal(EvalMethod, OrigGoal, PredId, ProcId,
+ PredInfo, Module, HeadVars, HeadVarModes,
+ VarTypes0, VarTypes, VarSet0, VarSet, Goal) :-
+ get_input_output_vars(HeadVars, HeadVarModes, Module, InputVars,
OutputVars),
- generate_non_lookup_goal(InputVars, Module, VarTypes0, VarTypes1,
- VarSet0, VarSet1, TableVar, LookUpGoal),
- generate_call("table_have_all_ans", [TableVar], semidet, semipure,
+ generate_non_lookup_goal(InputVars, Module, PredId, ProcId,
+ VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
+ generate_call("table_have_all_ans", [TableVar], semidet, semipure,
[], Module, HaveAllAnsCheckGoal),
generate_non_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
VarSet1, VarSet2, Module, SaveAnsGoal0),
@@ -539,10 +542,10 @@
VarTypes3, VarSet2, VarSet3, RestoreAllAnsGoal),
generate_call("table_have_some_ans", [TableVar], semidet, semipure,
[], Module, HaveSomeAnsCheckGoal),
- generate_suspend_goal(OutputVars, TableVar, Module, VarTypes3,
+ generate_suspend_goal(OutputVars, TableVar, Module, VarTypes3,
VarTypes4, VarSet3, VarSet4, SuspendGoal),
generate_loop_error_goal(PredInfo, Module, VarTypes4, VarTypes,
- VarSet4, VarSet, LoopErrorGoal),
+ VarSet4, VarSet, LoopErrorGoal),
generate_call("table_mark_have_some_ans", [TableVar], det, impure,
[], Module, MarkHaveSomeAnsGoal),
generate_call("table_resume", [TableVar], failure, impure,
@@ -552,11 +555,11 @@
true_goal(TrueGoal),
fail_goal(FailGoal),
-
+
OrigGoal = _ - OrigGoalInfo,
goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
-
+
map__init(StoreMap),
(
EvalMethod = eval_memo
@@ -566,7 +569,7 @@
;
EvalMethod = eval_loop_check
->
- SaveAnsGoal = TrueGoal,
+ SaveAnsGoal = TrueGoal,
WorkingOnAnsGoal = LoopErrorGoal
;
EvalMethod = eval_minimal
@@ -578,7 +581,6 @@
"table_gen__create_new_non_goal: unsupported evaluation model")
),
-
GenAnsGoalPart1Ex = conj([MarkHaveSomeAnsGoal, OrigGoal, SaveAnsGoal]),
set__insert(OrigNonLocals, TableVar, GenAnsGoalPart1NonLocals),
create_instmap_delta([MarkHaveSomeAnsGoal, OrigGoal, SaveAnsGoal],
@@ -596,11 +598,11 @@
;
ResumeGoal = FailGoal
),
- GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal, MarkHaveAllAnsGoal],
+ GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal, MarkHaveAllAnsGoal],
StoreMap),
GenAnsGoal = GenAnsGoalEx - GenAnsGoalPart1GoalInfo,
- ITE1GoalEx = if_then_else([], HaveSomeAnsCheckGoal, WorkingOnAnsGoal,
+ ITE1GoalEx = if_then_else([], HaveSomeAnsCheckGoal, WorkingOnAnsGoal,
GenAnsGoal, StoreMap),
ITE1Goal = ITE1GoalEx - GenAnsGoalPart1GoalInfo,
@@ -608,8 +610,8 @@
EvalMethod = eval_loop_check
->
ITE2Goal = ITE1Goal
- ;
- ITE2GoalEx = if_then_else([], HaveAllAnsCheckGoal,
+ ;
+ ITE2GoalEx = if_then_else([], HaveAllAnsCheckGoal,
RestoreAllAnsGoal, ITE1Goal, StoreMap),
ITE2Goal = ITE2GoalEx - GenAnsGoalPart1GoalInfo
),
@@ -621,76 +623,43 @@
%------------------------------------------------------------------------------%
-
-:- pred generate_get_table_goals(map(prog_var, type), map(prog_var, type),
- prog_varset, prog_varset, module_info, prog_var, hlds_goal).
-:- mode generate_get_table_goals(in, out, in, out, in, out, out) is det.
-
-generate_get_table_goals(VarTypes0, VarTypes, VarSet0, VarSet, Module,
- TableVar, Goal) :-
- generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet,
- TableVar),
-
- % The predicate get_table/1 is used only for its pred_info
- % the code is not actually called. We have to steal the
- % pred_info for the c_code instruction below.
- module_info_get_predicate_table(Module, PredTable),
- mercury_private_builtin_module(BuiltinModule),
- (
- predicate_table_search_pred_m_n_a(PredTable,
- BuiltinModule, "get_table", 1,
- [PredId0])
- ->
- PredId = PredId0
- ;
- error("can't locate get_table/1")
- ),
- module_info_pred_info(Module, PredId, PredInfo),
- (
- pred_info_procids(PredInfo, [ProcId0])
- ->
- ProcId = ProcId0
- ;
- error("too many modes for predicate get_table/1")
- ),
-
- TableVarInst = ground(unique, no),
- TableVarMode = (free -> TableVarInst),
- get_table_var_type(TableVarType),
-
- default_attributes(Attrs0),
- set_may_call_mercury(Attrs0, will_not_call_mercury, Attrs),
- GoalEx = pragma_c_code(Attrs, PredId, ProcId, [TableVar],
- [yes("MC_table_var" - TableVarMode)],
- [TableVarType], ordinary(
-" {
- static Word MR_table = 0;
- MC_table_var = (Word)&MR_table;
- }
-",
- no)),
+:- pred generate_get_table_goal(map(prog_var, type), map(prog_var, type),
+ prog_varset, prog_varset, pred_id, proc_id, prog_var, hlds_goal).
+:- mode generate_get_table_goal(in, out, in, out, in, in, out, out) is det.
+
+generate_get_table_goal(VarTypes0, VarTypes, VarSet0, VarSet,
+ PredId, ProcId, TableVar, Goal) :-
+ generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet, TableVar),
+
+ ConsId = tabling_pointer_const(PredId, ProcId),
+ TableVarInst = ground(unique, no),
+ UnifyMode = (free -> TableVarInst) - (TableVarInst -> TableVarInst),
+ UnifyContext = unify_context(explicit, []),
+ GoalExpr = unify(TableVar, functor(ConsId, []), UnifyMode,
+ construct(TableVar, ConsId, [], []), UnifyContext),
set__singleton_set(NonLocals, TableVar),
instmap_delta_from_assoc_list([TableVar - TableVarInst],
InstMapDelta),
- goal_info_init(NonLocals, InstMapDelta, det,
+ goal_info_init(NonLocals, InstMapDelta, det,
GoalInfo0),
goal_info_add_feature(GoalInfo0, impure, GoalInfo),
- Goal = GoalEx - GoalInfo.
+ Goal = GoalExpr - GoalInfo.
%------------------------------------------------------------------------------%
-
-:- pred generate_det_lookup_goal(list(prog_var), module_info,
- map(prog_var, type), map(prog_var, type), prog_varset,
- prog_varset, prog_var, hlds_goal).
-:- mode generate_det_lookup_goal(in, in, in, out, in, out, out, out) is det.
-
-generate_det_lookup_goal(Vars, Module, VarTypes0, VarTypes, VarSet0, VarSet,
- TableVar, Goal) :-
- generate_get_table_goals(VarTypes0, VarTypes1, VarSet0, VarSet1, Module,
- TableVar0, GetTableGoal),
- generate_lookup_goals(Vars, TableVar0, TableVar, Module,
+:- pred generate_det_lookup_goal(list(prog_var), module_info, pred_id, proc_id,
+ map(prog_var, type), map(prog_var, type), prog_varset,
+ prog_varset, prog_var, hlds_goal).
+:- mode generate_det_lookup_goal(in, in, in, in, in, out, in, out, out, out)
+ is det.
+
+generate_det_lookup_goal(Vars, Module, PredId, ProcId, VarTypes0, VarTypes,
+ VarSet0, VarSet, TableVar, Goal) :-
+
+ generate_get_table_goal(VarTypes0, VarTypes1, VarSet0, VarSet1,
+ PredId, ProcId, TableVar0, GetTableGoal),
+ generate_lookup_goals(Vars, TableVar0, TableVar, Module,
VarTypes1, VarTypes, VarSet1, VarSet, LookupGoals),
GoalEx = conj([GetTableGoal | LookupGoals]),
@@ -699,20 +668,21 @@
instmap_delta_from_assoc_list([], InstMapDelta),
goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
Goal = GoalEx - GoalInfo.
-
-:- pred generate_non_lookup_goal(list(prog_var), module_info,
- map(prog_var, type), map(prog_var, type), prog_varset,
- prog_varset, prog_var, hlds_goal).
-:- mode generate_non_lookup_goal(in, in, in, out, in, out, out, out) is det.
-
-generate_non_lookup_goal(Vars, Module, VarTypes0, VarTypes, VarSet0, VarSet,
- TableVar, Goal) :-
- generate_get_table_goals(VarTypes0, VarTypes1, VarSet0, VarSet1, Module,
- TableVar0, GetTableGoal),
- generate_lookup_goals(Vars, TableVar0, TableVar1, Module,
+:- pred generate_non_lookup_goal(list(prog_var), module_info, pred_id, proc_id,
+ map(prog_var, type), map(prog_var, type), prog_varset,
+ prog_varset, prog_var, hlds_goal).
+:- mode generate_non_lookup_goal(in, in, in, in, in, out, in, out, out, out)
+ is det.
+
+generate_non_lookup_goal(Vars, Module, PredId, ProcId, VarTypes0, VarTypes,
+ VarSet0, VarSet, TableVar, Goal) :-
+
+ generate_get_table_goal(VarTypes0, VarTypes1, VarSet0, VarSet1,
+ PredId, ProcId, TableVar0, GetTableGoal),
+ generate_lookup_goals(Vars, TableVar0, TableVar1, Module,
VarTypes1, VarTypes2, VarSet1, VarSet2, LookupGoals),
- generate_new_table_var(VarTypes2, VarTypes, VarSet2, VarSet,
+ generate_new_table_var(VarTypes2, VarTypes, VarSet2, VarSet,
TableVar),
generate_call("table_setup", [TableVar1, TableVar], det, impure,
[TableVar - ground(unique, no)], Module, SetupGoal),
@@ -726,31 +696,28 @@
goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
Goal = GoalEx - GoalInfo.
-
-:- pred generate_lookup_goals(list(prog_var), prog_var, prog_var, module_info,
+:- pred generate_lookup_goals(list(prog_var), prog_var, prog_var, module_info,
map(prog_var, type), map(prog_var, type), prog_varset,
prog_varset, list(hlds_goal)).
:- mode generate_lookup_goals(in, in, out, in, in, out, in, out, out) is det.
-
-generate_lookup_goals([], TableVar, TableVar, _, VarTypes, VarTypes, VarSet,
+generate_lookup_goals([], TableVar, TableVar, _, VarTypes, VarTypes, VarSet,
VarSet, []).
-generate_lookup_goals([Var|Rest], TableVar0, TableVar, Module, VarTypes0,
+generate_lookup_goals([Var|Rest], TableVar0, TableVar, Module, VarTypes0,
VarTypes, VarSet0, VarSet, [Goal|RestGoals]) :-
map__lookup(VarTypes0, Var, VarType),
classify_type(VarType, Module, TypeCat),
gen_lookup_call_for_type(TypeCat, VarType, TableVar0, Var,
- Module, VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar1,
+ Module, VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar1,
Goal),
- generate_lookup_goals(Rest, TableVar1, TableVar, Module,
+ generate_lookup_goals(Rest, TableVar1, TableVar, Module,
VarTypes1, VarTypes, VarSet1, VarSet, RestGoals).
-
:- pred gen_lookup_call_for_type(builtin_type, type, prog_var, prog_var,
module_info, map(prog_var, type), map(prog_var, type),
prog_varset, prog_varset, prog_var, hlds_goal).
-:- mode gen_lookup_call_for_type(in, in, in, in, in, in, out, in,
+:- mode gen_lookup_call_for_type(in, in, in, in, in, in, out, in,
out, out, out) is det.
gen_lookup_call_for_type(TypeCat, Type, TableVar, ArgVar, Module, VarTypes0,
@@ -767,24 +734,24 @@
(
TypeBody = du_type(Ctors, _, yes, no)
->
- list__length(Ctors, EnumRange)
+ list__length(Ctors, EnumRange)
;
error(
- "gen_lookup_call_for_type: enum type is not du_type?")
+ "gen_lookup_call_for_type: enum type is not du_type?")
),
- gen_int_construction("RangeVar", EnumRange, VarTypes0,
- VarTypes1, VarSet0, VarSet1, RangeVar,
+ gen_int_construction("RangeVar", EnumRange, VarTypes0,
+ VarTypes1, VarSet0, VarSet1, RangeVar,
RangeUnifyGoal),
- generate_new_table_var(VarTypes1, VarTypes, VarSet1,
+ generate_new_table_var(VarTypes1, VarTypes, VarSet1,
VarSet, NextTableVar),
generate_call("table_lookup_insert_enum", [TableVar,
RangeVar, ArgVar, NextTableVar], det, impure,
- [NextTableVar - ground(unique, no)], Module,
+ [NextTableVar - ground(unique, no)], Module,
LookupGoal),
set__init(NonLocals0),
- set__insert_list(NonLocals0, [TableVar, ArgVar],
- NonLocals),
+ set__insert_list(NonLocals0, [TableVar, ArgVar],
+ NonLocals),
instmap_delta_from_assoc_list([], InstMapDelta),
goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
Goal = conj([RangeUnifyGoal, LookupGoal]) - GoalInfo
@@ -813,14 +780,13 @@
string__append("table_lookup_insert_", CatString,
LookupPredName)
),
- generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet,
+ generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet,
NextTableVar),
- generate_call(LookupPredName, [TableVar, ArgVar, NextTableVar],
- det, impure, [NextTableVar - ground(unique, no)],
+ generate_call(LookupPredName, [TableVar, ArgVar, NextTableVar],
+ det, impure, [NextTableVar - ground(unique, no)],
Module, Goal)
).
-
%------------------------------------------------------------------------------%
:- pred generate_save_goal(list(prog_var), prog_var, map(prog_var, type),
@@ -830,27 +796,27 @@
generate_save_goal(AnsList, TableVar, VarTypes0, VarTypes, VarSet0,
VarSet, Module, Goal) :-
-
+
list__length(AnsList, NumAnsVars),
(
NumAnsVars \= 0
->
- gen_int_construction("NumAnsVars", NumAnsVars, VarTypes0,
- VarTypes1, VarSet0, VarSet1, NumAnsVarsVar,
+ gen_int_construction("NumAnsVars", NumAnsVars, VarTypes0,
+ VarTypes1, VarSet0, VarSet1, NumAnsVarsVar,
NumAnsVarsUnifyGoal),
-
+
generate_new_table_var(VarTypes1, VarTypes2, VarSet1, VarSet2,
AnsTableVar),
-
- generate_call("table_create_ans_block", [TableVar,
- NumAnsVarsVar, AnsTableVar], det, impure,
- [AnsTableVar - ground(unique, no)], Module,
+
+ generate_call("table_create_ans_block", [TableVar,
+ NumAnsVarsVar, AnsTableVar], det, impure,
+ [AnsTableVar - ground(unique, no)], Module,
GenAnsBlockGoal),
-
- generate_save_goals(AnsList, AnsTableVar, 0, Module,
+
+ generate_save_goals(AnsList, AnsTableVar, 0, Module,
VarTypes2, VarTypes, VarSet2, VarSet, SaveGoals),
- GoalEx = conj([NumAnsVarsUnifyGoal, GenAnsBlockGoal |
+ GoalEx = conj([NumAnsVarsUnifyGoal, GenAnsBlockGoal |
SaveGoals]),
set__singleton_set(NonLocals0, TableVar),
set__insert_list(NonLocals0, AnsList, NonLocals),
@@ -865,7 +831,7 @@
generate_call("table_mark_as_succeeded", [TableVar], det,
impure, [], Module, Goal)
).
-
+
:- pred generate_non_save_goal(list(prog_var), prog_var, map(prog_var, type),
map(prog_var, type), prog_varset, prog_varset,
module_info, hlds_goal).
@@ -873,15 +839,15 @@
generate_non_save_goal(AnsList, TableVar, VarTypes0, VarTypes, VarSet0,
VarSet, Module, Goal) :-
-
+
generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
AnsTableVar0),
- generate_call("table_get_ans_table", [TableVar, AnsTableVar0], det,
- impure, [AnsTableVar0 - ground(unique, no)], Module,
+ generate_call("table_get_ans_table", [TableVar, AnsTableVar0], det,
+ impure, [AnsTableVar0 - ground(unique, no)], Module,
GetAnsTableGoal),
- generate_lookup_goals(AnsList, AnsTableVar0, AnsTableVar1, Module,
+ generate_lookup_goals(AnsList, AnsTableVar0, AnsTableVar1, Module,
VarTypes1, VarTypes2, VarSet1, VarSet2, LookupAnsGoals),
- generate_call("table_has_not_returned", [AnsTableVar1], semidet,
+ generate_call("table_has_not_returned", [AnsTableVar1], semidet,
semipure, [], Module, NewAnsCheckGoal),
generate_call("table_mark_as_returned", [AnsTableVar1], det, impure,
[], Module, MarkAsReturnedGoal),
@@ -891,22 +857,21 @@
generate_call("table_new_ans_slot", [TableVar, AnsBlockVar0], det,
impure, [AnsBlockVar0 - ground(unique, no)], Module,
GenAnsSlotGoal),
-
+
list__length(AnsList, NumAnsVars),
gen_int_construction("NumAnsVars", NumAnsVars, VarTypes3, VarTypes4,
VarSet3, VarSet4, NumAnsVarsVar, NumAnsVarsUnifyGoal),
generate_new_table_var(VarTypes4, VarTypes5, VarSet4, VarSet5,
AnsBlockVar),
generate_call("table_create_ans_block", [AnsBlockVar0, NumAnsVarsVar,
- AnsBlockVar], det, impure, [AnsBlockVar - ground(unique, no)],
+ AnsBlockVar], det, impure, [AnsBlockVar - ground(unique, no)],
Module, GenAnsBlockGoal),
-
+
generate_save_goals(AnsList, AnsBlockVar, 0, Module, VarTypes5,
VarTypes, VarSet5, VarSet, SaveGoals),
-
list__append([GetAnsTableGoal | LookupAnsGoals],
- [NewAnsCheckGoal, MarkAsReturnedGoal, GenAnsSlotGoal,
+ [NewAnsCheckGoal, MarkAsReturnedGoal, GenAnsSlotGoal,
NumAnsVarsUnifyGoal, GenAnsBlockGoal | SaveGoals], Goals),
GoalEx = conj(Goals),
@@ -917,7 +882,6 @@
goal_info_init(NonLocals, InstMapDelta, semidet, GoalInfo),
Goal = GoalEx - GoalInfo.
-
:- pred generate_save_goals(list(prog_var), prog_var, int, module_info,
map(prog_var, type), map(prog_var, type), prog_varset,
prog_varset, list(hlds_goal)).
@@ -925,29 +889,28 @@
generate_save_goals([], _TableVar, _Offset, _Module, VarTypes, VarTypes,
VarSet, VarSet, []).
-generate_save_goals([Var|Rest], TableVar, Offset0, Module, VarTypes0,
- VarTypes, VarSet0, VarSet, [OffsetUnifyGoal,
+generate_save_goals([Var|Rest], TableVar, Offset0, Module, VarTypes0,
+ VarTypes, VarSet0, VarSet, [OffsetUnifyGoal,
CallGoal|RestGoals]) :-
gen_int_construction("OffsetVar", Offset0, VarTypes0, VarTypes1,
VarSet0, VarSet1, OffsetVar, OffsetUnifyGoal),
-
+
map__lookup(VarTypes1, Var, VarType),
classify_type(VarType, Module, TypeCat),
-
- gen_save_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
+
+ gen_save_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
Module, CallGoal),
Offset is Offset0 + 1,
- generate_save_goals(Rest, TableVar, Offset, Module, VarTypes1,
+ generate_save_goals(Rest, TableVar, Offset, Module, VarTypes1,
VarTypes, VarSet1, VarSet, RestGoals).
-
:- pred gen_save_call_for_type(builtin_type, type, prog_var, prog_var,
prog_var, module_info, hlds_goal).
:- mode gen_save_call_for_type(in, in, in, in, in, in, out) is det.
-gen_save_call_for_type(TypeCat, _Type, TableVar, Var, OffsetVar, Module,
+gen_save_call_for_type(TypeCat, _Type, TableVar, Var, OffsetVar, Module,
Goal) :-
(
not_builtin_type(TypeCat)
@@ -958,60 +921,58 @@
string__append_list(["table_save_", CatString, "_ans"],
LookupPredName)
),
- generate_call(LookupPredName, [TableVar, OffsetVar, Var],
+ generate_call(LookupPredName, [TableVar, OffsetVar, Var],
det, impure, [], Module, Goal).
-
%------------------------------------------------------------------------------%
-
:- pred generate_restore_goal(list(prog_var), prog_var, module_info,
map(prog_var, type), map(prog_var, type), prog_varset,
prog_varset, hlds_goal).
:- mode generate_restore_goal(in, in, in, in, out, in, out, out) is det.
-generate_restore_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
+generate_restore_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
VarSet0, VarSet, Goal) :-
- generate_restore_goals(OutputVars, TableVar, 0, Module, VarTypes0,
+ generate_restore_goals(OutputVars, TableVar, 0, Module, VarTypes0,
VarTypes, VarSet0, VarSet, RestoreGoals),
-
+
GoalEx = conj(RestoreGoals),
set__singleton_set(NonLocals0, TableVar),
set__insert_list(NonLocals0, OutputVars, NonLocals),
create_instmap_delta(RestoreGoals, InstMapDelta0),
instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
- goal_info_init(NonLocals, InstMapDelta, det,
+ goal_info_init(NonLocals, InstMapDelta, det,
GoalInfo),
Goal = GoalEx - GoalInfo.
-
+
:- pred generate_restore_all_goal(list(prog_var), prog_var, module_info,
map(prog_var, type), map(prog_var, type), prog_varset,
prog_varset, hlds_goal).
:- mode generate_restore_all_goal(in, in, in, in, out, in, out, out) is det.
-generate_restore_all_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
+generate_restore_all_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
VarSet0, VarSet, Goal) :-
- generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
+ generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
AnsTableVar),
- generate_call("table_return_all_ans", [TableVar, AnsTableVar],
- nondet, semipure, [AnsTableVar - ground(unique, no)],
+ generate_call("table_return_all_ans", [TableVar, AnsTableVar],
+ nondet, semipure, [AnsTableVar - ground(unique, no)],
Module, ReturnAnsBlocksGoal),
-
- generate_restore_goals(OutputVars, AnsTableVar, 0, Module, VarTypes1,
+
+ generate_restore_goals(OutputVars, AnsTableVar, 0, Module, VarTypes1,
VarTypes, VarSet1, VarSet, RestoreGoals),
-
+
GoalEx = conj([ReturnAnsBlocksGoal | RestoreGoals]),
set__singleton_set(NonLocals0, TableVar),
set__insert_list(NonLocals0, OutputVars, NonLocals),
create_instmap_delta([ReturnAnsBlocksGoal | RestoreGoals],
InstMapDelta0),
instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
- goal_info_init(NonLocals, InstMapDelta, nondet,
+ goal_info_init(NonLocals, InstMapDelta, nondet,
GoalInfo),
Goal = GoalEx - GoalInfo.
-
+
:- pred generate_restore_goals(list(prog_var), prog_var, int, module_info,
map(prog_var, type), map(prog_var, type), prog_varset,
prog_varset, list(hlds_goal)).
@@ -1019,29 +980,28 @@
generate_restore_goals([], _TableVar, _Offset, _Module, VarTypes, VarTypes,
VarSet, VarSet, []).
-generate_restore_goals([Var|Rest], TableVar, Offset0, Module, VarTypes0,
- VarTypes, VarSet0, VarSet, [OffsetUnifyGoal,
+generate_restore_goals([Var|Rest], TableVar, Offset0, Module, VarTypes0,
+ VarTypes, VarSet0, VarSet, [OffsetUnifyGoal,
CallGoal|RestGoals]) :-
gen_int_construction("OffsetVar", Offset0, VarTypes0, VarTypes1,
VarSet0, VarSet1, OffsetVar, OffsetUnifyGoal),
-
+
map__lookup(VarTypes1, Var, VarType),
classify_type(VarType, Module, TypeCat),
-
- gen_restore_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
+
+ gen_restore_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
Module, CallGoal),
Offset is Offset0 + 1,
- generate_restore_goals(Rest, TableVar, Offset, Module, VarTypes1,
+ generate_restore_goals(Rest, TableVar, Offset, Module, VarTypes1,
VarTypes, VarSet1, VarSet, RestGoals).
-
:- pred gen_restore_call_for_type(builtin_type, type, prog_var, prog_var,
prog_var, module_info, hlds_goal).
:- mode gen_restore_call_for_type(in, in, in, in, in, in, out) is det.
-gen_restore_call_for_type(TypeCat, _Type, TableVar, Var, OffsetVar, Module,
+gen_restore_call_for_type(TypeCat, _Type, TableVar, Var, OffsetVar, Module,
Goal) :-
(
not_builtin_type(TypeCat)
@@ -1052,7 +1012,7 @@
string__append_list(["table_restore_", CatString, "_ans"],
LookupPredName)
),
- generate_call(LookupPredName, [TableVar, OffsetVar, Var],
+ generate_call(LookupPredName, [TableVar, OffsetVar, Var],
det, impure, [Var - ground(shared, no)], Module, Goal).
%------------------------------------------------------------------------------%
@@ -1062,61 +1022,60 @@
prog_varset, hlds_goal).
:- mode generate_suspend_goal(in, in, in, in, out, in, out, out) is det.
-generate_suspend_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
+generate_suspend_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
VarSet0, VarSet, Goal) :-
-
- generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
+
+ generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
AnsTableVar),
- generate_call("table_suspend", [TableVar, AnsTableVar],
- nondet, semipure, [AnsTableVar - ground(unique, no)],
+ generate_call("table_suspend", [TableVar, AnsTableVar],
+ nondet, semipure, [AnsTableVar - ground(unique, no)],
Module, ReturnAnsBlocksGoal),
-
- generate_restore_goals(OutputVars, AnsTableVar, 0, Module, VarTypes1,
+
+ generate_restore_goals(OutputVars, AnsTableVar, 0, Module, VarTypes1,
VarTypes, VarSet1, VarSet, RestoreGoals),
-
+
GoalEx = conj([ReturnAnsBlocksGoal | RestoreGoals]),
set__singleton_set(NonLocals0, TableVar),
set__insert_list(NonLocals0, OutputVars, NonLocals),
create_instmap_delta([ReturnAnsBlocksGoal | RestoreGoals],
InstMapDelta0),
instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
- goal_info_init(NonLocals, InstMapDelta, nondet,
+ goal_info_init(NonLocals, InstMapDelta, nondet,
GoalInfo),
- Goal = GoalEx - GoalInfo.
+ Goal = GoalEx - GoalInfo.
%------------------------------------------------------------------------------%
-:- pred generate_loop_error_goal(pred_info, module_info, map(prog_var, type),
+:- pred generate_loop_error_goal(pred_info, module_info, map(prog_var, type),
map(prog_var, type), prog_varset, prog_varset, hlds_goal).
:- mode generate_loop_error_goal(in, in, in, out, in, out, out) is det.
generate_loop_error_goal(PredInfo, ModuleInfo, VarTypes0, VarTypes,
VarSet0, VarSet, Goal) :-
- pred_info_module(PredInfo, Module),
+ pred_info_module(PredInfo, Module),
pred_info_name(PredInfo, Name),
pred_info_arity(PredInfo, Arity),
pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
hlds_out__pred_or_func_to_str(PredOrFunc, PredOrFuncS),
prog_out__sym_name_to_string(qualified(Module, Name), NameS),
- string__int_to_string(Arity, ArityS),
+ string__int_to_string(Arity, ArityS),
string__append_list(["detected infinite recursion in ", PredOrFuncS,
" ", NameS, "/", ArityS], Message),
gen_string_construction("MessageS", Message, VarTypes0, VarTypes,
VarSet0, VarSet, MessageVar, MessageConsGoal),
- generate_call("table_loopcheck_error", [MessageVar], erroneous,
+ generate_call("table_loopcheck_error", [MessageVar], erroneous,
impure, [], ModuleInfo, CallGoal),
-
+
GoalEx = conj([MessageConsGoal, CallGoal]),
set__init(NonLocals),
create_instmap_delta([MessageConsGoal, CallGoal],
InstMapDelta0),
instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
- goal_info_init(NonLocals, InstMapDelta, erroneous,
+ goal_info_init(NonLocals, InstMapDelta, erroneous,
GoalInfo),
- Goal = GoalEx - GoalInfo.
-
-
+ Goal = GoalEx - GoalInfo.
+
%------------------------------------------------------------------------------%
:- pred generate_new_table_var(map(prog_var, type), map(prog_var, type),
@@ -1138,7 +1097,7 @@
(
Detism0 = failure
->
- Detism = det
+ Detism = det
;
Detism = Detism0
),
@@ -1147,13 +1106,13 @@
module_info_get_predicate_table(Module, PredTable),
(
predicate_table_search_pred_m_n_a(PredTable,
- BuiltinModule, PredName, Arity,
+ BuiltinModule, PredName, Arity,
[PredId0])
->
PredId = PredId0
;
string__int_to_string(Arity, ArityS),
- string__append_list(["can't locate ", PredName,
+ string__append_list(["can't locate ", PredName,
"/", ArityS], ErrorMessage),
error(ErrorMessage)
),
@@ -1167,16 +1126,16 @@
string__append_list(["too many modes for pred ",
PredName, "/", ArityS], ErrorMessage),
error(ErrorMessage)
-
+
),
Call = call(PredId, ProcId, Args, not_builtin, no, qualified(
- BuiltinModule, PredName)),
+ BuiltinModule, PredName)),
set__init(NonLocals0),
set__insert_list(NonLocals0, Args, NonLocals),
(
Detism = erroneous
->
- instmap_delta_init_unreachable(InstMapDelta)
+ instmap_delta_init_unreachable(InstMapDelta)
;
instmap_delta_from_assoc_list(InstMap, InstMapDelta)
),
@@ -1188,14 +1147,13 @@
->
fail_goal(FailGoal),
instmap_delta_init_unreachable(UnreachInstMapDelta),
- goal_info_init(NonLocals, UnreachInstMapDelta, failure,
+ goal_info_init(NonLocals, UnreachInstMapDelta, failure,
GoalInfo),
Goal = conj([CallGoal, FailGoal]) - GoalInfo
;
Goal = CallGoal
).
-
:- pred gen_int_construction(string, int, map(prog_var, type),
map(prog_var, type), prog_varset, prog_varset, prog_var,
hlds_goal).
@@ -1203,7 +1161,7 @@
gen_int_construction(VarName, VarValue, VarTypes0, VarTypes, VarSet0, VarSet,
Var, Goal) :-
-
+
varset__new_named_var(VarSet0, VarName, Var, VarSet),
term__context_init(Context),
VarType = term__functor(term__atom("int"), [], Context),
@@ -1211,16 +1169,16 @@
Inst = bound(unique, [functor(int_const(VarValue), [])]),
VarUnify = unify(Var, functor(int_const(VarValue), []),
- (free -> Inst) - (Inst -> Inst),
+ (free -> Inst) - (Inst -> Inst),
construct(Var, int_const(VarValue), [], []),
unify_context(explicit, [])),
set__singleton_set(VarNonLocals, Var),
instmap_delta_from_assoc_list([Var - Inst],
VarInstMapDelta),
- goal_info_init(VarNonLocals, VarInstMapDelta, det,
+ goal_info_init(VarNonLocals, VarInstMapDelta, det,
VarGoalInfo),
Goal = VarUnify - VarGoalInfo.
-
+
:- pred gen_string_construction(string, string, map(prog_var, type),
map(prog_var, type), prog_varset, prog_varset, prog_var,
hlds_goal).
@@ -1228,7 +1186,7 @@
gen_string_construction(VarName, VarValue, VarTypes0, VarTypes, VarSet0, VarSet,
Var, Goal) :-
-
+
varset__new_named_var(VarSet0, VarName, Var, VarSet),
term__context_init(Context),
VarType = term__functor(term__atom("string"), [], Context),
@@ -1236,22 +1194,22 @@
Inst = bound(unique, [functor(string_const(VarValue), [])]),
VarUnify = unify(Var, functor(string_const(VarValue), []),
- (free -> Inst) - (Inst -> Inst),
+ (free -> Inst) - (Inst -> Inst),
construct(Var, string_const(VarValue), [], []),
unify_context(explicit, [])),
set__singleton_set(VarNonLocals, Var),
instmap_delta_from_assoc_list([Var - Inst],
VarInstMapDelta),
- goal_info_init(VarNonLocals, VarInstMapDelta, det,
+ goal_info_init(VarNonLocals, VarInstMapDelta, det,
VarGoalInfo),
Goal = VarUnify - VarGoalInfo.
-
+
:- pred get_table_var_type(type).
:- mode get_table_var_type(out) is det.
get_table_var_type(Type) :-
mercury_public_builtin_module(BuiltinModule),
- construct_type(qualified(BuiltinModule, "c_pointer") - 0, [], Type).
+ construct_type(qualified(BuiltinModule, "c_pointer") - 0, [], Type).
:- pred get_input_output_vars(list(prog_var), list(mode), module_info,
list(prog_var), list(prog_var)).
@@ -1290,14 +1248,13 @@
create_instmap_delta(Rest, IMD1),
instmap_delta_apply_instmap_delta(IMD0, IMD1, IMD).
-
:- pred not_builtin_type(builtin_type).
:- mode not_builtin_type(in) is semidet.
not_builtin_type(pred_type).
not_builtin_type(enum_type).
not_builtin_type(polymorphic_type).
-not_builtin_type(user_type).
+not_builtin_type(user_type).
:- pred builtin_type_to_string(builtin_type, string).
:- mode builtin_type_to_string(in, out) is det.
Index: compiler/transform_llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/transform_llds.m,v
retrieving revision 1.2
diff -u -u -r1.2 transform_llds.m
--- transform_llds.m 1998/11/19 06:13:36 1.2
+++ transform_llds.m 1998/11/23 04:23:48
@@ -49,8 +49,8 @@
:- pred transform_c_file(c_file, c_file, io__state, io__state).
:- mode transform_c_file(in, out, di, uo) is det.
-transform_c_file(c_file(ModuleName, HeaderInfo, A, B, C, Modules0),
- c_file(ModuleName, HeaderInfo, A, B, C, Modules)) -->
+transform_c_file(c_file(ModuleName, HeaderInfo, A, B, C, D, Modules0),
+ c_file(ModuleName, HeaderInfo, A, B, C, D, Modules)) -->
transform_c_module_list(Modules0, Modules).
%-----------------------------------------------------------------------------%
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.92
diff -u -u -r1.92 unify_gen.m
--- unify_gen.m 1998/11/20 04:09:36 1.92
+++ unify_gen.m 1998/11/23 02:43:54
@@ -231,6 +231,9 @@
unify_gen__generate_tag_rval_2(base_typeclass_info_constant(_, _, _), _, _) :-
% This should never happen
error("Attempted base_typeclass_info unification").
+unify_gen__generate_tag_rval_2(tabling_pointer_constant(_, _), _, _) :-
+ % This should never happen
+ error("Attempted tabling_pointer unification").
unify_gen__generate_tag_rval_2(no_tag, _Rval, TestRval) :-
TestRval = const(true).
unify_gen__generate_tag_rval_2(simple_tag(SimpleTag), Rval, TestRval) :-
@@ -345,6 +348,19 @@
{ Code = empty },
code_info__cache_expression(Var, const(data_addr_const(data_addr(
ModuleName, base_typeclass_info(ClassId, Instance))))).
+unify_gen__generate_construction_2(tabling_pointer_constant(PredId, ProcId),
+ Var, Args, _Modes, Code) -->
+ ( { Args = [] } ->
+ []
+ ;
+ { error("unify_gen: tabling pointer constant has args") }
+ ),
+ { Code = empty },
+ code_info__get_module_info(ModuleInfo),
+ { code_util__make_proc_label(ModuleInfo, PredId, ProcId, ProcLabel) },
+ { module_info_name(ModuleInfo, ModuleName) },
+ { DataAddr = data_addr(ModuleName, tabling_pointer(ProcLabel)) },
+ code_info__cache_expression(Var, const(data_addr_const(DataAddr))).
unify_gen__generate_construction_2(code_addr_constant(PredId, ProcId),
Var, Args, _Modes, Code) -->
( { Args = [] } ->
@@ -614,6 +630,9 @@
{ Code = empty }
;
{ Tag = base_typeclass_info_constant(_, _, _) },
+ { Code = empty }
+ ;
+ { Tag = tabling_pointer_constant(_, _) },
{ Code = empty }
;
{ Tag = no_tag },
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util
More information about the developers
mailing list