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
Showing
12 changed files
with
119 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.aya.syntax.concrete.decl; | ||
|
||
public interface Decl { | ||
} |
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,16 @@ | ||
package org.aya.syntax.concrete.expr; | ||
|
||
import org.aya.syntax.ref.LocalVar; | ||
import org.aya.util.error.SourceNode; | ||
import org.aya.util.error.SourcePos; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public sealed interface Expr { | ||
record Node(@NotNull SourcePos sourcePos, @NotNull Expr expr) implements SourceNode {} | ||
|
||
record Lam(@NotNull LocalVar var, @NotNull Node body) implements Expr {} | ||
|
||
record Ref(@NotNull LocalVar var) implements Expr {} | ||
|
||
record App(@NotNull Node fun, @NotNull Node arg) implements Expr {} | ||
} |
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,4 @@ | ||
package org.aya.syntax.core.def; | ||
|
||
public interface Def { | ||
} |
2 changes: 1 addition & 1 deletion
2
...ain/java/org/aya/syntax/core/AppTerm.java → ...ava/org/aya/syntax/core/term/AppTerm.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
2 changes: 1 addition & 1 deletion
2
...in/java/org/aya/syntax/core/FreeTerm.java → ...va/org/aya/syntax/core/term/FreeTerm.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
4 changes: 2 additions & 2 deletions
4
...ain/java/org/aya/syntax/core/LamTerm.java → ...ava/org/aya/syntax/core/term/LamTerm.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
2 changes: 1 addition & 1 deletion
2
...n/java/org/aya/syntax/core/LocalTerm.java → ...a/org/aya/syntax/core/term/LocalTerm.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
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,12 @@ | ||
package org.aya.syntax.ref; | ||
|
||
import org.jetbrains.annotations.Debug; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author kiva | ||
*/ | ||
@Debug.Renderer(hasChildren = "false", text = "name()") | ||
public interface AnyVar { | ||
@NotNull String name(); | ||
} |
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 @@ | ||
package org.aya.syntax.ref; | ||
|
||
import kala.collection.immutable.ImmutableSeq; | ||
import org.aya.syntax.concrete.decl.Decl; | ||
import org.aya.syntax.core.def.Def; | ||
import org.aya.util.binop.Assoc; | ||
import org.aya.util.binop.OpDecl; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.UnknownNullability; | ||
|
||
public final class DefVar<Core extends Def, Concrete extends Decl> implements AnyVar { | ||
private final @NotNull String name; | ||
/** Initialized in parsing, so it might be null for deserialized user definitions. */ | ||
public @UnknownNullability Concrete concrete; | ||
/** Initialized in type checking or core deserialization, so it might be null for unchecked user definitions. */ | ||
public @UnknownNullability Core core; | ||
/** Initialized in the resolver or core deserialization */ | ||
public @Nullable ImmutableSeq<String> module; | ||
public @Nullable ImmutableSeq<String> fileModule; // TODO: unify `module` and `fileModule` | ||
/** Initialized in the resolver or core deserialization */ | ||
public @Nullable OpDecl opDecl; | ||
|
||
@Contract(pure = true) public @Nullable Assoc assoc() { | ||
if (opDecl == null) return null; | ||
if (opDecl.opInfo() == null) return null; | ||
return opDecl.opInfo().assoc(); | ||
} | ||
|
||
@Contract(pure = true) public @NotNull String name() { | ||
return name; | ||
} | ||
|
||
private DefVar(Concrete concrete, Core core, @NotNull String name) { | ||
this.concrete = concrete; | ||
this.core = core; | ||
this.name = name; | ||
} | ||
|
||
/** Used in user definitions. */ | ||
public static <Core extends Def, Concrete extends Decl> | ||
@NotNull DefVar<Core, Concrete> concrete(@NotNull Concrete concrete, @NotNull String name) { | ||
return new DefVar<>(concrete, null, name); | ||
} | ||
|
||
/** Used in the serialization of core and primitive definitions. */ | ||
public static <Core extends Def, Concrete extends Decl> | ||
@NotNull DefVar<Core, Concrete> empty(@NotNull String name) { | ||
return new DefVar<>(null, null, name); | ||
} | ||
|
||
@Override public boolean equals(Object o) { | ||
return this == o; | ||
} | ||
|
||
public boolean isInModule(@NotNull ImmutableSeq<String> moduleName) { | ||
var maybeSubmodule = module; | ||
if (maybeSubmodule == null) return false; | ||
if (maybeSubmodule.sizeLessThan(moduleName.size())) return false; | ||
return maybeSubmodule.sliceView(0, moduleName.size()).sameElements(moduleName); | ||
} | ||
|
||
public @NotNull ImmutableSeq<String> qualifiedName() { | ||
return module == null ? ImmutableSeq.of(name) : module.appended(name); | ||
} | ||
} |
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