summaryrefslogtreecommitdiff
path: root/src/flint.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-04 14:24:27 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-04 14:24:27 +1200
commit70dbbd733758b61317af37af1cbbec6aa4b6e2a5 (patch)
tree659b61d54ce36dbb82769bd2cc952a8665596d7c /src/flint.cr
parent221d689daf4637c7169f9104df0d4b66d00d0370 (diff)
Minor refactors
Diffstat (limited to 'src/flint.cr')
-rw-r--r--src/flint.cr16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/flint.cr b/src/flint.cr
index 02255b2..20a9b54 100644
--- a/src/flint.cr
+++ b/src/flint.cr
@@ -9,8 +9,13 @@ require "./thue/*"
module Flint
VERSION = "0.1.1"
+ enum ExecutionMode
+ Interpret
+ Compile
+ end
+
def self.main
- execution_mode = :interpret
+ execution_mode = ExecutionMode::Interpret
chosen_language = nil
memory_size = nil
source_file = nil
@@ -21,7 +26,6 @@ module Flint
parser.on("brainfuck", "select brainfuck as the language") do
chosen_language = :brainfuck
- memory_size = Brainfuck::DEFAULT_TAPE_SIZE
parser.banner = "Usage: flint brainfuck [OPTIONS] [FILE]"
parser.on("-t CELLS", "--tape-size=CELLS", "specify the number of memory cells in the tape, defaults to 30,000") do |_cells|
@@ -42,14 +46,14 @@ module Flint
end
parser.on("-i", "--interpet", "interpet the provided source code, implied by default, overridden by '-c' or '--compile'") { nil }
parser.on("-c", "--compile", "produce a binary or different source code file instead of interpeting the code, overrides an explicit '-i' or '--intepret' flag") do
- execution_mode = :compile
+ execution_mode = ExecutionMode::Compile
end
parser.on("--stdin", "read source code from STDIN instead of a file") do
read_stdin = true
end
parser.unknown_args do |_args|
- source_file = _args[0] unless _args.empty?
+ source_file = _args[0]?
end
end
@@ -79,9 +83,9 @@ module Flint
begin
p = program.not_nil!
case execution_mode
- when :interpret
+ when ExecutionMode::Interpret
p.interpret
- when :compile
+ when ExecutionMode::Compile
p.compile
end
rescue ex : Util::ParserError