2022-06-07 13:36:48 +02:00
|
|
|
package io.gitlab.jfronny.muscript.compiler.expr.dynamic.unpack;
|
|
|
|
|
2022-06-29 15:41:44 +02:00
|
|
|
import io.gitlab.jfronny.commons.data.dynamic.Dynamic;
|
|
|
|
import io.gitlab.jfronny.commons.data.dynamic.DynamicTypeConversionException;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.expr.DynamicExpr;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.expr.NumberExpr;
|
2022-06-13 13:31:54 +02:00
|
|
|
import io.gitlab.jfronny.muscript.compiler.expr.annotations.*;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2022-06-29 15:41:44 +02:00
|
|
|
@CanThrow
|
|
|
|
@UncheckedDynamic
|
2022-06-07 13:36:48 +02:00
|
|
|
public class NumberUnpack extends NumberExpr {
|
|
|
|
private final DynamicExpr inner;
|
|
|
|
|
2022-06-13 13:31:54 +02:00
|
|
|
public NumberUnpack(int character, DynamicExpr inner) {
|
|
|
|
super(character);
|
2022-06-07 13:36:48 +02:00
|
|
|
this.inner = inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-06-13 13:31:54 +02:00
|
|
|
public Double get(Dynamic<?> dataRoot) {
|
|
|
|
try {
|
|
|
|
return inner.get(dataRoot).asNumber().getValue();
|
|
|
|
} catch (DynamicTypeConversionException e) {
|
|
|
|
throw e.locational(character);
|
|
|
|
}
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|
|
|
|
}
|