-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1002: Shape matcher code review r=ice1000 a=ice1000 xsajxnsakjnxsajkxnjksaxnjksanxjsknxakjs Co-authored-by: HoshinoTented <hoshinotented@qq.com> Co-authored-by: ice1000 <ice1000kotlin@foxmail.com> Co-authored-by: imkiva <imkiva@islovely.icu>
- Loading branch information
Showing
14 changed files
with
614 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2020-2023 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.core.repr; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author kiva | ||
*/ | ||
sealed public interface ParamShape { | ||
enum Any implements ParamShape { | ||
INSTANCE; | ||
} | ||
|
||
record Licit( | ||
@NotNull CodeShape.MomentId name, | ||
@NotNull TermShape type, | ||
Licit.Kind kind | ||
) implements ParamShape, CodeShape.Moment { | ||
enum Kind { | ||
Any, Ex, Im | ||
} | ||
} | ||
|
||
static @NotNull ParamShape explicit(@NotNull TermShape type) { | ||
return explicit(CodeShape.LocalId.IGNORED, type); | ||
} | ||
|
||
static @NotNull ParamShape explicit(@NotNull CodeShape.LocalId name, @NotNull TermShape type) { | ||
return new Licit(name, type, Licit.Kind.Ex); | ||
} | ||
|
||
static @NotNull ParamShape implicit(@NotNull TermShape type) { | ||
return new Licit(CodeShape.LocalId.IGNORED, type, Licit.Kind.Im); | ||
} | ||
|
||
static @NotNull ParamShape anyLicit(@NotNull CodeShape.MomentId name, @NotNull TermShape type) { | ||
return new Licit(name, type, Licit.Kind.Any); | ||
} | ||
|
||
static @NotNull ParamShape anyLicit(@NotNull TermShape type) { | ||
return anyLicit(CodeShape.LocalId.IGNORED, type); | ||
} | ||
|
||
static @NotNull ParamShape anyEx() { | ||
return explicit(TermShape.Any.INSTANCE); | ||
} | ||
|
||
static @NotNull ParamShape anyIm() { | ||
return implicit(TermShape.Any.INSTANCE); | ||
} | ||
|
||
// anyLicit(TermShape.Any) would be equivalent to ParamShape.Any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2020-2023 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.core.repr; | ||
|
||
import kala.collection.immutable.ImmutableSeq; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
// TODO[h]: Licit, we can use generalized ParamShape | ||
|
||
/** | ||
* @author kiva | ||
*/ | ||
public sealed interface PatShape { | ||
enum Any implements PatShape { | ||
INSTANCE; | ||
} | ||
|
||
record Bind(@NotNull CodeShape.MomentId name) implements PatShape, CodeShape.Moment { | ||
} | ||
|
||
sealed interface CtorLike extends PatShape permits Ctor, ShapedCtor { | ||
@NotNull ImmutableSeq<PatShape> innerPats(); | ||
} | ||
|
||
record Ctor(@NotNull ImmutableSeq<PatShape> innerPats) implements CtorLike { | ||
} | ||
|
||
/** | ||
* Expecting a certain ctor, {@link ShapeMatcher} will crash if the {@param name} is invalid (such as undefined or not a DataShape) | ||
* | ||
* @param dataId a reference to a {@link CodeShape.DataShape}d term | ||
* @param ctorId the {@link CodeShape.MomentId} to the ctor | ||
*/ | ||
record ShapedCtor(@NotNull CodeShape.MomentId dataId, @NotNull CodeShape.GlobalId ctorId, | ||
@NotNull ImmutableSeq<PatShape> innerPats) implements CtorLike { | ||
public static @NotNull ShapedCtor of(@NotNull CodeShape.MomentId name, @NotNull CodeShape.GlobalId id) { | ||
return new ShapedCtor(name, id, ImmutableSeq.empty()); | ||
} | ||
} | ||
} |
Oops, something went wrong.