summaryrefslogtreecommitdiff
path: root/src/flint.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-04 14:02:19 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-04 14:02:19 +1200
commitb51ed9b9736eb0b333585b0b9cb1797054c4b69f (patch)
tree1b947d5672bc1d53c0cc9fdc0eacb0d64db3b5c2 /src/flint.cr
parent8dfc184c00f7c04e70f861914a944e3dbee3a136 (diff)
Custom exceptions are a bit more robust
Diffstat (limited to 'src/flint.cr')
-rw-r--r--src/flint.cr19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/flint.cr b/src/flint.cr
index 8f11223..89f1d3f 100644
--- a/src/flint.cr
+++ b/src/flint.cr
@@ -57,7 +57,7 @@ module Flint
if read_stdin
source_io = STDIN
- elsif source_file
+ elsif !source_file.nil?
# compilier complains without the not_nil!
source_io = File.new(source_file.not_nil!)
else
@@ -80,14 +80,25 @@ module Flint
end
begin
- program.not_nil!.interpret
+ p = program.not_nil!
+ case execution_mode
+ when :interpret
+ p.interpret
+ when :compile
+ p.compile
+ end
rescue ex : Util::ParserError
puts "Caught ParserError"
puts ex.message
exit(1)
- rescue ex : Brainfuck::MemoryError
- puts "Caught MemoryError"
+ rescue ex : Util::InterpreterError
+ puts "Error encountered while interpreting:"
+ puts ex.message
+ exit(1)
+ rescue ex : Util::CompilerError
+ puts "Failed to compile program:"
puts ex.message
+ exit(1)
end
end
end