Browse Source

Main: Fix compilation of older steps

master
Riyyi 2 years ago
parent
commit
88d9253219
  1. 17
      src/step0_repl.cpp
  2. 21
      src/step1_read_print.cpp
  3. 29
      src/step2_eval.cpp
  4. 27
      src/step3_env.cpp
  5. 26
      src/step4_if_fn_do.cpp
  6. 26
      src/step5_tco.cpp
  7. 1
      src/step7_quote.cpp
  8. 1
      src/step8_macros.cpp

17
src/step0_repl.cpp

@ -3,6 +3,8 @@
#include <string> // std::getline
#include <string_view>
#include "forward.h"
#if 0
auto read(std::string_view data) -> std::string_view
{
@ -41,4 +43,19 @@ auto main() -> int
return 0;
}
// Below is needed for compilation
namespace blaze {
auto read(std::string_view) -> ValuePtr
{
return {};
}
auto eval(ValuePtr, EnvironmentPtr) -> ValuePtr
{
return {};
}
} // namespace blaze
#endif

21
src/step1_read_print.cpp

@ -9,35 +9,40 @@
#include "ast.h"
#include "error.h"
#include "forward.h"
#include "lexer.h"
#include "printer.h"
#include "reader.h"
#include "settings.h"
#if 0
auto read(std::string_view input) -> blaze::ASTNodePtr
namespace blaze {
auto read(std::string_view input) -> ValuePtr
{
blaze::Lexer lexer(input);
Lexer lexer(input);
lexer.tokenize();
if (blaze::Settings::the().get("dump-lexer") == "1") {
if (Settings::the().get("dump-lexer") == "1") {
lexer.dump();
}
blaze::Reader reader(std::move(lexer.tokens()));
Reader reader(std::move(lexer.tokens()));
reader.read();
if (blaze::Settings::the().get("dump-reader") == "1") {
if (Settings::the().get("dump-reader") == "1") {
reader.dump();
}
return reader.node();
}
auto eval(blaze::ASTNodePtr ast) -> blaze::ASTNodePtr
auto eval(ValuePtr ast, EnvironmentPtr) -> ValuePtr
{
return ast;
}
auto print(blaze::ASTNodePtr exp) -> std::string
} // namespace blaze
auto print(blaze::ValuePtr exp) -> std::string
{
blaze::Printer printer;
return printer.print(exp);
@ -48,7 +53,7 @@ auto rep(std::string_view input) -> void
blaze::Error::the().clearErrors();
blaze::Error::the().setInput(input);
print("{}\n", print(eval(read(input))).c_str());
print("{}\n", print(blaze::eval(blaze::read(input), nullptr)).c_str());
}
static auto cleanup(int signal) -> void

29
src/step2_eval.cpp

@ -8,7 +8,9 @@
#include "ast.h"
#include "environment.h"
#include "error.h"
#include "eval.h"
#include "forward.h"
#include "lexer.h"
#include "printer.h"
#include "reader.h"
@ -16,33 +18,38 @@
#include "settings.h"
#if 0
auto read(std::string_view input) -> blaze::ASTNodePtr
static blaze::EnvironmentPtr s_outer_env = blaze::Environment::create();
namespace blaze {
auto read(std::string_view input) -> ValuePtr
{
blaze::Lexer lexer(input);
Lexer lexer(input);
lexer.tokenize();
if (blaze::Settings::the().get("dump-lexer") == "1") {
if (Settings::the().get("dump-lexer") == "1") {
lexer.dump();
}
blaze::Reader reader(std::move(lexer.tokens()));
Reader reader(std::move(lexer.tokens()));
reader.read();
if (blaze::Settings::the().get("dump-reader") == "1") {
if (Settings::the().get("dump-reader") == "1") {
reader.dump();
}
return reader.node();
}
auto eval(blaze::ASTNodePtr ast) -> blaze::ASTNodePtr
auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr
{
blaze::GlobalEnvironment env;
blaze::Eval eval(ast, &env);
Eval eval(ast, env);
eval.eval();
return eval.ast();
}
auto print(blaze::ASTNodePtr exp) -> std::string
} // namespace blaze
auto print(blaze::ValuePtr exp) -> std::string
{
blaze::Printer printer;
@ -54,7 +61,7 @@ auto rep(std::string_view input) -> std::string
blaze::Error::the().clearErrors();
blaze::Error::the().setInput(input);
return print(eval(read(input)));
return print(blaze::eval(blaze::read(input), s_outer_env));
}
static auto cleanup(int signal) -> void
@ -87,6 +94,8 @@ auto main(int argc, char* argv[]) -> int
std::signal(SIGINT, cleanup);
std::signal(SIGTERM, cleanup);
installFunctions(s_outer_env);
blaze::Readline readline(pretty_print, history_path);
std::string input;

27
src/step3_env.cpp

@ -10,6 +10,7 @@
#include "environment.h"
#include "error.h"
#include "eval.h"
#include "forward.h"
#include "lexer.h"
#include "printer.h"
#include "reader.h"
@ -17,34 +18,38 @@
#include "settings.h"
#if 0
static blaze::EnvironmentPtr env = blaze::makePtr<blaze::GlobalEnvironment>();
static blaze::EnvironmentPtr s_outer_env = blaze::Environment::create();
auto read(std::string_view input) -> blaze::ASTNodePtr
namespace blaze {
auto read(std::string_view input) -> ValuePtr
{
blaze::Lexer lexer(input);
Lexer lexer(input);
lexer.tokenize();
if (blaze::Settings::the().get("dump-lexer") == "1") {
if (Settings::the().get("dump-lexer") == "1") {
lexer.dump();
}
blaze::Reader reader(std::move(lexer.tokens()));
Reader reader(std::move(lexer.tokens()));
reader.read();
if (blaze::Settings::the().get("dump-reader") == "1") {
if (Settings::the().get("dump-reader") == "1") {
reader.dump();
}
return reader.node();
}
auto eval(blaze::ASTNodePtr ast) -> blaze::ASTNodePtr
auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr
{
blaze::Eval eval(ast, env);
Eval eval(ast, env);
eval.eval();
return eval.ast();
}
auto print(blaze::ASTNodePtr exp) -> std::string
} // namespace blaze
auto print(blaze::ValuePtr exp) -> std::string
{
blaze::Printer printer;
@ -56,7 +61,7 @@ auto rep(std::string_view input) -> std::string
blaze::Error::the().clearErrors();
blaze::Error::the().setInput(input);
return print(eval(read(input)));
return print(blaze::eval(blaze::read(input), s_outer_env));
}
static auto cleanup(int signal) -> void
@ -89,6 +94,8 @@ auto main(int argc, char* argv[]) -> int
std::signal(SIGINT, cleanup);
std::signal(SIGTERM, cleanup);
installFunctions(s_outer_env);
blaze::Readline readline(pretty_print, history_path);
std::string input;

26
src/step4_if_fn_do.cpp

@ -23,9 +23,7 @@ static blaze::EnvironmentPtr s_outer_env = blaze::Environment::create();
static auto cleanup(int signal) -> void;
static auto installLambdas(blaze::EnvironmentPtr env) -> void;
static auto rep(std::string_view input, blaze::EnvironmentPtr env) -> std::string;
static auto read(std::string_view input) -> blaze::ASTNodePtr;
static auto eval(blaze::ASTNodePtr ast, blaze::EnvironmentPtr env) -> blaze::ASTNodePtr;
static auto print(blaze::ASTNodePtr exp) -> std::string;
static auto print(blaze::ValuePtr exp) -> std::string;
auto main(int argc, char* argv[]) -> int
{
@ -93,35 +91,39 @@ static auto rep(std::string_view input, blaze::EnvironmentPtr env) -> std::strin
blaze::Error::the().clearErrors();
blaze::Error::the().setInput(input);
return print(eval(read(input), env));
return print(blaze::eval(blaze::read(input), env));
}
static auto read(std::string_view input) -> blaze::ASTNodePtr
namespace blaze {
auto read(std::string_view input) -> ValuePtr
{
blaze::Lexer lexer(input);
Lexer lexer(input);
lexer.tokenize();
if (blaze::Settings::the().get("dump-lexer") == "1") {
if (Settings::the().get("dump-lexer") == "1") {
lexer.dump();
}
blaze::Reader reader(std::move(lexer.tokens()));
Reader reader(std::move(lexer.tokens()));
reader.read();
if (blaze::Settings::the().get("dump-reader") == "1") {
if (Settings::the().get("dump-reader") == "1") {
reader.dump();
}
return reader.node();
}
static auto eval(blaze::ASTNodePtr ast, blaze::EnvironmentPtr env) -> blaze::ASTNodePtr
auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr
{
blaze::Eval eval(ast, env);
Eval eval(ast, env);
eval.eval();
return eval.ast();
}
static auto print(blaze::ASTNodePtr exp) -> std::string
} // namespace blaze
static auto print(blaze::ValuePtr exp) -> std::string
{
blaze::Printer printer;

26
src/step5_tco.cpp

@ -29,9 +29,7 @@ static blaze::EnvironmentPtr s_outer_env = blaze::Environment::create();
static auto cleanup(int signal) -> void;
static auto installLambdas(blaze::EnvironmentPtr env) -> void;
static auto rep(std::string_view input, blaze::EnvironmentPtr env) -> std::string;
static auto read(std::string_view input) -> blaze::ASTNodePtr;
static auto eval(blaze::ASTNodePtr ast, blaze::EnvironmentPtr env) -> blaze::ASTNodePtr;
static auto print(blaze::ASTNodePtr exp) -> std::string;
static auto print(blaze::ValuePtr exp) -> std::string;
auto main(int argc, char* argv[]) -> int
{
@ -99,35 +97,39 @@ static auto rep(std::string_view input, blaze::EnvironmentPtr env) -> std::strin
blaze::Error::the().clearErrors();
blaze::Error::the().setInput(input);
return print(eval(read(input), env));
return print(blaze::eval(blaze::read(input), env));
}
static auto read(std::string_view input) -> blaze::ASTNodePtr
namespace blaze {
auto read(std::string_view input) -> ValuePtr
{
blaze::Lexer lexer(input);
Lexer lexer(input);
lexer.tokenize();
if (blaze::Settings::the().get("dump-lexer") == "1") {
if (Settings::the().get("dump-lexer") == "1") {
lexer.dump();
}
blaze::Reader reader(std::move(lexer.tokens()));
Reader reader(std::move(lexer.tokens()));
reader.read();
if (blaze::Settings::the().get("dump-reader") == "1") {
if (Settings::the().get("dump-reader") == "1") {
reader.dump();
}
return reader.node();
}
static auto eval(blaze::ASTNodePtr ast, blaze::EnvironmentPtr env) -> blaze::ASTNodePtr
auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr
{
blaze::Eval eval(ast, env);
Eval eval(ast, env);
eval.eval();
return eval.ast();
}
static auto print(blaze::ASTNodePtr exp) -> std::string
} // namespace blaze
static auto print(blaze::ValuePtr exp) -> std::string
{
blaze::Printer printer;

1
src/step7_quote.cpp

@ -119,7 +119,6 @@ auto main(int argc, char* argv[]) -> int
arg_parser.addOption(dump_reader, 'r', "dump-reader", nullptr, nullptr);
arg_parser.addOption(pretty_print, 'c', "color", nullptr, nullptr);
arg_parser.addOption(history_path, 'h', "history-path", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
// TODO: Add overload for addArgument(std::vector<std::string_view>)
arg_parser.addArgument(arguments, "arguments", nullptr, nullptr, ruc::ArgParser::Required::No);
arg_parser.parse(argc, argv);

1
src/step8_macros.cpp

@ -126,7 +126,6 @@ auto main(int argc, char* argv[]) -> int
arg_parser.addOption(dump_reader, 'r', "dump-reader", nullptr, nullptr);
arg_parser.addOption(pretty_print, 'c', "color", nullptr, nullptr);
arg_parser.addOption(history_path, 'h', "history-path", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
// TODO: Add overload for addArgument(std::vector<std::string_view>)
arg_parser.addArgument(arguments, "arguments", nullptr, nullptr, ruc::ArgParser::Required::No);
arg_parser.parse(argc, argv);

Loading…
Cancel
Save