1 module bf_test;
2 /*
3 import bf_parser;
4 
5 bool checkNoRepeat (const RepeatedToken[] src) {
6 	BFTokenEnum last = src[0].token;
7 	foreach(rt;src[1 .. $]) {
8 		if (rt.token == last) {
9 			return false;
10 		} else {
11 			last = rt.token;
12 		}
13 	}
14 	
15 	return true;
16 }
17 */
18 enum helloWorldBf = `
19 ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
20 `;
21 import bf_executor;
22 
23 
24 string bf_to_code(string bf_src)
25 {
26     import bf_parser;
27     import bf_compiler;
28 
29     const RepeatedToken[] parsed = parseBf(bf_src);
30     return genCode(parsed, TargetEnum.AnonymousFunction);
31 }
32 
33 static assert(execute!helloWorldBf == cast(ubyte[]) "Hello World!\n");
34 auto hw = execute!helloWorldBf;
35 enum fbIntSource = `
36 >>>,[->+>+<<]>>[-<<+>>]>++++[<++++++++>-]<+<[->>+>>+<<<<]>>>>[-<<<<+>>
37 >>]<<<[->>+>+<<<]>>>[-<<<+>>>]<<[>[->+<]<[-]]>[-]>[[-]<<<<->-<[->>+>>+
38 <<<<]>>>>[-<<<<+>>>>]<<<[->>+>+<<<]>>>[-<<<+>>>]<<[>[->+<]<[-]]>[-]>]<
39 <<<[->>+<<]>[->+<]>[[-]<<<[->+>+<<]>>[-<<+>>]>++++++[<+++++++>-]<+<[->
40 >>+>+<<<<]>>>>[-<<<<+>>>>]<<<[->+>>+<<<]>>>[-<<<+>>>]<[<[->>+<<]>[-]]<
41 [-]>>[[-]<<<<->-<[->>>+>+<<<<]>>>>[-<<<<+>>>>]<<<[->+>>+<<<]>>>[-<<<+>
42 >>]<[<[->>+<<]>[-]]<[-]>>]<<<<[->>>+<<<]>[->>+<<]>+>[<->[-]]<[<<<<+>>>
43 >[-]]<<<[->+>+<<]>>[-<<+>>]>+++++[<+++++++++>-]<<[->>>+>+<<<<]>>>>[-<<
44 <<+>>>>]<<<[->+>>+<<<]>>>[-<<<+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]]]]]]]<[[-][-]<[->+>+<
118 <]>>[-<<+>>]<<[[-<<<<<+>>>>>]>[-<<<<<+>>>>>]<<<<<<-]<<<<<<<<[-]>>>>>>>
119 >>[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<<<[->>>>>>>>>>+<+<<<<<<<<<]>>>>>>>>>[-
120 <<<<<<<<<+>>>>>>>>>]>[<[->>>>>+<<<<<]>[->>>>>+<<<<<]>>>>+>-]>>>[-<<<+>
121 +>>]<<[->>+<<]<<[[-<<<<<+>>>>>]>[-<<<<<+>>>>>]<<<<<<-]>[-<<<<<<+>>>>>>
122 ]<<<<<<[->>>>>>>+<<<<<<<]<<<[->>>>>>>>>+<<<<<<+<<<]>>>[-<<<+>>>]>>>>>>
123 [<[->>>>>+<<<<<]>[->>>>>+<<<<<]>[->>>>>+<<<<<]>>>+>-]>[[-]<+[<[-<<<<<+
124 >>>>>]>[-<<<<<+>>>>>]<<<<<<->>>[->>+<<<+>]<[->+<]>>>[-[-[-[-[-[-[-<<<+
125 >>>[<<<->>>[-]]]]]]]]]<<<[<->[-]]>[->>+<<<+>]<[->+<]>>>[-[-[-[-[-[-[-[
126 -<<<+>>>[<<<->>>[-]]]]]]]]]]<<<[<+>[-]]<]>[-]]<<[->>>>>+<<<<<]>>>>>+>[
127 -]]>>]`;
128 
129 enum addOne = ",+.";
130 static assert(execute!addOne(cast(ubyte[]) "a") == cast(ubyte[]) "b");
131 pragma(msg, cast(string) execute!helloWorldBf);