-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.hpp
55 lines (40 loc) · 1.04 KB
/
memory.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include "common/macros.hpp"
#include "common/list.hpp"
#include "common/string.hpp"
#include "turing-machine/tape.hpp"
namespace meta {
namespace brainfuck {
using initial_memory = meta::turing::tape<chr<>, list<>, list<>, chr<>>;
template <typename c>
struct __inc_chr;
template <char c>
struct __inc_chr<chr<c>> {
using result = chr<c+1>;
};
template <>
struct __inc_chr<chr<(char)255>> {
using result = chr<>;
};
CREATE_ALIAS(_inc_chr);
using inc_chr = lambda<_inc_chr>;
template <typename c>
struct __dec_chr;
template <char c>
struct __dec_chr<chr<c>> {
using result = chr<c-1>;
};
template <>
struct __dec_chr<chr<(char)0>> {
using result = chr<(char)255>;
};
CREATE_ALIAS(_dec_chr);
using dec_chr = lambda<_dec_chr>;
template <typename mem>
using _inc_cursor = typename mem::template set<call<inc_chr, typename mem::get>>;
using inc_cursor = lambda<_inc_cursor>;
template <typename mem>
using _dec_cursor = typename mem::template set<call<dec_chr, typename mem::get>>;
using dec_cursor = lambda<_dec_cursor>;
}
}