Skip to content

Commit

Permalink
Merge pull request #28 from X-FRI/main
Browse files Browse the repository at this point in the history
Add cli module
  • Loading branch information
muqiuhan authored Apr 24, 2024
2 parents 6c5492f + 950f8f9 commit 9b00eca
Show file tree
Hide file tree
Showing 27 changed files with 7,216 additions and 356 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ContinuationIndentWidth: 2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveMacros:
Expand Down
43 changes: 43 additions & 0 deletions cli/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <string>
#include "utils/structopt.hpp"
#include "compiler.h"

STRUCTOPT(
swallow::compiler::CompilerOptions,
file,
verbose,
dump_ast,
dump_types,
dump_gmachine_ir);

int main(int argc, char *argv[])
{
try
{
const std::string command = argv[1] == nullptr ? "" : argv[1];
if (command == "c" || command == "compile")
{
return swallow::compiler::Compiler(
structopt::app(
"swa compile",
swallow::compiler::CompilerOptions::VERSION,
swallow::compiler::CompilerOptions::HELP)
.parse<swallow::compiler::CompilerOptions>(argc - 1, &argv[1]));
}
else if (command == "i" || command == "repl")
{
return 0;
}
else
{
std::cout << "USAGE: swa [command]\n\ncommand:\n\tc, compile\tcall the "
"compiler\n\ti, repl\t\tcall the repl interpreter\n";
}
}
catch (const structopt::exception &e)
{
std::cout << e.what() << '\n';
std::cout << e.help() << '\n';
}
return 0;
}
Loading

0 comments on commit 9b00eca

Please sign in to comment.