Browse Source

Meta: Move main to example target, better include compatibility

master
Riyyi 1 year ago
parent
commit
f87eb4d934
  1. 22
      CMakeLists.txt
  2. 25
      example/CMakeLists.txt
  3. 10
      example/src/main.cpp
  4. 12
      src/blaze/ast.cpp
  5. 2
      src/blaze/ast.h
  6. 10
      src/blaze/env/environment.cpp
  7. 4
      src/blaze/env/environment.h
  8. 8
      src/blaze/env/functions/collection-access.cpp
  9. 8
      src/blaze/env/functions/collection-constructor.cpp
  10. 12
      src/blaze/env/functions/collection-modify.cpp
  11. 6
      src/blaze/env/functions/compare.cpp
  12. 6
      src/blaze/env/functions/convert.cpp
  13. 10
      src/blaze/env/functions/format.cpp
  14. 10
      src/blaze/env/functions/meta.cpp
  15. 12
      src/blaze/env/functions/mutable.cpp
  16. 6
      src/blaze/env/functions/operators.cpp
  17. 10
      src/blaze/env/functions/other.cpp
  18. 6
      src/blaze/env/functions/predicate.cpp
  19. 8
      src/blaze/env/functions/repl.cpp
  20. 4
      src/blaze/env/macro.h
  21. 4
      src/blaze/error.h
  22. 20
      src/blaze/eval-special-form.cpp
  23. 14
      src/blaze/eval.cpp
  24. 2
      src/blaze/eval.h
  25. 0
      src/blaze/forward.h
  26. 4
      src/blaze/lexer.cpp
  27. 0
      src/blaze/lexer.h
  28. 4
      src/blaze/macro.h
  29. 14
      src/blaze/printer.cpp
  30. 3
      src/blaze/printer.h
  31. 10
      src/blaze/reader.cpp
  32. 4
      src/blaze/reader.h
  33. 2
      src/blaze/readline.cpp
  34. 0
      src/blaze/readline.h
  35. 20
      src/blaze/repl.cpp
  36. 4
      src/blaze/repl.h
  37. 8
      src/blaze/settings.cpp
  38. 0
      src/blaze/settings.h
  39. 0
      src/blaze/types.h
  40. 4
      src/blaze/util.h

22
CMakeLists.txt

