aboutsummaryrefslogtreecommitdiff
path: root/example/turing/src/state.h
diff options
context:
space:
mode:
Diffstat (limited to 'example/turing/src/state.h')
-rw-r--r--example/turing/src/state.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/example/turing/src/state.h b/example/turing/src/state.h
index f5bd7f2..51fe347 100644
--- a/example/turing/src/state.h
+++ b/example/turing/src/state.h
@@ -9,12 +9,26 @@ namespace machine {
namespace state {
-struct field {
+namespace 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_accessor state)
+// (lambda (field)
+// (nth field state)))
+template <typename State>
+struct state_accessor {
+ static_assert(
+ tav::IsPair<State>::value,
+ "machine state is invalid"
+ );
+
+ template <typename Field>
+ using get = tav::Nth<Field, State>;
};
// (define (state_predicate id read)
@@ -54,7 +68,9 @@ struct transition {
typename State,
typename Symbol
>
- using state = findState<State, Symbol, States>;
+ using state = state_accessor<
+ findState<State, Symbol, States>
+ >;
};
}