From e229d19b7c2dfdc71813f91709f1afadff0abede Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 24 Jul 2019 01:56:37 +0200 Subject: [PATCH] Updated the command line parsing a little bit, as well as the README. --- .gitignore | 4 +- README.md | 20 ++- src/build/build_options.c | 256 ++++++++++++++++++++++++++++++++++- src/build/build_options.h | 22 ++- src/build/project_creation.c | 1 + src/main.c | 189 +++----------------------- 6 files changed, 317 insertions(+), 175 deletions(-) diff --git a/.gitignore b/.gitignore index 2f62d91eb..7f58cd346 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,6 @@ modules.order Module.symvers Mkfile.old dkms.conf -cmake-build-debug/ \ No newline at end of file +cmake-build-debug/ + +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 108fd43c7..e4b886446 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,23 @@ # C3 Language -This is a prototype language branched off C2. It goes further than C2 in several regards, while still embracing the goals of C2. +This is a prototype language heavily inspired by C2. It goes further than C2 in several regards, while still embracing the goals of C2. + +### Design Principles +- Procedural "get things done"-type of language. +- Try to stay close to C - only change where truly needed. +- Flawless C integration. +- Learning C3 should be easy for a C programmer. +- Dare violating the "close to metal" principle if the value is great. +- Not an object oriented language. +- Avoid "big ideas". +- Avoid the kitchen sink language trap. + +### Current status As of now, very little code towards the compiler will be added here. -There is a "work-in-progress" C2 compiler in C called Titanos, which an eventual compiler might be based on. \ No newline at end of file +There is a "work-in-progress" C2 compiler in C called Titanos, which an eventual compiler might be based on. + +A design draft can be found here: https://lerno.github.io/c3docs/ + +Discuss the language on the r/ProgrammingLanguages Discord server: https://discord.gg/cfu4wdk \ No newline at end of file diff --git a/src/build/build_options.c b/src/build/build_options.c index 63b43ebca..17509d642 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -3,5 +3,259 @@ // license that can be found in the LICENSE file. #include "build_options.h" +#include +#include +#include +#include +#include +#include -BuildOptions build_options; \ No newline at end of file +#include "../utils/errors.h" + +static const char* DEFAULT_TARGET = "default"; + +BuildOptions build_options; +static int arg_index; +static int arg_count; +static const char** args; +static const char* current_arg; + + +#define OUTPUT(string, ...) fprintf(stdout, string "\n", ##__VA_ARGS__) +#define FAIL_WITH_ERR(string, ...) do { fprintf(stderr, "Error: " string "\n\n", ##__VA_ARGS__); usage(); exit(EXIT_FAILURE); } while (0) + +static void usage(void) +{ + OUTPUT("Usage: %s [] []", args[0]); + OUTPUT(""); + OUTPUT("Commands:"); + OUTPUT(""); + OUTPUT(" compile [ ...] Compile files without a project into an executable."); + OUTPUT(" init Initialize a new project structure."); + OUTPUT(" build [] Build the target in the current project."); + OUTPUT(" clean Clean all build files."); + OUTPUT(" run [] Run (and build if needed) the target in the current project."); + OUTPUT(" dist [] Clean and build a target for distribution."); + OUTPUT(" docs [] Generate documentation for the target."); + OUTPUT(" bench [] Benchmark a target."); + OUTPUT(" clean-run [] Clean, then run the target."); + OUTPUT(" compile-run [ ...] Compile files then immediately run the result."); + OUTPUT(""); + OUTPUT("Options:"); + OUTPUT(" --lib - Use this directory as the c3 library path."); + OUTPUT(" --path - Use this as the base directory for the current command."); + OUTPUT(" --template