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
d075918
commit f06e263
Showing
5 changed files
with
93 additions
and
20 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
42 changes: 42 additions & 0 deletions
42
base/src/main/java/org/aya/tyck/tycker/AbstractExprTycker.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,42 @@ | ||
// Copyright (c) 2020-2024 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.tyck.tycker; | ||
|
||
import org.aya.syntax.ref.LocalCtx; | ||
import org.aya.tyck.ExprTycker; | ||
import org.aya.tyck.TyckState; | ||
import org.aya.util.reporter.Reporter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public sealed abstract class AbstractExprTycker implements StatedTycker, ContextTycker, Problematic permits ExprTycker { | ||
public @NotNull TyckState state; | ||
private @NotNull LocalCtx localCtx; | ||
public final @NotNull Reporter reporter; | ||
|
||
protected AbstractExprTycker(@NotNull TyckState state, @NotNull LocalCtx ctx, @NotNull Reporter reporter) { | ||
this.state = state; | ||
this.localCtx = ctx; | ||
this.reporter = reporter; | ||
} | ||
|
||
@Override | ||
public @NotNull LocalCtx localCtx() { | ||
return this.localCtx; | ||
} | ||
|
||
@Override public @NotNull LocalCtx setLocalCtx(@NotNull LocalCtx ctx) { | ||
var old = this.localCtx; | ||
this.localCtx = ctx; | ||
return old; | ||
} | ||
|
||
@Override | ||
public @NotNull TyckState state() { | ||
return this.state; | ||
} | ||
|
||
@Override | ||
public @NotNull Reporter reporter() { | ||
return this.reporter; | ||
} | ||
} |
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,27 @@ | ||
// Copyright (c) 2020-2024 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.tyck.tycker; | ||
|
||
import org.aya.syntax.ref.LocalCtx; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public sealed interface ContextTycker permits AbstractExprTycker { | ||
@NotNull LocalCtx localCtx(); | ||
|
||
/** | ||
* Update {@code localCtx} with the given one | ||
* | ||
* @param ctx new {@link LocalCtx} | ||
* @return old context | ||
*/ | ||
@NotNull LocalCtx setLocalCtx(@NotNull LocalCtx ctx); | ||
|
||
default <R> R subscoped(@NotNull Supplier<R> action) { | ||
var parentCtx = setLocalCtx(localCtx().derive()); | ||
var result = action.get(); | ||
setLocalCtx(parentCtx); | ||
return result; | ||
} | ||
} |
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