diff options
author | Adrian Kummerlaender | 2015-02-21 17:27:52 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-02-21 17:27:52 +0100 |
commit | c15edae4532f53e7e5bac9dae125c360d93f848d (patch) | |
tree | 58a3ded412834ba730aea9ebe6874e4ee4920975 /example/turing/src/state.h | |
parent | effddfdd69cf9e5ec700aeda2980c0210575e320 (diff) | |
download | TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.gz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.bz2 TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.lz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.xz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.zst TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.zip |
Separated Turing machine implementation into components
* i.e. separate namespaces and headers for _Tape_ and _State_ functions
* `void` is now used as the `BLANK` field value
Diffstat (limited to 'example/turing/src/state.h')
-rw-r--r-- | example/turing/src/state.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/example/turing/src/state.h b/example/turing/src/state.h new file mode 100644 index 0000000..f5bd7f2 --- /dev/null +++ b/example/turing/src/state.h @@ -0,0 +1,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_ |