48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package io.gitlab.jfronny.muscript.ast.dynamic;
|
|
|
|
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
|
|
import io.gitlab.jfronny.muscript.ast.Expr;
|
|
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
|
|
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
|
import io.gitlab.jfronny.muscript.compiler.Order;
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
|
import io.gitlab.jfronny.muscript.data.dynamic.Dynamic;
|
|
import io.gitlab.jfronny.muscript.data.dynamic.additional.DFinal;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.stream.Stream;
|
|
|
|
public class ListOf extends DynamicExpr {
|
|
private final List<DynamicExpr> elements;
|
|
|
|
protected ListOf(CodeLocation location, List<DynamicExpr> elements) {
|
|
super(Order.Primary, location);
|
|
this.elements = elements;
|
|
}
|
|
|
|
@Override
|
|
public Dynamic get(Scope dataRoot) {
|
|
return DFinal.of(elements.stream().map(s -> s.get(dataRoot)).toList());
|
|
}
|
|
|
|
@Override
|
|
public DynamicExpr optimize() {
|
|
return new ListOf(location, elements.stream().map(DynamicExpr::optimize).toList());
|
|
}
|
|
|
|
@Override
|
|
public Stream<Expr<?>> extractSideEffects() {
|
|
return elements.stream().flatMap(Expr::extractSideEffects);
|
|
}
|
|
|
|
@Override
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
new Call(
|
|
location,
|
|
new Variable(location, "listOf"),
|
|
elements.stream().map(s -> new Call.Arg(s, false)).toList()
|
|
).decompile(writer);
|
|
}
|
|
}
|