feat(muscript): remove type argument in favor of more specific subtypes
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-08-14 16:55:49 +02:00
parent 04dd1e4af0
commit fd7efac605
Signed by: Johannes
GPG Key ID: E76429612C2929F4
40 changed files with 115 additions and 99 deletions

View File

@ -2,7 +2,7 @@ plugins {
id("commons.library")
}
version = "1.3-SNAPSHOT"
version = "1.4-SNAPSHOT"
publishing {
publications {

View File

@ -136,8 +136,8 @@ public class StandardLib {
public static DBool contains(DList args) {
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for contains: expected 2 but got " + args.size());
Dynamic<?> arg0 = args.get(0);
Dynamic<?> arg1 = args.get(1);
Dynamic arg0 = args.get(0);
Dynamic arg1 = args.get(1);
boolean contained = false;
contained |= arg0.isList() && arg0.asList().getValue().contains(arg1);
contained |= arg0.isObject() && arg0.asObject().getValue().containsKey(arg1.asString().getValue());
@ -157,7 +157,7 @@ public class StandardLib {
public static DNumber len(DList args) {
if (args.size() != 1) throw new IllegalArgumentException("Invalid number of arguments for len: expected 1 but got " + args.size());
Dynamic<?> arg0 = args.get(0);
Dynamic arg0 = args.get(0);
if (arg0.isString()) return of(arg0.asString().getValue().length());
if (arg0.isObject()) return of(arg0.asObject().getValue().size());
return of(args.get(0).asList().size());
@ -165,7 +165,7 @@ public class StandardLib {
public static DBool isEmpty(DList args) {
if (args.size() != 1) throw new IllegalArgumentException("Invalid number of arguments for isEmpty: expected 1 but got " + args.size());
Dynamic<?> arg0 = args.get(0);
Dynamic arg0 = args.get(0);
if (arg0.isObject()) return of(arg0.asObject().getValue().isEmpty());
return of(arg0.asList().isEmpty());
}
@ -194,7 +194,7 @@ public class StandardLib {
public static DList map(DList args) {
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for map: expected 2 but got " + args.size());
return of(args.get(0).asList().getValue().stream().<Dynamic<?>>map(args.get(1).asCallable()::call).toList());
return of(args.get(0).asList().getValue().stream().<Dynamic>map(args.get(1).asCallable()::call).toList());
}
public static DList flatMap(DList args) {
@ -203,16 +203,16 @@ public class StandardLib {
return of(args.get(0).asList().getValue().stream().flatMap(a -> dc.call(a).asList().getValue().stream()).toList());
}
public static Dynamic<?> fold(DList args) {
public static Dynamic fold(DList args) {
if (args.size() != 3) throw new IllegalArgumentException("Invalid number of arguments for fold: expected 3 but got " + args.size());
return args.get(0).asList().getValue().stream().<Dynamic<?>>map(Function.identity()).reduce(args.get(1), args.get(2).asCallable()::call);
return args.get(0).asList().getValue().stream().<Dynamic>map(Function.identity()).reduce(args.get(1), args.get(2).asCallable()::call);
}
public static Dynamic<?> forEach(DList args) {
public static Dynamic forEach(DList args) {
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for forEach: expected 2 but got " + args.size());
Dynamic<?> result = new DNull();
Dynamic result = new DNull();
DCallable dc = args.get(1).asCallable();
for (Dynamic<?> dynamic : args.get(0).asList().getValue()) {
for (Dynamic dynamic : args.get(0).asList().getValue()) {
result = dc.call(dynamic);
}
return result;
@ -226,7 +226,7 @@ public class StandardLib {
.asList()
.getValue()
.stream()
.collect(Collectors.<Dynamic<?>, String, Dynamic<?>, LinkedHashMap<String, Dynamic<?>>>toMap(
.collect(Collectors.<Dynamic, String, Dynamic, LinkedHashMap<String, Dynamic>>toMap(
a -> keyMapper.call(a).asString().getValue(),
valueMapper::call,
(a, b) -> b,

View File

@ -4,7 +4,7 @@ import io.gitlab.jfronny.muscript.compiler.*;
import io.gitlab.jfronny.muscript.data.dynamic.Dynamic;
import io.gitlab.jfronny.muscript.ast.dynamic.unpack.*;
public abstract non-sealed class DynamicExpr extends Expr<Dynamic<?>> {
public abstract non-sealed class DynamicExpr extends Expr<Dynamic> {
protected DynamicExpr(Order order, CodeLocation location) {
super(order, location);
}

View File

@ -24,7 +24,7 @@ public abstract sealed class Expr<T> extends Decompilable
return get(dataRoot instanceof Scope scope ? scope : new Scope(dataRoot));
}
@Deprecated
public T get(Dynamic<?> dataRoot) {
public T get(Dynamic dataRoot) {
return get(dataRoot.asObject());
}
public abstract Expr<T> optimize();

View File

@ -25,7 +25,7 @@ public class Equal extends BoolExpr {
}
private Object unwrap(Object o) {
if (o instanceof Dynamic<?> a) return unwrap(a.getValue());
if (o instanceof Dynamic a) return unwrap(a.getValue());
return o;
}

View File

@ -23,7 +23,7 @@ public class DynamicConditional extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
return condition.get(dataRoot) ? trueExpr.get(dataRoot) : falseExpr.get(dataRoot);
}

View File

@ -50,7 +50,7 @@ public class UnresolvedConditional extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
// unresolved conditionals may exist as root elements in scripts/closures
// thus, this needs to be handled, but the result will always be null
if (condition.get(dataRoot)) trueExpr.get(dataRoot);

View File

@ -21,9 +21,9 @@ public class Bind extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
return DFinal.of("<bind>", args -> {
List<Dynamic<?>> argsWithParameter = new LinkedList<>(args.getValue());
List<Dynamic> argsWithParameter = new LinkedList<>(args.getValue());
argsWithParameter.add(0, parameter.get(dataRoot));
return callable.get(dataRoot)
.asCallable()

View File

@ -27,11 +27,11 @@ public class Call extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
DCallable dc;
DList arg;
try {
Dynamic<?> lv = left.get(dataRoot);
Dynamic lv = left.get(dataRoot);
if (Dynamic.isNull(lv)) throw new LocationalException(location, "Cannot invoke null");
dc = lv.asCallable();
arg = DFinal.of(args.stream().flatMap(e -> e.get(dataRoot)).toArray(Dynamic[]::new));
@ -97,7 +97,7 @@ public class Call extends DynamicExpr {
}
public record Arg(DynamicExpr expr, boolean variadic) {
public Stream<? extends Dynamic<?>> get(Scope dataRoot) {
public Stream<? extends Dynamic> get(Scope dataRoot) {
return variadic ? expr.get(dataRoot).asList().getValue().stream() : Stream.of(expr.get(dataRoot));
}

View File

@ -43,7 +43,7 @@ public class Closure extends DynamicExpr {
for (int i = 0; i < ae; i++) fork.set(boundArgs.get(i), args.get(i));
if (variadic) {
fork.set(boundArgs.get(boundArgs.size() - 1), IntStream.range(ae, ac)
.<Dynamic<?>>mapToObj(args::get)
.mapToObj(args::get)
.toList());
}
for (Expr<?> step : steps) {

View File

@ -26,7 +26,7 @@ public class DynamicCoerce extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
if (inner instanceof DynamicExpr e) return e.get(dataRoot);
if (inner instanceof BoolExpr e) return DFinal.of(e.get(dataRoot));
if (inner instanceof StringExpr e) return DFinal.of(e.get(dataRoot));

View File

@ -29,8 +29,8 @@ public class Get extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
Dynamic<?> left = this.left.get(dataRoot);
public Dynamic get(Scope dataRoot) {
Dynamic left = this.left.get(dataRoot);
if (Dynamic.isNull(left)) throw new LocationalException(location, "Could not get \"" + name.asStringExpr().get(dataRoot) + "\" because left is null");
if (left.isObject()) {
DObject o = left.asObject();

View File

@ -20,8 +20,8 @@ public class ObjectLiteral extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
Map<String, Dynamic<?>> result = new LinkedHashMap<>();
public Dynamic get(Scope dataRoot) {
Map<String, Dynamic> result = new LinkedHashMap<>();
this.content.forEach((k, v) -> result.put(k, v.get(dataRoot)));
return DFinal.of(result);
}
@ -29,7 +29,7 @@ public class ObjectLiteral extends DynamicExpr {
@Override
public DynamicExpr optimize() {
Map<String, DynamicExpr> content = new LinkedHashMap<>();
Map<String, Dynamic<?>> literalContent = new LinkedHashMap<>();
Map<String, Dynamic> literalContent = new LinkedHashMap<>();
boolean literal = true;
for (Map.Entry<String, DynamicExpr> entry : this.content.entrySet()) {
DynamicExpr de = entry.getValue().optimize();

View File

@ -21,7 +21,7 @@ public class Variable extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
if (name.equals("this")) return dataRoot;
if (dataRoot.has(name)) return dataRoot.get(name);
else throw new LocationalException(location, "This object doesn't contain '" + name + "'");

View File

@ -21,8 +21,8 @@ public class DynamicAssign extends DynamicExpr {
}
@Override
public Dynamic<?> get(Scope dataRoot) {
Dynamic<?> data = value.get(dataRoot);
public Dynamic get(Scope dataRoot) {
Dynamic data = value.get(dataRoot);
dataRoot.set(name, data.isCallable() ? data.asCallable().named(name) : data);
return data;
}

View File

@ -27,7 +27,7 @@ public class BoolUnpack extends BoolExpr {
@Override
public Boolean get(Scope dataRoot) {
try {
Dynamic<?> iv = inner.get(dataRoot);
Dynamic iv = inner.get(dataRoot);
if (Dynamic.isNull(iv)) throw new LocationalException(location, "Cannot unpack null");
return iv.asBool().getValue();
} catch (DynamicTypeConversionException e) {

View File

@ -27,7 +27,7 @@ public class NumberUnpack extends NumberExpr {
@Override
public Double get(Scope dataRoot) {
try {
Dynamic<?> iv = inner.get(dataRoot);
Dynamic iv = inner.get(dataRoot);
if (Dynamic.isNull(iv)) throw new LocationalException(location, "Cannot unpack null");
return iv.asNumber().getValue();
} catch (DynamicTypeConversionException e) {

View File

@ -27,7 +27,7 @@ public class StringUnpack extends StringExpr {
@Override
public String get(Scope dataRoot) {
try {
Dynamic<?> iv = inner.get(dataRoot);
Dynamic iv = inner.get(dataRoot);
if (Dynamic.isNull(iv)) throw new LocationalException(location, "Cannot unpack null");
return iv.asString().getValue();
} catch (DynamicTypeConversionException e) {

View File

@ -8,15 +8,15 @@ import io.gitlab.jfronny.muscript.ast.DynamicExpr;
import java.io.IOException;
public final class DynamicLiteral<T> extends DynamicExpr {
public final Dynamic<T> value;
public final Dynamic value;
public DynamicLiteral(CodeLocation location, Dynamic<T> value) {
public DynamicLiteral(CodeLocation location, Dynamic value) {
super(Order.Primary, location);
this.value = value;
}
@Override
public Dynamic<T> get(Scope dataRoot) {
public Dynamic get(Scope dataRoot) {
return value;
}

View File

@ -10,7 +10,7 @@ import java.util.function.Function;
public class Scope implements DObject {
private final @Nullable Scope source;
private final Map<String, Dynamic<?>> override = new HashMap<>();
private final Map<String, Dynamic> override = new HashMap<>();
public Scope() {
this(null);
@ -32,7 +32,7 @@ public class Scope implements DObject {
}
@Override
public Map<String, Dynamic<?>> getValue() {
public Map<String, Dynamic> getValue() {
if (source == null) return ImmCollection.of(override);
var map = new HashMap<>(source.getValue());
map.putAll(override);
@ -43,7 +43,7 @@ public class Scope implements DObject {
* @deprecated Using the convenience methods is recommended wherever possible.
*/
@Deprecated(forRemoval = false)
public Scope set(String key, Dynamic<?> value) {
public Scope set(String key, Dynamic value) {
if (key.startsWith("$")) {
if (!setGlobal(key, value)) override.put(key, value);
} else {
@ -52,7 +52,7 @@ public class Scope implements DObject {
return this;
}
private boolean setGlobal(String key, Dynamic<?> value) {
private boolean setGlobal(String key, Dynamic value) {
if (override.containsKey(key)) {
override.put(key, value);
return true;
@ -75,15 +75,15 @@ public class Scope implements DObject {
return set(key, DFinal.of(value));
}
public Scope set(String key, Map<String, ? extends Dynamic<?>> value) {
public Scope set(String key, Map<String, ? extends Dynamic> value) {
return set(key, DFinal.of(value));
}
public Scope set(String key, List<? extends Dynamic<?>> value) {
public Scope set(String key, List<? extends Dynamic> value) {
return set(key, DFinal.of(value));
}
public Scope set(String key, Function<DList, ? extends Dynamic<?>> value) {
public Scope set(String key, Function<DList, ? extends Dynamic> value) {
return set(key, DFinal.of(value, () -> key));
}

View File

@ -32,11 +32,11 @@ public class Script extends Decompilable {
this.file = file;
}
public Dynamic<?> run(DObject scope) {
public Dynamic run(DObject scope) {
return run(new Scope(scope));
}
public Dynamic<?> run(Scope scope) {
public Dynamic run(Scope scope) {
for (Expr<?> expression : steps) {
expression.get(scope);
}

View File

@ -4,9 +4,12 @@ import io.gitlab.jfronny.muscript.ast.BoolExpr;
import io.gitlab.jfronny.muscript.ast.literal.BoolLiteral;
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
public non-sealed interface DBool extends Dynamic<Boolean> {
public non-sealed interface DBool extends Dynamic {
@Override
default BoolExpr toExpr() {
return new BoolLiteral(CodeLocation.NONE, getValue());
}
@Override
Boolean getValue();
}

View File

@ -5,12 +5,12 @@ import io.gitlab.jfronny.muscript.data.dynamic.additional.NamedDCallable;
import java.util.function.Function;
public non-sealed interface DCallable extends Dynamic<Function<DList, Dynamic<?>>> {
default Dynamic<?> call(DList args) {
public non-sealed interface DCallable extends Dynamic {
default Dynamic call(DList args) {
return getValue().apply(args);
}
default Dynamic<?> call(Dynamic<?>... args) {
default Dynamic call(Dynamic... args) {
return call(DFinal.of(args));
}
@ -21,4 +21,7 @@ public non-sealed interface DCallable extends Dynamic<Function<DList, Dynamic<?>
default DCallable named(String name) {
return new NamedDCallable(this, name);
}
@Override
Function<DList, Dynamic> getValue();
}

View File

@ -7,8 +7,8 @@ import io.gitlab.jfronny.muscript.compiler.CodeLocation;
import java.util.List;
public non-sealed interface DList extends Dynamic<List<? extends Dynamic<?>>> {
default Dynamic<?> get(int i) {
public non-sealed interface DList extends Dynamic {
default Dynamic get(int i) {
return getValue().get(i);
}
@ -24,4 +24,7 @@ public non-sealed interface DList extends Dynamic<List<? extends Dynamic<?>>> {
default DynamicExpr toExpr() {
return new Call(CodeLocation.NONE, new Variable(CodeLocation.NONE, "listOf"), getValue().stream().map(s -> new Call.Arg(s.toExpr().asDynamicExpr(), false)).toList());
}
@Override
List<? extends Dynamic> getValue();
}

View File

@ -3,7 +3,7 @@ package io.gitlab.jfronny.muscript.data.dynamic;
import io.gitlab.jfronny.muscript.ast.NullLiteral;
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
public final class DNull implements Dynamic<Object> {
public final class DNull implements Dynamic {
@Override
public Object getValue() {
return null;

View File

@ -4,9 +4,12 @@ import io.gitlab.jfronny.muscript.ast.NumberExpr;
import io.gitlab.jfronny.muscript.ast.literal.NumberLiteral;
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
public non-sealed interface DNumber extends Dynamic<Double> {
public non-sealed interface DNumber extends Dynamic {
@Override
default NumberExpr toExpr() {
return new NumberLiteral(CodeLocation.NONE, getValue());
}
@Override
Double getValue();
}

View File

@ -8,8 +8,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.stream.Collectors;
public non-sealed interface DObject extends Dynamic<Map<String, ? extends Dynamic<?>>> {
default @Nullable Dynamic<?> get(String key) {
public non-sealed interface DObject extends Dynamic {
default @Nullable Dynamic get(String key) {
return getValue().get(key);
}
@ -21,4 +21,7 @@ public non-sealed interface DObject extends Dynamic<Map<String, ? extends Dynami
default DynamicExpr toExpr() {
return new ObjectLiteral(CodeLocation.NONE, getValue().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, s -> s.getValue().toExpr().asDynamicExpr())));
}
@Override
Map<String, ? extends Dynamic> getValue();
}

View File

@ -4,9 +4,12 @@ import io.gitlab.jfronny.muscript.ast.StringExpr;
import io.gitlab.jfronny.muscript.ast.literal.StringLiteral;
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
public non-sealed interface DString extends Dynamic<String> {
public non-sealed interface DString extends Dynamic {
@Override
default StringExpr toExpr() {
return new StringLiteral(CodeLocation.NONE, getValue());
}
@Override
String getValue();
}

View File

@ -15,20 +15,19 @@ import java.io.IOException;
/**
* Represents a value of an unknown type
* Override toString(StringBuilder) to support custom serialization (note: the serialized form is ran with muScript to generate the tree)
* @param <T> the type represented
*/
public sealed interface Dynamic<T> permits DBool, DCallable, DList, DNull, DNumber, DObject, DString, DynamicBase {
public sealed interface Dynamic permits DBool, DCallable, DList, DNull, DNumber, DObject, DString, DynamicBase {
/**
* Deserialize simply dynamic values. DOES NOT SUPPORT CALLABLES!
* Use Parser.parse() if you truly need to deserialize them, but be aware that that might enable DOS attacks
*/
static Dynamic<?> deserialize(String source) {
static Dynamic deserialize(String source) {
DynamicExpr expr = Parser.parse(source).asDynamicExpr();
if (!DirectPreconditionVisitor.visit(expr)) throw new IllegalArgumentException("This expression does not directly express a dynamic and may not be loaded this way");
return expr.get(StandardLib.createScope());
}
static String serialize(Dynamic<?> dynamic) {
static String serialize(Dynamic dynamic) {
StringBuilder sb = new StringBuilder();
try (ExprWriter ew = new ExprWriter(sb, true)) {
dynamic.serialize(ew);
@ -38,11 +37,11 @@ public sealed interface Dynamic<T> permits DBool, DCallable, DList, DNull, DNumb
return sb.toString();
}
static boolean isNull(Dynamic<?> dynamic) {
static boolean isNull(Dynamic dynamic) {
return dynamic == null || dynamic instanceof DNull;
}
static @NotNull Dynamic<?> fromNullable(@Nullable Dynamic<?> dynamic) {
static @NotNull Dynamic fromNullable(@Nullable Dynamic dynamic) {
return dynamic == null ? new DNull() : dynamic;
}
@ -51,7 +50,7 @@ public sealed interface Dynamic<T> permits DBool, DCallable, DList, DNull, DNumb
}
Expr<?> toExpr();
T getValue();
Object getValue();
default boolean isBool() {
return this instanceof DBool;

View File

@ -3,7 +3,6 @@ package io.gitlab.jfronny.muscript.data.dynamic;
/**
* Use this for ABSTRACT (!) implementations of custom dynamic containers.
* Any concrete implementation MUST still implement a valid Dynamic subtype (DBool, DString, ...)
* @param <T> the type represented
*/
public non-sealed interface DynamicBase<T> extends Dynamic<T> {
public non-sealed interface DynamicBase extends Dynamic {
}

View File

@ -9,7 +9,7 @@ public class DynamicTypeConversionException extends RuntimeException {
private final String target;
private final String actual;
public DynamicTypeConversionException(String target, Dynamic<?> dynamic) {
public DynamicTypeConversionException(String target, Dynamic dynamic) {
super(MESSAGE1 + (dynamic == null ? "null" : dynamic.getClass().getSimpleName()) + MESSAGE2 + target);
this.target = target;
this.actual = dynamic == null ? "null" : dynamic.getClass().getSimpleName();

View File

@ -8,9 +8,9 @@ import io.gitlab.jfronny.muscript.data.dynamic.*;
import java.util.List;
import java.util.Map;
public record DCallableObject(Map<String, ? extends Dynamic<?>> value, DCallable callable) implements DObject {
public record DCallableObject(Map<String, ? extends Dynamic> value, DCallable callable) implements DObject {
@Override
public Map<String, ? extends Dynamic<?>> getValue() {
public Map<String, ? extends Dynamic> getValue() {
return value;
}

View File

@ -3,7 +3,7 @@ package io.gitlab.jfronny.muscript.data.dynamic.additional;
import io.gitlab.jfronny.muscript.data.dynamic.Dynamic;
import io.gitlab.jfronny.muscript.data.dynamic.DynamicBase;
public abstract class DContainer<T> implements DynamicBase<T> {
public abstract class DContainer<T> implements DynamicBase {
private T value;
@Override

View File

@ -16,7 +16,7 @@ import java.util.function.Supplier;
public record DDate(Supplier<LocalDate> date) implements DObject {
@Override
public Map<String, Dynamic<?>> getValue() {
public Map<String, Dynamic> getValue() {
return Map.of(
"year", DFinal.of(date.get().getYear()),
"month", DFinal.of(date.get().getMonthValue()),

View File

@ -15,12 +15,12 @@ import java.util.*;
* An enum represented as an OObject.
* May also have a selected value with automatic conversions to a number (index) and string
*/
public record DEnum(Map<String, ? extends Dynamic<?>> values, @Nullable DEnumEntry value) implements DObject {
public DEnum(Map<String, ? extends Dynamic<?>> values) {
public record DEnum(Map<String, ? extends Dynamic> values, @Nullable DEnumEntry value) implements DObject {
public DEnum(Map<String, ? extends Dynamic> values) {
this(values, (DEnumEntry) null);
}
public DEnum(Map<String, ? extends Dynamic<?>> values, @Nullable String value) {
public DEnum(Map<String, ? extends Dynamic> values, @Nullable String value) {
this(values, value == null ? null : new DEnumEntry(value, values.keySet().stream().toList().indexOf(value), true));
}
@ -33,7 +33,7 @@ public record DEnum(Map<String, ? extends Dynamic<?>> values, @Nullable DEnumEnt
}
@Override
public Map<String, ? extends Dynamic<?>> getValue() {
public Map<String, ? extends Dynamic> getValue() {
return values;
}
@ -75,8 +75,8 @@ public record DEnum(Map<String, ? extends Dynamic<?>> values, @Nullable DEnumEnt
return new Call(CodeLocation.NONE, new Variable(CodeLocation.NONE, "enum"), args);
}
private static Map<String, Dynamic<?>> createMap(List<String> values, String value) {
Map<String, Dynamic<?>> result = new LinkedHashMap<>();
private static Map<String, Dynamic> createMap(List<String> values, String value) {
Map<String, Dynamic> result = new LinkedHashMap<>();
DEnumEntry v = new DEnumEntry(value, values.indexOf(value), true);
result.put("value", v);
for (int i = 0; i < values.size(); i++) {

View File

@ -27,32 +27,32 @@ public class DFinal {
return new FString(b);
}
public static DObject of(Map<String, ? extends Dynamic<?>> b) {
public static DObject of(Map<String, ? extends Dynamic> b) {
return new FObject(Map.copyOf(b));
}
public static DList of(Dynamic<?>... b) {
public static DList of(Dynamic... b) {
return new FList(List.of(b));
}
public static DList of(List<? extends Dynamic<?>> b) {
return new FList(ImmCollection.of((List<Dynamic<?>>) b));
public static DList of(List<? extends Dynamic> b) {
return new FList(ImmCollection.of((List<Dynamic>) b));
}
public static DCallable of(Function<DList, ? extends Dynamic<?>> b, Supplier<String> serialized) {
public static DCallable of(Function<DList, ? extends Dynamic> b, Supplier<String> serialized) {
return of(b, serialized, null);
}
public static DCallable of(Function<DList, ? extends Dynamic<?>> b, String name) {
public static DCallable of(Function<DList, ? extends Dynamic> b, String name) {
return of(name, b, () -> new Variable(CodeLocation.NONE, name));
}
public static DCallable of(Function<DList, ? extends Dynamic<?>> b, Supplier<String> serialized, String name) {
public static DCallable of(Function<DList, ? extends Dynamic> b, Supplier<String> serialized, String name) {
return of(name, b, () -> Parser.parse(serialized.get()));
}
public static DCallable of(String name, Function<DList, ? extends Dynamic<?>> b, Supplier<Expr<?>> serialized) {
return new FCallable((Function<DList, Dynamic<?>>) b, new LazySupplier<>(serialized), name);
public static DCallable of(String name, Function<DList, ? extends Dynamic> b, Supplier<Expr<?>> serialized) {
return new FCallable((Function<DList, Dynamic>) b, new LazySupplier<>(serialized), name);
}
/**
@ -97,9 +97,9 @@ public class DFinal {
}
}
private record FObject(Map<String, Dynamic<?>> value) implements DObject, FImpl {
private record FObject(Map<String, Dynamic> value) implements DObject, FImpl {
@Override
public Map<String, Dynamic<?>> getValue() {
public Map<String, Dynamic> getValue() {
return value;
}
@ -109,9 +109,9 @@ public class DFinal {
}
}
private record FList(List<Dynamic<?>> value) implements DList, FImpl {
private record FList(List<Dynamic> value) implements DList, FImpl {
@Override
public List<Dynamic<?>> getValue() {
public List<Dynamic> getValue() {
return value;
}
@ -121,14 +121,14 @@ public class DFinal {
}
}
private record FCallable(Function<DList, Dynamic<?>> value, Supplier<Expr<?>> gen, String name) implements DCallable, FImpl {
private record FCallable(Function<DList, Dynamic> value, Supplier<Expr<?>> gen, String name) implements DCallable, FImpl {
@Override
public Expr<?> toExpr() {
return gen.get();
}
@Override
public Function<DList, Dynamic<?>> getValue() {
public Function<DList, Dynamic> getValue() {
return value;
}

View File

@ -16,7 +16,7 @@ import java.util.function.Supplier;
public record DTime(Supplier<LocalTime> time) implements DObject {
@Override
public Map<String, Dynamic<?>> getValue() {
public Map<String, Dynamic> getValue() {
return Map.of(
"hour", DFinal.of(time.get().getHour()),
"minute", DFinal.of(time.get().getMinute()),

View File

@ -6,8 +6,8 @@ import io.gitlab.jfronny.muscript.data.dynamic.*;
import java.io.IOException;
public interface DelegateDynamic<T> extends DynamicBase<T> {
Dynamic<T> getDelegate();
public interface DelegateDynamic extends DynamicBase {
Dynamic getDelegate();
@Override
default void serialize(ExprWriter writer) throws IOException {
@ -20,7 +20,7 @@ public interface DelegateDynamic<T> extends DynamicBase<T> {
}
@Override
default T getValue() {
default Object getValue() {
return getDelegate().getValue();
}

View File

@ -27,7 +27,7 @@ public class DirectPreconditionVisitor {
return false; // unknown expression
}
public static boolean visit(Dynamic<?> dynamic) {
public static boolean visit(Dynamic dynamic) {
if (dynamic instanceof DNull) return true;
if (dynamic instanceof DFinal.FImpl) {
if (dynamic instanceof DBool) return true;

View File

@ -22,7 +22,7 @@ public record NamedDCallable(DCallable inner, String name) implements DCallable
}
@Override
public Function<DList, Dynamic<?>> getValue() {
public Function<DList, Dynamic> getValue() {
return inner.getValue();
}
}