From ce423971e6ea3b4126806eea4b6874daee9f07b2 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 19 Aug 2024 01:15:51 +0800 Subject: Added a checker module. NOTE: I think I should look at guava or commons for some sort of sealable Map instead of the current Scope :D --- checker/build.gradle.kts | 30 +++++ .../main/java/lv/enes/orang/checker/Checker.java | 146 +++++++++++++++++++++ .../lv/enes/orang/checker/CheckerException.java | 9 ++ checker/src/main/java/module-info.java | 9 ++ .../java/lv/enes/orang/core/ImmutableScope.java | 47 +++++++ .../main/java/lv/enes/orang/core/MutableScope.java | 26 ++++ .../lv/enes/orang/core/OrangRuntimeException.java | 11 ++ core/src/main/java/lv/enes/orang/core/Scope.java | 31 +++++ orang/build.gradle.kts | 1 + orang/src/main/java/lv/enes/orang/Builtins.java | 1 + orang/src/main/java/lv/enes/orang/Evaluator.java | 9 +- .../main/java/lv/enes/orang/ImmutableScope.java | 45 ------- orang/src/main/java/lv/enes/orang/Main.java | 11 +- .../src/main/java/lv/enes/orang/MutableScope.java | 24 ---- .../java/lv/enes/orang/OrangRuntimeException.java | 13 -- orang/src/main/java/lv/enes/orang/Scope.java | 34 ----- orang/src/main/java/lv/enes/orang/value/Array.java | 2 +- .../java/lv/enes/orang/value/BuiltinFunction.java | 2 +- .../main/java/lv/enes/orang/value/Function.java | 5 +- .../java/lv/enes/orang/value/OrangBoolean.java | 2 +- .../java/lv/enes/orang/value/OrangInteger.java | 2 +- .../main/java/lv/enes/orang/value/OrangString.java | 2 +- .../enes/orang/value/PartialBuiltinFunction.java | 2 +- .../java/lv/enes/orang/value/PartialFunction.java | 7 +- orang/src/main/java/lv/enes/orang/value/Value.java | 2 +- orang/src/main/java/module-info.java | 1 + settings.gradle.kts | 2 +- 27 files changed, 342 insertions(+), 134 deletions(-) create mode 100644 checker/build.gradle.kts create mode 100644 checker/src/main/java/lv/enes/orang/checker/Checker.java create mode 100644 checker/src/main/java/lv/enes/orang/checker/CheckerException.java create mode 100644 checker/src/main/java/module-info.java create mode 100644 core/src/main/java/lv/enes/orang/core/ImmutableScope.java create mode 100644 core/src/main/java/lv/enes/orang/core/MutableScope.java create mode 100644 core/src/main/java/lv/enes/orang/core/OrangRuntimeException.java create mode 100644 core/src/main/java/lv/enes/orang/core/Scope.java delete mode 100644 orang/src/main/java/lv/enes/orang/ImmutableScope.java delete mode 100644 orang/src/main/java/lv/enes/orang/MutableScope.java delete mode 100644 orang/src/main/java/lv/enes/orang/OrangRuntimeException.java delete mode 100644 orang/src/main/java/lv/enes/orang/Scope.java diff --git a/checker/build.gradle.kts b/checker/build.gradle.kts new file mode 100644 index 0000000..08e9b33 --- /dev/null +++ b/checker/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + java + id("io.freefair.lombok") version "8.6" +} + +val slf4jVersion = "2.0.13" + +repositories { + mavenCentral() +} + +dependencies { + implementation("org.slf4j:slf4j-api:$slf4jVersion") + + implementation(project(":ast")) + implementation(project(":core")) + implementation(project(":utils")) +} + +java { + sourceCompatibility = JavaVersion.VERSION_22 + targetCompatibility = JavaVersion.VERSION_22 + toolchain { + languageVersion = JavaLanguageVersion.of(22) + } +} + +tasks.withType { + options.compilerArgs.add("--enable-preview") +} \ No newline at end of file diff --git a/checker/src/main/java/lv/enes/orang/checker/Checker.java b/checker/src/main/java/lv/enes/orang/checker/Checker.java new file mode 100644 index 0000000..446d3f1 --- /dev/null +++ b/checker/src/main/java/lv/enes/orang/checker/Checker.java @@ -0,0 +1,146 @@ +package lv.enes.orang.checker; + +import lv.enes.orang.ast.*; +import lv.enes.orang.core.ImmutableScope; +import lv.enes.orang.core.Scope; + +import java.util.HashMap; +import java.util.Map; + +public class Checker implements ExpressionVisitor, StatementVisitor { + private final Scope definitions; + + public static Checker of(Map builtins) { + var boolMap = builtins.keySet() + .stream() + .>collect( + HashMap::new, + (map, elem) -> map.put(elem, true), + Map::putAll + ); + return new Checker(ImmutableScope.of(boolMap)); + } + + private Checker(Scope definitions) { + this.definitions = definitions; + } + + @Override + public Void visitArray(ArrayExpression array) throws CheckerException { + for (var expr : array.items()) { + visit(expr); + } + return null; + } + + @Override + public Void visitBoolean(BooleanLiteral expr) { + // Always ok + return null; + } + + @Override + public Void visitBinaryExpression(BinaryExpression expr) throws CheckerException { + visit(expr.lhs()); + visit(expr.rhs()); + return null; + } + + @Override + public Void visitCallExpression(CallExpression expr) throws CheckerException { + visit(expr.callee()); + visit(expr.arg()); + return null; + } + + @Override + public Checker visitDefinition(Definition def) throws CheckerException { + if (definitions.hasDefinition(def.name())) { + throw new CheckerException(STR."Top-level definition '\{def.name()}' redefined!"); + } + return new Checker(ImmutableScope.of(definitions, def.name(), true)); + } + + @Override + public Void visitDoExpression(DoExpression expr) throws CheckerException { + for (var child : expr.body()) { + visit(child); + } + return null; + } + + @Override + public Checker visitExpression(ExpressionStatement expr) throws CheckerException { + visit(expr.expr()); + return this; + } + + @Override + public Void visitFnExpression(FnExpression expr) throws CheckerException { + var args = new HashMap(); + for (var arg : expr.args()) { + args.put(arg.name, true); + } + new Checker(ImmutableScope.of(definitions, args)).visit(expr.body()); + return null; + } + + @Override + public Void visitIfElseExpression(IfElseExpression expr) throws CheckerException { + visit(expr.condition()); + visit(expr.trueBranch()); + visit(expr.falseBranch()); + return null; + } + + @Override + public Void visitIntLiteral(IntLiteral expr) { + // Always ok + return null; + } + + @Override + public Void visitLetInExpression(LetInExpression expr) throws CheckerException { + var locals = new HashMap(); + for (var local : expr.bindings()) { + locals.put(local.name(), true); + } + new Checker(ImmutableScope.of(definitions, locals)).visit(expr.body()); + return null; + } + + @Override + public Checker visitProgram(Program program) throws CheckerException { + var checker = this; + for (var stmt : program.statements()) { + checker = checker.visit(stmt); + } + return checker; + } + + @Override + public Void visitStringLiteral(StringLiteral expr) { + // Always ok + return null; + } + + @Override + public Void visitUnaryExpression(UnaryExpression expr) throws CheckerException { + visit(expr.child()); + return null; + } + + @Override + public Void visitVariable(VariableExpression expr) throws CheckerException { + if (!definitions.hasDefinition(expr.name())) { + throw new CheckerException(STR."Variable named '\{expr.name()}' not defined!"); + } + return null; + } + + @Override + public Void visitVoidExpression() { + // Always ok + return null; + } +} diff --git a/checker/src/main/java/lv/enes/orang/checker/CheckerException.java b/checker/src/main/java/lv/enes/orang/checker/CheckerException.java new file mode 100644 index 0000000..9354f27 --- /dev/null +++ b/checker/src/main/java/lv/enes/orang/checker/CheckerException.java @@ -0,0 +1,9 @@ +package lv.enes.orang.checker; + +import lv.enes.orang.core.OrangException; + +public class CheckerException extends OrangException { + public CheckerException(String message) { + super(message); + } +} diff --git a/checker/src/main/java/module-info.java b/checker/src/main/java/module-info.java new file mode 100644 index 0000000..6e5fa47 --- /dev/null +++ b/checker/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module lv.enes.orang.checker { + exports lv.enes.orang.checker; + + requires lv.enes.orang.ast; + requires lv.enes.orang.core; + requires lv.enes.orang.utils; + + requires static lombok; +} \ No newline at end of file diff --git a/core/src/main/java/lv/enes/orang/core/ImmutableScope.java b/core/src/main/java/lv/enes/orang/core/ImmutableScope.java new file mode 100644 index 0000000..5120b08 --- /dev/null +++ b/core/src/main/java/lv/enes/orang/core/ImmutableScope.java @@ -0,0 +1,47 @@ +package lv.enes.orang.core; + +import java.util.HashMap; +import java.util.Map; + +public class ImmutableScope extends Scope { + public static ImmutableScope of(Map builtins) { + return new ImmutableScope<>(null, new HashMap<>(builtins)); + } + + public static ImmutableScope of(Scope parent) { + if (parent instanceof ImmutableScope imm) { + return imm; + } + return ImmutableScope.of(parent, Map.of()); + } + + public static ImmutableScope of(Scope parent, String key, E value) { + return ImmutableScope.of(parent, Map.of(key, value)); + } + + public static ImmutableScope of(Scope parent, Map definitions) { + return new ImmutableScope<>(parent, definitions).maybeFlattened(); + } + + protected ImmutableScope(Scope parent, Map definitions) { + super(parent, Map.copyOf(definitions)); + } + + public ImmutableScope maybeFlattened() { + if (depth > MAX_DEPTH) { + return flattened(); + } + return this; + } + + private ImmutableScope flattened() { + if (parent instanceof ImmutableScope immParent) { + var flatParent = immParent.flattened(); + var newDefs = new HashMap<>(flatParent.definitions); + newDefs.putAll(definitions); + return new ImmutableScope<>(flatParent.parent, newDefs); + } + + return this; + } +} diff --git a/core/src/main/java/lv/enes/orang/core/MutableScope.java b/core/src/main/java/lv/enes/orang/core/MutableScope.java new file mode 100644 index 0000000..8d8b455 --- /dev/null +++ b/core/src/main/java/lv/enes/orang/core/MutableScope.java @@ -0,0 +1,26 @@ +package lv.enes.orang.core; + +import java.util.HashMap; +import java.util.Map; + +public class MutableScope extends Scope { + public static MutableScope of(Map builtins) { + return new MutableScope<>(null, new HashMap<>(builtins)); + } + + public static MutableScope of(Scope parent) { + return new MutableScope<>(parent, Map.of()); + } + + public static MutableScope of(Scope parent, String name, E value) { + return new MutableScope<>(parent, Map.of(name, value)); + } + + protected MutableScope(Scope parent, Map definitions) { + super(parent, new HashMap<>(definitions)); + } + + public void setDefinition(String key, E value) { + definitions.put(key, value); + } +} diff --git a/core/src/main/java/lv/enes/orang/core/OrangRuntimeException.java b/core/src/main/java/lv/enes/orang/core/OrangRuntimeException.java new file mode 100644 index 0000000..6ce5f70 --- /dev/null +++ b/core/src/main/java/lv/enes/orang/core/OrangRuntimeException.java @@ -0,0 +1,11 @@ +package lv.enes.orang.core; + +public class OrangRuntimeException extends OrangException { + public OrangRuntimeException(String message) { + super(message); + } + + public OrangRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/core/src/main/java/lv/enes/orang/core/Scope.java b/core/src/main/java/lv/enes/orang/core/Scope.java new file mode 100644 index 0000000..0f4d23a --- /dev/null +++ b/core/src/main/java/lv/enes/orang/core/Scope.java @@ -0,0 +1,31 @@ +package lv.enes.orang.core; + +import java.util.Map; + +public abstract class Scope { + public static final int MAX_DEPTH = 4; + + protected final Scope parent; + protected final Map definitions; + protected final int depth; + + protected Scope(Scope parent, Map definitions) { + this.parent = parent; + this.definitions = definitions; + this.depth = parent == null ? 0 : parent.depth + 1; + } + + public E getDefinition(String name) throws OrangRuntimeException { + if (definitions.containsKey(name)) { + return definitions.get(name); + } else if (parent != null) { + return parent.getDefinition(name); + } else { + throw new OrangRuntimeException(STR."Value named \{name} is not defined!"); + } + } + + public boolean hasDefinition(String name) { + return definitions.containsKey(name) || parent != null && parent.hasDefinition(name); + } +} diff --git a/orang/build.gradle.kts b/orang/build.gradle.kts index ef78ded..ea8fbe0 100644 --- a/orang/build.gradle.kts +++ b/orang/build.gradle.kts @@ -23,6 +23,7 @@ dependencies { implementation("org.slf4j:slf4j-simple:$slf4jVersion") implementation(project(":ast")) + implementation(project(":checker")) implementation(project(":core")) implementation(project(":parser")) implementation(project(":utils")) diff --git a/orang/src/main/java/lv/enes/orang/Builtins.java b/orang/src/main/java/lv/enes/orang/Builtins.java index de296ac..a83f4c5 100644 --- a/orang/src/main/java/lv/enes/orang/Builtins.java +++ b/orang/src/main/java/lv/enes/orang/Builtins.java @@ -1,6 +1,7 @@ package lv.enes.orang; import lombok.extern.slf4j.Slf4j; +import lv.enes.orang.core.OrangRuntimeException; import lv.enes.orang.value.*; import java.io.IOException; diff --git a/orang/src/main/java/lv/enes/orang/Evaluator.java b/orang/src/main/java/lv/enes/orang/Evaluator.java index 5d09508..8930f5c 100644 --- a/orang/src/main/java/lv/enes/orang/Evaluator.java +++ b/orang/src/main/java/lv/enes/orang/Evaluator.java @@ -1,17 +1,20 @@ package lv.enes.orang; import lv.enes.orang.ast.*; +import lv.enes.orang.core.MutableScope; +import lv.enes.orang.core.OrangRuntimeException; +import lv.enes.orang.core.Scope; import lv.enes.orang.value.*; import java.util.ArrayList; import java.util.Collections; -public record Evaluator(Scope scope, Value lastResult) implements ExpressionVisitor, StatementVisitor { +public record Evaluator(Scope scope, Value lastResult) implements ExpressionVisitor, StatementVisitor { public Evaluator() { - this(Scope.topLevel()); + this(MutableScope.of(Builtins.BUILTINS)); } - public Evaluator(Scope scope) { + public Evaluator(Scope scope) { this(scope, Undefined.INSTANCE); } diff --git a/orang/src/main/java/lv/enes/orang/ImmutableScope.java b/orang/src/main/java/lv/enes/orang/ImmutableScope.java deleted file mode 100644 index 9cb6138..0000000 --- a/orang/src/main/java/lv/enes/orang/ImmutableScope.java +++ /dev/null @@ -1,45 +0,0 @@ -package lv.enes.orang; - -import lv.enes.orang.value.Value; - -import java.util.HashMap; -import java.util.Map; - -public class ImmutableScope extends Scope { - public static ImmutableScope of(Scope parent) { - if (parent instanceof ImmutableScope imm) { - return imm; - } - return ImmutableScope.of(parent, Map.of()); - } - - public static ImmutableScope of(Scope parent, String key, Value value) { - return ImmutableScope.of(parent, Map.of(key, value)); - } - - public static ImmutableScope of(Scope parent, Map definitions) { - return new ImmutableScope(parent, definitions).maybeFlattened(); - } - - protected ImmutableScope(Scope parent, Map definitions) { - super(parent, Map.copyOf(definitions)); - } - - public ImmutableScope maybeFlattened() { - if (depth > MAX_DEPTH) { - return flattened(); - } - return this; - } - - private ImmutableScope flattened() { - if (parent instanceof ImmutableScope immParent) { - var flatParent = immParent.flattened(); - var newDefs = new HashMap<>(flatParent.definitions); - newDefs.putAll(definitions); - return new ImmutableScope(flatParent.parent, newDefs); - } - - return this; - } -} diff --git a/orang/src/main/java/lv/enes/orang/Main.java b/orang/src/main/java/lv/enes/orang/Main.java index 7175dac..9a061fe 100644 --- a/orang/src/main/java/lv/enes/orang/Main.java +++ b/orang/src/main/java/lv/enes/orang/Main.java @@ -1,5 +1,6 @@ package lv.enes.orang; +import lv.enes.orang.checker.Checker; import lv.enes.orang.core.OrangException; import lv.enes.orang.parser.Parser; @@ -17,11 +18,13 @@ public class Main { } private static void repl() throws IOException { + var checker = Checker.of(Builtins.BUILTINS); var evaluator = new Evaluator(); try (var stream = Main.class.getResourceAsStream("prelude.orang")) { var prog = Parser.parseProgram(stream); - evaluator = evaluator.visitProgram(prog); + checker = checker.visit(prog); + evaluator = evaluator.visit(prog); } catch (OrangException ex) { STDOUT.println(STR."While evaluating prelude: \{ex}"); throw new RuntimeException(ex); @@ -51,7 +54,8 @@ public class Main { var filename = line.substring(2).trim(); try (var reader = new FileReader((filename))) { var prog = Parser.parseProgram(reader); - evaluator = evaluator.visitProgram(prog); + checker = checker.visit(prog); + evaluator = evaluator.visit(prog); } catch (IOException | OrangException ex) { STDOUT.println(ex); } @@ -67,7 +71,8 @@ public class Main { try { var prog = Parser.parseReplProgram(line); - evaluator = evaluator.visitProgram(prog); + checker = checker.visit(prog); + evaluator = evaluator.visit(prog); if (evaluator.lastResult() != null) { STDOUT.print("-> "); STDOUT.println(evaluator.lastResult().stringify()); diff --git a/orang/src/main/java/lv/enes/orang/MutableScope.java b/orang/src/main/java/lv/enes/orang/MutableScope.java deleted file mode 100644 index 8d900a4..0000000 --- a/orang/src/main/java/lv/enes/orang/MutableScope.java +++ /dev/null @@ -1,24 +0,0 @@ -package lv.enes.orang; - -import lv.enes.orang.value.Value; - -import java.util.HashMap; -import java.util.Map; - -public class MutableScope extends Scope { - public static MutableScope of(Scope parent) { - return new MutableScope(parent, Map.of()); - } - - public static MutableScope of(Scope parent, String name, Value value) { - return new MutableScope(parent, Map.of(name, value)); - } - - protected MutableScope(Scope parent, Map definitions) { - super(parent, new HashMap<>(definitions)); - } - - public void setDefinition(String key, Value value) { - definitions.put(key, value); - } -} diff --git a/orang/src/main/java/lv/enes/orang/OrangRuntimeException.java b/orang/src/main/java/lv/enes/orang/OrangRuntimeException.java deleted file mode 100644 index 8a7d575..0000000 --- a/orang/src/main/java/lv/enes/orang/OrangRuntimeException.java +++ /dev/null @@ -1,13 +0,0 @@ -package lv.enes.orang; - -import lv.enes.orang.core.OrangException; - -public class OrangRuntimeException extends OrangException { - public OrangRuntimeException(String message) { - super(message); - } - - public OrangRuntimeException(Throwable cause) { - super(cause); - } -} diff --git a/orang/src/main/java/lv/enes/orang/Scope.java b/orang/src/main/java/lv/enes/orang/Scope.java deleted file mode 100644 index 7fe57c7..0000000 --- a/orang/src/main/java/lv/enes/orang/Scope.java +++ /dev/null @@ -1,34 +0,0 @@ -package lv.enes.orang; - -import lv.enes.orang.value.Value; - -import java.util.HashMap; -import java.util.Map; - -public abstract class Scope { - public static final int MAX_DEPTH = 4; - - protected final Scope parent; - protected final Map definitions; - protected final int depth; - - public static MutableScope topLevel() { - return new MutableScope(null, new HashMap<>(Builtins.BUILTINS)); - } - - protected Scope(Scope parent, Map definitions) { - this.parent = parent; - this.definitions = definitions; - this.depth = parent == null ? 0 : parent.depth + 1; - } - - public Value getDefinition(String name) throws OrangRuntimeException { - if (definitions.containsKey(name)) { - return definitions.get(name); - } else if (parent != null) { - return parent.getDefinition(name); - } else { - throw new OrangRuntimeException(STR."Value named \{name} is not defined!"); - } - } -} diff --git a/orang/src/main/java/lv/enes/orang/value/Array.java b/orang/src/main/java/lv/enes/orang/value/Array.java index c3b645d..33e1516 100644 --- a/orang/src/main/java/lv/enes/orang/value/Array.java +++ b/orang/src/main/java/lv/enes/orang/value/Array.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; import java.util.ArrayList; import java.util.Collections; diff --git a/orang/src/main/java/lv/enes/orang/value/BuiltinFunction.java b/orang/src/main/java/lv/enes/orang/value/BuiltinFunction.java index 92ccc2e..1a61cfb 100644 --- a/orang/src/main/java/lv/enes/orang/value/BuiltinFunction.java +++ b/orang/src/main/java/lv/enes/orang/value/BuiltinFunction.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; import java.util.List; diff --git a/orang/src/main/java/lv/enes/orang/value/Function.java b/orang/src/main/java/lv/enes/orang/value/Function.java index 6e3c83a..d0500b9 100644 --- a/orang/src/main/java/lv/enes/orang/value/Function.java +++ b/orang/src/main/java/lv/enes/orang/value/Function.java @@ -1,11 +1,12 @@ package lv.enes.orang.value; -import lv.enes.orang.*; import lv.enes.orang.ast.ArgSpec; import lv.enes.orang.ast.Expression; +import lv.enes.orang.core.OrangRuntimeException; +import lv.enes.orang.core.Scope; import lv.enes.orang.utils.NonEmptyList; -public record Function(Scope scope, NonEmptyList args, Expression body) implements Value { +public record Function(Scope scope, NonEmptyList args, Expression body) implements Value { @Override public String typeName() { return "Function"; diff --git a/orang/src/main/java/lv/enes/orang/value/OrangBoolean.java b/orang/src/main/java/lv/enes/orang/value/OrangBoolean.java index 8a4776c..59aa9b7 100644 --- a/orang/src/main/java/lv/enes/orang/value/OrangBoolean.java +++ b/orang/src/main/java/lv/enes/orang/value/OrangBoolean.java @@ -1,7 +1,7 @@ package lv.enes.orang.value; import lombok.EqualsAndHashCode; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; @EqualsAndHashCode public final class OrangBoolean implements Value { diff --git a/orang/src/main/java/lv/enes/orang/value/OrangInteger.java b/orang/src/main/java/lv/enes/orang/value/OrangInteger.java index 9b8d505..63a44da 100644 --- a/orang/src/main/java/lv/enes/orang/value/OrangInteger.java +++ b/orang/src/main/java/lv/enes/orang/value/OrangInteger.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; public record OrangInteger(int value) implements Value { @Override diff --git a/orang/src/main/java/lv/enes/orang/value/OrangString.java b/orang/src/main/java/lv/enes/orang/value/OrangString.java index c03f7ac..b4ede1f 100644 --- a/orang/src/main/java/lv/enes/orang/value/OrangString.java +++ b/orang/src/main/java/lv/enes/orang/value/OrangString.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; public record OrangString(String value) implements Value { @Override diff --git a/orang/src/main/java/lv/enes/orang/value/PartialBuiltinFunction.java b/orang/src/main/java/lv/enes/orang/value/PartialBuiltinFunction.java index 37278a4..c1be22a 100644 --- a/orang/src/main/java/lv/enes/orang/value/PartialBuiltinFunction.java +++ b/orang/src/main/java/lv/enes/orang/value/PartialBuiltinFunction.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; import java.util.ArrayList; import java.util.Collections; diff --git a/orang/src/main/java/lv/enes/orang/value/PartialFunction.java b/orang/src/main/java/lv/enes/orang/value/PartialFunction.java index cee0cd4..e73ba0c 100644 --- a/orang/src/main/java/lv/enes/orang/value/PartialFunction.java +++ b/orang/src/main/java/lv/enes/orang/value/PartialFunction.java @@ -3,10 +3,13 @@ package lv.enes.orang.value; import lv.enes.orang.*; import lv.enes.orang.ast.ArgSpec; import lv.enes.orang.ast.Expression; +import lv.enes.orang.core.MutableScope; +import lv.enes.orang.core.OrangRuntimeException; +import lv.enes.orang.core.Scope; import lv.enes.orang.utils.NonEmptyList; -public record PartialFunction(Scope scope, NonEmptyList remainingArgs, Expression body) implements Value { - public static Value of(Scope scope, NonEmptyList remainingArgs, Expression body, Value param) throws OrangRuntimeException { +public record PartialFunction(Scope scope, NonEmptyList remainingArgs, Expression body) implements Value { + public static Value of(Scope scope, NonEmptyList remainingArgs, Expression body, Value param) throws OrangRuntimeException { var spec = remainingArgs.getFirst(); var newScope = MutableScope.of(scope); switch (spec.type) { diff --git a/orang/src/main/java/lv/enes/orang/value/Value.java b/orang/src/main/java/lv/enes/orang/value/Value.java index 0816dc2..07e6848 100644 --- a/orang/src/main/java/lv/enes/orang/value/Value.java +++ b/orang/src/main/java/lv/enes/orang/value/Value.java @@ -1,6 +1,6 @@ package lv.enes.orang.value; -import lv.enes.orang.OrangRuntimeException; +import lv.enes.orang.core.OrangRuntimeException; public sealed interface Value permits Array, BuiltinFunction, Function, Nothing, OrangBoolean, OrangInteger, OrangString, PartialBuiltinFunction, PartialFunction, Undefined { diff --git a/orang/src/main/java/module-info.java b/orang/src/main/java/module-info.java index 353d0dd..5b7b601 100644 --- a/orang/src/main/java/module-info.java +++ b/orang/src/main/java/module-info.java @@ -3,6 +3,7 @@ module lv.enes.orang { exports lv.enes.orang.value; requires lv.enes.orang.ast; + requires lv.enes.orang.checker; requires lv.enes.orang.core; requires lv.enes.orang.parser; requires lv.enes.orang.utils; diff --git a/settings.gradle.kts b/settings.gradle.kts index 391d33b..a64dfa6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,3 @@ rootProject.name = "orang" -include("ast", "core", "lexer", "orang", "parser", "utils") \ No newline at end of file +include("ast", "checker", "core", "lexer", "orang", "parser", "utils") \ No newline at end of file -- cgit v1.2.3