2023-01-20 18:52:57 +01:00
|
|
|
package io.gitlab.jfronny.muscript.ast.literal;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import io.gitlab.jfronny.commons.StringFormatter;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.Order;
|
2023-01-20 21:05:04 +01:00
|
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
2023-01-20 18:52:57 +01:00
|
|
|
import io.gitlab.jfronny.muscript.ast.NumberExpr;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2022-06-07 13:36:48 +02:00
|
|
|
public final class NumberLiteral extends NumberExpr {
|
2022-06-29 17:38:05 +02:00
|
|
|
public final double value;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-01-20 17:47:41 +01:00
|
|
|
public NumberLiteral(int chStart, int chEnd, double value) {
|
2023-03-12 15:28:44 +01:00
|
|
|
super(Order.Primary, chStart, chEnd);
|
2022-06-07 13:36:48 +02:00
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-20 21:05:04 +01:00
|
|
|
public Double get(Scope dataRoot) {
|
2022-06-07 13:36:48 +02:00
|
|
|
return value;
|
|
|
|
}
|
2022-06-29 17:38:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public NumberExpr optimize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
@Override
|
|
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
|
|
writer.append(StringFormatter.toString(value));
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:38:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof NumberLiteral literal && value == literal.value;
|
|
|
|
}
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|