mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Add the new builtin types: int64 and uint64.
Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:
- Extends the compiler to recognise 'int64' and 'uint64' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators
to cover the new types.
- Adds the new internal option '--unboxed-int64s' to the compiler; this will be
used to control whether 64-bit integer types are boxed or not.
- Extends all of the code generators to handle the new types.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intend to contain basic operations
on the new types. (These are currently empty and not documented.)
There are bunch of limitations marks with "XXX INT64"; these will be lifted in
part 2 of this change. Also, 64-bit integer types are currently always boxed,
again this limitation will be lifted in later changes.
compiler/options.m:
Add the new option --unboxed-int64s.
compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
Recognise int64 and uint64 as builtin types.
compiler/builtin_ops.m:
Add builtin operations for the new types.
compiler/hlds_data.m:
Add new tag types for the new types.
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/table_gen.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
Conform to the above changes to the parse tree and HLDS.
compiler/c_util.m:
Support writing out constants of the new types.
compiler/llds.m:
Add a representation for constants of the new types to the LLDS.
compiler/stack_layout.m:
Add a new field to the stack layout params that records whether
64-bit integers are boxed or not.
compiler/call_gen.:m
compiler/code_info.m:
compiler/disj_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/mercury_compile_llds_back_end.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/var_locn.m b/compiler/var_locn.m:
Support the new types in the LLDS code generator.
compiler/mlds.m:
Support constants of the new types in the MLDS.
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_global_data.m:
compiler/ml_rename_classes.m:
compiler/ml_top_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
compiler/rtti_to_mlds.m:
Conform to the above changes to the MLDS.
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
Generate the appropriate target code for constants of the new types
and operations involving them.
compiler/bytecode.m:
compiler/bytecode_gen.m:
Handle the new types in the bytecode generator; we just abort if we
encounter them for now.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
Handle the new types in the Erlang code generator.
library/private_builtin.m:
Add placeholders for the builtin unify and compare operations for
the new types. Since the bootstrapping compiler will not recognise
the new types we give them polymorphic arguments. These can be
replaced after this change has bootstrapped.
Update the Java list of TypeCtorRep constants here.
library/int64.m:
library/uint64.m:
New modules that will eventually contain builtin operations on the new
types.
library/library.m:
library/MODULES_UNDOC:
Do not include the above modules in the library documentation for now.
library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/table_statistics.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
Handle the new types.
configure.ac:
runtime/mercury_conf.h.in:
Define the macro MR_BOXED_INT64S. For now it is always defined, support for
unboxed 64-bit integers will be enabled in a later change.
runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
Update the list of type_ctor reps.
runtime/mercury.h:
runtime/mercury_int.[ch]:
Add macros for int64 / uint64 -> MR_Word conversion, boxing and
unboxing.
Add functions for hashing 64-bit integer types suitable for use
with the tabling mechanism.
runtime/mercury_tabling.[ch]:
Add additional HashTableSlot structs for 64-bit integer types.
Omit the '%' character from the conversion specifiers we pass via
the 'key_format' argument to the macros that generate the table lookup
function. This is so we can use the C99 exact size integer conversion
specifiers (e.g. PRIu64 etc.) directly here.
runtime/mercury_hash_lookup_or_add_body.h:
Add the '%' character that was omitted above to the call to debug_key_msg.
runtime/mercury_memory.h:
Add new builtin allocation sites for boxed 64-bit integer types.
runtime/mercury_builtin_types.[ch]:
runtime/mercury_builitn_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
Add the new builtin types and handle them throughout the runtime.
runtime/Mmakefile:
Add mercury_int.c to the list of .c files.
doc/reference_manual.texi:
Add the new types to the list of reserved type names.
Add the mapping from the new types to their target language types.
These are commented out for now.
245 lines
9.7 KiB
Mathematica
245 lines
9.7 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2008-2012 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: implementation_defined_literals.m.
|
|
% Author: wangp.
|
|
%
|
|
% This module replaces "implementation-defined literals" such as $file and
|
|
% $line by real constants. We transform clauses rather than procedures
|
|
% because, currently, clauses are written out to `.opt' files and $file and
|
|
% $line need to be substituted beforehand.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module check_hlds.implementation_defined_literals.
|
|
:- interface.
|
|
|
|
:- import_module hlds.hlds_module.
|
|
|
|
:- pred subst_impl_defined_literals(module_info::in, module_info::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.
|
|
:- import_module hlds.hlds_clauses.
|
|
:- import_module hlds.hlds_goal.
|
|
:- import_module hlds.hlds_out.
|
|
:- import_module hlds.hlds_out.hlds_out_util.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module hlds.make_goal.
|
|
:- import_module libs.
|
|
:- import_module libs.compute_grade.
|
|
:- import_module mdbcomp.
|
|
:- import_module mdbcomp.sym_name.
|
|
:- import_module parse_tree.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- import_module list.
|
|
:- import_module map.
|
|
:- import_module require.
|
|
:- import_module term.
|
|
|
|
:- type subst_literals_info
|
|
---> subst_literals_info(
|
|
module_info,
|
|
pred_info,
|
|
pred_id
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
subst_impl_defined_literals(!ModuleInfo) :-
|
|
module_info_get_preds(!.ModuleInfo, Preds0),
|
|
map.map_values(subst_literals_in_pred(!.ModuleInfo), Preds0, Preds),
|
|
module_info_set_preds(Preds, !ModuleInfo).
|
|
|
|
:- pred subst_literals_in_pred(module_info::in, pred_id::in, pred_info::in,
|
|
pred_info::out) is det.
|
|
|
|
subst_literals_in_pred(ModuleInfo, PredId, PredInfo0, PredInfo) :-
|
|
pred_info_get_clauses_info(PredInfo0, ClausesInfo0),
|
|
clauses_info_get_clauses_rep(ClausesInfo0, ClausesRep0, ItemNumbers),
|
|
get_clause_list_for_replacement(ClausesRep0, Clauses0),
|
|
Info = subst_literals_info(ModuleInfo, PredInfo0, PredId),
|
|
list.map(subst_literals_in_clause(Info), Clauses0, Clauses),
|
|
set_clause_list(Clauses, ClausesRep),
|
|
clauses_info_set_clauses_rep(ClausesRep, ItemNumbers,
|
|
ClausesInfo0, ClausesInfo),
|
|
pred_info_set_clauses_info(ClausesInfo, PredInfo0, PredInfo).
|
|
|
|
:- pred subst_literals_in_clause(subst_literals_info::in, clause::in,
|
|
clause::out) is det.
|
|
|
|
subst_literals_in_clause(Info, Clause0, Clause) :-
|
|
Body0 = Clause0 ^ clause_body,
|
|
subst_literals_in_goal(Info, Body0, Body),
|
|
Clause = Clause0 ^ clause_body := Body.
|
|
|
|
:- pred subst_literals_in_goal(subst_literals_info::in, hlds_goal::in,
|
|
hlds_goal::out) is det.
|
|
|
|
subst_literals_in_goal(Info, Goal0, Goal) :-
|
|
Goal0 = hlds_goal(GoalExpr0, GoalInfo0),
|
|
(
|
|
GoalExpr0 = unify(Var, RHS0, Mode, Kind, UnifyContext),
|
|
(
|
|
RHS0 = rhs_functor(ConsId, _, _),
|
|
(
|
|
ConsId = impl_defined_const(Name),
|
|
Context = goal_info_get_context(GoalInfo0),
|
|
make_impl_defined_literal(Var, Name, Context, Info, Goal1),
|
|
Goal1 = hlds_goal(GoalExpr, _),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
( ConsId = cons(_, _, _)
|
|
; ConsId = tuple_cons(_)
|
|
; ConsId = closure_cons(_, _)
|
|
; ConsId = int_const(_)
|
|
; ConsId = uint_const(_)
|
|
; ConsId = int8_const(_)
|
|
; ConsId = uint8_const(_)
|
|
; ConsId = int16_const(_)
|
|
; ConsId = uint16_const(_)
|
|
; ConsId = int32_const(_)
|
|
; ConsId = uint32_const(_)
|
|
; ConsId = int64_const(_)
|
|
; ConsId = uint64_const(_)
|
|
; ConsId = float_const(_)
|
|
; ConsId = char_const(_)
|
|
; ConsId = string_const(_)
|
|
; ConsId = type_ctor_info_const(_, _, _)
|
|
; ConsId = base_typeclass_info_const(_, _, _, _)
|
|
; ConsId = type_info_cell_constructor(_)
|
|
; ConsId = typeclass_info_cell_constructor
|
|
; ConsId = type_info_const(_)
|
|
; ConsId = typeclass_info_const(_)
|
|
; ConsId = ground_term_const(_, _)
|
|
; ConsId = tabling_info_const(_)
|
|
; ConsId = deep_profiling_proc_layout(_)
|
|
; ConsId = table_io_entry_desc(_)
|
|
),
|
|
Goal = Goal0
|
|
)
|
|
;
|
|
RHS0 = rhs_lambda_goal(LambdaPurity, Groundness, PredOrFunc,
|
|
EvalMethod, LambdaNonLocals, LambdaQuantVars,
|
|
LambdaModes, LambdaDetism, LambdaGoal0),
|
|
subst_literals_in_goal(Info, LambdaGoal0, LambdaGoal),
|
|
RHS = rhs_lambda_goal(LambdaPurity, Groundness, PredOrFunc,
|
|
EvalMethod, LambdaNonLocals, LambdaQuantVars,
|
|
LambdaModes, LambdaDetism, LambdaGoal),
|
|
GoalExpr = unify(Var, RHS, Mode, Kind, UnifyContext),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
RHS0 = rhs_var(_),
|
|
Goal = Goal0
|
|
)
|
|
;
|
|
GoalExpr0 = negation(SubGoal0),
|
|
subst_literals_in_goal(Info, SubGoal0, SubGoal),
|
|
GoalExpr = negation(SubGoal),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = scope(Reason, SubGoal0),
|
|
% Implementation-defined literals may appear in
|
|
% from_ground_term_construct scopes.
|
|
subst_literals_in_goal(Info, SubGoal0, SubGoal),
|
|
GoalExpr = scope(Reason, SubGoal),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = conj(ConjType, Goals0),
|
|
list.map(subst_literals_in_goal(Info), Goals0, Goals),
|
|
GoalExpr = conj(ConjType, Goals),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = disj(Goals0),
|
|
list.map(subst_literals_in_goal(Info), Goals0, Goals),
|
|
GoalExpr = disj(Goals),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = switch(Var, CanFail, Cases0),
|
|
list.map(subst_literals_in_case(Info), Cases0, Cases),
|
|
GoalExpr = switch(Var, CanFail, Cases),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = if_then_else(Vars, Cond0, Then0, Else0),
|
|
subst_literals_in_goal(Info, Cond0, Cond),
|
|
subst_literals_in_goal(Info, Then0, Then),
|
|
subst_literals_in_goal(Info, Else0, Else),
|
|
GoalExpr = if_then_else(Vars, Cond, Then, Else),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
GoalExpr0 = shorthand(Shorthand0),
|
|
(
|
|
Shorthand0 = bi_implication(A0, B0),
|
|
subst_literals_in_goal(Info, A0, A),
|
|
subst_literals_in_goal(Info, B0, B),
|
|
Shorthand = bi_implication(A, B)
|
|
;
|
|
Shorthand0 = atomic_goal(GoalType, OuterVars, InnerVars,
|
|
OutputVars, MainGoal0, OrElseGoals0, OrElseInners),
|
|
subst_literals_in_goal(Info, MainGoal0, MainGoal),
|
|
list.map(subst_literals_in_goal(Info), OrElseGoals0, OrElseGoals),
|
|
Shorthand = atomic_goal(GoalType, OuterVars, InnerVars,
|
|
OutputVars, MainGoal, OrElseGoals, OrElseInners)
|
|
;
|
|
Shorthand0 = try_goal(MaybeIOVars, ResultVar, TryGoal0),
|
|
subst_literals_in_goal(Info, TryGoal0, TryGoal),
|
|
Shorthand = try_goal(MaybeIOVars, ResultVar, TryGoal)
|
|
),
|
|
GoalExpr = shorthand(Shorthand),
|
|
Goal = hlds_goal(GoalExpr, GoalInfo0)
|
|
;
|
|
( GoalExpr0 = call_foreign_proc(_, _, _, _, _, _, _)
|
|
; GoalExpr0 = generic_call(_, _, _, _, _)
|
|
; GoalExpr0 = plain_call(_, _, _, _, _, _)
|
|
),
|
|
Goal = Goal0
|
|
).
|
|
|
|
:- pred subst_literals_in_case(subst_literals_info::in, case::in, case::out)
|
|
is det.
|
|
|
|
subst_literals_in_case(Info, Case0, Case) :-
|
|
Case0 = case(MainConsId, OtherConsIds, Goal0),
|
|
subst_literals_in_goal(Info, Goal0, Goal),
|
|
Case = case(MainConsId, OtherConsIds, Goal).
|
|
|
|
:- pred make_impl_defined_literal(prog_var::in, string::in,
|
|
term.context::in, subst_literals_info::in, hlds_goal::out) is det.
|
|
|
|
make_impl_defined_literal(Var, Name, Context, Info, Goal) :-
|
|
Context = term.context(File, Line),
|
|
Info = subst_literals_info(ModuleInfo, PredInfo, PredId),
|
|
( if Name = "file" then
|
|
make_string_const_construction(Var, File, Goal)
|
|
else if Name = "line" then
|
|
make_int_const_construction(Var, Line, Goal)
|
|
else if Name = "module" then
|
|
ModuleName = pred_info_module(PredInfo),
|
|
Str = sym_name_to_string(ModuleName),
|
|
make_string_const_construction(Var, Str, Goal)
|
|
else if Name = "pred" then
|
|
Str = pred_id_to_string(ModuleInfo, PredId),
|
|
make_string_const_construction(Var, Str, Goal)
|
|
else if Name = "grade" then
|
|
module_info_get_globals(ModuleInfo, Globals),
|
|
grade_directory_component(Globals, Grade),
|
|
make_string_const_construction(Var, Grade, Goal)
|
|
else
|
|
% These should have been caught during type checking.
|
|
unexpected($module, $pred, "unknown literal")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module check_hlds.implementation_defined_literals.
|
|
%-----------------------------------------------------------------------------%
|