From 70dbbd733758b61317af37af1cbbec6aa4b6e2a5 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sun, 4 Sep 2022 14:24:27 +1200 Subject: Minor refactors --- src/flint.cr | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/flint.cr') 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 -- cgit v1.2.1