Skip to content

Commit

Permalink
Merge pull request #463 from yamacir-kit/boot
Browse files Browse the repository at this point in the history
Boot
  • Loading branch information
yamacir-kit authored Sep 28, 2023
2 parents c9d5970 + 2f14010 commit 854b0fb
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build
include/meevax/basis
include/meevax/unicode
src/kernel/basis.cpp
src/kernel/version.cpp
54 changes: 31 additions & 23 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,26 +60,18 @@ 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/basis.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/basis.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/version.cpp)

# ---- Target kernel -----------------------------------------------------------

add_library(kernel SHARED "")
add_library(kernel SHARED)

add_library(${PROJECT_NAME}::kernel ALIAS kernel)

file(GLOB_RECURSE ${PROJECT_NAME}_KERNEL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*/*.cpp)

target_sources(kernel PRIVATE ${${PROJECT_NAME}_KERNEL_SOURCES}
PRIVATE ${${PROJECT_NAME}_OBJECTS})
target_sources(kernel PRIVATE ${${PROJECT_NAME}_KERNEL_SOURCES})

target_include_directories(kernel PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -96,9 +85,27 @@ set_target_properties(kernel PROPERTIES OUTPUT_NAME ${PROJECT_NAME} # Rename lib
SOVERSION ${PROJECT_VERSION_MAJOR}
LINK_FLAGS_RELEASE -s)

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

add_executable(format)

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

target_link_libraries(format PRIVATE kernel)

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

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

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

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

add_dependencies(shell basis)

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

target_link_libraries(shell PRIVATE kernel)

Expand Down Expand Up @@ -178,6 +185,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})
add_dependencies(assert-${FILENAME} basis)
target_link_libraries(assert-${FILENAME} PRIVATE kernel)
add_test(NAME assert-${FILENAME}
COMMAND ${${PROJECT_NAME}_MEMORY_CHECK_COMMAND}
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.811_amd64.deb
sudo apt install build/meevax_0.4.818_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.811.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.4.818.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.4.811_amd64.deb`
| `package` | Generate debian package `meevax_0.4.818_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.811
0.4.818
17 changes: 17 additions & 0 deletions basis/configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
execute_process(
COMMAND git rev-parse --show-toplevel
COMMAND tr -d "\n"
OUTPUT_VARIABLE TOPLEVEL)

file(GLOB ${PROJECT_NAME}_BASIS_SOURCES ${TOPLEVEL}/basis/*.ss)

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

configure_file(
${TOPLEVEL}/configure/basis.hpp
${TOPLEVEL}/include/meevax/basis/scheme.hpp)
52 changes: 0 additions & 52 deletions configure/basis.cpp

This file was deleted.

62 changes: 62 additions & 0 deletions configure/basis.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
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.
*/

#ifndef INCLUDED_MEEVAX_KERNEL_BASIS_HPP
#define INCLUDED_MEEVAX_KERNEL_BASIS_HPP

#include <array>

namespace meevax
{
inline namespace kernel
{
template <typename... Ts>
constexpr auto make_array(Ts&&... xs) -> std::array<std::decay_t<std::common_type_t<Ts...>>, sizeof...(Ts)>
{
return { std::forward<decltype(xs)>(xs)... };
}

constexpr auto basis()
{
return make_array(
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

#endif // INCLUDED_MEEVAX_KERNEL_BASIS_HPP
1 change: 1 addition & 0 deletions example/example.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <meevax/basis/scheme.hpp>
#include <meevax/kernel/environment.hpp>

using namespace meevax; // NOTE: DIRTY HACK
Expand Down
15 changes: 15 additions & 0 deletions include/meevax/kernel/boot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@
#ifndef INCLUDED_MEEVAX_KERNEL_BOOT_HPP
#define INCLUDED_MEEVAX_KERNEL_BOOT_HPP

#include <meevax/kernel/environment.hpp>
#include <meevax/kernel/interaction_environment.hpp>

namespace meevax
{
inline namespace kernel
{
auto boot() -> void;

template <typename Sources>
auto boot(Sources const& sources) -> void
{
for (auto&& source : sources)
{
for (let const& x : input_string_port(source))
{
interaction_environment().as<environment>().evaluate(x);
}
}
}
} // namespace kernel
} // namespace meevax

Expand Down
1 change: 0 additions & 1 deletion include/meevax/kernel/syntactic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <meevax/kernel/identity.hpp>
#include <meevax/kernel/implementation_dependent.hpp>
#include <meevax/kernel/include.hpp>
#include <meevax/kernel/list.hpp>
#include <meevax/kernel/transformer.hpp>

namespace meevax
Expand Down
21 changes: 10 additions & 11 deletions include/meevax/kernel/basis.hpp → src/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
limitations under the License.
*/

#ifndef INCLUDED_MEEVAX_KERNEL_BASIS_HPP
#define INCLUDED_MEEVAX_KERNEL_BASIS_HPP
#include <meevax/kernel/input_file_port.hpp>

#include <vector>

namespace meevax
{
inline namespace kernel
auto main(int const, char const* const* const argv) -> int
{
auto basis() -> std::vector<char const*>;
} // namespace kernel
} // namespace meevax
using namespace meevax;

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

#endif // INCLUDED_MEEVAX_KERNEL_BASIS_HPP
return EXIT_SUCCESS;
}
11 changes: 0 additions & 11 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <filesystem>
#include <numeric>

#include <meevax/kernel/basis.hpp>
#include <meevax/kernel/binary_input_file_port.hpp>
#include <meevax/kernel/binary_output_file_port.hpp>
#include <meevax/kernel/boot.hpp>
Expand Down Expand Up @@ -1574,16 +1573,6 @@ inline namespace kernel
xs[1].as<textual_output_port>().write_simple(xs[0]);
});
});

auto boot_loader = environment();

for (auto each : basis())
{
for (let const& x : input_string_port(each))
{
boot_loader.evaluate(x);
}
}
}
} // namespace kernel
} // namespace meevax
Loading

0 comments on commit 854b0fb

Please sign in to comment.