@ -11,6 +11,7 @@ endif()
# Options # Options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BLAZE_BUILD_EXAMPLES "Build the Blaze example programs" ${BLAZE_STANDALONE}) option(BLAZE_BUILD_EXAMPLES "Build the Blaze example programs" ${BLAZE_STANDALONE})
option(BLAZE_BUILD_TESTS "Build the Blaze test programs" ${BLAZE_STANDALONE})
# ------------------------------------------ # ------------------------------------------
@ -55,18 +56,19 @@ endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ------------------------------------------ # ------------------------------------------
# Library # Dependencies
add_subdirectory("vendor/ruc") add_subdirectory("vendor/ruc")
# ------------------------------------------ # ------------------------------------------
# Application target # Library target
# Define source files # Define source files
file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp") file(GLOB_RECURSE LIBRARY_SOURCES "src/*.cpp")
add_executable(${PROJECT} ${PROJECT_SOURCES}) add_library(${PROJECT} ${LIBRARY_SOURCES})
target_include_directories(${PROJECT} PRIVATE "src") target_include_directories(${PROJECT} PUBLIC
"src")
target_link_libraries(${PROJECT} readline ruc) target_link_libraries(${PROJECT} readline ruc)
# ------------------------------------------ # ------------------------------------------
@ -78,15 +80,16 @@ add_custom_target(${PROJECT}-lisp
add_dependencies(${PROJECT} ${PROJECT}-lisp) add_dependencies(${PROJECT} ${PROJECT}-lisp)
# ------------------------------------------ # ------------------------------------------
# Execute target # Example target
add_custom_target(run if (BLAZE_BUILD_EXAMPLES)
COMMAND ${PROJECT} -c add_subdirectory("example")
DEPENDS ${PROJECT}) endif()
# ------------------------------------------ # ------------------------------------------
# Test targets # Test targets
if (BLAZE_BUILD_TESTS)
function(make_test_target target_name step_name) function(make_test_target target_name step_name)
add_custom_target(${target_name} add_custom_target(${target_name}
COMMAND ../vendor/mal/runtest.py --deferrable --optional ../tests/${step_name}.mal -- ./${PROJECT}) COMMAND ../vendor/mal/runtest.py --deferrable --optional ../tests/${step_name}.mal -- ./${PROJECT})
@ -128,3 +131,4 @@ add_custom_target(perf
COMMAND ./${PROJECT} ../tests/perf2.mal COMMAND ./${PROJECT} ../tests/perf2.mal
COMMAND ./${PROJECT} ../tests/perf3.mal) COMMAND ./${PROJECT} ../tests/perf3.mal)
add_dependencies(perf ${PROJECT}) add_dependencies(perf ${PROJECT})
endif()

25
example/CMakeLists.txt

@ -0,0 +1,25 @@
# ------------------------------------------
# User config between these lines
# Set project name
set(EXAMPLE "repl")
# ------------------------------------------
project(${EXAMPLE} CXX)
# Define game source files
file(GLOB_RECURSE EXAMPLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_executable(${EXAMPLE} ${EXAMPLE_SOURCES})
target_include_directories(${EXAMPLE} PRIVATE
"src")
target_link_libraries(${EXAMPLE} ${PROJECT})
# ------------------------------------------
# Add 'make run' target
add_custom_target(run
COMMAND ${EXAMPLE} -c
DEPENDS ${PROJECT}
WORKING_DIRECTORY "..")

10
src/main.cpp → example/src/main.cpp

@ -13,11 +13,11 @@
#include "ruc/format/color.h" #include "ruc/format/color.h"
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "forward.h" #include "blaze/forward.h"
#include "repl.h" #include "blaze/repl.h"
#include "settings.h" #include "blaze/settings.h"
namespace blaze { namespace blaze {

12
src/ast.cpp → src/blaze/ast.cpp

@ -10,12 +10,12 @@
#include <utility> // std::move #include <utility> // std::move
#include <vector> #include <vector>
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "error.h" #include "blaze/error.h"
#include "forward.h" #include "blaze/forward.h"
#include "printer.h" #include "blaze/printer.h"
#include "types.h" #include "blaze/types.h"
namespace blaze { namespace blaze {

2
src/ast.h → src/blaze/ast.h

@ -20,7 +20,7 @@
#include "ruc/format/formatter.h" #include "ruc/format/formatter.h"
#include "forward.h" #include "blaze/forward.h"
namespace blaze { namespace blaze {

10
src/env/environment.cpp → src/blaze/env/environment.cpp vendored

@ -11,11 +11,11 @@
#include "ruc/file.h" #include "ruc/file.h"
#include "ruc/format/format.h" #include "ruc/format/format.h"
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "error.h" #include "blaze/error.h"
#include "forward.h" #include "blaze/forward.h"
#include "repl.h" #include "blaze/repl.h"
namespace blaze { namespace blaze {

4
src/env/environment.h → src/blaze/env/environment.h vendored

@ -11,8 +11,8 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "ast.h" #include "blaze/ast.h"
#include "forward.h" #include "blaze/forward.h"
namespace blaze { namespace blaze {

8
src/env/functions/collection-access.cpp → src/blaze/env/functions/collection-access.cpp vendored

@ -7,10 +7,10 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <memory> // std:static_pointer_cast #include <memory> // std:static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "forward.h" #include "blaze/forward.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

8
src/env/functions/collection-constructor.cpp → src/blaze/env/functions/collection-constructor.cpp vendored

@ -7,10 +7,10 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <memory> // std:static_pointer_cast #include <memory> // std:static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "forward.h" #include "blaze/forward.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

12
src/env/functions/collection-modify.cpp → src/blaze/env/functions/collection-modify.cpp vendored

@ -8,12 +8,12 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <memory> // std::static_pointer_cast #include <memory> // std::static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "forward.h" #include "blaze/forward.h"
#include "repl.h" #include "blaze/repl.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

6
src/env/functions/compare.cpp → src/blaze/env/functions/compare.cpp vendored

@ -8,9 +8,9 @@
#include <functional> // std::function #include <functional> // std::function
#include <memory> // std::static_pointer_cast #include <memory> // std::static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

6
src/env/functions/convert.cpp → src/blaze/env/functions/convert.cpp vendored

@ -8,9 +8,9 @@
#include <memory> #include <memory>
#include <system_error> // std::errc #include <system_error> // std::errc
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

10
src/env/functions/format.cpp → src/blaze/env/functions/format.cpp vendored

@ -7,13 +7,13 @@
#include <iterator> // std::next #include <iterator> // std::next
#include <string> #include <string>
#include "reader.h"
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "printer.h" #include "blaze/printer.h"
#include "util.h" #include "blaze/reader.h"
#include "blaze/util.h"
namespace blaze { namespace blaze {

10
src/env/functions/meta.cpp → src/blaze/env/functions/meta.cpp vendored

@ -4,11 +4,11 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "error.h" #include "blaze/error.h"
#include "forward.h" #include "blaze/forward.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

12
src/env/functions/mutable.cpp → src/blaze/env/functions/mutable.cpp vendored

@ -7,12 +7,12 @@
#include <algorithm> // std::copy #include <algorithm> // std::copy
#include <memory> // std::static_pointer_cast #include <memory> // std::static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "forward.h" #include "blaze/forward.h"
#include "repl.h" #include "blaze/repl.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

6
src/env/functions/operators.cpp → src/blaze/env/functions/operators.cpp vendored

@ -7,9 +7,9 @@
#include <cstdint> // int64_t #include <cstdint> // int64_t
#include <memory> // std::static_pointer_cast #include <memory> // std::static_pointer_cast
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

10
src/env/functions/other.cpp → src/blaze/env/functions/other.cpp vendored

@ -7,11 +7,11 @@
#include <chrono> // std::chrono::sytem_clock #include <chrono> // std::chrono::sytem_clock
#include <cstdint> // int64_t #include <cstdint> // int64_t
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "error.h" #include "blaze/error.h"
#include "forward.h" #include "blaze/forward.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

6
src/env/functions/predicate.cpp → src/blaze/env/functions/predicate.cpp vendored

@ -4,9 +4,9 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

8
src/env/functions/repl.cpp → src/blaze/env/functions/repl.cpp vendored

@ -8,10 +8,10 @@
#include "ruc/file.h" #include "ruc/file.h"
#include "ast.h" #include "blaze/ast.h"
#include "env/macro.h" #include "blaze/env/macro.h"
#include "repl.h" #include "blaze/repl.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

4
src/env/macro.h → src/blaze/env/macro.h vendored

@ -4,9 +4,11 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#pragma once
#include <unordered_map> #include <unordered_map>
#include "env/environment.h" #include "blaze/env/environment.h"
#define ADD_FUNCTION(name, signature, documentation, lambda) \ #define ADD_FUNCTION(name, signature, documentation, lambda) \
Environment::registerFunction( \ Environment::registerFunction( \

4
src/error.h → src/blaze/error.h

@ -10,8 +10,8 @@
#include "ruc/singleton.h" #include "ruc/singleton.h"
#include "forward.h" #include "blaze/forward.h"
#include "lexer.h" #include "blaze/lexer.h"
namespace blaze { namespace blaze {

20
src/eval-special-form.cpp → src/blaze/eval-special-form.cpp

@ -16,16 +16,16 @@
#include "ruc/format/format.h" #include "ruc/format/format.h"
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "error.h" #include "blaze/error.h"
#include "eval.h" #include "blaze/eval.h"
#include "forward.h" #include "blaze/forward.h"
#include "macro.h" #include "blaze/macro.h"
#include "printer.h" #include "blaze/printer.h"
#include "settings.h" #include "blaze/settings.h"
#include "types.h" #include "blaze/types.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

14
src/eval.cpp → src/blaze/eval.cpp

@ -10,13 +10,13 @@
#include <span> // std::span #include <span> // std::span
#include <string> #include <string>
#include "ast.h" #include "blaze/ast.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "error.h" #include "blaze/error.h"
#include "eval.h" #include "blaze/eval.h"
#include "forward.h" #include "blaze/forward.h"
#include "types.h" #include "blaze/types.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

2
src/eval.h → src/blaze/eval.h

@ -8,7 +8,7 @@
#include <vector> #include <vector>
#include "forward.h" // EnvironmentPtr #include "blaze/forward.h" // EnvironmentPtr
namespace blaze { namespace blaze {

0
src/forward.h → src/blaze/forward.h

4
src/lexer.cpp → src/blaze/lexer.cpp

@ -11,8 +11,8 @@
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "ruc/genericlexer.h" #include "ruc/genericlexer.h"
#include "error.h" #include "blaze/error.h"
#include "lexer.h" #include "blaze/lexer.h"
namespace blaze { namespace blaze {

0
src/lexer.h → src/blaze/lexer.h

4
src/macro.h → src/blaze/macro.h

@ -4,7 +4,9 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "eval.h" #pragma once
#include "blaze/eval.h"
#define CONCAT(a, b) CONCAT_IMPL(a, b) #define CONCAT(a, b) CONCAT_IMPL(a, b)
#define CONCAT_IMPL(a, b) a##b #define CONCAT_IMPL(a, b) a##b

14
src/printer.cpp → src/blaze/printer.cpp

@ -11,13 +11,13 @@
#include "ruc/format/color.h" #include "ruc/format/color.h"
#include "ruc/format/format.h" #include "ruc/format/format.h"
#include "ast.h" #include "blaze/ast.h"
#include "error.h" #include "blaze/error.h"
#include "lexer.h" #include "blaze/lexer.h"
#include "printer.h" #include "blaze/printer.h"
#include "settings.h" #include "blaze/settings.h"
#include "types.h" #include "blaze/types.h"
#include "util.h" #include "blaze/util.h"
namespace blaze { namespace blaze {

3
src/printer.h → src/blaze/printer.h

@ -6,9 +6,10 @@
#pragma once #pragma once
#include "ast.h"
#include <string> #include <string>
#include "blaze/ast.h"
namespace blaze { namespace blaze {
// Serializer -> return to string // Serializer -> return to string

10
src/reader.cpp → src/blaze/reader.cpp

@ -12,14 +12,14 @@
#include <system_error> // std::errc #include <system_error> // std::errc
#include <utility> // std::move #include <utility> // std::move
#include "error.h"
#include "ruc/format/color.h" #include "ruc/format/color.h"
#include "ruc/meta/assert.h" #include "ruc/meta/assert.h"
#include "ast.h" #include "blaze/ast.h"
#include "reader.h" #include "blaze/error.h"
#include "settings.h" #include "blaze/reader.h"
#include "types.h" #include "blaze/settings.h"
#include "blaze/types.h"
namespace blaze { namespace blaze {

4
src/reader.h → src/blaze/reader.h

@ -10,8 +10,8 @@
#include <memory> // std::shared_ptr #include <memory> // std::shared_ptr
#include <vector> #include <vector>
#include "ast.h" #include "blaze/ast.h"
#include "lexer.h" #include "blaze/lexer.h"
#define INDENTATION_WIDTH 2 #define INDENTATION_WIDTH 2

2
src/readline.cpp → src/blaze/readline.cpp

@ -15,7 +15,7 @@
#include "ruc/format/color.h" #include "ruc/format/color.h"
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "readline.h" #include "blaze/readline.h"
namespace blaze { namespace blaze {

0
src/readline.h → src/blaze/readline.h

20
src/repl.cpp → src/blaze/repl.cpp

@ -11,16 +11,16 @@
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "error.h" #include "blaze/error.h"
#include "eval.h" #include "blaze/eval.h"
#include "forward.h" #include "blaze/forward.h"
#include "lexer.h" #include "blaze/lexer.h"
#include "printer.h" #include "blaze/printer.h"
#include "reader.h" #include "blaze/reader.h"
#include "readline.h" #include "blaze/readline.h"
#include "repl.h" #include "blaze/repl.h"
#include "settings.h" #include "blaze/settings.h"
namespace blaze { namespace blaze {

4
src/repl.h → src/blaze/repl.h

@ -10,8 +10,8 @@
#include <string_view> #include <string_view>
#include <vector> #include <vector>
#include "forward.h" #include "blaze/forward.h"
#include "readline.h" #include "blaze/readline.h"
namespace blaze { namespace blaze {

8
src/settings.cpp → src/blaze/settings.cpp

@ -8,10 +8,10 @@
#include "ruc/meta/assert.h" #include "ruc/meta/assert.h"
#include "env/environment.h" #include "blaze/env/environment.h"
#include "forward.h" #include "blaze/forward.h"
#include "settings.h" #include "blaze/settings.h"
#include "types.h" #include "blaze/types.h"
namespace blaze { namespace blaze {

0
src/settings.h → src/blaze/settings.h

0
src/types.h → src/blaze/types.h

4
src/util.h → src/blaze/util.h

@ -10,8 +10,8 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include "error.h" #include "blaze/error.h"
#include "types.h" #include "blaze/types.h"
// ----------------------------------------- // -----------------------------------------
Loading…
Cancel
Save