diff --git a/config.mk b/config.mk index 18a346b..6245c40 100644 --- a/config.mk +++ b/config.mk @@ -1,12 +1,12 @@ MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)" CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -Wno-maybe-uninitialized -CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -Ilib/ut/ -Ilib/midi/include -I. -Ilib/bestline/ +CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -Ilib/midi/include -I. -Ilib/bestline/ -RELEASE_FLAGS=-O3 +RELEASE_FLAGS=-O2 DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug CXX=g++ -LDFLAGS=-L./lib/midi/ +LDFLAGS=-L./lib/midi/ -flto LDLIBS=-lmidi-alsa -lasound -lpthread -static-libgcc -static-libstdc++ diff --git a/musique/interpreter/builtin_functions.cc b/musique/interpreter/builtin_functions.cc index 8270883..9a5ec9c 100644 --- a/musique/interpreter/builtin_functions.cc +++ b/musique/interpreter/builtin_functions.cc @@ -21,13 +21,13 @@ void Interpreter::register_callbacks() /// Check if type has index method template -concept With_Index_Method = requires (T t, Interpreter interpreter, usize position) { +concept With_Index_Method = requires (T &t, Interpreter interpreter, usize position) { { t.index(interpreter, position) } -> std::convertible_to>; }; /// Check if type has either (index operator or method) and size() method template -concept Iterable = (With_Index_Method || With_Index_Operator) && requires (T const t) { +concept Iterable = (With_Index_Method || With_Index_Operator) && requires (T const& t) { { t.size() } -> std::convertible_to; }; @@ -44,7 +44,8 @@ static Result> deep_flat(Interpreter &interpreter, Iterable a } if (auto collection = get_if(element)) { - std::ranges::move(Try(deep_flat(interpreter, *collection)), std::back_inserter(result)); + auto array = Try(deep_flat(interpreter, *collection)); + std::move(array.begin(), array.end(), std::back_inserter(result)); } else { result.push_back(std::move(element)); } @@ -709,7 +710,7 @@ static Result builtin_reverse(Interpreter &i, std::vector args) /// Get minimum of arguments static Result builtin_min(Interpreter &i, std::vector args) { - auto array = Try(deep_flat(i, std::move(args))); + auto array = Try(deep_flat(i, args)); if (auto min = std::ranges::min_element(array); min != array.end()) return *min; return Value{}; @@ -718,7 +719,7 @@ static Result builtin_min(Interpreter &i, std::vector args) /// Get maximum of arguments static Result builtin_max(Interpreter &i, std::vector args) { - auto array = Try(deep_flat(i, std::move(args))); + auto array = Try(deep_flat(i, args)); if (auto max = std::ranges::max_element(array); max != array.end()) return *max; return Value{}; @@ -741,7 +742,7 @@ static Result builtin_partition(Interpreter &i, std::vector args) Array tuple[2] = {}; for (auto &value : array) { - tuple[Try(predicate(i, { std::move(value) })).truthy()].elements.push_back(std::move(value)); + tuple[Try(predicate(i, { value })).truthy()].elements.push_back(std::move(value)); } return Array {{ diff --git a/regression-tests/builtin/typeof.mq b/regression-tests/builtin/typeof.mq new file mode 100644 index 0000000..48f0f03 --- /dev/null +++ b/regression-tests/builtin/typeof.mq @@ -0,0 +1,7 @@ +say (typeof (call flat)); +say (typeof 0); +say (typeof []); +say (typeof c); +say (typeof false); +say (typeof nil); +say (typeof say); diff --git a/regression-tests/builtin/uniq.mq b/regression-tests/builtin/uniq.mq new file mode 100644 index 0000000..3d087fc --- /dev/null +++ b/regression-tests/builtin/uniq.mq @@ -0,0 +1,5 @@ +say (uniq (up 10 & down 10)); +say (uniq [1;1;1;3;5;3;4;4;1]); + +-- Multiple uniq applications shouldn't matter +say (uniq (uniq [1;1;1;3;5;3;4;4;1])); diff --git a/regression-tests/builtin/unique.mq b/regression-tests/builtin/unique.mq new file mode 100644 index 0000000..92a808c --- /dev/null +++ b/regression-tests/builtin/unique.mq @@ -0,0 +1,5 @@ +say (unique (up 10 & down 10)); +say (unique [1;1;1;3;5;3;4;4;1]); + +-- Multiple unique applications shouldn't matter +say (unique (unique [1;1;1;3;5;3;4;4;1]));