aboutsummaryrefslogtreecommitdiff
path: root/example/turing/src/state.h
blob: f5bd7f2807f9d446d35a226b384ff2b564a16d79 (plain)
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
56
57
58
59
60
61
62
63
64
#ifndef TYPEASVALUE_EXAMPLE_TURING_SRC_STATE_H_
#define TYPEASVALUE_EXAMPLE_TURING_SRC_STATE_H_

#include "type.h"
#include "list/list.h"
#include "list/operation/higher/find.h"

namespace machine {

namespace state {

struct field {
	using ID    = tav::Size<0>;
	using READ  = tav::Size<1>;
	using WRITE = tav::Size<2>;
	using NEXT  = tav::Size<3>;
	using MOVE  = tav::Size<4>;
};

// (define (state_predicate id read)
//   (lambda (state)
//           (and (= id   (nth ID   state))
//                (= read (nth READ state)))))
template <
	typename Id,
	typename Read
>
struct state_predicate {
	template <typename State>
	using function = tav::And<
		tav::IsEqualValue<Id,   tav::Nth<field::ID,   State>>,
		tav::IsEqualValue<Read, tav::Nth<field::READ, State>>
	>;
};

// (define (findState id read states)
//   (find (state_predicate id read) states))
template <
	typename Id,
	typename Read,
	typename States
>
using findState = tav::Find<
	state_predicate<Id, Read>::template function,
	States
>;

// (define (transition states)
//   (lambda (state symbol)
//           (findState state symbol states)))
template <typename States>
struct transition {
	template <
		typename State,
		typename Symbol
	>
	using state = findState<State, Symbol, States>;
};

}

}

#endif // TYPEASVALUE_EXAMPLE_TURING_SRC_STATE_H_