operand: fix integer float data (#393)

Issue #387 pointed out that integer float data is printed incorrectly, such
that it is not parsed correctly by the Go assembler. Specifically, integer
values need the decimal point, otherwise they will be treated as integers. For
example, 1 must be represented as `$(1.)` or `$(1.0)` to be parsed correctly.

This PR fixes that problem and adds a regression test.  The root of the
problem was that the formatting verb `%#v` does not have the right behavior
for integers. We fix it by deferring to custom `String()` function for the
float operand types.

Fixes #387
Closes #388
This commit is contained in:
Michael McLoughlin
2023-06-11 16:12:59 -07:00
committed by GitHub
parent 9bef88dadc
commit 0d789c8353
9 changed files with 172 additions and 4 deletions

View File

@@ -35,7 +35,7 @@ func (u U16) constant() {}
// F32 is a 32-bit floating point constant.
type F32 float32
func (f F32) Asm() string { return fmt.Sprintf("$(%#v)", f) }
func (f F32) Asm() string { return fmt.Sprintf("$(%s)", f) }
func (f F32) Bytes() int { return 4 }
func (f F32) constant() {}
@@ -56,7 +56,7 @@ func (u U32) constant() {}
// F64 is a 64-bit floating point constant.
type F64 float64
func (f F64) Asm() string { return fmt.Sprintf("$(%#v)", f) }
func (f F64) Asm() string { return fmt.Sprintf("$(%s)", f) }
func (f F64) Bytes() int { return 8 }
func (f F64) constant() {}