mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 04:53:42 +00:00
compiler: add support for complex add and sub
This is fairly trivial to add and follows the implementation of gc: https://github.com/golang/go/blob/170b8b4b12be50eeccbcdadb8523fb4fc670ca72/src/cmd/compile/internal/gc/ssa.go#L2179-L2192
This commit is contained in:
committed by
Ron Evans
parent
1113f9ec0c
commit
638bc17eeb
@@ -1821,6 +1821,22 @@ func (c *Compiler) parseBinOp(op token.Token, typ types.Type, x, y llvm.Value, p
|
||||
ieq := c.builder.CreateFCmp(llvm.FloatOEQ, i1, i2, "")
|
||||
neq := c.builder.CreateAnd(req, ieq, "")
|
||||
return c.builder.CreateNot(neq, ""), nil
|
||||
case token.ADD, token.SUB:
|
||||
var r, i llvm.Value
|
||||
switch op {
|
||||
case token.ADD:
|
||||
r = c.builder.CreateFAdd(r1, r2, "")
|
||||
i = c.builder.CreateFAdd(i1, i2, "")
|
||||
case token.SUB:
|
||||
r = c.builder.CreateFSub(r1, r2, "")
|
||||
i = c.builder.CreateFSub(i1, i2, "")
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{r.Type(), i.Type()}, false))
|
||||
cplx = c.builder.CreateInsertValue(cplx, r, 0, "")
|
||||
cplx = c.builder.CreateInsertValue(cplx, i, 1, "")
|
||||
return cplx, nil
|
||||
default:
|
||||
return llvm.Value{}, c.makeError(pos, "todo: binop on complex number: "+op.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user