|
1 |
| -// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang. |
| 1 | +// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang. |
2 | 2 | // Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
|
3 | 3 | package org.aya.compiler.serializers;
|
4 | 4 |
|
|
7 | 7 | import kala.tuple.Tuple;
|
8 | 8 | import kala.tuple.Tuple2;
|
9 | 9 | import org.aya.compiler.free.*;
|
| 10 | +import org.aya.compiler.free.data.FieldRef; |
10 | 11 | import org.aya.compiler.free.data.MethodRef;
|
11 | 12 | import org.aya.compiler.serializers.ModuleSerializer.MatchyRecorder;
|
12 | 13 | import org.aya.generic.stmt.Shaped;
|
|
25 | 26 |
|
26 | 27 | import java.lang.constant.ClassDesc;
|
27 | 28 | import java.util.function.BiFunction;
|
28 |
| -import java.util.function.Function; |
29 | 29 | import java.util.function.Supplier;
|
30 | 30 |
|
31 | 31 | /**
|
32 | 32 | * Build the "constructor form" of {@link Term}, but in Java.
|
33 | 33 | */
|
34 | 34 | public final class TermExprializer extends AbstractExprializer<Term> {
|
35 |
| - /** |
36 |
| - * Terms that should be instantiated |
37 |
| - */ |
| 35 | + public static final @NotNull FieldRef TYPE0_FIELD = FreeJavaResolver.resolve(SortTerm.class, "Type0"); |
| 36 | + public static final @NotNull FieldRef ISET_FIELD = FreeJavaResolver.resolve(SortTerm.class, "ISet"); |
| 37 | + /// Terms that should be instantiated |
38 | 38 | private final @NotNull ImmutableSeq<FreeJavaExpr> instantiates;
|
39 | 39 | private final @NotNull MutableLinkedHashMap<LocalVar, FreeJavaExpr> binds;
|
40 | 40 |
|
41 |
| - /** |
42 |
| - * Whether allow LocalTerm, false in default (in order to report unexpected LocalTerm) |
43 |
| - */ |
| 41 | + /// Whether allow {@link LocalTerm}, false in default (in order to report unexpected LocalTerm) |
44 | 42 | private final boolean allowLocalTerm;
|
45 | 43 | private final @NotNull MatchyRecorder recorder;
|
46 | 44 |
|
@@ -188,11 +186,8 @@ case FnCall(var ref, var ulift, var args) -> buildFnInvoke(
|
188 | 186 | ));
|
189 | 187 | yield builder.invoke(Constants.RULEREDUCER_MAKE, onStuck, ImmutableSeq.empty());
|
190 | 188 | }
|
191 |
| - // TODO: make the resolving const |
192 |
| - case SortTerm sort when sort.equals(SortTerm.Type0) -> |
193 |
| - builder.refField(FreeJavaResolver.resolve(SortTerm.class, "Type0")); |
194 |
| - case SortTerm sort when sort.equals(SortTerm.ISet) -> |
195 |
| - builder.refField(FreeJavaResolver.resolve(SortTerm.class, "ISet")); |
| 189 | + case SortTerm sort when sort.equals(SortTerm.Type0) -> builder.refField(TYPE0_FIELD); |
| 190 | + case SortTerm sort when sort.equals(SortTerm.ISet) -> builder.refField(ISET_FIELD); |
196 | 191 | case SortTerm(var kind, var ulift) ->
|
197 | 192 | builder.mkNew(SortTerm.class, ImmutableSeq.of(builder.refEnum(kind), builder.iconst(ulift)));
|
198 | 193 | case DepTypeTerm(var kind, var param, var body) -> builder.mkNew(DepTypeTerm.class, ImmutableSeq.of(
|
@@ -271,11 +266,6 @@ yield buildMatchyInvoke(NameSerializer.getClassDesc(ref),
|
271 | 266 | });
|
272 | 267 | }
|
273 | 268 |
|
274 |
| - // TODO: unify with makeClosure |
275 |
| - private @NotNull FreeJavaExpr makeThunk(@NotNull Function<TermExprializer, FreeJavaExpr> cont) { |
276 |
| - return makeLambda(Constants.THUNK, (_, te) -> cont.apply(te)); |
277 |
| - } |
278 |
| - |
279 | 269 | private @NotNull FreeJavaExpr makeClosure(@NotNull BiFunction<TermExprializer, FreeJavaExpr, FreeJavaExpr> cont) {
|
280 | 270 | return makeLambda(Constants.CLOSURE, (ap, te) -> cont.apply(te, ap.arg(0).ref()));
|
281 | 271 | }
|
|
0 commit comments