16int main(
int argc,
char** argv)
18 using namespace clipp;
21#if ARK_VERSION_MAJOR == 4
22# error "this code block should be removed from ArkScript 4.x.y"
25 namespace fs = std::filesystem;
26 fs::path program(argv[0]);
28 if (program.stem() ==
"ark")
29 std::cout << termcolor::yellow <<
"Warning" << termcolor::reset <<
" the command `ark' is being deprecated in favor of `arkscript'" << std::endl;
45 mode selected = mode::repl;
48 std::string file =
"",
53 constexpr uint16_t max_uint16 = std::numeric_limits<uint16_t>::max();
55 uint16_t bcr_page = max_uint16;
56 uint16_t bcr_start = max_uint16;
57 uint16_t bcr_end = max_uint16;
60 std::vector<std::string> wrong, script_args;
62 std::string libdir =
"";
63 std::vector<std::string> libenv;
67 option(
"-h",
"--help").set(selected, mode::help).doc(
"Display this message")
68 | option(
"-v",
"--version").set(selected, mode::version).doc(
"Display ArkScript version and exit")
69 | option(
"--dev-info").set(selected, mode::dev_info).doc(
"Display development information and exit")
71 required(
"-e",
"--eval").set(selected, mode::eval).doc(
"Evaluate ArkScript expression")
72 & value(
"expression", eval_expresion)
75 required(
"-c",
"--compile").set(selected, mode::compile).doc(
"Compile the given program to bytecode, but do not run")
77 , joinable(repeatable(option(
"-d",
"--debug").call([&]{ debug++; }).doc(
"Increase debug level (default: 0)")))
80 required(
"-bcr",
"--bytecode-reader").set(selected, mode::bytecode_reader).doc(
"Launch the bytecode reader")
90 , option(
"-s",
"--slice").doc(
"Select a slice of instructions in the bytecode")
91 & value(
"start", bcr_start)
92 & value(
"end", bcr_end)
96 , option(
"-p",
"--page").doc(
"Set the bytecode reader code segment to display")
97 & value(
"page", bcr_page)
102 value(
"file", file).set(selected, mode::run)
104 joinable(repeatable(option(
"-d",
"--debug").call([&]{ debug++; })))
108 option(
"-L",
"--lib").doc(
"Set the location of the ArkScript standard library. Paths can be delimited by ';'")
109 & value(
"lib_dir", libdir)
112 , any_other(script_args)
115 required(
"--ast").set(selected, mode::ast).doc(
"Compile the given program and output its AST as JSON to stdout")
116 & value(
"file", file)
117 , joinable(repeatable(option(
"-d",
"--debug").call([&]{ debug++; }).doc(
"Increase debug level (default: 0)")))
120 option(
"-L",
"--lib").doc(
"Set the location of the ArkScript standard library. Paths can be delimited by ';'")
121 & value(
"lib_dir", libdir)
128 auto fmt = doc_formatting {}
132 .split_alternatives(
true)
133 .merge_alternative_flags_with_common_prefix(
true)
136 if (parse(argc, argv, cli) && wrong.empty())
141 libenv = Utils::splitString(libdir,
';');
147 std::cout << make_man_page(cli,
"arkscript", fmt)
148 .prepend_section(
"DESCRIPTION",
" ArkScript programming language")
149 .append_section(
"LICENSE",
" Mozilla Public License 2.0")
160 "Have been compiled with %s, options: %s\n\n"
161 "sizeof(Ark::Value) = %zuB\n"
162 " sizeof(Value_t) = %zuB\n"
163 " sizeof(ValueType) = %zuB\n"
164 " sizeof(ProcType) = %zuB\n"
165 " sizeof(Ark::Closure) = %zuB\n"
166 " sizeof(Ark::UserType) = %zuB\n"
167 "\nVirtual Machine\n"
168 "sizeof(Ark::VM) = %zuB\n"
169 " sizeof(Ark::State) = %zuB\n"
170 " sizeof(Ark::Scope) = %zuB\n"
171 " sizeof(ExecutionContext) = %zuB\n"
173 " sizeof(vector<Ark::Value>) = %zuB\n"
174 " sizeof(std::string) = %zuB\n"
175 " sizeof(String) = %zuB\n"
176 " sizeof(char) = %zuB\n"
177 "\nsizeof(Node) = %zuB\n",
192 sizeof(std::vector<Ark::Value>),
214 std::cerr <<
"Could not compile file at " << file <<
"\n";
229 std::cerr <<
"Could not run file at " << file <<
"\n";
236#ifdef ARK_PROFILER_COUNT
240 "\tCreations: %u\n\tCopies: %u\n\tMoves: %u\n\n\tCopy coeff: %f",
241 Ark::internal::value_creations,
242 Ark::internal::value_copies,
243 Ark::internal::value_moves,
244 static_cast<float>(Ark::internal::value_copies) / Ark::internal::value_creations);
255 if (!state.
doString(eval_expresion))
257 std::cerr <<
"Could not evaluate expression\n";
269 std::cout << jcompiler.
compile() << std::endl;
273 case mode::bytecode_reader:
280 if (bcr_page == max_uint16 && bcr_start == max_uint16)
282 else if (bcr_page != max_uint16 && bcr_start == max_uint16)
283 bcr.
display(segment, std::nullopt, std::nullopt, bcr_page);
284 else if (bcr_page == max_uint16 && bcr_start != max_uint16)
285 bcr.
display(segment, bcr_start, bcr_end);
287 bcr.
display(segment, bcr_start, bcr_end, bcr_page);
289 catch (
const std::exception& e)
291 std::printf(
"%s\n", e.what());
299 for (
const auto& arg : wrong)
300 std::printf(
"'%s' ins't a valid argument\n", arg.c_str());
303 std::cout << make_man_page(cli,
"arkscript", fmt)
304 .prepend_section(
"DESCRIPTION",
" ArkScript programming language")
305 .append_section(
"LICENSE",
" Mozilla Public License 2.0")
Includes the needed files to start using ArkScript.
constexpr int ARK_VERSION_MAJOR
constexpr int ARK_VERSION_PATCH
#define ARK_COMPILATION_OPTIONS
constexpr int ARK_VERSION_MINOR
Lots of utilities about the filesystem.
ArkScript REPL - Read Eval Print Loop.
This class is just a helper to.
void display(BytecodeSegment segment=BytecodeSegment::All, std::optional< uint16_t > sStart=std::nullopt, std::optional< uint16_t > sEnd=std::nullopt, std::optional< uint16_t > cPage=std::nullopt)
Display the bytecode opcode in a human friendly way.
void feed(const std::string &file)
Construct needed data before displaying information about a given file.
void feed(const std::string &code, const std::string &filename=ARK_NO_NAME_FILE)
Feed the differents variables with information taken from the given source code file.
std::string compile()
Start the compilation.
Ark state to handle the dirty job of loading and compiling ArkScript code.
void setArgs(const std::vector< std::string > &args) noexcept
Set the script arguments in sys:args.
void setDebug(unsigned level) noexcept
Set the debug level.
bool doFile(const std::string &filename)
Compile a file, and use the resulting bytecode.
bool doString(const std::string &code)
Compile a string (representing ArkScript code) and store resulting bytecode in m_bytecode.
A class to be use C++ objects in ArkScript.
The ArkScript virtual machine, executing ArkScript bytecode.
int run() noexcept
Run the bytecode held in the state.
Value(*)(std::vector< Value > &, VM *) ProcType
std::variant< double, String, internal::PageAddr_t, ProcType, internal::Closure, UserType, std::vector< Value >, Value * > Value_t
A node of an Abstract Syntax Tree for ArkScript.
A class to handle the VM scope more efficiently.
int main(int argc, char **argv)
std::string readFile(const std::string &name)
Helper to read a file.
constexpr uint16_t DefaultFeatures
constexpr uint16_t FeatureRemoveUnusedVars