-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLauncher.cpp
More file actions
58 lines (47 loc) · 1.54 KB
/
Launcher.cpp
File metadata and controls
58 lines (47 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Copyright (c) 2019-2025 Javier Pimás, Jan Vrany, Labware.
See (MIT) license in root directory.
*/
#include <vector>
#include <filesystem>
#include "Launcher.h"
#include "Util.h"
#include "Loader.h"
#include "GCedRef.h"
#include "Evaluator/Runtime.h"
using namespace Egg;
int
Launcher::main(const int argc, const char** argv)
{
if (argc != 2) {
printf("Usage: %s <module name>\n", argv[0]);
return 1;
}
Egg::Initialize();
// Determine modules directory from the module path argument
std::filesystem::path modulePath(argv[1]);
std::string modulesDir;
if (modulePath.has_parent_path()) {
modulesDir = modulePath.parent_path().string();
} else {
modulesDir = "modules";
}
auto loader = new Loader(modulesDir);
Runtime* runtime = loader->loadKernel();
if (!runtime) {
return 1;
}
// Extract module name from path
auto moduleName = modulePath.filename().string();
auto kernelModule = (Object*)runtime->_kernel->_exports["__module__"];
runtime->sendLocal_to_("useHostModuleLoader", kernelModule);
auto moduleNameSym = (Object*)runtime->addSymbol_(moduleName);
auto module = runtime->sendLocal_to_with_("load:", kernelModule, moduleNameSym);
GCedRef moduleRef(module);
auto args = std::vector<Object*>();
for (int i = 0; i < argc; i++)
args.push_back((Object*)runtime->newString_(argv[i]));
auto array = runtime->newArray_(args);
runtime->sendLocal_to_with_("main:", moduleRef.get(), (Object*)array);
return 0;
}