[M3devel] m3front/TInt/TFloat should maintain "textual expressions" for constants?

Rodney M. Bates rodney_bates at lcwb.coop
Sun Aug 19 23:48:27 CEST 2012



On 08/19/2012 02:11 AM, Jay K wrote:
> I propose the following changed to m3front, TInt, TFloat.
> It does kind of "infact" the front/middle end with the "intent" of a specific backend.
>
>
> When a TInt or TFloat is initialized from text, that text is remembered.
> When such a TInt/TFloat is added/subtracted/multiplied/divided by another,
> the obvious text is built up in the target.
>
>
> Initialization of TInt with constants could/should also maintain the textual representation.
>
>
> The implication is multi part:
>
>
> 1) init_float in a C-or-such backend can just output the textual expression.
> No need to worry about roundtripping it.
>
>
> 2) Longer term, TInt "constant expressions" could contain like "sizeof(INTEGER)"
> (preceded by a typedef for INTEGER in the larger context)..thereby factoring
> out the target from the generated C.
>
>
> 3) This provides some hypothetical portability when host/target
> don't use the "same" sort of floating point. Ignoring rounding details however.
> And TFloat does seem to round correctly at compile-time, assuming host/target
> are about the same -- and they all are.
> (What does the language definition say here anyway? I'll have to check..)
>

As far as I can find, the language says nothing about this.

However, I feel *extremely* strongly that arithmetic done at
compile time should be *exactly* the same as on the target machine,
including what happens in exceptional cases, e.g., overflows,
NaNs, etc.

I know this can be hard to get right, and it raises hard questions
about division of work between front/back.  Even harder when there
are multiple back ends, especially ones you don't control.
But I consider it a serious compiler bug if CT and RT arithmetic
differ.  This might be something that could be postponed for more
urgent things, but the design at least should anticipate it.

I have no problems with the principal of preserving/generating
textual representations.  However, if you really implement target
arithmetic somewhere, it might be easier to convert back and forth
than to do faithful target arithmetic on character strings.  If
that is what you are referring to as {not} roundtripping.

>
> Reasonable?
>
>
> For now I'll probably punt.
>   I can just use TFloat.ToChars and munge it slightly.
> But this is probably a good direction.
> In the short term I'm trying hard to make do w/o m3front/m3middle changes.
>
>
> You know..implementing another backend, you tend to visit more of the system,
> gradually understand it..think of what you how one might prefer it to be..esp.
> for the task at hand. :)
>
>
> Obviously this is somewhat of a hack, in that...what should the syntax of the expressions be?
> If/when I make the change, I'll probably use C. It will be almost identical to Modula-3 anyway.
>
>
>   - Jay
>
>




More information about the M3devel mailing list