summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/brainfuck/program.cr2
-rw-r--r--src/flint.cr19
-rw-r--r--src/thue/program.cr5
-rw-r--r--src/util.cr14
4 files changed, 34 insertions, 6 deletions
diff --git a/src/brainfuck/program.cr b/src/brainfuck/program.cr
index 5994d40..5b569df 100644
--- a/src/brainfuck/program.cr
+++ b/src/brainfuck/program.cr
@@ -60,7 +60,7 @@ class Brainfuck::Program
end
def compile
- raise NotImplementedError.new
+ raise Util::NoCompilerAvailableError.new("No available compiler for brainfuck")
end
# assumes valid code
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
diff --git a/src/thue/program.cr b/src/thue/program.cr
index f449f5a..96e1284 100644
--- a/src/thue/program.cr
+++ b/src/thue/program.cr
@@ -1,5 +1,6 @@
require "./thue.cr"
require "./parser.cr"
+require "../util.cr"
class Thue::Program
def initialize(@parser : Parser)
@@ -17,5 +18,9 @@ class Thue::Program
puts state
end
+
+ def compile
+ raise Util::NoCompilerAvailableError.new("No available compilier for Thue")
+ end
end
diff --git a/src/util.cr b/src/util.cr
index 841a2b2..8c5df5c 100644
--- a/src/util.cr
+++ b/src/util.cr
@@ -1,5 +1,17 @@
module Util
- class ParserError < Exception
+ class FlintError < Exception
+ end
+
+ class ParserError < FlintError
+ end
+
+ class InterpreterError < FlintError
+ end
+
+ class CompilerError < FlintError
+ end
+
+ class NoCompilerAvailableError < CompilerError
end
end