From ecabf885f3f6efb0b0924ac550a54455c8a12e85 Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Sat, 8 Oct 2022 17:18:55 +0200 Subject: [PATCH] Compiling with mingw --- Makefile | 6 +----- config.mk | 5 +++-- musique/common.hh | 1 + musique/main.cc | 33 +++++++++++---------------------- scripts/release.mk | 4 ++-- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 9ae20dd..72c7a07 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,10 @@ include scripts/debug.mk include scripts/release.mk include scripts/test.mk -bin/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h - @echo "CC $@" - @$(CC) $< -c -O3 -o $@ - # http://www.music.mcgill.ca/~gary/rtmidi/#compiling bin/rtmidi.o: lib/rtmidi/RtMidi.cpp lib/rtmidi/RtMidi.h @echo "CXX $@" - @$(CXX) $< -c -O2 -o $@ -D__LINUX_ALSA__ + @$(CXX) $< -c -O2 -o $@ -D__WINDOWS_MM__ doc: Doxyfile musique/*.cc musique/*.hh doxygen diff --git a/config.mk b/config.mk index c41bf54..40c44b2 100644 --- a/config.mk +++ b/config.mk @@ -6,7 +6,8 @@ CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ RELEASE_FLAGS=-O2 DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug -CXX=g++ +CC=i686-w64-mingw32-gcc +CXX=i686-w64-mingw32-g++ LDFLAGS=-flto -LDLIBS=-lasound -lpthread -static-libgcc -static-libstdc++ +LDLIBS=-lwinmm -lpthread -static-libgcc -static-libstdc++ diff --git a/musique/common.hh b/musique/common.hh index 871a74f..800b12b 100644 --- a/musique/common.hh +++ b/musique/common.hh @@ -20,6 +20,7 @@ using i64 = std::int64_t; using usize = std::size_t; using isize = std::ptrdiff_t; +using uint = unsigned int; /// Combine several lambdas into one for visiting std::variant template diff --git a/musique/main.cc b/musique/main.cc index 2d57a21..142873b 100644 --- a/musique/main.cc +++ b/musique/main.cc @@ -16,10 +16,6 @@ #include #include -extern "C" { -#include -} - namespace fs = std::filesystem; static bool ast_only_mode = false; @@ -194,23 +190,19 @@ struct Runner /// some of the strings are only views into source std::vector eternal_sources; -void completion(char const* buf, bestlineCompletions *lc) +bool is_tty() { - std::string_view in{buf}; - - for (auto scope = Runner::the->interpreter.env.get(); scope != nullptr; scope = scope->parent.get()) { - for (auto const& [name, _] : scope->variables) { - if (name.starts_with(in)) { - bestlineAddCompletion(lc, name.c_str()); - } - } - } +#ifdef __linux__ + return isatty(STDOUT_FILENO); +#else + return true; +#endif } /// Fancy main that supports Result forwarding on error (Try macro) static std::optional Main(std::span args) { - if (isatty(STDOUT_FILENO) && getenv("NO_COLOR") == nullptr) { + if (is_tty() && getenv("NO_COLOR") == nullptr) { pretty::terminal_mode(); } @@ -314,23 +306,20 @@ static std::optional Main(std::span args) if (runnables.empty() || enable_repl) { repl_line_number = 1; enable_repl = true; - bestlineSetCompletionCallback(completion); for (;;) { - char *input_buffer = bestlineWithHistory("> ", "musique"); - if (input_buffer == nullptr) { + std::string_view raw; + if (auto s = new std::string{}; std::getline(std::cin, *s)) { + raw = *s; + } else { break; } - // Raw input line used for execution in language - std::string_view raw = input_buffer; - // Used to recognize REPL commands std::string_view command = raw; trim(command); if (command.empty()) { // Line is empty so there is no need to execute it or parse it - free(input_buffer); continue; } diff --git a/scripts/release.mk b/scripts/release.mk index d7c77b6..c2916a1 100644 --- a/scripts/release.mk +++ b/scripts/release.mk @@ -4,6 +4,6 @@ bin/%.o: musique/%.cc @echo "CXX $@" @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c -bin/musique: $(Release_Obj) bin/main.o bin/bestline.o bin/rtmidi.o +bin/musique: $(Release_Obj) bin/main.o bin/rtmidi.o @echo "CXX $@" - @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/bestline.o bin/rtmidi.o $(LDFLAGS) $(LDLIBS) + @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/rtmidi.o $(LDFLAGS) $(LDLIBS)