├── .gitattributes ├── .gitignore ├── Cargo.toml ├── LICENSE ├── Makefile ├── README.md ├── bench.py ├── bf ├── bench.bf ├── hanoi.bf ├── hello.bf ├── hello2.bf ├── loop.bf └── mandelbrot.bf ├── bf_gen.py ├── comp.py └── src ├── bf_types.rs ├── interpreter ├── interp.rs ├── interp_1.rs ├── interp_2.rs ├── interp_3.rs ├── interp_4.rs ├── interp_5.rs ├── interp_6.rs └── mod.rs ├── jit ├── aarch64_jit.rs ├── generic_jit.rs ├── mod.rs └── x64_jit.rs ├── main.rs ├── tests ├── mod.rs └── test_helper.rs └── transpiler ├── bf2c.rs ├── bf2js.rs └── mod.rs /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | /target 6 | 7 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 8 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 9 | Cargo.lock 10 | 11 | # These are backup files generated by rustfmt 12 | **/*.rs.bk 13 | 14 | # MSVC Windows builds of rustc generate these, which store debugging information 15 | *.pdb 16 | 17 | 18 | # Added by cargo 19 | 20 | /target 21 | 22 | *.out 23 | *.exe 24 | *.c 25 | *.js 26 | *.tmp 27 | 28 | 29 | *.json 30 | 31 | mandelbrot_clang 32 | mandelbrot_gcc -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "brainfuck" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | clap = { version = "4.5.7", features = ["derive"] } 10 | dynasm = "3.2.0" 11 | dynasmrt = "2.0.0" 12 | itertools = "0.13.0" 13 | 14 | lazy_static = "1.4.0" 15 | libc = "0.2.155" 16 | stdio-override = "0.1.3" 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Soiri Hiroka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | hanoi: 2 | cargo run --release -- -i bf/hanoi.bf 3 | 4 | hello: 5 | cargo run --release -- -i bf/hello.bf 6 | 7 | hello2: 8 | cargo run --release -- -i bf/hello2.bf 9 | 10 | bench: 11 | cargo run --release -- -i bf/bench.bf 12 | 13 | mandelbrot: 14 | cargo run --release -- -i bf/mandelbrot.bf 15 | 16 | test: 17 | cargo test -- --test-threads=1 18 | 19 | small_bf: 20 | gcc -m32 -o bf.exe bf.c -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -Wno-error=implicit-function-declaration -Wno-error=implicit-int -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bf-jit-rs 2 | 3 | bf-jit-rs is a JIT compiler/interpreter for the Brainfuck written in Rust. 4 | 5 | ## Prerequisites 6 | 7 | Before using bf-jit-rs, ensure you have the [Rust toolchain](https://www.rust-lang.org/learn/get-started). 8 | 9 | ## Build & Run 10 | 11 | To build and run a Brainfuck program with bf-jit-rs, use the following command: 12 | 13 | ``` 14 | cargo run --release -- -i path/to/program.bf 15 | ``` 16 | 17 | ## Get help 18 | 19 | ``` 20 | cargo run --release -- --help 21 | ``` -------------------------------------------------------------------------------- /bench.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import time 3 | import json 4 | import statistics 5 | from datetime import datetime 6 | 7 | def run_command_benchmark(command): 8 | timings = [] 9 | 10 | for _ in range(100): 11 | start_time = time.time() 12 | try: 13 | # Run the command as a subprocess 14 | subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 15 | except subprocess.CalledProcessError as e: 16 | print(f"Error while executing command: {e}") 17 | end_time = time.time() 18 | 19 | # Calculate the duration 20 | timings.append(end_time - start_time) 21 | 22 | # Calculate statistics 23 | timings.sort() 24 | min_time = min(timings) 25 | max_time = max(timings) 26 | mean_time = statistics.mean(timings) 27 | median_time = statistics.median(timings) 28 | p10_time = timings[int(len(timings) * 0.1)] 29 | p90_time = timings[int(len(timings) * 0.9)] 30 | # top_25_percent = timings[int(len(timings) * 0.75):] 31 | # bottom_25_percent = timings[:int(len(timings) * 0.25)] 32 | 33 | # Prepare JSON data 34 | results = { 35 | "command": command, 36 | "timings": timings, 37 | "statistics": { 38 | "min": min_time, 39 | "max": max_time, 40 | "mean": mean_time, 41 | "median": median_time, 42 | "10th_percentile": p10_time, 43 | "90th_percentile": p90_time, 44 | # "top_25_percent": top_25_percent, 45 | # "bottom_25_percent": bottom_25_percent 46 | } 47 | } 48 | 49 | # Generate a timestamped filename 50 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") 51 | filename = f"benchmark_results_{timestamp}.json" 52 | 53 | # Write to JSON file 54 | with open(filename, "w") as json_file: 55 | json.dump(results, json_file, indent=4) 56 | 57 | print(f"Benchmark results saved to {filename}") 58 | 59 | if __name__ == "__main__": 60 | import sys 61 | if len(sys.argv) != 2: 62 | print("Usage: python script.py ") 63 | else: 64 | command = sys.argv[1] 65 | run_command_benchmark(command) 66 | -------------------------------------------------------------------------------- /bf/bench.bf: -------------------------------------------------------------------------------- 1 | Benchmark brainf*ck program 2 | >++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ 3 | [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ 4 | ++++++++[>++++++++++[>++++++++++[>++++++++++[>+ 5 | +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++. 6 | -------------------------------------------------------------------------------- /bf/hanoi.bf: -------------------------------------------------------------------------------- 1 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[-]>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 | >>>>>>>>>>>>>[-]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[-]>>>>>>>>>>>>>>>> 4 | >>>>>>>>>>>>>>>>>>>>>>>>>[-]>[-]+++++++++++++++++++++++++++.++++++++++++++++ 5 | ++++++++++++++++++++++++++++++++++++++++++++++++.-------------------.------- 6 | --------------------------------------.+++++++++++++++++++++++++++++++++++++ 7 | +++++++++++++++++++++++++++.-----------------------------------------.++++++ 8 | ++++++++++++++++++.[-]+++++++++++++++++++++++++++.++++++++++++++++++++++++++ 9 | ++++++++++++++++++++++++++++++++++++++.------------------------------------- 10 | ----.+++++++++.---------.+++++.+++++++++++++++++.++++++++++++.++++++++++++++ 11 | +++++++++++++.++++++++.------------------.+++++++++++++.+.------------------ 12 | -----------------------------------------------------------------.++++++++++ 13 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------ 14 | ---.----------------------------------------------------------------------.+ 15 | +++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++.++++++++++ 16 | +++.+.------.--------------------------------------------------------------- 17 | ----------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 18 | ++++++++.+++++.------------------------------------------------------------- 19 | -----------------.++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++ 20 | +++++++++++++++++++++++++.-----------------.++++++++.+++++.--------.-------- 21 | ----------------------------------------------------.+++++++++++++++++++++++ 22 | ++++++++++++++++++++++++++++++++++.++++++++.[-]+++++++++++++++++++++++++++.+ 23 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------ 24 | ----------------------------.++++++++.----------.++++.+++++++++++++++++++.++ 25 | +++++++++++++.+++++++++++++++++++++++++++.---------.+++++++++++..----------- 26 | ----.+++++++++.------------------------------------------------------------- 27 | -----------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 28 | ++++++++.+++++++++++++++++++++++.------------------------------------------- 29 | ----------------------------------------------.+++++++++++++++++++++++++++++ 30 | ++++++.+++++++++++++++++++++++++++++++++++++++++.---.---..+++++++++.+++.---- 31 | ----------.----------------------------------------------------------------- 32 | ---.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++ 33 | ++++++++.---.------.-------------------------------------------------------- 34 | --------------.++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++ 35 | ++++++++++++.++++++++++++..----.-------------------------------------------- 36 | ----------.-----------..++++++++++++++++++++++++++++++++++++++++++++++++++++ 37 | ++++++++++++++++++++...----------------------------------------------------- 38 | --------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++.+ 39 | ++++++++.---.---..+++++++++.+++.--------------.----------------------------- 40 | -------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++ 41 | +.+++++++++++++++++++.------------------------------------------------------ 42 | ---------------.+++++++++++++++++++++++++++++++++++++++++++++++++++.++++.--- 43 | .+++++++++++++.+++++.------------------------------------------------------- 44 | ---------------.+++++++++++++++.[-]>[-]+++++++++>[-]+++>>[-]>[-]<<<<<[->>>>> 45 | +<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++<<[-]>>>[-]>[-]<<<[->>>+<<<]>>>[[-<< 46 | <+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>>+<<<] 47 | >>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<]>>[[- 48 | <<+>>]<<<[-]+>>>][-]<[->+<]>[[-<+>]<<<[-]+>>>]<<<[>[-]++++++++++++++++++++++ 49 | +++++++++++++++++++++++>[-]<<<<<[->>>>>+<<<<<]>>>>>[[-<<<<<+>>>>>]<+++++++++ 50 | ++++++++++++++++++++++++++++++++++>]<<<[>>>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<< 51 | ->>>][-]++++++++++++++++>[-]++++++++++++++>>>>[-]>[-]<<<<<<<<<[->>>>>>>>>+<< 52 | <<<<<<<]>>>>>>>>>[-<+<<<<<<<<+>>>>>>>>>][-]<<[-]+>>>[-]>[-]<<<[->>>+<<<]>>>[ 53 | [-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>>+ 54 | <<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<]> 55 | >[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<<[[-]<<<<+++++>>>>]>[-]>[- 56 | ]<<<<<<<<<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>[-<+<<<<<<<<+>>>>>>>>>][-]+<<[-]+>> 57 | >[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]< 58 | ]<[<<->->[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<< 59 | [-]+>>]<]<][-]<<[->>+<<]>>[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<< 60 | [[-]<<<++++++++++>>>][-]>[-]<<<<<<<<[->>>>>>>>+<<<<<<<<]>>>>>>>>[-<+<<<<<<<+ 61 | >>>>>>>>][-]+++++++++++++++++++++++++<<<[-]>>[>>[-]<[->+<]>[-<+<<<+>>>>]<<-] 62 | [-]<<[->>+<<]>>[-<<+<<+>>>>][-]<<<<<<<<[->>>>>>>>+<<<<<<<<]>>>>>>>>[-<<<<<<< 63 | <+>>>>->>>>][-]<<<<<<<<[->>>>>>>>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>->>>>]>[-] 64 | >[-]<<<<<<<<<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>[-<+<<<<<<<<+>>>>>>>>>][-]++<<[- 65 | ]+>>>[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+ 66 | >>]<]<[<<->->[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>> 67 | >]<<[-]+>>]<]<][-]<<[->>+<<]>>[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>> 68 | ]<<<[[-]<<<<----->>>>][-]<<<<<<<<<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<< 69 | +>>>>>>->>>][-]+++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++ 70 | +++++++++++++++++++++++++++++++.>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>> 71 | >>]>>>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++>[-]<<[>>>[ 72 | -]<<[->>+<<]>[-]>[-<<+>+>][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++++++++++++++++++++++++++++++++++++++.<+++++++++++++++++++++++++++++ 100 | +++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>-< 101 | ]>[[-]>[-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]<<<<+++++++++++++++++++++++ 102 | +++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++. 103 | >>>>>>-<]>[[-]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>>>] 104 | <<]<<<<<<--------------------------------.>[-]>[-]<<<<<<[->>>>>>+<<<<<<]>>>> 105 | >>[-<+<<<<<+>>>>>>]>>>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]+++++ 106 | +++++>[-]<<[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<< 107 | +>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+ 108 | <<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<]<<<]<<<[-] 109 | >>>>>>[-]<[->+<]>[[-<+>]>[-]<<<[->>>+<<<]>>>[-<<<+<<<<+>>>>>>>]<<[-<<<<<->>> 110 | >>]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++<<<<<[-]> 111 | >>>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[ 112 | -]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>> 113 | >[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-]<<[->>+<<] 114 | >>[[-<<+>>]<[-]>]<[[-]<<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<+>]>[-]<<<[->>>+<<<]>>>[- 128 | <<<+<<+>>>>>]<<[-<<<->>>]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>] 129 | [-]++++++++++<<<<<[-]>>>>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<< 130 | <<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]> 131 | [-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>] 132 | <]<][-]+>[-]<<[->>+<<]>>[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]<[->+<]>> 133 | [-]+<[[-<+>]<++++++++++++++++++++++++++++++++++++++++++++++++.<+++++++++++++ 134 | +++++++++++++++++++++++++++++++++++.<+++++++++++++++++++++++++++++++++++++++ 135 | +++++++++.>>>>-<]>[[-]>[-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]<<<<+++++++ 136 | +++++++++++++++++++++++++++++++++++++++++.<+++++++++++++++++++++++++++++++++ 137 | +++++++++++++++.>>>>>>-<]>[[-]<<<<<<++++++++++++++++++++++++++++++++++++++++ 138 | ++++++++.>>>>>>]<<]<<<<<<+++++++++++++.>[-]>[-]<<<<<<<[->>>>>>>+<<<<<<<]>>>> 139 | >>>[-<+<<<<<<+>>>>>>>][-]+++++++++++++++++++++++++++++++++++++++++++++++++++ 140 | +++++++++++++++++++++++++++++++++++++<<[-]+>>>[-]>[-]<<<[->>>+<<<]>>>[[-<<<+ 141 | >>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>>+<<<]>> 142 | >[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<]>>[[-<< 143 | +>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<[-]+<[[-]>>[-]++++++++++++++++++ 144 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 145 | ++++++++++++++++++++++++++.<-<]>[[-]<<<<<<.>>>>>>]<[-]<<<<<<<<[->>>>>>>>+<<< 146 | <<<<<]>>>>>>[-]>>[-<<<<<<<<+>>>>>>+>>][-]<<[->>+<<]>>[[-<<+>>]<<->>]<<[<<<.. 147 | >>>-]<<<.>>>>>[-]<<<<<<<<[->>>>>>>>+<<<<<<<<]>>>>>>[-]>>[-<<<<<<<<+>>>>>>+>> 148 | ][-]<<[->>+<<]>>[[-<<+>>]<<->>]<<[<<<..>>>-]>>>[-]>[-]<<<<<<<[->>>>>>>+<<<<< 149 | <<]>>>>>>>[-<+<<<<<<+>>>>>>>][-]++++++++++++++++++++++++++++++++++++++++++++ 150 | ++++++++++++++++++++++++++++++++++++++++++++<<[-]+>>>[-]>[-]<<<[->>>+<<<]>>> 151 | [[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>> 152 | +<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<] 153 | >>[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<[-]+<[[-]>>[-]+++++++++++ 154 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 155 | +++++++++++++++++++++++++++++++++.<-<]>[[-]<<<<<<.>>>>>>]<<<<<<<<]>>>[-]<<<< 156 | <[->>>>>+<<<<<]>>>>>[[-<<<<<+>>>>>]<<<<<<<[-]<[-]<[-]>>>>>>>>>>[-]<<<<<[->>> 157 | >>+<<<<<]>>>>>[-<<<<<+<<<+>>>>>>>>][-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 158 | <<<<<<<<<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443 | <<<<<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 444 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[-]>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<< 445 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>> 446 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 447 | >>>>>>>>>>>>>+>>>]<]<[->>>>[-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]>>[-]<< 448 | <<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>[-]>>>> 449 | >[-<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>+>>>>>][-]<<<<<<<<[->>>>>>>>+<<<<<<<<]>>> 450 | >[-]>>>>[-<<<<<<<<+>>>>+>>>>]<<<[-]++++++++++++++++++++++++++++++++>>-<]>[[- 451 | ]>[-]<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<]>>>>>>>>>>>[-]>>>>> 452 | [-<<<<<<<<<<<<<<<<+>>>>>>>>>>>+>>>>>][-]<<<<<<<[->>>>>>>+<<<<<<<]>>>[-]>>>>[ 453 | -<<<<<<<+>>>+>>>>]<<<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++ 454 | ++++++++++++++++++++++++++++++++++++>>]<[-]++++++++++++++++>[-]+++++++++++++ 455 | +>>>>[-]>[-]<<<<<<<<<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>[-<+<<<<<<<<+>>>>>>>>>][ 456 | -]<<[-]+>>>[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<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+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[ 471 | -]+>>]<]<][-]<<[->>+<<]>>[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<<[ 472 | [-]<<<<----->>>>][-]<<<<<<[->>>>>>+<<<<<<]>>>>>>[-<<<<<<+>>>->>>][-]++++++++ 473 | +++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 474 | ++++++++.>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>]>>>[-]>[-]<<<<<[->>> 475 | >>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++>[-]<<[>>>[-]<<[->>+<<]>[-]>[-<<+> 476 | +>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<< 477 | [-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<] 478 | >>>[[-<<<+>>>]<<[-]+>>]<]<]<<<]<<<[-]>>>>>>[-]<[->+<]>[[-<+>]>[-]<<<[->>>+<< 479 | <]>>>[-<<<+<<<<+>>>>>>>]<<[-<<<<<->>>>>]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>> 480 | [-<+<<<<+>>>>>][-]++++++++++<<<<<[-]>>>>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[ 481 | -]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]< 482 | ]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<< 483 | <+>>>]<<[-]+>>]<]<][-]+>[-]<<[->>+<<]>>[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]< 484 | <<][-]>[-]<<<<<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>]<<[-<<<->>>]>]<<<[-]>[-]<< 498 | <<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++<<<<<[-]>>>>[>>>[-]<<[->>+ 499 | <<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>> 500 | >[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[- 501 | ]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-]<<[->>+<<]>>[[-<<+>>]<[-]>] 502 | <[[-]<<<<<<<+>>>>>>>]<<<][-]<[->+<]>>[-]+<[[-<+>]<++++++++++++++++++++++++++ 503 | ++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++.<++ 504 | ++++++++++++++++++++++++++++++++++++++++++++++.>>>>-<]>[[-]>[-]<<<<[->>>>+<< 505 | <<]>>>>>[-]+<[[-<<<<+>>>>]<<<<++++++++++++++++++++++++++++++++++++++++++++++ 506 | ++.<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>>>-<]>[[-]<<<<<<+++ 507 | +++++++++++++++++++++++++++++++++++++++++++++.>>>>>>]<<]<<<<<<-------------- 508 | ------------------.>[-]>[-]<<<<<<[->>>>>>+<<<<<<]>>>>>>[-<+<<<<<+>>>>>>]>>>[ 509 | -]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++>[-]<<[>>>[-]<<[-> 510 | >+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<] 511 | >>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]> 512 | [-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<]<<<]<<<[-]>>>>>>[-]<[->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->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-]<<[->>+<<]>>[[-<<+> 527 | >]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>> 528 | >>][-]++++++++++>[-]<<[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<] 529 | >>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-] 530 | <<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]< 531 | ]<<<]<[-]>>>>[-]<[->+<]>[[-<+>]>[-]<<<[->>>+<<<]>>>[-<<<+<<+>>>>>]<<[-<<<->> 532 | >]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++<<<<<[-]>> 533 | >>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[- 534 | ]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>> 535 | [[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-]<<[->>+<<]> 536 | >[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]<[->+<]>>[-]+<[[-<+>]<++++++++++ 537 | ++++++++++++++++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++ 538 | ++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>-<]>[[-]> 539 | [-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]<<<<++++++++++++++++++++++++++++++ 540 | ++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>>>- 541 | <]>[[-]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++.>>>>>>]<<]<<<< 542 | <<+++++++++++++.>[-]>[-]<<<<<<<[->>>>>>>+<<<<<<<]>>>>>>>[-<+<<<<<<+>>>>>>>][ 543 | -]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 544 | ++++++++++++++<<[-]+>>>[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>> 545 | >[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->> 546 | >+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<]>>[[-<<+>>]<<<[-]>>>][-]<[->+< 547 | ]>[[-<+>]<<<[-]>>>]<<[-]+<[[-]>>[-]+++++++++++++++++++++++++++++++++++++++++ 548 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 549 | +++.<-<]>[[-]<<<<<<.>>>>>>]<[-]<<<<<<<<<<<[->>>>>>>>>>>+<<<<<<<<<<<]>>>>>>>> 550 | >[-]>>[-<<<<<<<<<<<+>>>>>>>>>+>>][-]<<[->>+<<]>>[[-<<+>>]<<->>]<<[<<<..>>>-] 551 | <<<.>>>>>[-]<<<<<<<<<<<[->>>>>>>>>>>+<<<<<<<<<<<]>>>>>>>>>[-]>>[-<<<<<<<<<<< 552 | +>>>>>>>>>+>>][-]<<[->>+<<]>>[[-<<+>>]<<->>]<<[<<<..>>>-]>>>[-]>[-]<<<<<<<[- 553 | >>>>>>>+<<<<<<<]>>>>>>>[-<+<<<<<<+>>>>>>>][-]+++++++++++++++++++++++++++++++ 554 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<[-]+>>>[-]>[-]<<< 555 | [->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[- 556 | ]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<] 557 | [-]<<[->>+<<]>>[[-<<+>>]<<<[-]>>>][-]<[->+<]>[[-<+>]<<<[-]>>>]<<[-]+<[[-]>>[ 558 | -]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 559 | ++++++++++++++++++++++++++++++++++++++++++++++.<-<]>[[-]<<<<<<.>>>>>>]<<<<<< 560 | <<<]>[-]++++++++++.[-]+>[-]+>[-]+++++++++++++++++++++++++++.++++++++++++++++ 561 | ++++++++++++++++++++++++++++++++++++++++++++++++.>[-]>[-]<<<[->>>+<<<]>>>[-< 562 | +<<+>>>]>>>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++>[-]<< 563 | [>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]< 564 | <<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[ 565 | -<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<]<<<]<<<[-]>>>>>>[-]<[ 566 | ->+<]>[[-<+>]>[-]<<<[->>>+<<<]>>>[-<<<+<<<<+>>>>>>>]<<[-<<<<<->>>>>]>]<<<[-] 567 | >[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++<<<<<[-]>>>>[>>>[-]< 568 | <[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+ 569 | <<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>> 570 | >>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-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+>>]<]<]<<<]<[-]>>>>[-]<[->+<]>[[-<+>]>[-]<<<[->>>+<<<]>>>[-<<<+<<+>>>> 585 | >]<<[-<<<->>>]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++ 586 | ++<<<<<[-]>>>>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-< 587 | <<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->> 588 | >>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[- 589 | ]<<[->>+<<]>>[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]<[->+<]>>[-]+<[[-<+> 590 | ]<++++++++++++++++++++++++++++++++++++++++++++++++.<++++++++++++++++++++++++ 591 | ++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++++.> 592 | >>>-<]>[[-]>[-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]<<<<++++++++++++++++++ 593 | ++++++++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++ 594 | ++++.>>>>>>-<]>[[-]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++.>> 595 | >>>>]<<]<<<<<<--------------------------------.>[-]>[-]<<<<[->>>>+<<<<]>>>>[ 596 | -<+<<<+>>>>]>>>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++++++++>[ 597 | -]<<[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]> 598 | [-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<<[->>>>+<<<<]>> 599 | >>[[-<<<<+>>>>]>[-]<<<[->>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[-]>[-]<<<<[->>>>+< 613 | <<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]+>[-]<<[ 614 | ->>+<<]>>[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]>[-]<<<<<[->>>>>+<<<<<]> 615 | >>>>[-<+<<<<+>>>>>][-]++++++++++>[-]<<[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-] 616 | <<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]< 617 | [<<<->>->[-]>[-]<<<<[->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+ 618 | >>>]<<[-]+>>]<]<]<<<]<[-]>>>>[-]<[->+<]>[[-<+>]>[-]<<<[->>>+<<<]>>>[-<<<+<<+ 619 | >>>>>]<<[-<<<->>>]>]<<<[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<<<<+>>>>>][-]++++ 620 | ++++++<<<<<[-]>>>>[>>>[-]<<[->>+<<]>[-]>[-<<+>+>][-]>[-]<<<<[->>>>+<<<<]>>>> 621 | [[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<[<<<->>->[-]>[-]<<<< 622 | [->>>>+<<<<]>>>>[[-<<<<+>>>>]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-] 623 | +>[-]<<[->>+<<]>>[[-<<+>>]<[-]>]<[[-]<<<<<<<+>>>>>>>]<<<][-]<[->+<]>>[-]+<[[ 624 | -<+>]<++++++++++++++++++++++++++++++++++++++++++++++++.<++++++++++++++++++++ 625 | ++++++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++++++++ 626 | ++.>>>>-<]>[[-]>[-]<<<<[->>>>+<<<<]>>>>>[-]+<[[-<<<<+>>>>]<<<<++++++++++++++ 627 | ++++++++++++++++++++++++++++++++++.<++++++++++++++++++++++++++++++++++++++++ 628 | ++++++++.>>>>>>-<]>[[-]<<<<<<+++++++++++++++++++++++++++++++++++++++++++++++ 629 | +.>>>>>>]<<]<<<<<<+++++++++++++.<<[-]+++++++++++++++++++++++++++++++++++++++ 630 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 631 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 632 | +++++++++[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 633 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 634 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[>[-]+++++++++ 635 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 636 | +++++++++++++++[-]<-]<-]<<<<<]<<<<+>>>>[-]>[-]<<<<<[->>>>>+<<<<<]>>>>>[-<+<< 637 | <<+>>>>>][-]++++<<[-]>>>[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[->>>+<<<]> 638 | >>[[-<<<+>>>]<<[-]+>>]<]<[<<->->[-]>[-]<<<[->>>+<<<]>>>[[-<<<+>>>]>[-]<<<[-> 639 | >>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<<[->>+<<]>>[[-<<+>>]<<<[-]+>>>][-]<[-> 640 | +<]>[[-<+>]<<<[-]+>>>]<<<]<<->>[-]<<[->>+<<]>>[[-<<+>>]<<<<<<<<-<<<<<<<<<<<< 641 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 642 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 643 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-]<[-]<[-]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-]<<<[->>>+<<<]>>>[[-<<<+>>>]<<[-]+>>]<]<][-]<[- 709 | >+<]>[[-<+>]<<<[-]+>>>]<<<]<<<<+>>>]<<]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 710 | -------------------------------------------------------------------------------- /bf/hello.bf: -------------------------------------------------------------------------------- 1 | ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. -------------------------------------------------------------------------------- /bf/hello2.bf: -------------------------------------------------------------------------------- 1 | [impeccable.b -- compute impeccable numbers 2 | (c) 2016 Daniel B. Cristofani 3 | http://brainfuck.org/] 4 | 5 | [ This is Daniel's original code 6 | 7 | >>>->+[ 8 | [ 9 | [<<+>+>-]++++++[<<++++++++>>-]<<-.[-]< 10 | ]++++++++++.[-]>>>++<[ 11 | [-[[>>>]<<<-[+>>>]<<<[<<<]+>]<-[+>++++++++++>>]>]>>> 12 | [[>+<-]>>>]<<[-[<++>-[<++>-[<++>-[<++>-[<[-]>-[<++>-]>>[<+<]>[->]<++<<]]]]]<+<<] 13 | > 14 | ]>[>>>]<<< 15 | ] 16 | 17 | This program outputs sequence (http://oeis.org/A014221). Although this sequence 18 | is technically nonterminating, computing its eighth term would require more 19 | storage than can exist in this universe, so you may as well kill this program 20 | after the seventh term. 21 | 22 | ] 23 | 24 | Print out the zero that's supposed to start the sequence 25 | ++++++[->++++++++<]>.[----<+>]<--. 26 | 27 | Only print six more to avoid the end of the universe 28 | [-]++++++[->> 29 | >>>++<[ 30 | [-[[>>>]<<<-[+>>>]<<<[<<<]+>]<-[+>++++++++++>>]>]>>> 31 | [[>+<-]>>>]<<[-[<++>-[<++>-[<++>-[<++>-[<[-]>-[<++>-]>>[<+<]>[->]<++<<]]]]]<+<<] 32 | > 33 | ]>[>>>]<<< 34 | 35 | Print the number we've found 36 | [ 37 | [<<+>+>-]++++++[<<++++++++>>-]<<-.[-]< 38 | ]++++++++++.[-] 39 | 40 | <<] 41 | 42 | >[-]<[-]++++++[->+++++++++++<]>+.-[---<+++++>]<+.--.+++.+++++.-.>+++++[< 43 | ---->-]<+.->+++++[<++++>-]<.-----------.++++++.-.--[--->+<]>----.+++++[- 44 | <+++>]<.---------.[--->+<]>--.---[-<++++>]<.------------.---.--[--->+<]> 45 | -.+[-<+++>]<++.++++.--.+.++++++++++++.------------.--[--->+<]>--.+++[-<+ 46 | ++>]<.++++.+++.-----------.--..--.+.++++++++++.-------.--[--->+<]>-.++++ 47 | [-<+++>]<++.+++++++.--------.-----------.+++.+++++++++++++.[--->+<]>---- 48 | --.[-<+++>]<+.+.+++++++++++++.+++.++.---------------.-.-[--->+<]>-.+[-<+ 49 | ++>]<+.+>++++[<++++>-]<.>++++[<---->-]<.--[--->+<]>-.---[-<++++>]<.----- 50 | .[--->+<]>-----.---[-<++++>]<.------------.---.--[--->+<]>-.+++[-<+++>]< 51 | .++++..----.+++++.---------.+++++++++.++++++.[---->+<]>+++.+[-<+++>]<++. 52 | +++++++++.----------.-[--->+<]>-.+++++[-<+++>]<.---------.[--->+<]>--.-- 53 | -[-<++++>]<.------------.---.--[--->+<]>-.---[-<++++>]<+.-------.-----.+ 54 | ++++++++++++.>++++[<---->-]<-.+++++++++++++.+.--------------.-[-->+<]>-- 55 | --.[-]++++++++++.[-]< -------------------------------------------------------------------------------- /bf/loop.bf: -------------------------------------------------------------------------------- 1 | +[+.] 2 | -------------------------------------------------------------------------------- /bf/mandelbrot.bf: -------------------------------------------------------------------------------- 1 | A mandelbrot set fractal viewer in brainf*** written by Erik Bosman 2 | http://esoteric DOT sange DOT fi/brainfuck/utils/mandelbrot/ 3 | 4 | +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ 5 | >>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ 6 | <<<<<<<+++++[-[->>>>>>>>>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>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>> 145 | >>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++ 146 | +[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< 147 | <<<<<]]>>>] 148 | -------------------------------------------------------------------------------- /bf_gen.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def string_to_brainfuck(s): 4 | brainfuck_code = "" 5 | current_value = 0 6 | 7 | for char in s: 8 | target_value = ord(char) 9 | diff = target_value - current_value 10 | 11 | if diff > 0: 12 | brainfuck_code += '+' * diff 13 | elif diff < 0: 14 | brainfuck_code += '-' * (-diff) 15 | 16 | brainfuck_code += '.' 17 | current_value = target_value 18 | 19 | # brainfuck_code += "[-]." 20 | return brainfuck_code 21 | 22 | if __name__ == "__main__": 23 | if len(sys.argv) != 2: 24 | print("Usage: python script.py ") 25 | sys.exit(1) 26 | 27 | input_string = sys.argv[1] 28 | input_string = eval(f"\"{input_string}\"") 29 | brainfuck_code = string_to_brainfuck(input_string) 30 | 31 | with open("res.bf", "w") as f: 32 | f.write(brainfuck_code) 33 | 34 | print(f"Brainfuck code written to res.bf") 35 | 36 | -------------------------------------------------------------------------------- /comp.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def clean_brainfuck(file_path): 4 | # Define the set of valid Brainfuck commands 5 | valid_commands = {'>', '<', '+', '-', '.', ',', '[', ']'} 6 | 7 | try: 8 | # Read the content of the file 9 | with open(file_path, 'r') as file: 10 | content = file.read() 11 | 12 | # Filter out non-command characters 13 | cleaned_content = ''.join(char for char in content if char in valid_commands) 14 | 15 | # Print the cleaned Brainfuck code 16 | print(cleaned_content) 17 | 18 | except FileNotFoundError: 19 | print(f"Error: The file '{file_path}' was not found.") 20 | except Exception as e: 21 | print(f"An error occurred: {e}") 22 | 23 | if __name__ == '__main__': 24 | # Check if the script received exactly one argument 25 | if len(sys.argv) != 2: 26 | print("Usage: python clean_brainfuck.py ") 27 | else: 28 | # Get the file path from the argument 29 | file_path = sys.argv[1] 30 | # Clean the Brainfuck source code 31 | clean_brainfuck(file_path) 32 | -------------------------------------------------------------------------------- /src/bf_types.rs: -------------------------------------------------------------------------------- 1 | // type bf program should be equivalent to Vec 2 | // pub type BfSrc = Vec; 3 | pub const BF_MEMORY_SIZE: usize = 30_000; 4 | -------------------------------------------------------------------------------- /src/interpreter/interp.rs: -------------------------------------------------------------------------------- 1 | use std::error; 2 | 3 | use crate::interpreter::*; 4 | 5 | pub enum OptimizationLevel { 6 | Raw, 7 | None, 8 | Low, 9 | Medium, 10 | High, 11 | } 12 | 13 | pub fn run( 14 | prog: &[u8], 15 | optimization_level: Option, 16 | ) -> Result<(), Box> { 17 | let ol = optimization_level.unwrap_or(OptimizationLevel::High); 18 | 19 | match ol { 20 | OptimizationLevel::Raw => interp_1::run(prog), 21 | OptimizationLevel::None => interp_2::run(prog), 22 | OptimizationLevel::Low => interp_3::run(prog), 23 | OptimizationLevel::Medium => interp_4::run(prog), 24 | OptimizationLevel::High => interp_5::run(prog), 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/interpreter/interp_1.rs: -------------------------------------------------------------------------------- 1 | // pub mod inter_1 { 2 | use std::{ 3 | error, 4 | io::{self, Read, Write}, 5 | }; 6 | 7 | use crate::bf_types; 8 | 9 | /// Run a bf program 10 | /// 11 | /// # Examples 12 | /// 13 | /// ``` 14 | /// let prog = fs::read(env::args().nth(1).unwrap())?; 15 | /// inter_1::run(prog)?; 16 | /// ``` 17 | /// 18 | /// This is a naive implementation, which we will optimize further in other implementations. 19 | pub fn run(prog: &[u8]) -> Result<(), Box> { 20 | let mut pc = 0; /* Program counter tracks location in the code */ 21 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; /* memory */ 22 | let mut cc = 0; /* Cell counter (data pointer) points to active location in memory*/ 23 | while pc < prog.len() { 24 | match prog[pc] as char { 25 | '<' => { 26 | cc -= 1; 27 | } 28 | '>' => { 29 | cc += 1; 30 | } 31 | '+' => { 32 | cells[cc] = cells[cc].wrapping_add(1); 33 | } 34 | '-' => { 35 | cells[cc] = cells[cc].wrapping_sub(1); 36 | } 37 | '[' if cells[cc] == 0 => { 38 | let mut level = 1; 39 | while level > 0 { 40 | pc += 1; 41 | match prog[pc] as char { 42 | '[' => { 43 | level += 1; 44 | } 45 | ']' => { 46 | level -= 1; 47 | } 48 | _ => (), 49 | } 50 | } 51 | } 52 | ']' if cells[cc] != 0 => { 53 | let mut level = 1; 54 | while level > 0 { 55 | pc -= 1; 56 | match prog[pc] as char { 57 | '[' => { 58 | level -= 1; 59 | } 60 | ']' => { 61 | level += 1; 62 | } 63 | _ => (), 64 | } 65 | } 66 | } 67 | '.' => io::stdout().write_all(&cells[cc..cc + 1])?, 68 | ',' => io::stdin().read_exact(&mut cells[cc..cc + 1])?, 69 | _ => (), 70 | } 71 | pc += 1; 72 | } 73 | Ok(()) 74 | } 75 | 76 | #[cfg(test)] 77 | mod tests { 78 | use crate::tests::test_helper::{test_hell, test_run}; 79 | 80 | use super::*; 81 | 82 | #[test] 83 | fn hello() { 84 | assert!(test_run(&run).is_ok()); 85 | } 86 | #[test] 87 | fn hello_hell() { 88 | assert!(test_hell(&run).is_ok()); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/interpreter/interp_2.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | error, 3 | io::{self, Read, Write}, 4 | }; 5 | 6 | use crate::bf_types; 7 | 8 | /// Operations for BF 9 | #[derive(Debug)] 10 | enum Ops { 11 | Left, 12 | Right, 13 | Add, 14 | Sub, 15 | LBrack, 16 | RBrack, 17 | Output, 18 | Input, 19 | } 20 | 21 | type OpSequence = Vec; 22 | 23 | fn parse(prog: &[u8]) -> Result { 24 | let mut prog_ops = vec![]; 25 | /* First parse the program into a sequence of opcodes */ 26 | for &b in prog { 27 | match b as char { 28 | '<' => prog_ops.push(Ops::Left), 29 | '>' => prog_ops.push(Ops::Right), 30 | '+' => prog_ops.push(Ops::Add), 31 | '-' => prog_ops.push(Ops::Sub), 32 | '[' => prog_ops.push(Ops::LBrack), 33 | ']' => prog_ops.push(Ops::RBrack), 34 | '.' => prog_ops.push(Ops::Output), 35 | ',' => prog_ops.push(Ops::Input), 36 | _ => (), 37 | } 38 | } 39 | Ok(prog_ops) 40 | } 41 | 42 | pub fn run(prog: &[u8]) -> Result<(), Box> { 43 | /* Notice: prog is now a vec of OpCodes, not a string */ 44 | let prog_ops = parse(prog)?; 45 | 46 | let mut pc = 0; 47 | 48 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; 49 | let mut cc = 0; 50 | while pc < prog_ops.len() { 51 | match prog_ops[pc] { 52 | Ops::Left => { 53 | cc -= 1; 54 | } 55 | Ops::Right => { 56 | cc += 1; 57 | } 58 | Ops::Add => { 59 | cells[cc] = cells[cc].wrapping_add(1); 60 | } 61 | Ops::Sub => { 62 | cells[cc] = cells[cc].wrapping_sub(1); 63 | } 64 | Ops::LBrack if cells[cc] == 0 => { 65 | let mut level = 1; 66 | while level > 0 { 67 | pc += 1; 68 | match prog_ops[pc] { 69 | Ops::LBrack => { 70 | level += 1; 71 | } 72 | Ops::RBrack => { 73 | level -= 1; 74 | } 75 | _ => (), 76 | } 77 | } 78 | } 79 | Ops::RBrack if cells[cc] != 0 => { 80 | let mut level = 1; 81 | while level > 0 { 82 | pc -= 1; 83 | match prog_ops[pc] { 84 | Ops::LBrack => { 85 | level -= 1; 86 | } 87 | Ops::RBrack => { 88 | level += 1; 89 | } 90 | _ => (), 91 | } 92 | } 93 | } 94 | Ops::Output => io::stdout().write_all(&cells[cc..cc + 1])?, 95 | Ops::Input => io::stdin().read_exact(&mut cells[cc..cc + 1])?, 96 | _ => (), 97 | } 98 | pc += 1; 99 | } 100 | Ok(()) 101 | } 102 | #[cfg(test)] 103 | mod tests { 104 | use crate::tests::test_helper::{test_hell, test_run}; 105 | 106 | use super::*; 107 | 108 | #[test] 109 | fn hello() { 110 | assert!(test_run(&run).is_ok()); 111 | } 112 | #[test] 113 | fn hello_hell() { 114 | assert!(test_hell(&run).is_ok()); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/interpreter/interp_3.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | error, 3 | io::{self, Read, Write}, 4 | }; 5 | 6 | use crate::bf_types; 7 | 8 | #[derive(Debug)] 9 | enum Ops { 10 | Left, 11 | Right, 12 | Add, 13 | Sub, 14 | LBrack(usize), 15 | RBrack(usize), 16 | Output, 17 | Input, 18 | } 19 | 20 | type OpSequence = Vec; 21 | 22 | fn parse(prog: &[u8]) -> Result { 23 | let mut prog_ops = vec![]; 24 | // a stack to keep track of the brackets 25 | let mut bracket_index_stack = vec![]; 26 | let mut i: usize = 0; 27 | while i < prog.len() { 28 | match prog[i] as char { 29 | '<' => prog_ops.push(Ops::Left), 30 | '>' => prog_ops.push(Ops::Right), 31 | '+' => prog_ops.push(Ops::Add), 32 | '-' => prog_ops.push(Ops::Sub), 33 | '[' => { 34 | // Place holder 35 | bracket_index_stack.push(prog_ops.len()); 36 | prog_ops.push(Ops::LBrack(usize::MAX)); 37 | } 38 | ']' => { 39 | let open_bracket = bracket_index_stack.pop().unwrap(); 40 | prog_ops[open_bracket] = Ops::LBrack(prog_ops.len() - 1); 41 | prog_ops.push(Ops::RBrack(open_bracket)); 42 | } 43 | '.' => prog_ops.push(Ops::Output), 44 | ',' => prog_ops.push(Ops::Input), 45 | _ => (), 46 | } 47 | i += 1; 48 | } 49 | Ok(prog_ops) 50 | } 51 | 52 | pub fn run(prog: &[u8]) -> Result<(), Box> { 53 | let prog_ops = parse(prog).unwrap(); 54 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; 55 | let mut cp = 0; 56 | let mut pc = 0; 57 | while pc < prog_ops.len() { 58 | match prog_ops[pc] { 59 | Ops::Left => cp -= 1, 60 | Ops::Right => cp += 1, 61 | Ops::Add => cells[cp] = cells[cp].wrapping_add(1), 62 | Ops::Sub => cells[cp] = cells[cp].wrapping_sub(1), 63 | Ops::LBrack(jump) if cells[cp] == 0 => pc = jump, 64 | Ops::RBrack(jump) if cells[cp] != 0 => pc = jump, 65 | Ops::Output => io::stdout().write_all(&cells[cp..cp + 1])?, 66 | Ops::Input => io::stdin().read_exact(&mut cells[cp..cp + 1])?, 67 | _ => (), 68 | } 69 | pc += 1; 70 | } 71 | Ok(()) 72 | } 73 | #[cfg(test)] 74 | mod tests { 75 | use crate::tests::test_helper::{test_hell, test_run}; 76 | 77 | use super::*; 78 | 79 | #[test] 80 | fn hello() { 81 | assert!(test_run(&run).is_ok()); 82 | } 83 | #[test] 84 | fn hello_hell() { 85 | assert!(test_hell(&run).is_ok()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/interpreter/interp_4.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | error, 3 | io::{self, Read, Write}, 4 | }; 5 | 6 | use crate::bf_types; 7 | 8 | #[derive(Debug)] 9 | enum Ops { 10 | Left(usize), 11 | Right(usize), 12 | Add(u8), 13 | Sub(u8), 14 | LBrack(usize), 15 | RBrack(usize), 16 | Output, 17 | Input, 18 | } 19 | 20 | type OpSequence = Vec; 21 | 22 | fn parse(prog: &[u8]) -> Result { 23 | let mut prog_ops = vec![]; 24 | let mut bracket_index_stack = vec![]; 25 | let mut i = 0; 26 | while i < prog.len() { 27 | match prog[i] as char { 28 | '<' => { 29 | let mut count = 1; 30 | let mut j = i + 1; 31 | while j < prog.len() && prog[j] as char == '<' { 32 | count += 1; 33 | j += 1; 34 | } 35 | prog_ops.push(Ops::Left(count)); 36 | i = j - 1; 37 | } 38 | '>' => { 39 | let mut count = 1; 40 | let mut j = i + 1; 41 | while j < prog.len() && prog[j] as char == '>' { 42 | count += 1; 43 | j += 1; 44 | } 45 | prog_ops.push(Ops::Right(count)); 46 | i = j - 1; 47 | } 48 | '-' => { 49 | let mut count = 1; 50 | let mut j = i + 1; 51 | while j < prog.len() && prog[j] as char == '-' { 52 | count += 1; 53 | j += 1; 54 | } 55 | prog_ops.push(Ops::Sub(count)); 56 | i = j - 1; 57 | } 58 | '+' => { 59 | let mut count = 1; 60 | let mut j = i + 1; 61 | while j < prog.len() && prog[j] as char == '+' { 62 | count += 1; 63 | j += 1; 64 | } 65 | prog_ops.push(Ops::Add(count)); 66 | i = j - 1; 67 | } 68 | '[' => { 69 | // Place holder 70 | bracket_index_stack.push(prog_ops.len()); 71 | prog_ops.push(Ops::LBrack(usize::MAX)); 72 | } 73 | ']' => { 74 | let open_bracket = bracket_index_stack.pop().unwrap(); 75 | prog_ops[open_bracket] = Ops::LBrack(prog_ops.len() - 1); 76 | prog_ops.push(Ops::RBrack(open_bracket)); 77 | } 78 | '.' => prog_ops.push(Ops::Output), 79 | ',' => prog_ops.push(Ops::Input), 80 | _ => (), 81 | } 82 | i += 1; 83 | } 84 | 85 | Ok(prog_ops) 86 | } 87 | 88 | pub fn run(prog: &[u8]) -> Result<(), Box> { 89 | let prog_ops = parse(prog).unwrap(); 90 | 91 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; 92 | let mut cc = 0usize; 93 | let mut pc = 0; 94 | while pc < prog_ops.len() { 95 | match prog_ops[pc] { 96 | Ops::Left(v) => cc -= v, 97 | Ops::Right(v) => cc += v, 98 | Ops::Add(v) => cells[cc] = cells[cc].wrapping_add(v), 99 | Ops::Sub(v) => cells[cc] = cells[cc].wrapping_sub(v), 100 | Ops::LBrack(jump) if cells[cc] == 0 => pc = jump, 101 | Ops::RBrack(jump) if cells[cc] != 0 => pc = jump, 102 | Ops::Output => io::stdout().write_all(&cells[cc..cc + 1])?, 103 | Ops::Input => io::stdin().read_exact(&mut cells[cc..cc + 1])?, 104 | _ => (), 105 | } 106 | pc += 1; 107 | } 108 | Ok(()) 109 | } 110 | #[cfg(test)] 111 | mod tests { 112 | use crate::tests::test_helper::{test_hell, test_run}; 113 | 114 | use super::*; 115 | 116 | #[test] 117 | fn hello() { 118 | assert!(test_run(&run).is_ok()); 119 | } 120 | #[test] 121 | fn hello_hell() { 122 | assert!(test_hell(&run).is_ok()); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/interpreter/interp_5.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | error, 3 | io::{self, Read, Write}, 4 | }; 5 | 6 | use crate::bf_types; 7 | /// BrainFuck AST node 8 | #[derive(Debug)] 9 | enum Ops { 10 | Left(usize), 11 | Right(usize), 12 | Add(u8), 13 | Sub(u8), 14 | Zero, 15 | LBrack(usize), 16 | RBrack(usize), 17 | Output, 18 | Input, 19 | } 20 | 21 | type OpSequence = Vec; 22 | 23 | fn parse(prog_src: &[u8]) -> Result { 24 | let mut prog_ops = vec![]; 25 | let mut bracket_index_stack = vec![]; 26 | let mut i = 0; 27 | while i < prog_src.len() { 28 | match prog_src[i] as char { 29 | '<' => { 30 | let mut count = 1; 31 | let mut j = i + 1; 32 | while j < prog_src.len() && prog_src[j] as char == '<' { 33 | count += 1; 34 | j += 1; 35 | } 36 | prog_ops.push(Ops::Left(count)); 37 | i = j - 1; 38 | } 39 | '>' => { 40 | let mut count = 1; 41 | let mut j = i + 1; 42 | while j < prog_src.len() && prog_src[j] as char == '>' { 43 | count += 1; 44 | j += 1; 45 | } 46 | prog_ops.push(Ops::Right(count)); 47 | i = j - 1; 48 | } 49 | '-' => { 50 | let mut count = 1; 51 | let mut j = i + 1; 52 | while j < prog_src.len() && prog_src[j] as char == '-' { 53 | count += 1; 54 | j += 1; 55 | } 56 | prog_ops.push(Ops::Sub(count)); 57 | i = j - 1; 58 | } 59 | '+' => { 60 | let mut count = 1; 61 | let mut j = i + 1; 62 | while j < prog_src.len() && prog_src[j] as char == '+' { 63 | count += 1; 64 | j += 1; 65 | } 66 | prog_ops.push(Ops::Add(count)); 67 | i = j - 1; 68 | } 69 | '[' => { 70 | // Check if it is [-] 71 | if i + 2 < prog_src.len() 72 | && prog_src[i + 1] as char == '-' 73 | && prog_src[i + 2] as char == ']' 74 | { 75 | prog_ops.push(Ops::Zero); 76 | i += 3; 77 | continue; 78 | } 79 | bracket_index_stack.push(prog_ops.len()); 80 | prog_ops.push(Ops::LBrack(usize::MAX)); 81 | } 82 | ']' => { 83 | let open_bracket = bracket_index_stack.pop().unwrap(); 84 | prog_ops[open_bracket] = Ops::LBrack(prog_ops.len() - 1); 85 | prog_ops.push(Ops::RBrack(open_bracket)); 86 | } 87 | '.' => prog_ops.push(Ops::Output), 88 | ',' => prog_ops.push(Ops::Input), 89 | _ => (), 90 | } 91 | i += 1; 92 | } 93 | 94 | Ok(prog_ops) 95 | // TODO: Return error if program is not valid 96 | } 97 | 98 | pub fn run(prog: &[u8]) -> Result<(), Box> { 99 | let prog_ops = parse(prog)?; 100 | 101 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; 102 | let mut cc = 0usize; 103 | let mut pc = 0; 104 | while pc < prog_ops.len() { 105 | match prog_ops[pc] { 106 | Ops::Left(v) => cc -= v, 107 | Ops::Right(v) => cc += v, 108 | Ops::Add(v) => cells[cc] = cells[cc].wrapping_add(v), 109 | Ops::Sub(v) => cells[cc] = cells[cc].wrapping_sub(v), 110 | Ops::Zero => cells[cc] = 0, 111 | Ops::LBrack(jump) if cells[cc] == 0 => pc = jump, 112 | Ops::RBrack(jump) if cells[cc] != 0 => pc = jump, 113 | Ops::Output => io::stdout().write_all(&cells[cc..cc + 1])?, 114 | Ops::Input => io::stdin().read_exact(&mut cells[cc..cc + 1])?, 115 | _ => (), 116 | } 117 | pc += 1; 118 | } 119 | Ok(()) 120 | } 121 | #[cfg(test)] 122 | mod tests { 123 | use crate::tests::test_helper::{test_hell, test_run}; 124 | 125 | use super::*; 126 | 127 | #[test] 128 | fn hello() { 129 | assert!(test_run(&run).is_ok()); 130 | } 131 | #[test] 132 | fn hello_hell() { 133 | assert!(test_hell(&run).is_ok()); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/interpreter/interp_6.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | error, 3 | io::{self, Read}, 4 | }; 5 | 6 | use libc::c_int; 7 | 8 | use crate::bf_types; 9 | #[derive(Debug)] 10 | enum Ops { 11 | Left(usize), 12 | Right(usize), 13 | Add(u8), 14 | Sub(u8), 15 | Zero, 16 | LBrack(usize), 17 | RBrack(usize), 18 | Output, 19 | Input, 20 | } 21 | pub fn run(prog: &[u8]) -> Result<(), Box> { 22 | let mut prog_ops = vec![]; 23 | let bytes = prog; 24 | let mut i = 0; 25 | while i < prog.len() { 26 | match bytes[i] as char { 27 | '<' => { 28 | let mut count = 1; 29 | let mut j = i + 1; 30 | while j < bytes.len() && bytes[j] as char == '<' { 31 | count += 1; 32 | j += 1; 33 | } 34 | prog_ops.push(Ops::Left(count)); 35 | i = j - 1; 36 | } 37 | '>' => { 38 | let mut count = 1; 39 | let mut j = i + 1; 40 | while j < bytes.len() && bytes[j] as char == '>' { 41 | count += 1; 42 | j += 1; 43 | } 44 | prog_ops.push(Ops::Right(count)); 45 | i = j - 1; 46 | } 47 | '-' => { 48 | let mut count = 1; 49 | let mut j = i + 1; 50 | while j < bytes.len() && bytes[j] as char == '-' { 51 | count += 1; 52 | j += 1; 53 | } 54 | prog_ops.push(Ops::Sub(count)); 55 | i = j - 1; 56 | } 57 | '+' => { 58 | let mut count = 1; 59 | let mut j = i + 1; 60 | while j < bytes.len() && bytes[j] as char == '+' { 61 | count += 1; 62 | j += 1; 63 | } 64 | prog_ops.push(Ops::Add(count)); 65 | i = j - 1; 66 | } 67 | '[' => prog_ops.push(Ops::LBrack(usize::MAX)), 68 | ']' => prog_ops.push(Ops::RBrack(usize::MAX)), 69 | '.' => prog_ops.push(Ops::Output), 70 | ',' => prog_ops.push(Ops::Input), 71 | _ => (), 72 | } 73 | i += 1; 74 | } 75 | 76 | // Use indices to iterate over prog_ops to avoid immutable borrow 77 | let mut i = 0; 78 | let mut bracket_index_stack = vec![]; 79 | while i < prog_ops.len() { 80 | match prog_ops[i] { 81 | Ops::LBrack(_) => { 82 | bracket_index_stack.push(i); 83 | } 84 | Ops::RBrack(_) => { 85 | let open_bracket = bracket_index_stack.pop().unwrap(); 86 | // Safe to mutate prog_ops because we're not borrowing it as immutable 87 | prog_ops[open_bracket] = Ops::LBrack(i); 88 | prog_ops[i] = Ops::RBrack(open_bracket); 89 | } 90 | _ => (), 91 | } 92 | i += 1; 93 | } 94 | 95 | let mut i = 0; 96 | while i < prog_ops.len() - 4 { 97 | match prog_ops[i..i + 3] { 98 | [Ops::LBrack(_), Ops::Sub(_), Ops::RBrack(_)] => { 99 | prog_ops[i] = Ops::Zero; 100 | prog_ops[i + 1] = Ops::Zero; 101 | prog_ops[i + 2] = Ops::Zero; 102 | i += 3; 103 | } 104 | _ => { 105 | i += 1; 106 | } 107 | } 108 | } 109 | 110 | let mut cells = vec![0u8; bf_types::BF_MEMORY_SIZE]; 111 | let mut cc = 0usize; 112 | let mut pc = 0; 113 | while pc < prog_ops.len() { 114 | match prog_ops[pc] { 115 | // _ => todo!("Copy interp5, but update Ops::Sub, Ops::Left, Ops::Right instruction."), 116 | Ops::Left(v) => { 117 | cc -= v; 118 | } 119 | Ops::Right(v) => { 120 | cc += v; 121 | } 122 | Ops::Add(v) => { 123 | cells[cc] = cells[cc].wrapping_add(v); 124 | } 125 | Ops::Sub(v) => { 126 | cells[cc] = cells[cc].wrapping_sub(v); 127 | } 128 | Ops::Zero => { 129 | cells[cc] = 0; 130 | } 131 | Ops::LBrack(jump) if cells[cc] == 0 => { 132 | pc = jump; 133 | } 134 | Ops::RBrack(jump) if cells[cc] != 0 => { 135 | pc = jump; 136 | } 137 | Ops::Output => unsafe { 138 | let _ = libc::putchar(cells[cc] as c_int); 139 | }, 140 | Ops::Input => io::stdin().read_exact(&mut cells[cc..cc + 1])?, 141 | _ => (), 142 | } 143 | pc += 1; 144 | } 145 | 146 | Ok(()) 147 | } 148 | 149 | // #[cfg(test)] 150 | // mod tests { 151 | // use crate::tests::test_helper::test_run; 152 | 153 | // use super::*; 154 | 155 | // #[test] 156 | // fn it_works() { 157 | // assert!(test_run(run).is_ok()); 158 | // } 159 | // } 160 | -------------------------------------------------------------------------------- /src/interpreter/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod interp; 2 | pub mod interp_1; 3 | pub mod interp_2; 4 | pub mod interp_3; 5 | pub mod interp_4; 6 | pub mod interp_5; 7 | pub mod interp_6; 8 | -------------------------------------------------------------------------------- /src/jit/aarch64_jit.rs: -------------------------------------------------------------------------------- 1 | use dynasmrt::{AssemblyOffset, ExecutableBuffer}; 2 | use dynasmrt::{DynasmApi, DynasmLabelApi, dynasm}; 3 | 4 | use itertools::Itertools; 5 | use itertools::multipeek; 6 | 7 | use core::str; 8 | use std::error; 9 | use std::io::BufReader; 10 | use std::io::BufWriter; 11 | use std::io::stdin; 12 | use std::io::stdout; 13 | use std::io::{BufRead, Read, Write}; 14 | use std::mem; 15 | use std::slice; 16 | use std::u8; 17 | 18 | use crate::bf_types; 19 | use crate::bf_types::BF_MEMORY_SIZE; 20 | 21 | macro_rules! arm64_bf { 22 | ($ops:ident $($t:tt)*) => { 23 | dynasm!($ops 24 | ; .arch aarch64 25 | ; .alias a_state, x0 26 | ; .alias a_current, x1 27 | ; .alias a_begin, x2 28 | ; .alias a_end, x3 29 | ; .alias retval, x0 30 | $($t)* 31 | ); 32 | } 33 | } 34 | 35 | macro_rules! prologue { 36 | ($ops:ident) => {{ 37 | let start = $ops.offset(); 38 | arm64_bf!($ops 39 | ; str x30, [sp, #-16]! 40 | ; stp x0, x1, [sp, #-16]! 41 | ; stp x2, x3, [sp, #-16]! 42 | ); 43 | start 44 | }}; 45 | } 46 | 47 | macro_rules! epilogue { 48 | ($ops:ident, $e:expr) => {arm64_bf!($ops 49 | ; mov x0, $e 50 | ; add sp, sp, #32 51 | ; ldr x30, [sp], #16 52 | ; ret 53 | );}; 54 | } 55 | 56 | macro_rules! call_extern { 57 | ($ops:ident, $addr:ident) => {arm64_bf!($ops 58 | ; str x1, [sp, #24] 59 | ; ldr x9, ->$addr 60 | ; blr x9 61 | ; mov x9, x0 62 | ; ldp x0, x1, [sp, #16] 63 | ; ldp x2, x3, [sp] 64 | );}; 65 | } 66 | 67 | /// BrainFuck AST node 68 | #[derive(Debug)] 69 | enum Ops { 70 | Left(usize), 71 | Right(usize), 72 | Add(u8), 73 | Sub(u8), 74 | Zero, 75 | LBrack, 76 | RBrack, 77 | Output, 78 | Input, 79 | } 80 | 81 | type OpSequence = Vec; 82 | 83 | fn parse(prog_src: &bf_types::BfSrc) -> Result { 84 | let mut prog_ops = vec![]; 85 | let mut i = 0; 86 | while i < prog_src.len() { 87 | match prog_src[i] as char { 88 | '<' => { 89 | let mut count = 1; 90 | let mut j = i + 1; 91 | while j < prog_src.len() && prog_src[j] as char == '<' { 92 | count += 1; 93 | j += 1; 94 | } 95 | prog_ops.push(Ops::Left(count)); 96 | i = j - 1; 97 | } 98 | '>' => { 99 | let mut count = 1; 100 | let mut j = i + 1; 101 | while j < prog_src.len() && prog_src[j] as char == '>' { 102 | count += 1; 103 | j += 1; 104 | } 105 | prog_ops.push(Ops::Right(count)); 106 | i = j - 1; 107 | } 108 | '-' => { 109 | let mut count = 1; 110 | let mut j = i + 1; 111 | while j < prog_src.len() && prog_src[j] as char == '-' { 112 | count += 1; 113 | j += 1; 114 | } 115 | prog_ops.push(Ops::Sub(count)); 116 | i = j - 1; 117 | } 118 | '+' => { 119 | let mut count = 1; 120 | let mut j = i + 1; 121 | while j < prog_src.len() && prog_src[j] as char == '+' { 122 | count += 1; 123 | j += 1; 124 | } 125 | prog_ops.push(Ops::Add(count)); 126 | i = j - 1; 127 | } 128 | '[' => { 129 | // Check if it is [-] 130 | if i + 2 < prog_src.len() 131 | && prog_src[i + 1] as char == '-' 132 | && prog_src[i + 2] as char == ']' 133 | { 134 | prog_ops.push(Ops::Zero); 135 | i += 3; 136 | continue; 137 | } 138 | prog_ops.push(Ops::LBrack); 139 | } 140 | ']' => { 141 | prog_ops.push(Ops::RBrack); 142 | } 143 | '.' => prog_ops.push(Ops::Output), 144 | ',' => prog_ops.push(Ops::Input), 145 | _ => (), 146 | } 147 | i += 1; 148 | } 149 | Ok(prog_ops) 150 | } 151 | 152 | struct State<'a> { 153 | pub input: Box, 154 | pub output: Box, 155 | tape: [u8; BF_MEMORY_SIZE], 156 | } 157 | 158 | fn compile(prog: &bf_types::BfSrc) -> Result<(ExecutableBuffer, AssemblyOffset), &'static str> { 159 | let bf_ops = parse(&prog)?; 160 | let mut ops = dynasmrt::aarch64::Assembler::new().unwrap(); 161 | let mut loop_stack = vec![]; 162 | 163 | // literal pool 164 | dynasm!(ops 165 | ; ->getchar: 166 | ; .qword State::getchar as _ 167 | ; ->putchar: 168 | ; .qword State::putchar as _ 169 | ); 170 | 171 | let start = prologue!(ops); 172 | 173 | for c in bf_ops { 174 | match c { 175 | Ops::Left(amount) => { 176 | arm64_bf!(ops 177 | ; sub a_current, a_current, (amount) as u32 & 0xFFF 178 | ; sub a_current, a_current, (amount) as u32 >> 12, LSL #12 179 | ); 180 | } 181 | Ops::Right(amount) => { 182 | arm64_bf!(ops 183 | ; add a_current, a_current, (amount) as u32 & 0xFFF 184 | ; add a_current, a_current, (amount) as u32 >> 12, LSL #12 185 | ); 186 | } 187 | Ops::Add(amount) => { 188 | arm64_bf!(ops 189 | ; ldrb w9, [a_current] 190 | ; add w9, w9, amount as u32 191 | ; strb w9, [a_current] 192 | ); 193 | } 194 | Ops::Sub(amount) => { 195 | arm64_bf!(ops 196 | ; ldrb w9, [a_current] 197 | ; sub w9, w9, amount as u32 198 | ; strb w9, [a_current] 199 | ); 200 | } 201 | Ops::Zero => { 202 | arm64_bf!(ops 203 | ; strb wzr, [a_current] 204 | ); 205 | } 206 | Ops::LBrack => { 207 | let backward_label = ops.new_dynamic_label(); 208 | let forward_label = ops.new_dynamic_label(); 209 | loop_stack.push((backward_label, forward_label)); 210 | arm64_bf!(ops 211 | ; ldrb w9, [a_current] 212 | ; cbz w9, =>forward_label 213 | ;=>backward_label 214 | ); 215 | } 216 | Ops::RBrack => { 217 | if let Some((backward_label, forward_label)) = loop_stack.pop() { 218 | arm64_bf!(ops 219 | ; ldrb w9, [a_current] 220 | ; cbnz w9, =>backward_label 221 | ;=>forward_label 222 | ); 223 | } else { 224 | return Err("] without matching ["); 225 | } 226 | } 227 | Ops::Output => { 228 | arm64_bf!(ops 229 | ;; call_extern!(ops, putchar) 230 | ; cbnz x9, ->io_failure 231 | ); 232 | } 233 | Ops::Input => { 234 | arm64_bf!(ops 235 | ;; call_extern!(ops, getchar) 236 | ; cbnz x9, ->io_failure 237 | ); 238 | } 239 | } 240 | } 241 | if loop_stack.len() != 0 { 242 | return Err("[ without matching ]"); 243 | } 244 | 245 | arm64_bf!(ops 246 | ;; epilogue!(ops, 0) 247 | // ;->outbound: 248 | // ;; epilogue!(ops, 1) 249 | ;->io_failure: 250 | ;; epilogue!(ops, 2) 251 | ); 252 | 253 | Ok((ops.finalize().unwrap(), start)) 254 | } 255 | 256 | impl<'a> State<'a> { 257 | unsafe extern "C" fn getchar(state: *mut State, cell: *mut u8) -> u8 { 258 | let state = &mut *state; 259 | let err = state.output.flush().is_err(); 260 | (state 261 | .input 262 | .read_exact(slice::from_raw_parts_mut(cell, 1)) 263 | .is_err() 264 | || err) as u8 265 | } 266 | 267 | unsafe extern "C" fn putchar(state: *mut State, cell: *mut u8) -> u8 { 268 | let state = &mut *state; 269 | state 270 | .output 271 | .write_all(slice::from_raw_parts(cell, 1)) 272 | .is_err() as u8 273 | } 274 | 275 | fn new(input: Box, output: Box) -> State<'a> { 276 | State { 277 | input: input, 278 | output: output, 279 | tape: [0; BF_MEMORY_SIZE], 280 | } 281 | } 282 | } 283 | 284 | pub fn run(prog: &bf_types::BfSrc) -> Result<(), Box> { 285 | let (exe_buf, start) = compile(prog).unwrap(); 286 | let mut state = State::new( 287 | Box::new(BufReader::new(stdin())), 288 | Box::new(BufWriter::new(stdout())), 289 | ); 290 | 291 | let f: extern "C" fn(*mut State, *mut u8, *mut u8, *const u8) -> u8 = 292 | unsafe { mem::transmute(exe_buf.ptr(start)) }; 293 | 294 | let start = state.tape.as_mut_ptr(); 295 | let end = unsafe { start.offset(BF_MEMORY_SIZE as isize) }; 296 | let res = f(&mut state, start, start, end); 297 | 298 | if res == 0 { 299 | Ok(()) 300 | } else if res == 1 { 301 | Err(Box::::from("Memory Error")) 302 | } else if res == 2 { 303 | Err(Box::::from("IO error")) 304 | } else { 305 | panic!("Unknown error code"); 306 | } 307 | } 308 | 309 | #[cfg(test)] 310 | mod tests { 311 | use crate::tests::test_helper::{test_hell, test_run}; 312 | 313 | use super::*; 314 | 315 | #[test] 316 | fn hello() { 317 | assert!(test_run(&run).is_ok()); 318 | } 319 | #[test] 320 | fn hello_hell() { 321 | assert!(test_hell(&run).is_ok()); 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /src/jit/generic_jit.rs: -------------------------------------------------------------------------------- 1 | use std::error; 2 | 3 | #[cfg(target_arch = "x86_64")] 4 | use crate::jit::x64_jit; 5 | 6 | #[cfg(target_arch = "aarch64")] 7 | use crate::jit::aarch64_jit; 8 | 9 | /// Run a bf program 10 | /// 11 | /// # Examples 12 | /// 13 | /// ``` 14 | /// let prog = fs::read(env::args().nth(1).unwrap())?; 15 | /// inter_1::run(prog)?; 16 | /// ``` 17 | /// 18 | /// This is a naive implementation, which we will optimize further in other implementations. 19 | #[allow(unreachable_code)] 20 | pub fn run(prog: &[u8]) -> Result<(), Box> { 21 | // run 22 | #[cfg(target_arch = "x86_64")] 23 | { 24 | return x64_jit::run(prog); 25 | } 26 | #[cfg(target_arch = "aarch64")] 27 | { 28 | return aarch64_jit::run(prog); 29 | } 30 | println!("Architecture not supported!"); 31 | Ok(()) 32 | } 33 | 34 | #[cfg(test)] 35 | mod tests { 36 | use crate::tests::test_helper::test_run; 37 | 38 | use super::*; 39 | 40 | #[test] 41 | fn it_works() { 42 | assert!(test_run(&run).is_ok()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/jit/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::fn_to_numeric_cast)] 2 | 3 | #[cfg(target_arch = "x86_64")] 4 | mod x64_jit; 5 | 6 | #[cfg(target_arch = "aarch64")] 7 | mod aarch64_jit; 8 | 9 | mod generic_jit; 10 | 11 | pub use generic_jit::run; 12 | -------------------------------------------------------------------------------- /src/jit/x64_jit.rs: -------------------------------------------------------------------------------- 1 | use dynasmrt::{AssemblyOffset, ExecutableBuffer}; 2 | use dynasmrt::{DynasmApi, DynasmLabelApi, dynasm}; 3 | 4 | use core::str; 5 | use std::error; 6 | use std::io::BufReader; 7 | use std::io::BufWriter; 8 | use std::io::stdin; 9 | use std::io::stdout; 10 | use std::io::{BufRead, Read, Write}; 11 | use std::mem; 12 | use std::slice; 13 | 14 | use crate::bf_types::BF_MEMORY_SIZE; 15 | 16 | #[derive(Debug)] 17 | enum Ops { 18 | Left(usize), 19 | Right(usize), 20 | Add(u8), 21 | Sub(u8), 22 | Zero, 23 | LBrack, 24 | RBrack, 25 | Output, 26 | Input, 27 | } 28 | 29 | type OpSequence = Vec; 30 | 31 | fn parse(prog_src: &[u8]) -> Result { 32 | let mut prog_ops = vec![]; 33 | let mut i = 0; 34 | while i < prog_src.len() { 35 | match prog_src[i] as char { 36 | '<' => { 37 | let mut count = 1; 38 | let mut j = i + 1; 39 | while j < prog_src.len() && prog_src[j] as char == '<' { 40 | count += 1; 41 | j += 1; 42 | } 43 | prog_ops.push(Ops::Left(count)); 44 | i = j - 1; 45 | } 46 | '>' => { 47 | let mut count = 1; 48 | let mut j = i + 1; 49 | while j < prog_src.len() && prog_src[j] as char == '>' { 50 | count += 1; 51 | j += 1; 52 | } 53 | prog_ops.push(Ops::Right(count)); 54 | i = j - 1; 55 | } 56 | '-' => { 57 | let mut count = 1; 58 | let mut j = i + 1; 59 | while j < prog_src.len() && prog_src[j] as char == '-' { 60 | count += 1; 61 | j += 1; 62 | } 63 | prog_ops.push(Ops::Sub(count)); 64 | i = j - 1; 65 | } 66 | '+' => { 67 | let mut count = 1; 68 | let mut j = i + 1; 69 | while j < prog_src.len() && prog_src[j] as char == '+' { 70 | count += 1; 71 | j += 1; 72 | } 73 | prog_ops.push(Ops::Add(count)); 74 | i = j - 1; 75 | } 76 | '[' => { 77 | // Check if it is [-] 78 | if i + 2 < prog_src.len() 79 | && prog_src[i + 1] as char == '-' 80 | && prog_src[i + 2] as char == ']' 81 | { 82 | prog_ops.push(Ops::Zero); 83 | i += 3; 84 | continue; 85 | } 86 | prog_ops.push(Ops::LBrack); 87 | } 88 | ']' => { 89 | prog_ops.push(Ops::RBrack); 90 | } 91 | '.' => prog_ops.push(Ops::Output), 92 | ',' => prog_ops.push(Ops::Input), 93 | _ => (), 94 | } 95 | i += 1; 96 | } 97 | Ok(prog_ops) 98 | } 99 | 100 | struct State<'a> { 101 | pub input: Box, 102 | pub output: Box, 103 | } 104 | 105 | impl<'a> State<'a> { 106 | unsafe extern "win64" fn getchar(state: *mut State, cell: *mut u8) -> u8 { 107 | unsafe { 108 | let state = &mut *state; 109 | (state 110 | .input 111 | .read_exact(slice::from_raw_parts_mut(cell, 1)) 112 | .is_err()) as u8 113 | } 114 | } 115 | 116 | unsafe extern "win64" fn putchar(state: *mut State, cell: *mut u8) -> u8 { 117 | unsafe { 118 | let state = &mut *state; 119 | state 120 | .output 121 | .write_all(slice::from_raw_parts(cell, 1)) 122 | .is_err() as u8 123 | } 124 | } 125 | 126 | fn new(input: Box, output: Box) -> State<'a> { 127 | State { input, output } 128 | } 129 | } 130 | 131 | macro_rules! x64_bf { 132 | ($ops:ident $($t:tt)*) => { 133 | dynasm!($ops 134 | ; .arch x64 135 | ; .alias a_state, rcx // 1st arg in win64 136 | ; .alias a_current, rdx // 2nd arg in win64 137 | ; .alias retval, rax 138 | $($t)* 139 | ) 140 | } 141 | } 142 | 143 | macro_rules! call_extern { 144 | ($ops:ident, $addr:expr) => {x64_bf!($ops 145 | ; mov [rsp + 0x08], a_current 146 | ; mov retval, QWORD $addr as _ 147 | ; call retval 148 | ; mov a_state, [rsp + 0x00] 149 | ; mov a_current, [rsp + 0x08] 150 | );}; 151 | } 152 | 153 | fn compile(prog: &[u8]) -> Result<(ExecutableBuffer, AssemblyOffset), Box> { 154 | let bf_ops: Vec = parse(prog)?; 155 | let mut ops: dynasmrt::Assembler = 156 | dynasmrt::x64::Assembler::new()?; 157 | let mut loop_stack: Vec<(dynasmrt::DynamicLabel, dynasmrt::DynamicLabel)> = vec![]; 158 | 159 | let start = ops.offset(); 160 | x64_bf!(ops 161 | ; sub rsp, 0x18 162 | ; mov [rsp + 0x00], a_state 163 | ); 164 | 165 | for op in bf_ops { 166 | match op { 167 | Ops::Left(amount) => x64_bf!(ops; 168 | sub a_current, (amount) as _ 169 | ), 170 | Ops::Right(amount) => x64_bf!(ops; 171 | add a_current, (amount) as _ 172 | ), 173 | Ops::Add(amount) => x64_bf!(ops; 174 | add BYTE [a_current], amount as _ 175 | ), 176 | Ops::Sub(amount) => x64_bf!(ops; 177 | sub BYTE [a_current], amount as _ 178 | ), 179 | Ops::Zero => x64_bf!(ops; 180 | mov BYTE [a_current], 0 181 | ), 182 | Ops::LBrack => { 183 | let backward_label = ops.new_dynamic_label(); 184 | let forward_label = ops.new_dynamic_label(); 185 | loop_stack.push((backward_label, forward_label)); 186 | x64_bf!(ops 187 | ; cmp BYTE [a_current], 0 188 | ; jz =>forward_label 189 | ;=>backward_label 190 | ); 191 | } 192 | Ops::RBrack => { 193 | if let Some((backward_label, forward_label)) = loop_stack.pop() { 194 | x64_bf!(ops 195 | ; cmp BYTE [a_current], 0 196 | ; jnz =>backward_label 197 | ;=>forward_label 198 | ); 199 | } else { 200 | return Err("] without matching [".into()); 201 | } 202 | } 203 | Ops::Output => x64_bf!(ops 204 | ;; call_extern!(ops, State::putchar) 205 | ; cmp al, 0 206 | ; jnz ->io_failure 207 | ), 208 | Ops::Input => x64_bf!(ops 209 | ;; call_extern!(ops, State::getchar) 210 | ; cmp al, 0 211 | ; jnz ->io_failure 212 | ), 213 | } 214 | } 215 | if loop_stack.is_empty() { 216 | return Err("[ without matching ]".into()); 217 | } 218 | 219 | x64_bf!(ops 220 | ; mov retval, 0 221 | ; add rsp, 0x18 222 | ; ret 223 | ;->io_failure: 224 | ; mov retval, 1 225 | ; add rsp, 0x18 226 | ; ret 227 | ); 228 | 229 | let buffer = ops 230 | .finalize() 231 | .map_err(|e| format!("Assembler finalize error: {:?}", e))?; 232 | 233 | Ok((buffer, start)) 234 | } 235 | 236 | pub fn run(prog: &[u8]) -> Result<(), Box> { 237 | let (exe_buf, start) = compile(prog)?; 238 | let mut state = State::new( 239 | Box::new(BufReader::new(stdin())), 240 | Box::new(BufWriter::new(stdout())), 241 | ); 242 | let mut cells: [u8; BF_MEMORY_SIZE] = [0; BF_MEMORY_SIZE]; 243 | let cp = cells.as_mut_ptr(); 244 | 245 | let f: extern "win64" fn(*mut State, *mut u8) -> u8 = 246 | unsafe { mem::transmute(exe_buf.ptr(start)) }; 247 | 248 | let res = f(&mut state, cp); 249 | 250 | if res == 0 { 251 | Ok(()) 252 | } else if res == 1 { 253 | Err("IO error".into()) 254 | } else { 255 | Err(format!("Unknown Error: {res}").into()) 256 | } 257 | } 258 | 259 | #[cfg(test)] 260 | mod tests { 261 | use crate::tests::test_helper::{test_hell, test_run}; 262 | 263 | use super::*; 264 | 265 | #[test] 266 | fn hello() { 267 | assert!(test_run(&run).is_ok()); 268 | } 269 | #[test] 270 | fn hello_hell() { 271 | assert!(test_hell(&run).is_ok()); 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use std::{error, fs}; 3 | #[macro_use] 4 | extern crate lazy_static; 5 | pub mod bf_types; 6 | pub mod interpreter; 7 | pub mod jit; 8 | pub mod tests; 9 | pub mod transpiler; 10 | 11 | use clap::Parser; 12 | use interpreter::interp::OptimizationLevel; 13 | 14 | #[derive(Parser)] 15 | #[command(version, about, long_about = None)] 16 | struct Cli { 17 | /// Set the running mode (int, src, jit) 18 | #[arg(short, long, default_value_t =String::from("jit"))] 19 | mode: String, 20 | 21 | /// Set an output location (required for src mode) 22 | #[arg(short, long)] 23 | output: Option, 24 | 25 | /// Set the brainfuck file to run 26 | #[arg(short, long)] 27 | input: PathBuf, 28 | } 29 | 30 | fn main() -> Result<(), Box> { 31 | let cli = Cli::parse(); 32 | 33 | let mode = cli.mode; 34 | 35 | let bf_file = cli.input; 36 | 37 | let prog: Vec = fs::read(bf_file)?; 38 | 39 | match mode.as_str() { 40 | "int" => { 41 | interpreter::interp::run(&prog, None)?; 42 | } 43 | "int1" => { 44 | interpreter::interp::run(&prog, Some(OptimizationLevel::Raw))?; 45 | } 46 | "int2" => { 47 | interpreter::interp::run(&prog, Some(OptimizationLevel::None))?; 48 | } 49 | "int3" => { 50 | interpreter::interp::run(&prog, Some(OptimizationLevel::Low))?; 51 | } 52 | "int4" => { 53 | interpreter::interp::run(&prog, Some(OptimizationLevel::Medium))?; 54 | } 55 | "int5" => { 56 | interpreter::interp::run(&prog, Some(OptimizationLevel::High))?; 57 | } 58 | "jit" => { 59 | jit::run(&prog)?; 60 | } 61 | "bf2c" => { 62 | let output_file = cli.output.ok_or("Output file required for bf2c mode")?; 63 | transpiler::bf2c::transpile_to_file( 64 | &prog, 65 | output_file.to_str().ok_or("Invalid output file path")?, 66 | ) 67 | .expect("Failed to transpile Brainfuck to C"); 68 | println!("Transpiled to C: {:?}", output_file); 69 | } 70 | "bf2js" => { 71 | let output_file = cli.output.ok_or("Output file required for bf2js mode")?; 72 | transpiler::bf2js::transpile_to_file( 73 | &prog, 74 | output_file.to_str().ok_or("Invalid output file path")?, 75 | ) 76 | .expect("Failed to transpile Brainfuck to JavaScript"); 77 | println!("Transpiled to JavaScript: {:?}", output_file); 78 | } 79 | _ => panic!("Unknown mode: {}", mode), 80 | } 81 | 82 | // benchmarks(&prog)?; 83 | 84 | Ok(()) 85 | } 86 | -------------------------------------------------------------------------------- /src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod test_helper; 2 | -------------------------------------------------------------------------------- /src/tests/test_helper.rs: -------------------------------------------------------------------------------- 1 | use std::fs::{self}; 2 | use stdio_override::StdoutOverride; 3 | 4 | use std::sync::Mutex; 5 | 6 | lazy_static! { 7 | static ref TEST_MUTEX: Mutex<()> = Mutex::new(()); 8 | } 9 | 10 | use std::error::Error; 11 | 12 | type RunFn = (dyn Fn(&[u8]) -> Result<(), Box>); 13 | 14 | pub fn test_run(run_func: &RunFn) -> Result<(), Box> { 15 | let test_lock = TEST_MUTEX.lock().unwrap(); 16 | 17 | let tmp_filename = "./test.tmp"; 18 | 19 | // If the file exists, remove it 20 | if fs::metadata(tmp_filename).is_ok() { 21 | fs::remove_file(tmp_filename)?; 22 | } 23 | 24 | let hello_bf = "something something ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+hello there.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.[-]"; 25 | let guard = StdoutOverride::override_file(tmp_filename)?; 26 | let prog = hello_bf.as_bytes().to_vec(); 27 | let run_res = run_func(&prog); 28 | let content = fs::read_to_string(tmp_filename); 29 | 30 | // cleanup 31 | drop(guard); 32 | match fs::remove_file(tmp_filename) { 33 | Ok(_) => {} 34 | Err(e) => { 35 | drop(test_lock); 36 | panic!("Error removing file: {}", e) 37 | } 38 | } 39 | drop(test_lock); 40 | 41 | match run_res { 42 | Ok(_) => {} 43 | Err(e) => { 44 | panic!("Error running program: {}", e) 45 | } 46 | }; 47 | match content { 48 | Ok(c) => { 49 | assert_eq!(c, "Hello World!\n"); 50 | } 51 | Err(e) => { 52 | panic!("Error reading file: {}", e) 53 | } 54 | }; 55 | 56 | Ok(()) 57 | } 58 | 59 | const HELLO_HELL_STR: &str = r#"[ 60 | This routine is a demonstration of checking for the three cell sizes 61 | that are normal for Brainfuck. The demo code also checks for bugs 62 | that have been noted in various interpreters and compilers. 63 | 64 | It should print one of three slight variations of "Hello world" followed 65 | by an exclamation point then the maximum cell value (if it's less than a 66 | few thousand) and a newline. 67 | 68 | If the interpreter is broken in some way it can print a lot of other 69 | different strings and frequently causes the interpreter to crash. 70 | 71 | It does work correctly with 'bignum' cells. 72 | ] 73 | +>> 74 | 75 | This code runs at pointer offset two and unknown bit width; don't 76 | assume you have more that eight bits 77 | 78 | ======= DEMO CODE ======= 79 | First just print "Hello" 80 | 81 | Notice that I reset the cells despite knowing that they are zero 82 | this is a test for proper functioning of the ability to skip over 83 | a loop that's never executed but isn't actually a comment loop 84 | 85 | Secondly there's a NOP movement between the two 'l' characters 86 | 87 | Also there's some commented out code afterwards 88 | 89 | >[-]<[-]++++++++[->+++++++++<]>.----[--<+++>]<-.+++++++.><.+++. 90 | [-][[-]>[-]+++++++++[<+++++>-]<+...--------------.>++++++++++[<+ 91 | ++++>-]<.+++.-------.>+++++++++[<----->-]<.-.>++++++++[<+++++++> 92 | -]<++.-----------.--.-----------.+++++++.----.++++++++++++++.>++ 93 | ++++++++[<----->-]<..[-]++++++++++.[-]+++++++[.,]-] 94 | 95 | ===== END DEMO CODE ===== 96 | <<- 97 | 98 | Calculate the value 256 and test if it's zero 99 | If the interpreter errors on overflow this is where it'll happen 100 | ++++++++[>++++++++<-]>[<++++>-] 101 | +<[>-< 102 | Multiply by 256 again to get 65536 103 | [>++++<-]>[<++++++++>-]<[>++++++++<-] 104 | +>[> 105 | Cells should be 32bits at this point 106 | 107 | The pointer is at cell two and you can continue your code confident 108 | that there are big cells 109 | 110 | ======= DEMO CODE ======= 111 | This code rechecks that the test cells are in fact nonzero 112 | If the compiler notices the above is constant but doesn't 113 | properly wrap the values this will generate an incorrect 114 | string 115 | 116 | An optimisation barrier; unbalanced loops aren't easy 117 | >+[<]>-< 118 | 119 | Print a message 120 | ++>[-]++++++[<+++++++>-]<.------------.[-] 121 | <[>+<[-]]> 122 | ++++++++>[-]++++++++++[<+++++++++++>-]<.--------.+++.------. 123 | --------.[-] 124 | 125 | ===== END DEMO CODE ===== 126 | 127 | <[-]<[-]>] <[>> 128 | Cells should be 16bits at this point 129 | 130 | The pointer is at cell two and you can continue your code confident 131 | that there are medium sized cells; you can use all the cells on the 132 | tape but it is recommended that you leave the first two alone 133 | 134 | If you need 32bit cells you'll have to use a BF doubler 135 | 136 | ======= DEMO CODE ======= 137 | Space 138 | ++>[-]+++++[<++++++>-]<.[-] 139 | 140 | I'm rechecking that the cells are 16 bits 141 | this condition should always be true 142 | 143 | +>>++++[-<<[->++++<]>[-<+>]>]< + <[ >> 144 | 145 | Print a message 146 | >[-]++++++++++[<+++++++++++>-]<+++++++++.--------. 147 | +++.------.--------.[-] 148 | 149 | <[-]<[-] ] >[> > Dead code here 150 | This should never be executed because it's in an 8bit zone hidden 151 | within a 16bit zone; a really good compiler should delete this 152 | If you see this message you have dead code walking 153 | 154 | Print a message 155 | [-]>[-]+++++++++[<++++++++++>-]<. 156 | >++++[<+++++>-]<+.--.-----------.+++++++.----. 157 | [-] 158 | 159 | <<[-]]< 160 | ===== END DEMO CODE ===== 161 | 162 | <<[-]] >[-]< ] >[> 163 | Cells should be 8bits at this point 164 | 165 | The pointer is at cell two but you only have 8 bits cells 166 | and it's time to use the really big and slow BF quad encoding 167 | 168 | ======= DEMO CODE ======= 169 | 170 | A broken wrapping check 171 | +++++[>++++<-]>[<+++++++++++++>-]<----[[-]>[-]+++++[<++++++>-]<++. 172 | >+++++[<+++++++>-]<.>++++++[<+++++++>-]<+++++.>++++[<---->-]<-.++. 173 | ++++++++.------.-.[-]] 174 | 175 | Space 176 | ++>[-]+++++[<++++++>-]<.[-] 177 | 178 | An exponent checker for github user btzy 179 | >++[>++<-]>[<<+>>[-<<[>++++<-]>[<++++>-]>]]<<[>++++[>---<++++]>++. 180 | [<++>+]<.[>+<------]>.+++.[<--->++]<--.[-]<[-]] 181 | 182 | Another dead code check 183 | [-]>[-]>[-]<++[>++++++++<-]>[<++++++++>-]<[>++++++++<-]>[<++++++++>- 184 | ]<[<++++++++>-]<[[-]>[-]+++++++++[<++++++++++>-]<.>++++[<+++++>-]<+. 185 | --.-----------.+++++++.----.>>[-]<+++++[>++++++<-]>++.<<[-]] 186 | 187 | Print a message 188 | [-] <[>+<[-]]> +++++>[-]+++++++++[<+++++++++>-]<. 189 | >++++[<++++++>-]<.+++.------.--------. 190 | [-] 191 | ===== END DEMO CODE ===== 192 | 193 | <[-]]< 194 | 195 | +[[>]<-] Check unbalanced loops are ok 196 | 197 | >> 198 | ======= DEMO CODE ======= 199 | Back out and print the last two characters 200 | 201 | [<[[<[[<[[<[,]]]<]<]<]<][ Deep nesting non-comment comment loop ]] 202 | 203 | Check that an offset of 128 will work 204 | +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 205 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>-[+<-] 206 | 207 | And back 208 | +++[->++++++<]>[-<+++++++>]<[->>[>]+[<]<]>>[->]<<<<<<<<<<<<<<<<<<<<< 209 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 210 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 211 | 212 | And inside a loop 213 | --[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 214 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>++<<< 215 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 216 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+]+>----[++ 217 | ++>----]-[+<-] 218 | 219 | This is a simple multiply loop that looks like it goes off the 220 | start of the tape 221 | +[>]<- [- 222 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 223 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 224 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 225 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 226 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 227 | <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 228 | ++++ 229 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 230 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 231 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 232 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 233 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 234 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 235 | ] 236 | 237 | [ Check there are enough cells. This takes 18569597 steps. ] 238 | [ 239 | >++++++[<+++>-]<+[>+++++++++<-]>+[[->+>+<<]>> 240 | [-<<+>>]<[<[->>+<<]+>[->>+<<]+[>]<-]<-]<[-<] 241 | ] 242 | 243 | This loop is a bug check for handling of nested loops; it goes 244 | round the outer loop twice and the inner loop is skipped on the 245 | first pass but run on the second 246 | 247 | BTW: It's unlikely that an optimiser will notice how this works 248 | 249 | > 250 | +[>[ 251 | Print the exclamation point 252 | [-]+++> 253 | [-]+++++ +#- 254 | [<+++2+++>-]< 255 | . 256 | 257 | <[-]>[-]]+<] 258 | < 259 | 260 | Clean up any debris 261 | ++++++++[[>]+[<]>-]>[>]<[[-]<] 262 | 263 | This is a hard optimisation barrier 264 | It contains several difficult to 'prove' constructions close together 265 | and is likely to prevent almost all forms of optimisation 266 | +[[>]<-[,]+[>]<-[]] 267 | 268 | This part finds the actual value that the cell wraps at; even 269 | if it's not one of the standard ones; but it gets bored after 270 | a few thousand: any higher and we print nothing 271 | 272 | This has a reasonably deep nested loop and a couple of loops 273 | that have unbalanced pointer movements 274 | 275 | Find maxint (if small) 276 | [-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<++++[->>++++>>++++>>++ 277 | ++<<<<<<]++++++++++++++>>>>+>>++<<<<<<[->>[->+>[->+>[->+>+[> 278 | >>+<<]>>[-<<+>]<-[<<<[-]<<[-]<<[-]<<[-]>>>[-]>>[-]>>[-]>->+] 279 | <<<]>[-<+>]<<<]>[-<+>]<<<]>[-<+>]<<<]>+>[[-]<->]<[->>>>>>>[- 280 | <<<<<<<<+>>>>>>>>]<<<<<<<]< 281 | 282 | The number is only printed if we found the actual maxint 283 | >+<[ 284 | Space 285 | >[-]>[-]+++++[<++++++>-]<++.[-]< 286 | 287 | Print the number 288 | [[->>+<<]>>[-<++>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[<[-]+> 289 | ->+<[<-]]]]]]]]]]>]<<[>++++++[<++++++++>-]<-.[-]<]] 290 | 291 | ] 292 | 293 | Check if we should have had a value but didn't 294 | >[ 295 | >[-]>[-]++++[<++++++++>-]<[<++++++++>-]>+++[<++++++++>-]<+++++++ 296 | [<-------->-]<------->+<[[-]>-<]>[>[-]<[-]++++[->++++++++<]>.+++ 297 | +++[-<++>]<.[-->+++<]>++.<++++[>----<-]>.[-]<]< 298 | 299 | [-]>[-]++++++++[<++++++++>-]<[>++++<-]+>[<->[-]]<[>[-]<[-]++++[- 300 | >++++++++<]>.---[-<+++>]<.---.--------------.[-->+<]>--.[-]<] 301 | ]< 302 | 303 | Clean up any debris 304 | ++++++++[[>]+[<]>-]>[>]<[[-]<] 305 | 306 | One last thing: an exclamation point is not a valid BF instruction! 307 | 308 | Print the newline 309 | [-]++++++++++.[-] 310 | [ 311 | Oh, and now that I can use "!" the string you see should be one of: 312 | Hello World! 255 313 | Hello world! 65535 314 | Hello, world! 315 | 316 | And it should be followed by a newline. 317 | ] 318 | 319 | ===== END DEMO CODE ===== 320 | 321 | << Finish at cell zero"#; 322 | 323 | pub fn test_hell(run_func: &RunFn) -> Result<(), Box> { 324 | let test_lock = TEST_MUTEX.lock().unwrap(); 325 | 326 | let tmp_filename = "./test.tmp"; 327 | 328 | // If the file exists, remove it 329 | if fs::metadata(tmp_filename).is_ok() { 330 | fs::remove_file(tmp_filename)?; 331 | } 332 | 333 | let guard = StdoutOverride::override_file(tmp_filename)?; 334 | let prog = HELLO_HELL_STR.as_bytes().to_vec(); 335 | let run_res = run_func(&prog); 336 | let content = fs::read_to_string(tmp_filename); 337 | 338 | // cleanup 339 | drop(guard); 340 | match fs::remove_file(tmp_filename) { 341 | Ok(_) => {} 342 | Err(e) => { 343 | drop(test_lock); 344 | panic!("Error removing file: {}", e) 345 | } 346 | } 347 | drop(test_lock); 348 | 349 | match run_res { 350 | Ok(_) => {} 351 | Err(e) => { 352 | panic!("Error running program: {}", e) 353 | } 354 | }; 355 | 356 | println!("Test passed"); 357 | 358 | match content { 359 | Ok(c) => { 360 | // assert_eq!(c, "Hello World!\n"); 361 | print!("{}", c); 362 | match c.as_str() { 363 | "Hello World! 255\n" => { 364 | println!("Test passed with: Hello World! 255\n"); 365 | } 366 | "Hello world! 65535\n" => { 367 | println!("Test passed with: Hello world! 65535\n"); 368 | } 369 | "Hello, world!\n" => { 370 | println!("Test passed with: Hello, world!\n"); 371 | } 372 | _ => { 373 | panic!("Test failed, content: {}", c); 374 | } 375 | } 376 | } 377 | Err(e) => { 378 | panic!("Error reading file: {}", e) 379 | } 380 | }; 381 | 382 | Ok(()) 383 | } 384 | -------------------------------------------------------------------------------- /src/transpiler/bf2c.rs: -------------------------------------------------------------------------------- 1 | use std::{fs::File, io::Write}; 2 | 3 | pub fn transpile_to_string(bf_src: &[u8]) -> String { 4 | let mut c_program = String::new(); 5 | 6 | // C program header 7 | c_program.push_str("#include \n"); 8 | c_program.push_str("int main() {\n"); 9 | c_program.push_str(" char array[30000] = {0};\n"); 10 | c_program.push_str(" char *ptr = array;\n"); 11 | 12 | // Convert Brainfuck instructions to C 13 | for &command in bf_src { 14 | match command { 15 | b'>' => c_program.push_str(" ++ptr;\n"), 16 | b'<' => c_program.push_str(" --ptr;\n"), 17 | b'+' => c_program.push_str(" ++*ptr;\n"), 18 | b'-' => c_program.push_str(" --*ptr;\n"), 19 | b'.' => c_program.push_str(" putchar(*ptr);\n"), 20 | b',' => c_program.push_str(" *ptr = getchar();\n"), 21 | b'[' => c_program.push_str(" while (*ptr) {\n"), 22 | b']' => c_program.push_str(" }\n"), 23 | _ => (), // Ignore other characters (comments or invalid) 24 | } 25 | } 26 | 27 | // C program footer 28 | c_program.push_str(" return 0;\n"); 29 | c_program.push_str("}\n"); 30 | 31 | c_program 32 | } 33 | 34 | pub fn transpile_to_file(bf_src: &[u8], filename: &str) -> std::io::Result<()> { 35 | let c_program = transpile_to_string(bf_src); 36 | let mut file = File::create(filename)?; 37 | file.write_all(c_program.as_bytes())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/transpiler/bf2js.rs: -------------------------------------------------------------------------------- 1 | use std::{fs::File, io::Write}; 2 | 3 | pub fn transpile_to_string(bf_src: &[u8]) -> String { 4 | // Initialize the JavaScript code with necessary setup 5 | let mut js_code = String::from( 6 | "const memory = new Uint8Array(30000);\n\ 7 | let pointer = 0;\n\ 8 | const input = [];\n\ 9 | let output = '';\n\ 10 | const readInput = () => input.shift().charCodeAt(0);\n\ 11 | const writeOutput = (charCode) => { output += String.fromCharCode(charCode); };\n\ 12 | // Brainfuck program start\n", 13 | ); 14 | 15 | let mut comment_start = false; 16 | 17 | let mut comment_str; 18 | 19 | for &command in bf_src.iter() { 20 | let js_command: &str = match command { 21 | b'>' => { 22 | comment_start = false; 23 | "pointer++;\n" 24 | } 25 | b'<' => { 26 | comment_start = false; 27 | "pointer--;\n" 28 | } 29 | b'+' => { 30 | comment_start = false; 31 | "memory[pointer]++;\n" 32 | } 33 | b'-' => { 34 | comment_start = false; 35 | "memory[pointer]--;\n" 36 | } 37 | b'.' => { 38 | comment_start = false; 39 | "writeOutput(memory[pointer]);\n" 40 | } 41 | b',' => { 42 | comment_start = false; 43 | "memory[pointer] = readInput();\n" 44 | } 45 | b'[' => { 46 | comment_start = false; 47 | "while (memory[pointer] !== 0) {\n" 48 | } 49 | b']' => { 50 | comment_start = false; 51 | "}\n" 52 | } 53 | _ => match comment_start { 54 | true => { 55 | comment_str = format!("{}", command as char); 56 | &comment_str 57 | } 58 | false => { 59 | comment_str = format!("//{}", command as char); 60 | comment_start = true; 61 | &comment_str 62 | } 63 | }, // Ignore any non-Brainfuck characters 64 | }; 65 | js_code.push_str(js_command); 66 | } 67 | 68 | // Add return statement for output and close the function 69 | js_code.push_str("console.log(output);\n"); 70 | 71 | // Return the transpiled JavaScript code 72 | js_code 73 | } 74 | 75 | pub fn transpile_to_file(bf_src: &[u8], filename: &str) -> std::io::Result<()> { 76 | let c_program = transpile_to_string(bf_src); 77 | let mut file = File::create(filename)?; 78 | file.write_all(c_program.as_bytes())?; 79 | Ok(()) 80 | } 81 | -------------------------------------------------------------------------------- /src/transpiler/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod bf2c; 2 | pub mod bf2js; 3 | --------------------------------------------------------------------------------