[fpc-devel] Question about Currency support
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon Jun 4 11:40:31 CEST 2012
Fuxin Zhang wrote on Mon, 04 Jun 2012:
> I guess it is related to mips/ncpucvn.pas:
> tmipseltypeconvnode.first_int_to_real
> when compared to ncnv.pas, it seems ignore the floatype of resultdef. But
> using the inherited first_int_to_real is impossible since
> int64_to_float64/float32 etc. are not implemented(how can the sparc
> version work if so, it call the inherited one?)
Because of the two blocks rtl/linux/system.pp that are bracked with
{$if defined(CPUARM) or defined(CPUM68K) or defined(CPUSPARC)}. You
should probably add CPUMIPS to them, so it also imports the necessary
helpers.
> BTW,
> for the statement i := j / 10.0, is that in the div node,
It's a slash node, not a div node (a div node represents the "div" operator).
> resultdef
> refers to i, left refers to j, and right refers to 10.0?
resultdef refers to whatever the default result type of that division
is, which in turn depends on the result types of the arguments (j and
10.0). It will be set by the pass_typecheck method, which is called
during parsing.
The assignment node will insert a type conversion from this resultdef
(which is the resultdef of its right node, the division) to the
resultdef of the target of the assignment node (its left node, "i" in
this case). If the types are the same, the typeconversion will be
optimized away.
In general, the type using which Pascal expressions are evaluated is
completely independently from how the result is used afterwards.
Currency is a special case because of all the scaling going on though.
In addition to the resultdef, there's also the nf_is_currency node
flag to determine whether or not the value still has to be scaled.
> But for the typeconvnode, what is the result/left/right node?
There is no right node in a typeconvnode, only a left node
(ttypeconvnode inherits from tunarynode, not from binary node). Left
is whatever you are converting from, and resultdef (once it has been
set from ttypeconvnode.totypedef) is what you are converting to.
Jonas
More information about the fpc-devel
mailing list