optimizations
Some checks failed
Build / build (push) Successful in 9m47s
Publish Image / publish (push) Failing after 49s
Test / build (push) Failing after 6m19s

This commit is contained in:
Chuck Smith
2024-04-02 14:32:03 -04:00
parent 07fd82b261
commit 88e3330856
18 changed files with 510 additions and 31 deletions

View File

@@ -133,6 +133,9 @@ func Eval(ctx context.Context, node ast.Node, env *object.Environment) object.Ob
case *ast.IntegerLiteral:
return object.Integer{Value: node.Value}
case *ast.FloatLiteral:
return object.Float{Value: node.Value}
case *ast.Boolean:
return nativeBoolToBooleanObject(node.Value)
@@ -401,6 +404,8 @@ func evalInfixExpression(operator string, left, right object.Object) object.Obje
return evalBooleanInfixExpression(operator, left, right)
case left.Type() == object.IntegerType && right.Type() == object.IntegerType:
return evalIntegerInfixExpression(operator, left, right)
case left.Type() == right.Type() && left.Type() == object.FloatType:
return evalFloatInfixExpression(operator, left, right)
case left.Type() == object.StringType && right.Type() == object.StringType:
return evalStringInfixExpression(operator, left, right)
@@ -409,6 +414,36 @@ func evalInfixExpression(operator string, left, right object.Object) object.Obje
}
}
func evalFloatInfixExpression(operator string, left, right object.Object) object.Object {
leftVal := left.(object.Float).Value
rightVal := right.(object.Float).Value
switch operator {
case "+":
return object.Float{Value: leftVal + rightVal}
case "-":
return object.Float{Value: leftVal - rightVal}
case "*":
return object.Float{Value: leftVal * rightVal}
case "/":
return object.Float{Value: leftVal / rightVal}
case "<":
return nativeBoolToBooleanObject(leftVal < rightVal)
case "<=":
return nativeBoolToBooleanObject(leftVal <= rightVal)
case ">":
return nativeBoolToBooleanObject(leftVal > rightVal)
case ">=":
return nativeBoolToBooleanObject(leftVal >= rightVal)
case "==":
return nativeBoolToBooleanObject(leftVal == rightVal)
case "!=":
return nativeBoolToBooleanObject(leftVal != rightVal)
default:
return NULL
}
}
func evalBooleanInfixExpression(operator string, left, right object.Object) object.Object {
leftVal := left.(object.Boolean).Value
rightVal := right.(object.Boolean).Value