fix(muscript): clean up ExprGroup side effect handling for extractSideEffects and decompile
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
8aebf179d4
commit
26bd73d87e
|
@ -3,6 +3,7 @@ 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.ast.NullLiteral;
|
||||
import io.gitlab.jfronny.muscript.ast.string.Concatenate;
|
||||
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
|
||||
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
||||
import io.gitlab.jfronny.muscript.compiler.Order;
|
||||
|
@ -37,6 +38,7 @@ public class ExprGroup extends DynamicExpr {
|
|||
this.fin = expressions.get(expressions.size() - 1).asDynamicExpr();
|
||||
this.packedArgs = packedArgs;
|
||||
this.fork = fork;
|
||||
if (!fork && packedArgs != null) throw new UnsupportedOperationException("packedArgs may only be used for forking ExprGroups");
|
||||
}
|
||||
|
||||
public static Expr<?> of(CodeLocation location, List<Expr<?>> expressions) {
|
||||
|
@ -52,7 +54,7 @@ public class ExprGroup extends DynamicExpr {
|
|||
@Override
|
||||
public Dynamic get(Scope dataRoot) {
|
||||
Scope fork = this.fork ? dataRoot.fork() : dataRoot;
|
||||
if (packedArgs != null) {
|
||||
if (this.fork && packedArgs != null) {
|
||||
List<Dynamic> from = new LinkedList<>();
|
||||
for (Call.Arg arg : packedArgs.from) {
|
||||
Dynamic data = arg.expr().get(dataRoot);
|
||||
|
@ -95,23 +97,32 @@ public class ExprGroup extends DynamicExpr {
|
|||
|
||||
@Override
|
||||
public Stream<Expr<?>> extractSideEffects() {
|
||||
return Stream.of(of(location, stream().flatMap(Expr::extractSideEffects).toList()));
|
||||
return fork ? Stream.of(this) : Stream.of(of(location, stream().flatMap(Expr::extractSideEffects).toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decompile(ExprWriter writer) throws IOException {
|
||||
new Call(
|
||||
location,
|
||||
new Closure(
|
||||
location,
|
||||
packedArgs == null
|
||||
? List.of()
|
||||
: packedArgs.to,
|
||||
stream().toList(),
|
||||
false
|
||||
),
|
||||
packedArgs == null ? List.of() : packedArgs.from
|
||||
).decompile(writer);
|
||||
if (!fork) {
|
||||
// Use string concatenation since the result is ignored either way
|
||||
stream()
|
||||
.reduce((left, right) -> new Concatenate(location, left.asStringExpr(), right.asStringExpr()))
|
||||
.orElseGet(() -> new NullLiteral(location))
|
||||
.optimize()
|
||||
.decompile(writer);
|
||||
} else {
|
||||
new Call(
|
||||
location,
|
||||
new Closure(
|
||||
location,
|
||||
packedArgs == null
|
||||
? List.of()
|
||||
: packedArgs.to,
|
||||
stream().toList(),
|
||||
false
|
||||
),
|
||||
packedArgs == null ? List.of() : packedArgs.from
|
||||
).decompile(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<Expr<?>> stream() {
|
||||
|
|
Loading…
Reference in New Issue