#include #include "list/generator/make_list.h" #include "runtime/list/for_each.h" #include "src/machine.h" using BLANK = machine::tape::BLANK; // (define mirror (list (list 1 1 0 2 'R') [...])) using mirror = tav::List< // [state] [read] [write] [next state] [head movement] tav::List, tav::Int<1>, tav::Int<0>, tav::Size<2>, tav::Char<'R'>>, tav::List, tav::Int<0>, tav::Int<0>, void, tav::Char<'N'> >, tav::List, tav::Int<1>, tav::Int<1>, tav::Size<2>, tav::Char<'R'>>, tav::List, tav::Int<0>, tav::Int<0>, tav::Size<3>, tav::Char<'R'>>, tav::List, tav::Int<1>, tav::Int<1>, tav::Size<3>, tav::Char<'R'>>, tav::List, tav::Int<0>, tav::Int<1>, tav::Size<4>, tav::Char<'L'> >, tav::List, tav::Int<1>, tav::Int<1>, tav::Size<4>, tav::Char<'L'> >, tav::List, tav::Int<0>, tav::Int<0>, tav::Size<5>, tav::Char<'L'> >, tav::List, tav::Int<1>, tav::Int<1>, tav::Size<5>, tav::Char<'L'> >, tav::List, tav::Int<0>, tav::Int<1>, tav::Size<1>, tav::Char<'R'>> >; // (define busy_beaver (list (list 'A' 0 1 'B' 'R') [...])) using busy_beaver = tav::List< // [state] [read] [write] [next state] [head movement] tav::List, tav::Int<0>, tav::Int<1>, tav::Char<'B'>, tav::Char<'R'>>, tav::List, tav::Int<1>, tav::Int<1>, tav::Char<'C'>, tav::Char<'L'> >, tav::List, tav::Int<0>, tav::Int<1>, tav::Char<'A'>, tav::Char<'L'> >, tav::List, tav::Int<1>, tav::Int<1>, tav::Char<'B'>, tav::Char<'R'>>, tav::List, tav::Int<0>, tav::Int<1>, tav::Char<'B'>, tav::Char<'L'> >, tav::List, tav::Int<1>, tav::Int<1>, void, tav::Char<'N'> > >; // (define binary_increment (list (list 0 '() '() 1 'L') [...])) using binary_increment = tav::List< // [state] [read] [write] [next state] [head movement] tav::List, BLANK, BLANK, tav::Size<1>, tav::Char<'L'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<0>, tav::Char<'R'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<0>, tav::Char<'R'>>, tav::List, BLANK, tav::Boolean, tav::Size<2>, tav::Char<'R'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'L'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<1>, tav::Char<'L'>>, tav::List, BLANK, BLANK, void, tav::Char<'L'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'R'>>, tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'R'>> >; const auto printField = [](const auto x) { std::cout << x; }; template void printStates() { // (define position (car (head states))) using position = tav::Car>; // (define tape (cdr (head states))) using tape = tav::Cdr>; // (define prefix (make-list 3 " ")) using prefix = tav::MakeList, tav::Char<' '>>; // (for-each printField (concatenate prefix tape)) tav::runtime::for_each>(printField); std::cout << std::endl; // (for-each printField // (concatenate prefix // (make-list position " ") // (list "^"))) tav::runtime::for_each>, tav::List> >>(printField); std::cout << std::endl; printStates>(); } template <> void printStates() { } int main(int, char **) { // (define mirror_tape (list 1 1 1 0 0 0 0)) using mirror_tape = tav::ListOfType; std::cout << "1. Mirror" << std::endl; printStates< // (run mirror 1 mirror_tape 0) machine::run< mirror, tav::Size<1>, mirror_tape, tav::Size<0> > >(); // (define busy_beaver_tape (make-list 13 0)) using busy_beaver_tape = tav::MakeList, tav::Int<0>>; std::cout << "2. Busy Beaver" << std::endl; printStates< // (run busy_beaver "A" busy_beaver_tape 6) machine::run< busy_beaver, tav::Char<'A'>, busy_beaver_tape, tav::Size<6> > >(); // (define binary_increment_tape (list #t #f #t #f #t #f)) using binary_increment_tape = tav::ListOfType; std::cout << "3. Binary Increment" << std::endl; printStates< // (run binary_increment 0 binary_increment_tape 0) machine::run< binary_increment, tav::Size<0>, binary_increment_tape, tav::Size<0> > >(); }