diff --git a/Makefile b/Makefile index 370ddf6..62a857c 100644 --- a/Makefile +++ b/Makefile @@ -48,3 +48,4 @@ doc/wprowadzenie.html: doc/wprowadzenie.md $(shell mkdir -p $(subst musique/,bin/$(os)/,$(shell find musique/* -type d))) $(shell mkdir -p $(subst musique/,bin/$(os)/debug/,$(shell find musique/* -type d))) +$(shell mkdir -p bin/$(os)/server/) diff --git a/config.mk b/config.mk index dd14879..18d2a3e 100644 --- a/config.mk +++ b/config.mk @@ -1,16 +1,17 @@ MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)" -CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -LDFLAGS=-flto -LDLIBS= -lpthread - -RELEASE_FLAGS=-O2 -DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug - ifeq ($(shell uname),Darwin) os=macos else os=linux endif +CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result +CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -Ibin/$(os)/server/ +LDFLAGS=-flto +LDLIBS= -lpthread + +RELEASE_FLAGS=-O2 +DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug + + diff --git a/musique/interpreter/builtin_functions.cc b/musique/interpreter/builtin_functions.cc index d92d5d0..7236ce5 100644 --- a/musique/interpreter/builtin_functions.cc +++ b/musique/interpreter/builtin_functions.cc @@ -4,6 +4,8 @@ #include #include +#include + #include #include #include @@ -1109,6 +1111,19 @@ static Result builtin_call(Interpreter &i, std::vector args) return callable(i, std::move(args)); } +static Result builtin_start(Interpreter &interpreter, std::span args) +{ + Value ret{}; + + ServerBeginProtocol(); + + for (auto const& ast : args) { + ret = Try(interpreter.eval((Ast)ast)); + } + + return ret; +} + void Interpreter::register_builtin_functions() { auto &global = *Env::global; @@ -1152,6 +1167,7 @@ void Interpreter::register_builtin_functions() global.force_define("shuffle", builtin_shuffle); global.force_define("sim", builtin_sim); global.force_define("sort", builtin_sort); + global.force_define("start", builtin_start); global.force_define("try", builtin_try); global.force_define("typeof", builtin_typeof); global.force_define("uniq", builtin_uniq); diff --git a/musique/main.cc b/musique/main.cc index 3ae5fc7..b58b316 100644 --- a/musique/main.cc +++ b/musique/main.cc @@ -18,6 +18,8 @@ #include #include +#include + #ifdef _WIN32 extern "C" { #include @@ -171,6 +173,8 @@ struct Runner ensure(the == nullptr, "Only one instance of runner is supported"); the = this; + ServerInit(); + interpreter.midi_connection = &midi; if (output_port) { midi.connect_output(*output_port); diff --git a/scripts/build.mk b/scripts/build.mk index 0ef1b20..22f264c 100644 --- a/scripts/build.mk +++ b/scripts/build.mk @@ -1,16 +1,21 @@ Release_Obj=$(addprefix bin/$(os)/,$(Obj)) +Server=bin/$(os)/server/server.h bin/$(os)/server/server.o + +$(Server) &: server/src/*.go + cd server/src/; go build -o ../../bin/$(os)/server/server.o -buildmode=c-archive + bin/$(os)/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h @echo "CC $@" @$(CC) $< -c -O3 -o $@ -bin/$(os)/%.o: musique/%.cc +bin/$(os)/%.o: musique/%.cc $(Server) @echo "CXX $@" @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c -bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o $(Bestline) +bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o $(Bestline) $(Server) @echo "CXX $@" - @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o $(Bestline) $(LDFLAGS) $(LDLIBS) + @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o $(Bestline) $(LDFLAGS) $(LDLIBS) bin/$(os)/server/server.o Debug_Obj=$(addprefix bin/$(os)/debug/,$(Obj)) diff --git a/server/src/musique-bridge.go b/server/src/musique-bridge.go new file mode 100644 index 0000000..2b0e14c --- /dev/null +++ b/server/src/musique-bridge.go @@ -0,0 +1,27 @@ +package main + +import ( + "C" + "fmt" + "time" +) + +//export ServerInit +func ServerInit() { + fmt.Println("Initializing server") +} + +//export ServerBeginProtocol +func ServerBeginProtocol() { + protocol := []string { + "Make the plan", + "Execute the plan", + "Expect the plan to go off the rails", + "Throw away the plan", + } + + for i, msg := range protocol { + fmt.Printf("%d. %s\n", i, msg) + time.Sleep(300 * time.Millisecond) + } +}