summaryrefslogtreecommitdiff
path: root/src/flint.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-02 22:06:13 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-02 22:06:13 +1200
commit146f12187abbe8ba18df8f1d417a44cfe557b794 (patch)
treebc2e48f1b43e47add843da55f2d7f121b57a38f1 /src/flint.cr
parent4dd4e596ae6e5da84f2ce4296cbf9c030efe69bb (diff)
Able to interpret brainfuck
Diffstat (limited to 'src/flint.cr')
-rw-r--r--src/flint.cr9
1 files changed, 7 insertions, 2 deletions
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