This commit is contained in:
parent
bc58da6d49
commit
2c354c4a96
1 changed files with 9 additions and 4 deletions
|
|
@ -648,6 +648,11 @@ func (c *Compiler) compileBinary(binary *BinaryNode) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inType, err := c.deduceSignature(binary.Left) // type(left) == type(right) because res is valid
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
switch binary.BinaryOperation {
|
switch binary.BinaryOperation {
|
||||||
case BinaryAddition:
|
case BinaryAddition:
|
||||||
if res.Type() == TypeString {
|
if res.Type() == TypeString {
|
||||||
|
|
@ -685,25 +690,25 @@ func (c *Compiler) compileBinary(binary *BinaryNode) error {
|
||||||
c.add(InstructionNotEqual)
|
c.add(InstructionNotEqual)
|
||||||
|
|
||||||
case BinaryLess:
|
case BinaryLess:
|
||||||
if res.Type() == TypeFloat {
|
if inType.Type() == TypeFloat {
|
||||||
c.add(InstructionLessFloat)
|
c.add(InstructionLessFloat)
|
||||||
} else {
|
} else {
|
||||||
c.add(InstructionLessInt)
|
c.add(InstructionLessInt)
|
||||||
}
|
}
|
||||||
case BinaryGreater:
|
case BinaryGreater:
|
||||||
if res.Type() == TypeFloat {
|
if inType.Type() == TypeFloat {
|
||||||
c.add(InstructionGreaterFloat)
|
c.add(InstructionGreaterFloat)
|
||||||
} else {
|
} else {
|
||||||
c.add(InstructionGreaterInt)
|
c.add(InstructionGreaterInt)
|
||||||
}
|
}
|
||||||
case BinaryLessEqual:
|
case BinaryLessEqual:
|
||||||
if res.Type() == TypeFloat {
|
if inType.Type() == TypeFloat {
|
||||||
c.add(InstructionLessOrEqualFloat)
|
c.add(InstructionLessOrEqualFloat)
|
||||||
} else {
|
} else {
|
||||||
c.add(InstructionLessOrEqualInt)
|
c.add(InstructionLessOrEqualInt)
|
||||||
}
|
}
|
||||||
case BinaryGreaterEqual:
|
case BinaryGreaterEqual:
|
||||||
if res.Type() == TypeFloat {
|
if inType.Type() == TypeFloat {
|
||||||
c.add(InstructionGreaterOrEqualFloat)
|
c.add(InstructionGreaterOrEqualFloat)
|
||||||
} else {
|
} else {
|
||||||
c.add(InstructionGreaterOrEqualInt)
|
c.add(InstructionGreaterOrEqualInt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue