fix(muscript): clean up ExprGroup side effect handling for extractSideEffects and decompile
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
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.DynamicExpr;
|
||||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||||
import io.gitlab.jfronny.muscript.ast.NullLiteral;
|
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.CodeLocation;
|
||||||
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
||||||
import io.gitlab.jfronny.muscript.compiler.Order;
|
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.fin = expressions.get(expressions.size() - 1).asDynamicExpr();
|
||||||
this.packedArgs = packedArgs;
|
this.packedArgs = packedArgs;
|
||||||
this.fork = fork;
|
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) {
|
public static Expr<?> of(CodeLocation location, List<Expr<?>> expressions) {
|
||||||
|
@ -52,7 +54,7 @@ public class ExprGroup extends DynamicExpr {
|
||||||
@Override
|
@Override
|
||||||
public Dynamic get(Scope dataRoot) {
|
public Dynamic get(Scope dataRoot) {
|
||||||
Scope fork = this.fork ? dataRoot.fork() : dataRoot;
|
Scope fork = this.fork ? dataRoot.fork() : dataRoot;
|
||||||
if (packedArgs != null) {
|
if (this.fork && packedArgs != null) {
|
||||||
List<Dynamic> from = new LinkedList<>();
|
List<Dynamic> from = new LinkedList<>();
|
||||||
for (Call.Arg arg : packedArgs.from) {
|
for (Call.Arg arg : packedArgs.from) {
|
||||||
Dynamic data = arg.expr().get(dataRoot);
|
Dynamic data = arg.expr().get(dataRoot);
|
||||||
|
@ -95,11 +97,19 @@ public class ExprGroup extends DynamicExpr {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Stream<Expr<?>> extractSideEffects() {
|
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
|
@Override
|
||||||
public void decompile(ExprWriter writer) throws IOException {
|
public void decompile(ExprWriter writer) throws IOException {
|
||||||
|
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(
|
new Call(
|
||||||
location,
|
location,
|
||||||
new Closure(
|
new Closure(
|
||||||
|
@ -113,6 +123,7 @@ public class ExprGroup extends DynamicExpr {
|
||||||
packedArgs == null ? List.of() : packedArgs.from
|
packedArgs == null ? List.of() : packedArgs.from
|
||||||
).decompile(writer);
|
).decompile(writer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Stream<Expr<?>> stream() {
|
public Stream<Expr<?>> stream() {
|
||||||
return Stream.concat(steps.stream(), Stream.of(fin));
|
return Stream.concat(steps.stream(), Stream.of(fin));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user