Skip to content

Commit

Permalink
free: API
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Jan 4, 2025
1 parent 8a1bba2 commit 5852be6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.cli.library.incremental;

Expand All @@ -8,7 +8,6 @@
import org.aya.cli.library.source.LibrarySource;
import org.aya.cli.utils.CompilerUtil;
import org.aya.compiler.CompiledModule;
import org.aya.compiler.free.morphism.source.SourceFreeJavaBuilder;
import org.aya.compiler.serializers.ModuleSerializer;
import org.aya.compiler.serializers.NameSerializer;
import org.aya.prelude.GeneratedVersion;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void addURL(Path url) throws MalformedURLException {
@NotNull ModuleLoader recurseLoader
) throws IOException, ClassNotFoundException {
var javaCode = new ModuleSerializer(resolveInfo.shapeFactory())
.serialize(SourceFreeJavaBuilder.create(), new ModuleSerializer.ModuleResult(
.serializeWithBestBuilder(new ModuleSerializer.ModuleResult(
QPath.fileLevel(file.moduleName()),
defs.filterIsInstance(TopLevelDef.class)));
var libraryRoot = file.owner().outDir();
Expand Down
1 change: 0 additions & 1 deletion jit-compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
exports org.aya.compiler.free;
exports org.aya.compiler.free.data;
exports org.aya.compiler.serializers;
exports org.aya.compiler.free.morphism.source;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.compiler.serializers;

import kala.collection.immutable.ImmutableSeq;
import kala.collection.mutable.MutableList;
import org.aya.compiler.free.FreeClassBuilder;
import org.aya.compiler.free.FreeJavaBuilder;
import org.aya.compiler.free.morphism.source.SourceFreeJavaBuilder;
import org.aya.compiler.serializers.MatchySerializer.MatchyData;
import org.aya.primitive.ShapeFactory;
import org.aya.syntax.compile.JitUnit;
Expand Down Expand Up @@ -83,6 +84,10 @@ private void doSerialize(@NotNull FreeClassBuilder builder, @NotNull TyckDef uni
}
}

public String serializeWithBestBuilder(ModuleResult unit) {
return serialize(SourceFreeJavaBuilder.create(), unit);
}

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
10 changes: 4 additions & 6 deletions jit-compiler/src/test/java/FreeTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.

import org.aya.compiler.free.morphism.source.SourceFreeJavaBuilder;
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.ModuleSerializer;
import org.aya.resolve.module.DumbModuleLoader;
import org.aya.syntax.core.def.TopLevelDef;
Expand All @@ -12,7 +12,6 @@

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FreeTest {
public static ModuleSerializer serializer = null;
Expand All @@ -33,12 +32,11 @@ public static void init() {
);
}

@Test
public void free2source() throws IOException {
@Test public void free2source() throws IOException {
var free = serializer.serialize(FreeJavaBuilderImpl.INSTANCE, moduleResult);
var result = new FreeRunner<>(SourceFreeJavaBuilder.create())
.runFree(free);

Files.writeString(Paths.get("build/_baka.java"), result);
Files.writeString(CompileTester.GEN_DIR.resolve("freeJavaBaka.java"), result);
}
}

0 comments on commit 5852be6

Please sign in to comment.