Add a very simple evaluator for a subset of the language

This commit is contained in:
Sam Vervaeck 2023-06-03 11:54:31 +02:00
parent 4294063921
commit 73559460ec
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
3 changed files with 21 additions and 1 deletions

View file

@ -22,6 +22,7 @@ add_library(
src/Parser.cc src/Parser.cc
src/Types.cc src/Types.cc
src/Checker.cc src/Checker.cc
src/Evaluator.cc
) )
target_link_directories( target_link_directories(
BoltCore BoltCore

View file

@ -25,6 +25,11 @@ namespace bolt {
return Flags & ConfigFlags_TypeVarsRequireForall; return Flags & ConfigFlags_TypeVarsRequireForall;
} }
bool hasImmediateDiagnostics() const noexcept {
// TODO make this a configuration flag
return true;
}
}; };
} }

View file

@ -13,6 +13,7 @@
#include "bolt/Scanner.hpp" #include "bolt/Scanner.hpp"
#include "bolt/Parser.hpp" #include "bolt/Parser.hpp"
#include "bolt/Checker.hpp" #include "bolt/Checker.hpp"
#include "bolt/Evaluator.hpp"
using namespace bolt; using namespace bolt;
@ -56,7 +57,7 @@ int main(int argc, const char* argv[]) {
SF->setParents(); SF->setParents();
DiagnosticStore DS; DiagnosticStore DS;
Checker TheChecker { Config, DS }; Checker TheChecker { Config, DE }; // TODO set this to DS in production
TheChecker.check(SF); TheChecker.check(SF);
auto LT = [](const Diagnostic* L, const Diagnostic* R) { auto LT = [](const Diagnostic* L, const Diagnostic* R) {
@ -79,6 +80,19 @@ int main(int argc, const char* argv[]) {
DE.printDiagnostic(*D); DE.printDiagnostic(*D);
} }
if (DE.hasError()) {
return 1;
}
Evaluator E;
Env TheEnv;
TheEnv.add("print", Value::binding([](auto Args) {
ZEN_ASSERT(Args.size() == 1)
std::cerr << Args[0].asString() << "\n";
return Value::unit();
}));
E.evaluate(SF, TheEnv);
return 0; return 0;
} }