[m-dev.] for review: add null rval constant to MLDS
Tyson Dowd
trd at cs.mu.OZ.AU
Tue Sep 5 16:37:41 AEDT 2000
Hi,
Another one. Fergus or Pete can review this one.
===================================================================
Estimated hours taken: 1
Add a null type to MLDS.
This type represents NULL for pointer types (mlds__ptr_type, strings or
function pointers).
Previously int_const(0) was used instead, but in a typed backend (such
as IL or Java) this causes type errors in the generated code, and it was
difficult for the code generator to know what type of null to generate.
compiler/mlds.m:
Add null(MLDS_Type) as a type of rval_constant.
The type is required so we can generate the appropriate boxing
and unboxing operations on null if it is part of a data structure.
compiler/ml_unify_gen.m:
compiler/rtti_to_mlds.m:
Use the null type.
compiler/mlds_to_c.m:
Write "NULL" when you see null.
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.14
diff -u -r1.14 ml_unify_gen.m
--- compiler/ml_unify_gen.m 2000/06/06 05:45:22 1.14
+++ compiler/ml_unify_gen.m 2000/09/05 04:58:44
@@ -409,12 +409,12 @@
% (we do this just to match the structure used
% by the LLDS closure representation)
%
- { ClosureLayoutRval = const(int_const(0)) },
{ mercury_private_builtin_module(PrivateBuiltinModule) },
{ MLDS_PrivateBuiltinModule = mercury_module_name_to_mlds(
PrivateBuiltinModule) },
{ ClosureLayoutType = mlds__class_type(qual(MLDS_PrivateBuiltinModule,
"closure_layout"), 0, mlds__struct) },
+ { ClosureLayoutRval = const(null(ClosureLayoutType)) },
%
% Generate a wrapper function which just unboxes the
@@ -1070,8 +1070,7 @@
% for a construction unification. For each argument which
% is input to the construction unification, we produce the
% corresponding lval, but if the argument is free,
- % we just produce `0', meaning initialize that field to a
- % null value. (XXX perhaps we should have a special `null' rval.)
+ % we produce a null value.
:- pred ml_gen_cons_args_2(list(mlds__lval), list(prog_type),
list(uni_mode), module_info, list(mlds__rval)).
@@ -1084,8 +1083,7 @@
( mode_to_arg_mode(ModuleInfo, (RI -> RF), Type, top_in) ->
Rval = lval(Lval)
;
- % XXX perhaps we should have a special `null' rval.
- Rval = const(int_const(0))
+ Rval = const(null(mercury_type_to_mlds_type(ModuleInfo, Type)))
),
ml_gen_cons_args_2(Lvals, Types, UniModes, ModuleInfo, Rvals).
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.32
diff -u -r1.32 mlds.m
--- compiler/mlds.m 2000/08/24 10:01:50 1.32
+++ compiler/mlds.m 2000/09/05 04:46:29
@@ -1081,7 +1081,13 @@
% first null character.
; multi_string_const(int, string)
; code_addr_const(mlds__code_addr)
- ; data_addr_const(mlds__data_addr).
+ ; data_addr_const(mlds__data_addr)
+ % A null value, of the given type.
+ % Usually this will be a pointer (mlds__ptr_type)
+ % but it could be a place holder for a string or
+ % a func_type.
+ ; null(mlds__type).
+
:- type mlds__code_addr
---> proc(mlds__qualified_proc_label, mlds__func_signature)
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.53
diff -u -r1.53 mlds_to_c.m
--- compiler/mlds_to_c.m 2000/08/31 03:00:22 1.53
+++ compiler/mlds_to_c.m 2000/09/05 04:56:16
@@ -2746,6 +2746,8 @@
mlds_output_code_addr(CodeAddr).
mlds_output_rval_const(data_addr_const(DataAddr)) -->
mlds_output_data_addr(DataAddr).
+mlds_output_rval_const(null(_)) -->
+ io__write_string("NULL").
%-----------------------------------------------------------------------------%
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.5
diff -u -r1.5 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m 2000/05/31 06:04:16 1.5
+++ compiler/rtti_to_mlds.m 2000/09/05 04:43:58
@@ -29,7 +29,7 @@
:- implementation.
:- import_module prog_data.
-:- import_module pseudo_type_info, prog_util, prog_out.
+:- import_module pseudo_type_info, prog_util, prog_out, type_util.
:- import_module ml_code_util, ml_unify_gen.
:- import_module bool, list, std_util, string, term, require.
@@ -127,7 +127,10 @@
]).
gen_init_rtti_data_defn(field_names(_RttiTypeId, _Ordinal, MaybeNames), _, _,
Init, []) :-
- Init = gen_init_array(gen_init_maybe(gen_init_string), MaybeNames).
+ Init = gen_init_array(gen_init_maybe(
+ mercury_type(functor(atom("string"), [],
+ context("", 0)), str_type),
+ gen_init_string), MaybeNames).
gen_init_rtti_data_defn(field_types(_RttiTypeId, _Ordinal, Types),
ModuleName, _, Init, []) :-
Init = gen_init_array(
@@ -158,9 +161,11 @@
gen_init_int(Stag),
gen_init_int(Ordinal),
gen_init_rtti_name(ModuleName, RttiTypeId, ArgTypes),
- gen_init_maybe(gen_init_rtti_name(ModuleName, RttiTypeId),
+ gen_init_maybe(mlds__rtti_type(field_names(0)),
+ gen_init_rtti_name(ModuleName, RttiTypeId),
MaybeNames),
- gen_init_maybe(gen_init_rtti_name(ModuleName, RttiTypeId),
+ gen_init_maybe(mlds__rtti_type(exist_info(0)),
+ gen_init_rtti_name(ModuleName, RttiTypeId),
MaybeExist)
]).
gen_init_rtti_data_defn(enum_name_ordered_table(RttiTypeId, Functors),
@@ -249,7 +254,7 @@
gen_init_cast_rtti_name(mlds__generic_type,
ModuleName, RttiTypeId, DuFunctorsInfo).
gen_init_functors_info(no_functors, _, _) =
- gen_init_null_pointer.
+ gen_init_null_pointer(mlds__rtti_type(du_name_ordered_table)).
:- func gen_init_layout_info(type_ctor_layout_info, module_name,
rtti_type_id) = mlds__initializer.
@@ -267,13 +272,16 @@
gen_init_cast_rtti_data(mlds__generic_type, ModuleName,
EquivTypeInfo).
gen_init_layout_info(no_layout, _, _) =
- gen_init_null_pointer.
+ gen_init_null_pointer(mlds__rtti_type(du_ptag_ordered_table)).
:- func gen_init_maybe_proc_id(module_info, maybe(rtti_proc_label)) =
mlds__initializer.
+ % XXX the type here is a bit of a lie, but it is only used if we
+ % generate a null constant, so it's pretty harmless right now.
gen_init_maybe_proc_id(ModuleInfo, MaybeProcLabel) =
- gen_init_maybe(gen_init_proc_id(ModuleInfo), MaybeProcLabel).
+ gen_init_maybe(mlds__func_type(mlds__func_params([], [])),
+ gen_init_proc_id(ModuleInfo), MaybeProcLabel).
:- func gen_init_pseudo_type_info_defn(pseudo_type_info, module_name) =
mlds__initializer.
@@ -551,17 +559,16 @@
gen_init_array(Conv, List) = init_array(list__map(Conv, List)).
-:- func gen_init_maybe(func(T) = mlds__initializer, maybe(T)) =
+:- func gen_init_maybe(mlds__type, func(T) = mlds__initializer, maybe(T)) =
mlds__initializer.
-gen_init_maybe(Conv, yes(X)) = Conv(X).
-gen_init_maybe(_, no) = gen_init_null_pointer.
+gen_init_maybe(_Type, Conv, yes(X)) = Conv(X).
+gen_init_maybe(Type, _Conv, no) = gen_init_null_pointer(Type).
-:- func gen_init_null_pointer = mlds__initializer.
+:- func gen_init_null_pointer(mlds__type) = mlds__initializer.
-gen_init_null_pointer =
- % XXX the MLDS ought to have a null pointer constant
- init_obj(mlds__unop(cast(mlds__generic_type), const(int_const(0)))).
+gen_init_null_pointer(Type) =
+ init_obj(mlds__unop(cast(mlds__generic_type), const(null(Type)))).
:- func gen_init_string(string) = mlds__initializer.
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
trd at cs.mu.oz.au #
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list