From 733d84c124fdf14af3e80580055ece0285d98320 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 17 Aug 2023 22:02:10 +0200 Subject: [PATCH] Main: Fix *ARGV* with 0 arguments --- src/step6_file.cpp | 8 +++----- src/step7_quote.cpp | 8 +++----- src/step8_macros.cpp | 8 +++----- src/step9_try.cpp | 8 +++----- src/stepA_mal.cpp | 23 ++++++++++++++++++----- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/step6_file.cpp b/src/step6_file.cpp index e2f1cb9..3c4e421 100644 --- a/src/step6_file.cpp +++ b/src/step6_file.cpp @@ -94,11 +94,9 @@ static auto installLambdas(EnvironmentPtr env) -> void static auto makeArgv(EnvironmentPtr env, std::vector arguments) -> void { size_t count = arguments.size(); - auto nodes = ValueVector(count - 1); - if (count > 1) { - for (size_t i = 1; i < count; ++i) { - nodes.at(i) = makePtr(arguments[i]); - } + auto nodes = ValueVector(); + for (size_t i = 1; i < count; ++i) { + nodes.push_back(makePtr(arguments[i])); } env->set("*ARGV*", makePtr(nodes)); } diff --git a/src/step7_quote.cpp b/src/step7_quote.cpp index e2f1cb9..3c4e421 100644 --- a/src/step7_quote.cpp +++ b/src/step7_quote.cpp @@ -94,11 +94,9 @@ static auto installLambdas(EnvironmentPtr env) -> void static auto makeArgv(EnvironmentPtr env, std::vector arguments) -> void { size_t count = arguments.size(); - auto nodes = ValueVector(count - 1); - if (count > 1) { - for (size_t i = 1; i < count; ++i) { - nodes.at(i) = makePtr(arguments[i]); - } + auto nodes = ValueVector(); + for (size_t i = 1; i < count; ++i) { + nodes.push_back(makePtr(arguments[i])); } env->set("*ARGV*", makePtr(nodes)); } diff --git a/src/step8_macros.cpp b/src/step8_macros.cpp index 4c298c3..c398676 100644 --- a/src/step8_macros.cpp +++ b/src/step8_macros.cpp @@ -101,11 +101,9 @@ static auto installLambdas(EnvironmentPtr env) -> void static auto makeArgv(EnvironmentPtr env, std::vector arguments) -> void { size_t count = arguments.size(); - auto nodes = ValueVector(count - 1); - if (count > 1) { - for (size_t i = 1; i < count; ++i) { - nodes.at(i) = makePtr(arguments[i]); - } + auto nodes = ValueVector(); + for (size_t i = 1; i < count; ++i) { + nodes.push_back(makePtr(arguments[i])); } env->set("*ARGV*", makePtr(nodes)); } diff --git a/src/step9_try.cpp b/src/step9_try.cpp index 63bb230..c8f4a06 100644 --- a/src/step9_try.cpp +++ b/src/step9_try.cpp @@ -101,11 +101,9 @@ static auto installLambdas(EnvironmentPtr env) -> void static auto makeArgv(EnvironmentPtr env, std::vector arguments) -> void { size_t count = arguments.size(); - auto nodes = ValueVector(count - 1); - if (count > 1) { - for (size_t i = 1; i < count; ++i) { - nodes.at(i) = makePtr(arguments[i]); - } + auto nodes = ValueVector(); + for (size_t i = 1; i < count; ++i) { + nodes.push_back(makePtr(arguments[i])); } env->set("*ARGV*", makePtr(nodes)); } diff --git a/src/stepA_mal.cpp b/src/stepA_mal.cpp index 0ed1be7..ee10826 100644 --- a/src/stepA_mal.cpp +++ b/src/stepA_mal.cpp @@ -113,11 +113,9 @@ static auto installLambdas(EnvironmentPtr env) -> void static auto makeArgv(EnvironmentPtr env, std::vector arguments) -> void { size_t count = arguments.size(); - auto nodes = ValueVector(count - 1); - if (count > 1) { - for (size_t i = 1; i < count; ++i) { - nodes.at(i) = makePtr(arguments[i]); - } + auto nodes = ValueVector(); + for (size_t i = 1; i < count; ++i) { + nodes.push_back(makePtr(arguments[i])); } env->set("*ARGV*", makePtr(nodes)); } @@ -178,3 +176,18 @@ auto main(int argc, char* argv[]) -> int return 0; } + +// TODO: List of things below +// v Pass stepA tests (implement leftover functions) +// v Make Macro into a subclass of Lambda (?) to simplify some logic +// v Convert std::list -> std::vector, test speed before/after +// v Better way of running mal tests +// - Make Collections/HashMaps const, construct a new one with the added items +// - Basic performance testing macros, enabled in debug builds + +// Iterations to beat: +// Debug: ~5k +// Release: ~30k +// New: +// Debug: ~6k +// Release: ~37k