Add a very simple evaluator for a subset of the language
This commit is contained in:
parent
4294063921
commit
73559460ec
3 changed files with 21 additions and 1 deletions
|
@ -22,6 +22,7 @@ add_library(
|
|||
src/Parser.cc
|
||||
src/Types.cc
|
||||
src/Checker.cc
|
||||
src/Evaluator.cc
|
||||
)
|
||||
target_link_directories(
|
||||
BoltCore
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace bolt {
|
|||
return Flags & ConfigFlags_TypeVarsRequireForall;
|
||||
}
|
||||
|
||||
bool hasImmediateDiagnostics() const noexcept {
|
||||
// TODO make this a configuration flag
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
16
src/main.cc
16
src/main.cc
|
@ -13,6 +13,7 @@
|
|||
#include "bolt/Scanner.hpp"
|
||||
#include "bolt/Parser.hpp"
|
||||
#include "bolt/Checker.hpp"
|
||||
#include "bolt/Evaluator.hpp"
|
||||
|
||||
using namespace bolt;
|
||||
|
||||
|
@ -56,7 +57,7 @@ int main(int argc, const char* argv[]) {
|
|||
SF->setParents();
|
||||
|
||||
DiagnosticStore DS;
|
||||
Checker TheChecker { Config, DS };
|
||||
Checker TheChecker { Config, DE }; // TODO set this to DS in production
|
||||
TheChecker.check(SF);
|
||||
|
||||
auto LT = [](const Diagnostic* L, const Diagnostic* R) {
|
||||
|
@ -79,6 +80,19 @@ int main(int argc, const char* argv[]) {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue