Dear Gaby,

Gabriel Dos Reis <[EMAIL PROTECTED]> writes:

> Martin Rubey <[EMAIL PROTECTED]> writes:
> 
> [...]
> 
> | > | But I have no idea at what point during compilation the names of the
> | > | operations are determined.
> | > 
> | > Could you expand on exactly what you mean by this?  Do you mean the
> | > encoding, or do you mean the result of overload resolution?
> | 
> | I mean the encoding.
> 
> For encoding of exported functions, see compile.   
> The actual function that computes the encoding is encodeFunctionName.

[...]

> | To do so, I'd need to construct this name given the arguments of comp3. 
> 
> see encodeFunctionName.
> 
> | But I do not know whether this is possible.  It may well be that the
> | running index (??? above) is known only after all of the domain has been
> | compiled.  It might be helpful to know how the 8 in (elt $ 8) above is
> | determined...
> 
> The running index -- called $suffix -- is incremented one item at a time --
> as they are being compiled.

OK. So, we know the suffix only after all functions have been compiled?  That
probably means that we are out of luck :-(.

> But, again, I believe you need to justify why the transformation you want to
> do is OK.

> If the function is exported, why do you think it is safe to make the
> replacement?

I believe that it is safe to make the replacement under the following
circumstances:

1) the operation's definition is unconditional, i.e.,

    if X has Field then
       foo m == 1/m
    else
       foo m == 0

   is not OK.  Curiously,

    foo m ==
        if X has Field then 1/m else foo m == 0

   is OK.

   It goes without saying that the operation we want to inline (here foo) must
   be defined in the constructor where we want it inlined.

2) we are compiling a package or a domain.


If (1) and (2) hold, there is no way (not even in Aldor, say with "extend"), to
override the function.  Let's look at an example, say IIARRAY2.  We have

    qelt(m,i,j) ==
      qelt(qelt(m,i - minRowIndex m)$Rep,j - minColIndex m)

which is compiled into

    (DEFUN |IIARRAY2;qelt;$2IR;10| (|m| |i| |j| $)
      (ELT (ELT |m| (- |i| (SPADCALL |m| (QREFELT $ 24))))
           (- |j| (SPADCALL |m| (QREFELT $ 25))))) 

and positions 24 and 25 of the infovec are

    |IIARRAY2;minRowIndex;$I;4| |IIARRAY2;minColIndex;$I;5|

although that is not that essential...

I claim that 

    (DEFUN |IIARRAY2;qelt;$2IR;10| (|m| |i| |j| $)
      (ELT (ELT |m| (- |i| (|IIARRAY2;minRowIndex;$I;4| |m| $)))
           (- |j| (|IIARRAY2;minColIndex;$I;5| |m| $))))

would be just as correct, but significantly faster, since we are saving
SPADCALLs.

Suppose that it is incorrect, that is, in some situation 
(SPADCALL |m| (QREFELT $ 24)) would produce something other than
(|IIARRAY2;minRowIndex;$I;4| |m| $).

However this can only happen in two circumstances: the constructor (here
IIARRAY2) is a category and the operation (here minRowIndex) would be a default
implementation.  In this case, a domain is allowed to override minRowIndex, and
thus qelt would have to call the definition of minRowIndex given in the domain.

The other possibility is that minRowIndex is defined conditionally.  In this
case, the instantiation code of the domain replaces the corresponding position
in the infovec with the right function name.

Note that at first I thought that introducing Aldor's extend would invalidate
my reasoning.  But it turns out, that at least the current Aldor compiler does
*not* allow overriding domain definitions either.  I could not find anything
appropriate in the Aldor User Guide though.


I hope this explains matters?

Martin


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
open-axiom-devel mailing list
open-axiom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel

Reply via email to