[m-rev.] for review: fix float_to_string so that roundtripping works

Peter Ross pro at missioncriticalit.com
Thu Nov 21 20:20:15 AEDT 2002


On Thu, Nov 21, 2002 at 02:26:50AM +1100, Fergus Henderson wrote:
> > +:- pragma foreign_proc("il",
> >  	string__float_to_string(FloatVal::in, FloatString::uo),
> > +	[will_not_call_mercury, promise_pure, thread_safe, max_stack_size(1)], "
> > +	ldloca	'FloatVal'
> > +	ldstr	""R""
> >  
> > +		// The R format string prints the double out such that it
> > +		// can be round-tripped.
> > +		// XXX According to the documentation it tries the 15 digits of
> > +		// precision, then 17 digits skipping 16 digits of precision.
> > +		// unlike what we do for the C backend.
> > +	call instance string [mscorlib]System.Double::ToString(string)
> >  
> > +	stloc	'FloatString'
> > +").
> 
> This should be written in C# rather than IL.  IL is a low-level assembly
> language, so we don't want to write it by hand unless we have to.
> 
There are some advantages of writing the IL code by hand.  For starters
it is easy, you just cut and paste the code from the ildasm of the C#
code that you wrote in the start, you only need to get the stack size
right ;).

Once the code is in IL it has the advantage that it is inlineable by
the mercury compiler, this of course has performance implications.

> As proof of this, "ldloca" in the above is incorrect (it should be "ldloc")

No it isn't.  float64 is a valuetype so you need to load its address.

> and "max_stack_size(1)" is also incorrect (it should be 2).
> But please fix these problems by rewriting in C# rather than fixing the IL.
> 
--------------------------------------------------------------------------
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