From 88d92532191e3ff3797072f47f4c3a2e28db9397 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 17 Apr 2023 15:45:56 +0200 Subject: [PATCH] Main: Fix compilation of older steps --- src/step0_repl.cpp | 17 +++++++++++++++++ src/step1_read_print.cpp | 21 +++++++++++++-------- src/step2_eval.cpp | 29 +++++++++++++++++++---------- src/step3_env.cpp | 27 +++++++++++++++++---------- src/step4_if_fn_do.cpp | 26 ++++++++++++++------------ src/step5_tco.cpp | 26 ++++++++++++++------------ src/step7_quote.cpp | 1 - src/step8_macros.cpp | 1 - 8 files changed, 94 insertions(+), 54 deletions(-) diff --git a/src/step0_repl.cpp b/src/step0_repl.cpp index 3861738..80df72e 100644 --- a/src/step0_repl.cpp +++ b/src/step0_repl.cpp @@ -3,6 +3,8 @@ #include // std::getline #include +#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 diff --git a/src/step1_read_print.cpp b/src/step1_read_print.cpp index 479607d..a09f559 100644 --- a/src/step1_read_print.cpp +++ b/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 diff --git a/src/step2_eval.cpp b/src/step2_eval.cpp index 2fdd470..0b4bf5b 100644 --- a/src/step2_eval.cpp +++ b/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; diff --git a/src/step3_env.cpp b/src/step3_env.cpp index 0ee7056..0b4bf5b 100644 --- a/src/step3_env.cpp +++ b/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(); +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; diff --git a/src/step4_if_fn_do.cpp b/src/step4_if_fn_do.cpp index 2dfeaca..7af9d70 100644 --- a/src/step4_if_fn_do.cpp +++ b/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; diff --git a/src/step5_tco.cpp b/src/step5_tco.cpp index 514afb7..99418d0 100644 --- a/src/step5_tco.cpp +++ b/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; diff --git a/src/step7_quote.cpp b/src/step7_quote.cpp index 618ef7b..0ee8d5d 100644 --- a/src/step7_quote.cpp +++ b/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) arg_parser.addArgument(arguments, "arguments", nullptr, nullptr, ruc::ArgParser::Required::No); arg_parser.parse(argc, argv); diff --git a/src/step8_macros.cpp b/src/step8_macros.cpp index 819e818..dc296b2 100644 --- a/src/step8_macros.cpp +++ b/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) arg_parser.addArgument(arguments, "arguments", nullptr, nullptr, ruc::ArgParser::Required::No); arg_parser.parse(argc, argv);