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.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.data.dynamic.Dynamic;
|
|
|
|
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
|
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 DynamicLiteral<T> extends DynamicExpr {
|
2022-06-29 17:46:29 +02:00
|
|
|
public final Dynamic<T> value;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-01-20 17:47:41 +01:00
|
|
|
public DynamicLiteral(int chStart, int chEnd, Dynamic<T> 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 Dynamic<T> get(Scope dataRoot) {
|
2022-06-07 13:36:48 +02:00
|
|
|
return value;
|
|
|
|
}
|
2022-06-29 17:38:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public DynamicExpr optimize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
@Override
|
|
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
|
|
value.serialize(writer);
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:38:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof DynamicLiteral<?> literal && value.equals(literal.value);
|
|
|
|
}
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|