Skip to content

Commit

Permalink
Merge pull request #477 from yamacir-kit/memory
Browse files Browse the repository at this point in the history
Memory
  • Loading branch information
yamacir-kit authored Mar 24, 2024
2 parents 0a5a681 + a891dda commit 9fc5978
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 747 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS
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_RELEASE "-O2 -DNDEBUG ${AGGRESSIVE_OPTIMIZATION_OPTIONS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gdwarf-4 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG ${AGGRESSIVE_OPTIMIZATION_OPTIONS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-4")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.140_amd64.deb
sudo apt install build/meevax_0.5.157_amd64.deb
```

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

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.140.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.157.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.140_amd64.deb`
| `package` | Generate debian package `meevax_0.5.157_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.5.140
0.5.157
4 changes: 2 additions & 2 deletions include/meevax/kernel/dynamic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ inline namespace kernel
* where <closure> = (c' . e)
*
* ----------------------------------------------------------------- */
s = cons(make<closure, simple_allocator<void>>(cadr(c), e), s);
s = cons(make<closure, allocator<void>>(cadr(c), e), s);
c = cddr(c);
goto fetch;

Expand All @@ -216,7 +216,7 @@ inline namespace kernel
* where <continuation> = (s e c' . d)
*
* ----------------------------------------------------------------- */
s = cons(list(make<continuation, simple_allocator<void>>(s, cons(e, cons(cadr(c), d)))), s);
s = cons(list(make<continuation, allocator<void>>(s, cons(e, cons(cadr(c), d)))), s);
c = cddr(c);
goto fetch;

Expand Down
52 changes: 33 additions & 19 deletions include/meevax/kernel/pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@
#ifndef INCLUDED_MEEVAX_KERNEL_PAIR_HPP
#define INCLUDED_MEEVAX_KERNEL_PAIR_HPP

#include <meevax/functional/compose.hpp>
#include <meevax/kernel/character.hpp>
#include <meevax/kernel/instruction.hpp>
#include <meevax/memory/gc_pointer.hpp>
#include <meevax/memory/allocator.hpp>
#include <meevax/memory/collector.hpp>

namespace meevax
{
inline namespace kernel
{
using null = std::nullptr_t;

struct pair;

using object = gc_pointer<pair, bool, int, float, character, instruction>;
using default_collector = collector<pair, bool, int, float, character, instruction>;

using object = default_collector::mutator;

using let = object;

Expand All @@ -36,36 +42,37 @@ inline namespace kernel
template <typename T, typename Allocator, typename... Ts>
auto make(Ts&&... xs) -> decltype(auto)
{
return object::make<T, Allocator>(std::forward<decltype(xs)>(xs)...);
return default_collector::make<T, Allocator>(std::forward<decltype(xs)>(xs)...);
}

template <typename T, typename... Ts>
auto make(Ts&&... xs) -> decltype(auto)
{
if constexpr (std::is_same_v<T, pair>) {
return object::make<T, simple_allocator<void>>(std::forward<decltype(xs)>(xs)...);
return default_collector::make<T, allocator<void>>(std::forward<decltype(xs)>(xs)...);
} else {
return object::make<T, collector::default_allocator<void>>(std::forward<decltype(xs)>(xs)...);
return default_collector::make<T, std::allocator<void>>(std::forward<decltype(xs)>(xs)...);
}
}

template <typename T,
typename Allocator = collector::default_allocator<void>>
typename Allocator = std::allocator<void>>
auto make(T&& x) -> decltype(auto)
{
return object::make<std::decay_t<T>, Allocator>(std::forward<decltype(x)>(x));
return default_collector::make<std::decay_t<T>, Allocator>(std::forward<decltype(x)>(x));
}

template <template <typename...> typename Traits,
typename Allocator = collector::default_allocator<void>,
typename Allocator = std::allocator<void>,
typename... Ts,
REQUIRES(std::is_constructible<typename Traits<Ts...>::type, Ts...>)>
auto make(Ts&&... xs) -> decltype(auto)
{
return make<typename Traits<Ts...>::type, Allocator>(std::forward<decltype(xs)>(xs)...);
}

struct pair : public std::pair<object, object>
struct pair : public virtual default_collector::top
, public std::pair<object, object>
{
template <auto Const>
struct forward_iterator
Expand Down Expand Up @@ -139,45 +146,52 @@ inline namespace kernel

using const_iterator = forward_iterator<true>;

constexpr pair() = default;
pair() = default;

template <typename T, typename U = std::nullptr_t, REQUIRES(std::is_constructible<std::pair<object, object>, T, U>)>
explicit pair(T&& x, U&& y = nullptr)
: std::pair<object, object> { std::forward<decltype(x)>(x), std::forward<decltype(y)>(y) }
{}

virtual auto compare(pair const*) const -> bool;
~pair() override = default;

auto compare(top const*) const -> bool override;

virtual auto type() const noexcept -> std::type_info const&;
auto type() const noexcept -> std::type_info const& override;

virtual auto write(std::ostream &) const -> std::ostream &;
auto write(std::ostream &) const -> std::ostream & override;

auto view() const noexcept -> memory::view override
{
return { this, sizeof(*this) };
}

constexpr auto begin() noexcept
auto begin() noexcept
{
return iterator(this);
}

constexpr auto begin() const noexcept
auto begin() const noexcept
{
return const_iterator(this);
}

constexpr auto end() noexcept
auto end() noexcept
{
return iterator(nullptr);
}

constexpr auto end() const noexcept
auto end() const noexcept
{
return const_iterator(nullptr);
}

constexpr auto cbegin() const -> const_iterator
auto cbegin() const -> const_iterator
{
return std::as_const(*this).begin();
}

constexpr auto cend() const noexcept
auto cend() const noexcept
{
return std::as_const(*this).end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
limitations under the License.
*/

#ifndef INCLUDED_MEEVAX_MEMORY_SIMPLE_ALLOCATOR_HPP
#define INCLUDED_MEEVAX_MEMORY_SIMPLE_ALLOCATOR_HPP
#ifndef INCLUDED_MEEVAX_MEMORY_ALLOCATOR_HPP
#define INCLUDED_MEEVAX_MEMORY_ALLOCATOR_HPP

#include <cstddef>
#include <cstdint>
Expand All @@ -30,7 +30,7 @@ inline namespace memory
Simple Segregated Storage Allocator
*/
template <typename T, typename Capacity = std::integral_constant<std::size_t, 1024>>
class simple_allocator
class allocator
{
struct alignas(T) chunk
{
Expand Down Expand Up @@ -80,25 +80,25 @@ class simple_allocator
template <typename U>
struct rebind
{
using other = simple_allocator<U, Capacity>;
using other = allocator<U, Capacity>;
};

explicit simple_allocator()
explicit allocator()
: free_space { new block() }
{}

simple_allocator(simple_allocator &&) = delete;
allocator(allocator &&) = delete;

simple_allocator(simple_allocator const&) = delete;
allocator(allocator const&) = delete;

~simple_allocator()
~allocator()
{
delete free_space;
}

auto operator =(simple_allocator &&) -> simple_allocator & = delete;
auto operator =(allocator &&) -> allocator & = delete;

auto operator =(simple_allocator const&) -> simple_allocator & = delete;
auto operator =(allocator const&) -> allocator & = delete;

auto allocate(size_type = 1)
{
Expand Down Expand Up @@ -126,4 +126,4 @@ class simple_allocator
} // namespace memory
} // namespace meevax

#endif // INCLUDED_MEEVAX_MEMORY_SIMPLE_ALLOCATOR_HPP
#endif // INCLUDED_MEEVAX_MEMORY_ALLOCATOR_HPP
Loading

0 comments on commit 9fc5978

Please sign in to comment.