Skip to content

Commit

Permalink
Add new command format
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Sep 24, 2023
1 parent 6642281 commit 2427e64
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 55 deletions.
52 changes: 24 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ project(meevax DESCRIPTION "A programmable programming language"
LANGUAGES CXX
VERSION ${CURRENT_VERSION})

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_VERBOSE_MAKEFILE OFF)
include(GNUInstallDirs)

string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS
# "-flto" # This optimization causes a SEGV when compiling with Clang 10.
Expand All @@ -23,17 +19,18 @@ string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS
# "-mtune=native"
)

# NOTE: The `-gdwarf-4` option is set due to the following issues with Clang 14 and Valgrind versions below 3.20: https://bugzilla.mozilla.org/show_bug.cgi?id=1758782
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -gdwarf-4")
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_DEBUG "-Og -gdwarf-4") # NOTE: The `-gdwarf-4` option is set due to the following issues with Clang 14 and Valgrind versions below 3.20: https://bugzilla.mozilla.org/show_bug.cgi?id=1758782
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gdwarf-4 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${AGGRESSIVE_OPTIMIZATION_OPTIONS}")

include(GNUInstallDirs)

set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gdwarf-4 -DNDEBUG")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_VERBOSE_MAKEFILE OFF)

# ---- Configure ---------------------------------------------------------------

Expand Down Expand Up @@ -63,12 +60,6 @@ file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/unicode/upcase.hp

string(TOLOWER ${CMAKE_SYSTEM_NAME} ${PROJECT_NAME}_SYSTEM_NAME)

file(GLOB ${PROJECT_NAME}_BASIS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/basis/*.ss)
foreach(EACH IN LISTS ${PROJECT_NAME}_BASIS_SOURCES)
get_filename_component(FILENAME ${EACH} NAME)
file(READ ${EACH} ${PROJECT_NAME}_BASIS_${FILENAME})
endforeach()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/README.md ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/version.cpp)

Expand All @@ -94,24 +85,30 @@ set_target_properties(kernel PROPERTIES OUTPUT_NAME ${PROJECT_NAME} # Rename lib
SOVERSION ${PROJECT_VERSION_MAJOR}
LINK_FLAGS_RELEASE -s)

# ---- Target basis ------------------------------------------------------------
# ---- Target format -----------------------------------------------------------

add_executable(format)

add_library(basis INTERFACE)
target_sources(format PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/format.cpp)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/configure/basis.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/meevax/basis/scheme.hpp)
target_link_libraries(format PRIVATE kernel)

target_include_directories(basis INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
# ---- Target basis ------------------------------------------------------------

add_custom_target(basis
DEPENDS format
COMMAND ${CMAKE_COMMAND} -DREPOSITORY_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/basis/configure.cmake)

# ---- Target shell ------------------------------------------------------------

add_executable(shell)

add_dependencies(shell basis)

target_sources(shell PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)

target_link_libraries(shell PRIVATE kernel
PRIVATE basis)
target_link_libraries(shell PRIVATE kernel)

set_target_properties(shell PROPERTIES OUTPUT_NAME ${PROJECT_NAME} # Rename shell => meevax
LINK_FLAGS_RELEASE -s)
Expand Down Expand Up @@ -189,8 +186,7 @@ file(GLOB ${PROJECT_NAME}_TEST_CPP ${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp)
foreach(EACH IN LISTS ${PROJECT_NAME}_TEST_CPP)
get_filename_component(FILENAME ${EACH} NAME_WE)
add_executable(assert-${FILENAME} ${EACH})
target_link_libraries(assert-${FILENAME} PRIVATE kernel
PRIVATE basis)
target_link_libraries(assert-${FILENAME} PRIVATE kernel)
add_test(NAME assert-${FILENAME}
COMMAND ${${PROJECT_NAME}_MEMORY_CHECK_COMMAND}
${${PROJECT_NAME}_MEMORY_CHECK_COMMAND_OPTIONS}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Subset of R7RS-small.
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.4.815_amd64.deb
sudo apt install build/meevax_0.4.816_amd64.deb
```

or
Expand Down Expand Up @@ -106,9 +106,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.4.815.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.4.816.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.4.815_amd64.deb`
| `package` | Generate debian package `meevax_0.4.816_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.815
0.4.816
12 changes: 12 additions & 0 deletions basis/configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
file(GLOB ${PROJECT_NAME}_BASIS_SOURCES ${REPOSITORY_ROOT}/basis/*.ss)

foreach(EACH IN LISTS ${PROJECT_NAME}_BASIS_SOURCES)
get_filename_component(FILENAME ${EACH} NAME)
execute_process(
COMMAND ${REPOSITORY_ROOT}/build/bin/format ${EACH}
OUTPUT_VARIABLE CONFIGURED_${FILENAME})
endforeach()

configure_file(
${REPOSITORY_ROOT}/configure/basis.hpp
${REPOSITORY_ROOT}/include/meevax/basis/scheme.hpp)
46 changes: 23 additions & 23 deletions configure/basis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ inline namespace kernel
constexpr auto basis()
{
return make_array(
R"##(${${PROJECT_NAME}_BASIS_meevax.ss})##",
R"##(${${PROJECT_NAME}_BASIS_r4rs-essential.ss})##",
R"##(${${PROJECT_NAME}_BASIS_r4rs.ss})##",
R"##(${${PROJECT_NAME}_BASIS_r5rs.ss})##",
R"##(${${PROJECT_NAME}_BASIS_r7rs.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-0.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-1.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-4.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-6.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-8.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-9.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-11.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-16.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-23.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-31.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-34.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-38.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-39.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-45.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-78.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-98.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-111.ss})##",
R"##(${${PROJECT_NAME}_BASIS_srfi-149.ss})##");
R"##(${CONFIGURED_meevax.ss})##",
R"##(${CONFIGURED_r4rs-essential.ss})##",
R"##(${CONFIGURED_r4rs.ss})##",
R"##(${CONFIGURED_r5rs.ss})##",
R"##(${CONFIGURED_r7rs.ss})##",
R"##(${CONFIGURED_srfi-0.ss})##",
R"##(${CONFIGURED_srfi-1.ss})##",
R"##(${CONFIGURED_srfi-4.ss})##",
R"##(${CONFIGURED_srfi-6.ss})##",
R"##(${CONFIGURED_srfi-8.ss})##",
R"##(${CONFIGURED_srfi-9.ss})##",
R"##(${CONFIGURED_srfi-11.ss})##",
R"##(${CONFIGURED_srfi-16.ss})##",
R"##(${CONFIGURED_srfi-23.ss})##",
R"##(${CONFIGURED_srfi-31.ss})##",
R"##(${CONFIGURED_srfi-34.ss})##",
R"##(${CONFIGURED_srfi-38.ss})##",
R"##(${CONFIGURED_srfi-39.ss})##",
R"##(${CONFIGURED_srfi-45.ss})##",
R"##(${CONFIGURED_srfi-78.ss})##",
R"##(${CONFIGURED_srfi-98.ss})##",
R"##(${CONFIGURED_srfi-111.ss})##",
R"##(${CONFIGURED_srfi-149.ss})##");
}
} // namespace kernel
} // namespace meevax
Expand Down
29 changes: 29 additions & 0 deletions src/format.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2018-2023 Tatsuya Yamasaki.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <meevax/kernel/input_file_port.hpp>

auto main(int const, char const* const* const argv) -> int
{
using namespace meevax;

for (let const& x : input_file_port(argv[1]))
{
std::cout << x << std::flush;
}

return EXIT_SUCCESS;
}

0 comments on commit 2427e64

Please sign in to comment.