Implement string concatenation

This commit is contained in:
Ayke van Laethem
2018-08-29 22:10:46 +02:00
parent c912091f8b
commit 8b95b869ab
2 changed files with 28 additions and 1 deletions
+7 -1
View File
@@ -1835,7 +1835,13 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error
}
switch binop.Op {
case token.ADD: // +
return c.builder.CreateAdd(x, y, ""), nil
if typ, ok := binop.X.Type().(*types.Basic); ok && typ.Kind() == types.String {
// string concatenation
fn := c.mod.NamedFunction("runtime.stringConcat")
return c.builder.CreateCall(fn, []llvm.Value{x, y}, ""), nil
} else {
return c.builder.CreateAdd(x, y, ""), nil
}
case token.SUB: // -
return c.builder.CreateSub(x, y, ""), nil
case token.MUL: // *