Browse Source

Meta: Move main to example target, better include compatibility

master
Riyyi 1 year ago
parent
commit
f87eb4d934
  1. 86
      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

86
CMakeLists.txt

@ -11,6 +11,7 @@ endif()
# Options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
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)
# ------------------------------------------
# Library
# Dependencies
add_subdirectory("vendor/ruc")
# ------------------------------------------
# Application target
# Library target
# Define source files
file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp")
file(GLOB_RECURSE LIBRARY_SOURCES "src/*.cpp")
add_executable(${PROJECT} ${PROJECT_SOURCES})
target_include_directories(${PROJECT} PRIVATE "src")
add_library(${PROJECT} ${LIBRARY_SOURCES})
target_include_directories(${PROJECT} PUBLIC
"src")
target_link_libraries(${PROJECT} readline ruc)
# ------------------------------------------
@ -78,53 +80,55 @@ add_custom_target(${PROJECT}-lisp
add_dependencies(${PROJECT} ${PROJECT}-lisp)
# ------------------------------------------
# Execute target
# Example target
add_custom_target(run
COMMAND ${PROJECT} -c
DEPENDS ${PROJECT})
if (BLAZE_BUILD_EXAMPLES)
add_subdirectory("example")
endif()
# ------------------------------------------
# Test targets
function(make_test_target target_name step_name)
if (BLAZE_BUILD_TESTS)
function(make_test_target target_name step_name)
add_custom_target(${target_name}
COMMAND ../vendor/mal/runtest.py --deferrable --optional ../tests/${step_name}.mal -- ./${PROJECT})
add_dependencies(${target_name} ${PROJECT})
endfunction()
make_test_target("test0" "step0_repl")
make_test_target("test1" "step1_read_print")
make_test_target("test2" "step2_eval")
make_test_target("test3" "step3_env")
make_test_target("test4" "step4_if_fn_do")
make_test_target("test5" "step5_tco")
make_test_target("test6" "step6_file")
make_test_target("test7" "step7_quote")
make_test_target("test8" "step8_macros")
make_test_target("test9" "step9_try")
make_test_target("testA" "stepA_mal")
function(make_host_test_target target_name step_name)
endfunction()
make_test_target("test0" "step0_repl")
make_test_target("test1" "step1_read_print")
make_test_target("test2" "step2_eval")
make_test_target("test3" "step3_env")
make_test_target("test4" "step4_if_fn_do")
make_test_target("test5" "step5_tco")
make_test_target("test6" "step6_file")
make_test_target("test7" "step7_quote")
make_test_target("test8" "step8_macros")
make_test_target("test9" "step9_try")
make_test_target("testA" "stepA_mal")
function(make_host_test_target target_name step_name)
add_custom_target(${target_name}
COMMAND ../vendor/mal/runtest.py --deferrable --optional ../tests/${step_name}.mal -- ./${PROJECT} ../mal/${step_name}.mal)
add_dependencies(${target_name} ${PROJECT})
endfunction()
make_host_test_target("host_test0" "step0_repl")
make_host_test_target("host_test1" "step1_read_print")
make_host_test_target("host_test2" "step2_eval")
make_host_test_target("host_test3" "step3_env")
make_host_test_target("host_test4" "step4_if_fn_do")
# make_host_test_target("host_test5" "step5_tco") # disabled
make_host_test_target("host_test6" "step6_file")
make_host_test_target("host_test7" "step7_quote")
make_host_test_target("host_test8" "step8_macros")
make_host_test_target("host_test9" "step9_try")
make_host_test_target("host_testA" "stepA_mal")
add_custom_target(perf
endfunction()
make_host_test_target("host_test0" "step0_repl")
make_host_test_target("host_test1" "step1_read_print")
make_host_test_target("host_test2" "step2_eval")
make_host_test_target("host_test3" "step3_env")
make_host_test_target("host_test4" "step4_if_fn_do")
# make_host_test_target("host_test5" "step5_tco") # disabled
make_host_test_target("host_test6" "step6_file")
make_host_test_target("host_test7" "step7_quote")
make_host_test_target("host_test8" "step8_macros")
make_host_test_target("host_test9" "step9_try")
make_host_test_target("host_testA" "stepA_mal")
add_custom_target(perf
COMMAND ./${PROJECT} ../tests/perf1.mal
COMMAND ./${PROJECT} ../tests/perf2.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/print.h"
#include "ast.h"
#include "env/environment.h"
#include "forward.h"
#include "repl.h"
#include "settings.h"
#include "blaze/ast.h"
#include "blaze/env/environment.h"
#include "blaze/forward.h"
#include "blaze/repl.h"
#include "blaze/settings.h"
namespace blaze {

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

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

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

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

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

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

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

@ -11,8 +11,8 @@
#include <unordered_map>
#include <vector>
#include "ast.h"
#include "forward.h"
#include "blaze/ast.h"
#include "blaze/forward.h"
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 <memory> // std:static_pointer_cast
#include "ast.h"
#include "env/macro.h"
#include "forward.h"
#include "util.h"
#include "blaze/ast.h"
#include "blaze/env/macro.h"
#include "blaze/forward.h"
#include "blaze/util.h"
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 <memory> // std:static_pointer_cast
#include "ast.h"
#include "env/macro.h"
#include "forward.h"
#include "util.h"
#include "blaze/ast.h"
#include "blaze/env/macro.h"
#include "blaze/forward.h"
#include "blaze/util.h"
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 <memory> // std::static_pointer_cast
#include "ast.h"
#include "env/environment.h"
#include "env/macro.h"
#include "forward.h"
#include "repl.h"
#include "util.h"
#include "blaze/ast.h"
#include "blaze/env/environment.h"
#include "blaze/env/macro.h"
#include "blaze/forward.h"
#include "blaze/repl.h"
#include "blaze/util.h"
namespace blaze {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -10,8 +10,8 @@
#include "ruc/singleton.h"
#include "forward.h"
#include "lexer.h"
#include "blaze/forward.h"
#include "blaze/lexer.h"
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/print.h"
#include "ast.h"
#include "env/environment.h"
#include "error.h"
#include "eval.h"
#include "forward.h"
#include "macro.h"
#include "printer.h"
#include "settings.h"
#include "types.h"
#include "util.h"
#include "blaze/ast.h"
#include "blaze/env/environment.h"
#include "blaze/error.h"
#include "blaze/eval.h"
#include "blaze/forward.h"
#include "blaze/macro.h"
#include "blaze/printer.h"
#include "blaze/settings.h"
#include "blaze/types.h"
#include "blaze/util.h"
namespace blaze {

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

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

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

@ -8,7 +8,7 @@
#include <vector>
#include "forward.h" // EnvironmentPtr
#include "blaze/forward.h" // EnvironmentPtr
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/genericlexer.h"
#include "error.h"
#include "lexer.h"
#include "blaze/error.h"
#include "blaze/lexer.h"
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
*/
#include "eval.h"
#pragma once
#include "blaze/eval.h"
#define CONCAT(a, b) CONCAT_IMPL(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/format.h"
#include "ast.h"
#include "error.h"
#include "lexer.h"
#include "printer.h"
#include "settings.h"
#include "types.h"
#include "util.h"
#include "blaze/ast.h"
#include "blaze/error.h"
#include "blaze/lexer.h"
#include "blaze/printer.h"
#include "blaze/settings.h"
#include "blaze/types.h"
#include "blaze/util.h"
namespace blaze {

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

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

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

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

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

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

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

@ -15,7 +15,7 @@
#include "ruc/format/color.h"
#include "ruc/format/print.h"
#include "readline.h"
#include "blaze/readline.h"
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 "env/environment.h"
#include "error.h"
#include "eval.h"
#include "forward.h"
#include "lexer.h"
#include "printer.h"
#include "reader.h"
#include "readline.h"
#include "repl.h"
#include "settings.h"
#include "blaze/env/environment.h"
#include "blaze/error.h"
#include "blaze/eval.h"
#include "blaze/forward.h"
#include "blaze/lexer.h"
#include "blaze/printer.h"
#include "blaze/reader.h"
#include "blaze/readline.h"
#include "blaze/repl.h"
#include "blaze/settings.h"
namespace blaze {

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

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

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

@ -8,10 +8,10 @@
#include "ruc/meta/assert.h"
#include "env/environment.h"
#include "forward.h"
#include "settings.h"
#include "types.h"
#include "blaze/env/environment.h"
#include "blaze/forward.h"
#include "blaze/settings.h"
#include "blaze/types.h"
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_view>
#include "error.h"
#include "types.h"
#include "blaze/error.h"
#include "blaze/types.h"
// -----------------------------------------
Loading…
Cancel
Save