[m-rev.] for review: Modifications to the Java back-end
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Jan 23 08:35:53 AEDT 2002
On 22-Jan-2002, Michael Wybrow <mjwybrow at students.cs.mu.oz.au> wrote:
>
> Index: mlds_to_java.m
...
> @@ -289,21 +291,440 @@
> { MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName) },
> { Defns1 = Defns0 },
> % XXX The code to transform special predicates isn't working yet.
> - %{ transform_special_predicates(ModuleName, Defns0, Defns1) },
> + % { transform_special_predicates(ModuleName, Defns0, Defns1) },
I think you can delete that XXX now, since your change to handle function
pointers should be all that is needed to handle "special predicates"
(unify & compare).
> + %
> + % Find and build list of all methods which would have their addresses
> + % taken to be used as a function pointer.
> + %
> + { find_pointer_addressed_methods(Defns0, [], CodeAddrs0) },
> + { CodeAddrs = list__sort_and_remove_dups(CodeAddrs0) },
> %
> - % Output transformed MLDS as Java souce.
> + % Output transformed MLDS as Java source.
> %
> output_src_start(Indent, ModuleName, Imports, Defns1),
> - { list__filter(defn_is_rtti_data, Defns1, _RttiDefns, NonRttiDefns) },
> + %
> + % Create wrappers in MLDS for all pointer addressed methods.
> + %
> + { generate_code_addr_wrappers(Indent + 1, CodeAddrs, [],
> + WrapperDefns) },
> + { Defns2 = list__append(WrapperDefns, Defns1) },
Using infix `++' is general easier to read than prefix `list__append'.
> +method_ptrs_in_entity_defn(mlds__function(_MaybeID, _Params, Body,
> + _Attributes)) -->
> + ( { Body = mlds__defined_here(Statement) } ->
> + method_ptrs_in_statement(Statement)
> + ; % Body = mlds__external
> + []
> + ).
It's better to use a switch rather than an if-then-else,
because that way, the compiler will report an error if
a new alternative is added to the type and this code is not
modified.
> +method_ptrs_in_stmt(mlds__if_then_else(Rval, Statement1, MaybeStatement2)) -->
Since we use numbers at the end of variable names to indicate state variables,
it's best to avoid using numbers at the end of variable names for other
purposes. Hence s/Statement1/ThenStatement/ and
s/MaybeStatement2/MaybeElseStatement/
> +method_ptrs_in_stmt(mlds__try_commit(_Lval, Statement1, Statement2)) -->
> + method_ptrs_in_statement(Statement1),
> + method_ptrs_in_statement(Statement2).
You should either check for method ptrs in the Lval,
or put a comment somewhere explaining why this check is not needed.
Likewise for a lot of places below where Lvals are ignored.
> +method_ptrs_in_stmt(mlds__call(_FuncSig, _Rval, _MaybeThis, Rvals, _Lvals,
> + _IsTailCall)) -->
> + % We don't check "Rval" - it will be a code address but is a
> + % standard call rather than a function pointer use.
> + %
> + method_ptrs_in_rvals(Rvals).
s/will be/may be/
> +method_ptrs_in_stmt(mlds__atomic(AtomicStatement)) -->
> + ( { AtomicStatement = mlds__new_object(_Lval, _MaybeTag, _Bool, _Type,
> + _MemRval, _MaybeCtorName, Rvals, _Types) } ->
> + method_ptrs_in_rvals(Rvals)
You should either check for method ptrs in the _MemRval,
or put a comment explaining why this check is not needed.
> +% XXX This implementation will not corectly handle the case which occurs where
> +% there are two or more overloaded predicates (that we take the address of)
s/predicates/functions/
or s/predicates/MLDS functions/
or s/predicates/methods/
> +% with the same arity but different argument types, both in the same
s/same arity/same name and arity/
> +% module. This is due to the fact that the names of the generated wrapper
> +% classes are based purely on the method name.
s/name/name and arity/
> +generate_code_addr_wrappers(Indent, [CodeAddr|CodeAddrs], Defns0, Defns) :-
> + Context = mlds__make_context(term__context("", 0)),
Add an comment here "% XXX we should fill in the Context properly."
Use term__context_init rather than term__context("", 0).
> +generate_addr_wrapper_class(Interface, Context, CodeAddr, ClassDefn) :-
> + (
> + CodeAddr = mlds__proc(ProcLabel, _FuncSig),
> + MaybeSeqNum = no
> + ;
> + CodeAddr = mlds__internal(ProcLabel, SeqNum, _FuncSig),
> + MaybeSeqNum = yes(SeqNum)
> + ),
> + ProcLabel = mlds__qual(ModuleQualifier, EntityName),
> + PredLabel = fst(EntityName),
> + ProcID = snd(EntityName),
Just write that as
ProcLabel = mlds__qual(ModuleQualifier, PredLabel - ProcId),
> + %
> + % Create a name for this wrapper class based on the fully quantified
> + % method (predicate) name.
s/quantified/qualified/
> + %
> + ModuleNameStr = mlds_module_name_to_string(ModuleQualifier),
> + ClassEntityName = "AddrOf__" ++ ModuleNameStr ++ "__" ++ PredName,
You probably need to mangle the ModuleNameStr and PredName using
llds__name_mangle, to handle the case where they contain special
characters.
> +generate_call_method(CodeAddr, MethodDefn) :-
...
> + Context = mlds__make_context(term__context("", 0)),
Same comment as above.
[... to be continued ...]
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list