Add 'quiet' option, get_recursion_depth

This commit is contained in:
K. Lange 2023-12-24 09:09:07 +09:00
parent 416ed28206
commit 3a74ef5e21

View File

@ -203,12 +203,18 @@ KRK_Function(members) {
KRK_Function(set_recursion_depth) {
unsigned int maxdepth;
if (!krk_parseArgs("I",(const char*[]){"maxdepth"},&maxdepth)) return NONE_VAL();
int quiet = 0;
if (!krk_parseArgs("I|p",(const char*[]){"maxdepth","quiet"},&maxdepth,&quiet)) return NONE_VAL();
if (krk_currentThread.exitOnFrame != 0) {
if (quiet) return BOOLEAN_VAL(0);
return krk_runtimeError(vm.exceptions->valueError, "Can not change recursion depth in this context.");
}
krk_setMaximumRecursionDepth(maxdepth);
return NONE_VAL();
return BOOLEAN_VAL(1);
}
KRK_Function(get_recursion_depth) {
return INTEGER_VAL(krk_currentThread.maximumCallDepth);
}
void krk_module_init_kuroko(void) {
@ -262,6 +268,8 @@ void krk_module_init_kuroko(void) {
"Obtain a copy of a dict of the direct members of an object.");
KRK_DOC(BIND_FUNC(vm.system,set_recursion_depth),
"Change the maximum recursion depth of the current thread if possible.");
KRK_DOC(BIND_FUNC(vm.system,get_recursion_depth),
"Examine the maximum recursion depth of the current thread.");
krk_attachNamedObject(&vm.system->fields, "module", (KrkObj*)vm.baseClasses->moduleClass);
krk_attachNamedObject(&vm.system->fields, "path_sep", (KrkObj*)S(PATH_SEP));
KrkValue module_paths = krk_list_of(0,NULL,0);