Skip to content

Commit

Permalink
a lot of changes
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Carlson <[email protected]>
Co-authored-by: ojas_the_gr8 <[email protected]>
  • Loading branch information
3 people committed Jul 3, 2024
1 parent 5236f11 commit c98bb82
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 820 deletions.
10 changes: 10 additions & 0 deletions helix.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "helix-lang"
}
],
"settings": {
"svg.preview.background": "editor"
}
}
5 changes: 5 additions & 0 deletions source/cli/include/cli.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "cli/include/args.hh"
#include <array>
#include <cstddef>
#include <iostream>
#include <string>
197 changes: 150 additions & 47 deletions source/cli/source/cli.cc
Original file line number Diff line number Diff line change
@@ -1,48 +1,3 @@
/*
helix - command line interface
Usage:
helix [options] <file> [options-2]
helix (-h | --help)
helix --version
helix --license
Options:
-O1 --optimize1 Optimization level 1.
-O2 --optimize2 Optimization level 2.
-O3 --optimize3 Optimization level 3.
-O4 --optimize4 Optimization level 4.
-h --help Show this screen.
--version Show version.
--license Show license information.
--verbose Show verbose output.
--quiet Show no output.
--ast Show abstract syntax tree.
--tokens Show tokens.
--emit-llvm Show LLVM IR.
--emit-asm Show assembly.
--emit-ir Show intermediate representation. (C | C++)
--emit-doc Only extract doc-comments along with signatures.
--target <triple> Target triple.
--arch <arch> Target architecture.
--os <os> Target operating system.
--config <file> Specify configuration file.
--release Build in release mode.
--debug Build in debug mode.
Options-2:
-o <file> Output file.
--lib Compile as library.
-I<dir> Include directory.
-L<dir> Library directory.
-l<lib> Link library.
*/

/*
Helios - package manager / build system
Expand All @@ -64,6 +19,154 @@ Helios - package manager / build system
helios doc-gen Generate documentation.
*/

#include <cli/include/args.hh>
/*
helix - command line interface
Usage:
helix [options] <file> [options-2]
helix (-h | --help)
helix --version
helix --license
options:
-O1 --optimize1 Optimization level 1.
-O2 --optimize2 Optimization level 2.
-O3 --optimize3 Optimization level 3.
-O4 --optimize4 Optimization level 4.
-O5 --optimize5 Optimization level 5.
-h --help Show this screen.
-v --version Show version.
-l --license Show license information.
--verbose Show verbose output.
--quiet Show no output.
--emit-tokens Show tokens.
--emit-llvm Show LLVM IR.
--emit-asm Show assembly.
--emit-ast Show AST in json format
--emit-ir Show intermediate representation. (C++)
--emit-doc Only extract doc-comments along with signatures in json format.
--toolchain <options-3> Set the toolchain to use
--config <file> Specify configuration file.
-r --release Build in release mode.
-d --debug Build in debug mode with symbols.
options-2:
--lib [abi-options] Compile as library.
-o <file> Output file.
-I <dir> Include directory.
-L <dir> Library directory.
-l <lib> Link library.
options-3:
--target <triple> Target triple.
--arch <arch> Target architecture.
--os <os> Target operating system.
abi-options:
-py --python Python stub files gen and pylib compile
-rs --rust Rust source files gen and a rust compiler lib
-cxx --cxx C++ header files gen and linkable object file
-hlx --helix Helix ABI compatable libary
*/

#include <array>
#include <cstddef>
#include <iostream>
#include <string>

#include "cli/include/args.hh"

namespace command_line {
class CLIArgs {
template <size_t arr_size>
explicit CLIArgs(int argc, char **argv) {
args::ArgumentParser parser(
"This is a test program with a really long description that is probably going to have "
"to be wrapped across multiple different lines. This is a test to see how the line "
"wrapping works",
"This goes after the options. This epilog is also long enough that it will have to be "
"properly wrapped to display correctly on the screen");

args::HelpFlag help(parser, "HELP", "Show this help menu.", {'h', "help"});

args::ValueFlag<std::string> foo(parser, "FOO", "The foo flag.",
{'a', 'b', 'c', "a", "b", "c", "the-foo-flag"});

args::ValueFlag<std::string> bar(
parser, "BAR",
"The bar flag. This one has a lot of options, and will need wrapping in the "
"description, along with its long flag list.",
{'d', 'e', 'f', "d", "e", "f"});

args::ValueFlag<std::string> baz(
parser, "FOO",
"The baz flag. This one has a lot of options, and will need wrapping in the "
"description, even with its short flag list.",
{"baz"});

args::Positional<std::string> pos1(parser, "POS1", "The pos1 argument.");
args::PositionalList<std::string> poslist1(parser, "POSLIST1", "The poslist1 argument.");

try {
parser.ParseCLI(argc, argv);
} catch (args::Help) {
std::cout << parser;
return;
} catch (args::ParseError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return;
} catch (args::ValidationError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return;
}
}
};

struct HelixArguments {
// File and optional output file
std::string file;
std::optional<std::string> output_file;

// Options
bool optimize1 = false;
bool optimize2 = false;
bool optimize3 = false;
bool optimize4 = false;

bool help = false;
bool version = false;
bool license = false;

bool verbose = false;
bool quiet = false;

bool show_ast = false;
bool show_tokens = false;
bool emit_llvm = false;
bool emit_asm = false;
bool emit_ir = false;
bool emit_doc = false;

std::optional<std::string> target_triple;
std::optional<std::string> target_arch;
std::optional<std::string> target_os;

std::optional<std::string> config_file;
bool release = false;
bool debug = false;

void parse() {}
// Options-2
bool compile_as_library = false;
std::vector<std::string> include_dirs;
std::vector<std::string> library_dirs;
std::vector<std::string> link_libraries;
};
} // end namespace command_line
23 changes: 14 additions & 9 deletions source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@

#include <chrono>
#include <include/printV2>
#include <memory>

#include "token/include/lexer.hh"
#include "token/include/token.hh"
#include "parser/ast/include/parser.hh"
#include "parser/ast/include/nodes.hh"
#include "cli/include/cli.hh"
#include "parser/ast/include/ast.hh"
#include "tools/controllers/include/file_system.hh"
#include "parser/preprocessor/include/preprocessor.hh"

int main() {
int main(int argc, char **argv) {
using namespace token;
using namespace parser;
using namespace lexer;

auto start = std::chrono::high_resolution_clock::now();



std::string file_name = "/Volumes/Container/Projects/Helix/helix-lang/tests/main.hlx"; // relative to current working dir in POSIX shell (cmd/bash)

// read the file and tokenize its contents : stage 0
Expand All @@ -43,15 +48,15 @@ int main() {
// preprocessor::import_tree->print_tree(preprocessor::import_tree->get_root());

// print the preprocessed tokens
print_tokens(tokens);
// print_tokens(tokens);


for (auto &tok_ref : tokens) {
if (tok_ref->token_kind() == tokens::KEYWORD_FUNCTION) {
tok_ref.peek();
std::cout << tok_ref.peek()->get().value() << "\n";
}
}
auto node = std::make_unique<ast::Parentheses<ast::StringLiteral>>(tokens);

node->parse();

print(node->to_string());

// Print the time taken in nanoseconds and milliseconds
print("time taken: ", diff.count() * 1e+9, " ns");
print(" ", diff.count() * 1000, " ms");
Expand Down
Loading

0 comments on commit c98bb82

Please sign in to comment.