From 146f12187abbe8ba18df8f1d417a44cfe557b794 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Fri, 2 Sep 2022 22:06:13 +1200 Subject: Able to interpret brainfuck --- src/flint.cr | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/flint.cr') diff --git a/src/flint.cr b/src/flint.cr index 1c67cc9..f2323a2 100644 --- a/src/flint.cr +++ b/src/flint.cr @@ -24,7 +24,9 @@ module Flint memory_size = Brainfuck::DEFAULT_TAPE_SIZE parser.banner = "Useage: flint brainfuck [OPTIONS] [FILE]" - parser.on("-t CELLS", "--tape-size=CELLS", "specify the number of memory cells in the tape, defaults to 30,000") { nil } + parser.on("-t CELLS", "--tape-size=CELLS", "specify the number of memory cells in the tape, defaults to 30,000") do |_cells| + memory_size = _cells.to_i + end end parser.on("-h", "--help", "show this help and exit") do @@ -67,7 +69,7 @@ module Flint if chosen_language == :brainfuck bf_parser = Brainfuck::Parser.new(source_io) - program = Brainfuck::Program.new(bf_parser) + program = Brainfuck::Program.new(bf_parser, memory_size) end begin @@ -76,6 +78,9 @@ module Flint puts "Caught ParserError" puts ex.message exit(1) + rescue ex : Brainfuck::MemoryError + puts "Caught MemoryError" + puts ex.message end end end -- cgit v1.2.1