Skip to content

Commit

Permalink
free: use freeJava in aya serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Jan 4, 2025
1 parent 5852be6 commit f2787de
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import kala.collection.mutable.MutableList;
import org.aya.compiler.free.FreeClassBuilder;
import org.aya.compiler.free.FreeJavaBuilder;
import org.aya.compiler.free.morphism.free.FreeJavaBuilderImpl;
import org.aya.compiler.free.morphism.free.FreeRunner;
import org.aya.compiler.free.morphism.source.SourceFreeJavaBuilder;
import org.aya.compiler.serializers.MatchySerializer.MatchyData;
import org.aya.primitive.ShapeFactory;
Expand All @@ -14,6 +16,7 @@
import org.aya.syntax.core.repr.CodeShape;
import org.aya.syntax.ref.QPath;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

import java.lang.constant.ClassDesc;

Expand All @@ -36,15 +39,6 @@ public void addMatchy(Matchy clauses, int argsSize, int captureSize) {
}
}

public static <Carrier> Carrier serialize(
@NotNull ShapeFactory factory,
@NotNull FreeJavaBuilder<Carrier> builder,
@NotNull ModuleResult unit
) {
return new ModuleSerializer(factory)
.serialize(builder, unit);
}

private final @NotNull ShapeFactory shapeFactory;
private final @NotNull MatchyRecorder recorder = new MatchyRecorder();

Expand Down Expand Up @@ -85,9 +79,11 @@ private void doSerialize(@NotNull FreeClassBuilder builder, @NotNull TyckDef uni
}

public String serializeWithBestBuilder(ModuleResult unit) {
return serialize(SourceFreeJavaBuilder.create(), unit);
var freeJava = serialize(FreeJavaBuilderImpl.INSTANCE, unit);
return new FreeRunner<>(SourceFreeJavaBuilder.create()).runFree(freeJava);
}

@VisibleForTesting
public <Carrier> Carrier serialize(@NotNull FreeJavaBuilder<Carrier> builder, ModuleResult unit) {
var desc = ClassDesc.of(getReference(unit.name, null, NameSerializer.NameType.ClassName));
var metadata = new ClassTargetSerializer.CompiledAyaImpl(unit.name,
Expand Down

0 comments on commit f2787de

Please sign in to comment.