Skip to content

Commit 8cd0962

Browse files
committed
feat: Argon options are now accessible during runtime within the 'runtime' module
1 parent 9b93025 commit 8cd0962

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

argon/vm/config.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ bool argon::vm::ConfigInit(Config *config, int argc, char **argv) {
184184
exit(EXIT_SUCCESS);
185185
case 'i':
186186
interactive = true;
187+
config->interactive = interactive;
187188
break;
188189
case 'O': {
189190
auto lvl = *(status.argv[status.argc_cur]) - '0';

argon/vm/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace argon::vm {
2020
bool quiet;
2121
bool stack_trace;
2222
bool unbuffered;
23+
2324
int cmd;
2425
int file;
2526
int max_vc;

argon/vm/mod/runtime.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <argon/vm/runtime.h>
77
#include <argon/vm/version.h>
88

9+
#include <argon/vm/datatype/boolean.h>
910
#include <argon/vm/datatype/integer.h>
1011
#include <argon/vm/datatype/tuple.h>
1112

@@ -17,6 +18,70 @@ Tuple *ParseCMDArgs(int argc, char **argv);
1718

1819
// EOL
1920

21+
bool ExposeConfig(Module *self) {
22+
#define PUT_BOOL(name, field) \
23+
if (!DictInsert(ret, #name, (ArObject *) (field ? True : False))) { \
24+
Release(ret); \
25+
return false; }
26+
27+
#define PUT_INT(name, field) \
28+
if((tmp = (ArObject *) IntNew(field)) == nullptr) { \
29+
Release(ret); \
30+
return false; } \
31+
\
32+
if (!DictInsert(ret, #name, tmp)) { \
33+
Release(tmp); \
34+
Release(ret); \
35+
return false; } \
36+
\
37+
Release(tmp);
38+
39+
#define PUT_STR(name, field) \
40+
if((tmp = (ArObject *) StringNew(field)) == nullptr) { \
41+
Release(ret); \
42+
return false; } \
43+
\
44+
if (!DictInsert(ret, #name, tmp)) { \
45+
Release(tmp); \
46+
Release(ret); \
47+
return false; } \
48+
\
49+
Release(tmp);
50+
51+
auto *conf = argon::vm::GetFiber()->context->global_config;
52+
53+
auto *ret = DictNew();
54+
if (ret == nullptr)
55+
return false;
56+
57+
ArObject *tmp;
58+
59+
PUT_BOOL(interactive, conf->interactive)
60+
PUT_BOOL(nogc, conf->nogc)
61+
PUT_BOOL(quiet, conf->quiet)
62+
PUT_BOOL(stack_trace, conf->stack_trace)
63+
PUT_BOOL(unbuffered, conf->unbuffered)
64+
65+
PUT_INT(max_vc, conf->max_vc)
66+
PUT_INT(max_ost, conf->max_ost)
67+
PUT_INT(fiber_ss, conf->fiber_ss)
68+
PUT_INT(fiber_pool, conf->fiber_pool)
69+
PUT_INT(optim_lvl, conf->optim_lvl)
70+
71+
if (!ModuleAddObject(self, "config", (ArObject *) ret, MODULE_ATTRIBUTE_DEFAULT)) {
72+
Release(ret);
73+
74+
return false;
75+
}
76+
77+
Release(ret);
78+
79+
return true;
80+
#undef PUT_BOOL
81+
#undef PUT_INT
82+
#undef PUT_STR
83+
}
84+
2085
bool SetAbout(Module *self) {
2186
#define ADD_INFO(macro, key) \
2287
if ((tmp = (ArObject*) StringNew(macro)) == nullptr) \
@@ -114,6 +179,9 @@ bool SetOsName(Module *self) {
114179
}
115180

116181
bool RuntimeInit(Module *self) {
182+
if (!ExposeConfig(self))
183+
return false;
184+
117185
if (!SetAbout(self))
118186
return false;
119187

0 commit comments

Comments
 (0)