This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dc074e
commit 947ebec
Showing
6 changed files
with
107 additions
and
8 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
37 changes: 37 additions & 0 deletions
37
base/src/main/java/org/aya/syntax/core/term/call/ConCall.java
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,37 @@ | ||
// 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.syntax.core.term.call; | ||
|
||
import kala.collection.immutable.ImmutableSeq; | ||
import kala.function.IndexedFunction; | ||
import org.aya.syntax.concrete.stmt.decl.TeleDecl; | ||
import org.aya.syntax.core.def.CtorDef; | ||
import org.aya.syntax.core.def.DataDef; | ||
import org.aya.syntax.core.term.Term; | ||
import org.aya.syntax.ref.DefVar; | ||
import org.aya.util.Arg; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record ConCall( | ||
@Override @NotNull ConCall.Head head, | ||
@Override @NotNull ImmutableSeq<Arg<Term>> conArgs | ||
) implements ConCallLike { | ||
public @NotNull ConCall update(@NotNull Head head, @NotNull ImmutableSeq<Arg<Term>> conArgs) { | ||
return head == head() && conArgs.sameElements(conArgs(), true) ? this : new ConCall(head, conArgs); | ||
} | ||
|
||
@Override | ||
public @NotNull Term descent(@NotNull IndexedFunction<Term, Term> f) { | ||
return update(head.descent(x -> f.apply(0, x)), conArgs.map(x -> x.descent(t -> f.apply(0, t)))); | ||
} | ||
|
||
public ConCall( | ||
@NotNull DefVar<DataDef, TeleDecl.DataDecl> dataRef, | ||
@NotNull DefVar<CtorDef, TeleDecl.DataCtor> ref, | ||
@NotNull ImmutableSeq<Arg<@NotNull Term>> dataArgs, | ||
int ulift, | ||
@NotNull ImmutableSeq<Arg<@NotNull Term>> conArgs | ||
) { | ||
this(new Head(dataRef, ref, ulift, dataArgs), conArgs); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
base/src/main/java/org/aya/syntax/core/term/call/ConCallLike.java
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,67 @@ | ||
// 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.syntax.core.term.call; | ||
|
||
import kala.collection.immutable.ImmutableSeq; | ||
import org.aya.syntax.concrete.stmt.decl.TeleDecl; | ||
import org.aya.syntax.core.def.CtorDef; | ||
import org.aya.syntax.core.def.DataDef; | ||
import org.aya.syntax.core.term.Term; | ||
import org.aya.syntax.ref.DefVar; | ||
import org.aya.util.Arg; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
/** | ||
* Terms that behave like a {@link ConCall}, for example: | ||
* <ul> | ||
* <li>{@link IntegerTerm} behaves like a {@link ConCall}, in a efficient way</li> | ||
* <li>{@link RuleReducer.Con} behaves like a {@link ConCall}, but it produce a special term</li> | ||
* <li>Of course, {@link ConCall} haves like a {@link ConCall}</li> | ||
* </ul> | ||
*/ | ||
public sealed interface ConCallLike extends Callable.Tele permits ConCall { | ||
/** | ||
* @param dataArgs the arguments to the data type, NOT the constructor patterns!! | ||
* They need to be turned implicit when used as arguments. | ||
* @see org.aya.tyck.pat.PatternTycker#mischa | ||
*/ | ||
record Head( | ||
@NotNull DefVar<DataDef, TeleDecl.DataDecl> dataRef, | ||
@NotNull DefVar<CtorDef, TeleDecl.DataCtor> ref, | ||
int ulift, | ||
@NotNull ImmutableSeq<Arg<@NotNull Term>> dataArgs | ||
) { | ||
public @NotNull DataCall underlyingDataCall() { | ||
return new DataCall(dataRef, ulift, dataArgs); | ||
} | ||
|
||
public @NotNull Head descent(@NotNull UnaryOperator<@NotNull Term> f) { | ||
var args = dataArgs.map(arg -> arg.descent(f)); | ||
if (args.sameElements(dataArgs, true)) return this; | ||
return new Head(dataRef, ref, ulift, args); | ||
} | ||
} | ||
|
||
@NotNull ConCallLike.Head head(); | ||
@NotNull ImmutableSeq<Arg<Term>> conArgs(); | ||
|
||
@Override | ||
default @NotNull DefVar<CtorDef, TeleDecl.DataCtor> ref() { | ||
return head().ref(); | ||
} | ||
|
||
@Override | ||
default @NotNull ImmutableSeq<Arg<@NotNull Term>> args() { | ||
return head().dataArgs().view() | ||
.map(Arg::implicitify) | ||
.concat(conArgs()) | ||
.toImmutableSeq(); | ||
} | ||
|
||
@Override | ||
default int ulift() { | ||
return head().ulift(); | ||
} | ||
} |
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