Skip to content

Commit c14bad8

Browse files
author
Jacek Galowicz
committed
Update README.md
1 parent 145d57a commit c14bad8

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

README.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,49 @@ For practise reasons, i implemented this Brainfuck Interpreter on a long train r
44
It works completely at compile time, as it is implemented in a purely functional way, expressed in C++ Template Language.
55

66
The program and user input is provided via type lists, and the output is a type list again.
7-
The output string, as well as the Brainfuck Machine state can be printed as a compiler error message.
8-
Of course, it would also be possible to write code which prints the output on the terminal, when the compiled program is being run.
7+
The output string, as well as the Brainfuck Machine state can be printed as a compiler error message, or on the terminal when launching the program after compilation.
98

109
## Usage
1110

12-
The program is encoded like this in the source code:
13-
``` c++
14-
using input_list = char_tl_t<'a', 'b', 'c'>;
15-
using prog = char_tl_t<'+', '+', '+', '[', '.', '-', ']'>;
16-
17-
using BFM = bfm::io_bfm<bfm::make_t, input_list, tl::null_t>;
18-
19-
debug_t<bfm::run_tm_t<BFM, prog>::output> t;
11+
Program and user input are provided via preprocessor macros on the command line:
12+
``` bash
13+
Jacek.Galowicz ~/src/tmp_brainfuck $ g++ -o main main.cpp -std=c++14 -DINPUT_STR=\"z\" -DPROGRAM_STR=\",[.-]\"
14+
Jacek.Galowicz ~/src/tmp_brainfuck $ ./main
15+
zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
2016
```
2117
22-
The following is the (barely readable, but correct) output:
18+
The brainfuck program output can also be printed at compile time, by producing an error message with the helper type ```debug_t```:
2319
2420
``` bash
25-
Jacek.Galowicz ~/src/tmp_brainfuck $ g++ -o main main.cpp -std=c++14
26-
main.cpp:17:47: error: implicit instantiation of undefined template 'debug_t<tl::tl<char_t<'\x03'>, tl::tl<char_t<'\x02'>, tl::tl<char_t<'\x01'>, tl::null_t> > > >'
21+
Jacek.Galowicz ~/src/tmp_brainfuck $ g++ -o main main.cpp -std=c++14 -DINPUT_STR=\"z\" -DPROGRAM_STR=\",[.-]\"
22+
main.cpp:39:47: error: implicit instantiation of undefined template 'debug_t<tl::tl<char_t<'z'>, tl::tl<char_t<'y'>, tl::tl<char_t<'x'>, tl::tl<char_t<'w'>, tl::tl<char_t<'v'>, tl::tl<char_t<'u'>,
23+
tl::tl<char_t<'t'>, tl::tl<char_t<'s'>, tl::tl<char_t<'r'>, tl::tl<char_t<'q'>, tl::tl<char_t<'p'>, tl::tl<char_t<'o'>, tl::tl<char_t<'n'>, tl::tl<char_t<'m'>, tl::tl<char_t<'l'>,
24+
tl::tl<char_t<'k'>, tl::tl<char_t<'j'>, tl::tl<char_t<'i'>, tl::tl<char_t<'h'>, tl::tl<char_t<'g'>, tl::tl<char_t<'f'>, tl::tl<char_t<'e'>, tl::tl<char_t<'d'>, tl::tl<char_t<'c'>,
25+
tl::tl<char_t<'b'>, tl::tl<char_t<'a'>, tl::tl<char_t<'`'>, tl::tl<char_t<'_'>, tl::tl<char_t<'^'>, tl::tl<char_t<']'>, tl::tl<char_t<'\\'>, tl::tl<char_t<'['>, tl::tl<char_t<'Z'>,
26+
tl::tl<char_t<'Y'>, tl::tl<char_t<'X'>, tl::tl<char_t<'W'>, tl::tl<char_t<'V'>, tl::tl<char_t<'U'>, tl::tl<char_t<'T'>, tl::tl<char_t<'S'>, tl::tl<char_t<'R'>, tl::tl<char_t<'Q'>,
27+
tl::tl<char_t<'P'>, tl::tl<char_t<'O'>, tl::tl<char_t<'N'>, tl::tl<char_t<'M'>, tl::tl<char_t<'L'>, tl::tl<char_t<'K'>, tl::tl<char_t<'J'>, tl::tl<char_t<'I'>, tl::tl<char_t<'H'>,
28+
tl::tl<char_t<'G'>, tl::tl<char_t<'F'>, tl::tl<char_t<'E'>, tl::tl<char_t<'D'>, tl::tl<char_t<'C'>, tl::tl<char_t<'B'>, tl::tl<char_t<'A'>, tl::tl<char_t<'@'>, tl::tl<char_t<'?'>,
29+
tl::tl<char_t<'>'>, tl::tl<char_t<'='>, tl::tl<char_t<'<'>, tl::tl<char_t<';'>, tl::tl<char_t<':'>, tl::tl<char_t<'9'>, tl::tl<char_t<'8'>, tl::tl<char_t<'7'>, tl::tl<char_t<'6'>,
30+
tl::tl<char_t<'5'>, tl::tl<char_t<'4'>, tl::tl<char_t<'3'>, tl::tl<char_t<'2'>, tl::tl<char_t<'1'>, tl::tl<char_t<'0'>, tl::tl<char_t<'/'>, tl::tl<char_t<'.'>, tl::tl<char_t<'-'>,
31+
tl::tl<char_t<','>, tl::tl<char_t<'+'>, tl::tl<char_t<'*'>, tl::tl<char_t<')'>, tl::tl<char_t<'('>, tl::tl<char_t<'\''>, tl::tl<char_t<'&'>, tl::tl<char_t<'%'>, tl::tl<char_t<'$'>,
32+
tl::tl<char_t<'#'>, tl::tl<char_t<'\"'>, tl::tl<char_t<'!'>, tl::tl<char_t<' '>, tl::tl<char_t<'\x1F'>, tl::tl<char_t<'\x1E'>, tl::tl<char_t<'\x1D'>, tl::tl<char_t<'\x1C'>,
33+
tl::tl<char_t<'\x1B'>, tl::tl<char_t<'\x1A'>, tl::tl<char_t<'\x19'>, tl::tl<char_t<'\x18'>, tl::tl<char_t<'\x17'>, tl::tl<char_t<'\x16'>, tl::tl<char_t<'\x15'>, tl::tl<char_t<'\x14'>,
34+
tl::tl<char_t<'\x13'>, tl::tl<char_t<'\x12'>, tl::tl<char_t<'\x11'>, tl::tl<char_t<'\x10'>, tl::tl<char_t<'\x0F'>, tl::tl<char_t<'\x0E'>, tl::tl<char_t<'\x0D'>, tl::tl<char_t<'\x0C'>,
35+
tl::tl<char_t<'\x0B'>, tl::tl<char_t<'\n'>, tl::tl<char_t<'\t'>, tl::tl<char_t<'\x08'>, tl::tl<char_t<'\x07'>, tl::tl<char_t<'\x06'>, tl::tl<char_t<'\x05'>, tl::tl<char_t<'\x04'>,
36+
tl::tl<char_t<'\x03'>, tl::tl<char_t<'\x02'>, tl::tl<char_t<'\x01'>, tl::null_t> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
37+
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
2738
debug_t<bfm::run_tm_t<BFM, prog>::output> t;
2839
^
29-
main.cpp:8:29: note: template is declared here
40+
main.cpp:7:29: note: template is declared here
3041
template <typename T> class debug_t;
3142
^
3243
1 error generated.
3344
```
3445
35-
The "Hello World" output looks like this:
46+
The "Hello World" example looks like this:
3647
3748
``` bash
38-
Jacek.Galowicz ~/src/tmp_brainfuck $ g++ -o main main.cpp -std=c++14
39-
main.cpp:25:47: error: implicit instantiation of undefined template 'debug_t<tl::tl<char_t<'H'>, tl::tl<char_t<'e'>, tl::tl<char_t<'l'>, tl::tl<char_t<'l'>, tl::tl<char_t<'o'>, tl::tl<char_t<' '>, tl::tl<char_t<'W'>, tl::tl<char_t<'o'>, tl::tl<char_t<'r'>,
40-
tl::tl<char_t<'l'>, tl::tl<char_t<'d'>, tl::tl<char_t<'!'>, tl::tl<char_t<'\n'>, tl::null_t> > > > > > > > > > > > > >'
41-
debug_t<bfm::run_tm_t<BFM, prog>::output> t;
42-
^
43-
main.cpp:8:29: note: template is declared here
44-
template <typename T> class debug_t;
45-
^
46-
1 error generated.
49+
Jacek.Galowicz ~/src/tmp_brainfuck $ g++ -o main main.cpp -std=c++14 -DPROGRAM_STR='"++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.+++."'
50+
Jacek.Galowicz ~/src/tmp_brainfuck $ ./main
51+
Hello World!
4752
```

0 commit comments

Comments
 (0)