)clearImportCache

This commit is contained in:
dzaima 2022-06-05 17:17:20 +03:00
parent 0674c6bafb
commit 14b7942556
4 changed files with 33 additions and 13 deletions

View File

@ -10,14 +10,28 @@ Execute the contents of the file as if it were REPL input (but allowing multilin
Execute the expression, but don't print its result.
## `)profile expr` / `)profile@frequency expr`
## `)clearImportCache`
Profile the expression at the given sampling frequency, or 5000 samples/second by default
Clear the cache of monadic `•Import` calls, resulting in re-evaluating the source the next time one is executed
## `)t expr` / `)time expr` / `)t:n expr` / `)time:n expr`
Time the argument expression. `n` specifies the number of times to repeat. Exists to allow not escaping quotes and less overhead for timing very fast & small expressions.
## `)profile expr` / `)profile@frequency expr`
Profile the expression at the given sampling frequency, or 5000 samples/second by default
## `)vars`
List the globally defined variables.
## `)erase name`
Erase the specified variable name.
Not a system function because it only clears the variables value (previous code `↩`ing it will still be able to), and to allow it to be executed even when the VM is completely out of memory such that it can't even parse REPL input BQN.
## `)mem`
Get statistics on memory usage.
@ -26,16 +40,6 @@ Get statistics on memory usage.
`)mem s` to get a breakdown of the number of objects with a specific size.
`)mem f` to get breakdown of free bucket counts per size.
## `)erase name`
Erase the specified variable name.
Not a system function because it only clears the variables value (previous code `↩`ing it will still be able to), and to allow it to be executed even when the VM is completely out of memory such that it can't even parse an expression.
## `)vars`
List the globally defined variables.
## `)gc`
Force garbage collection.
@ -46,4 +50,4 @@ Not a system function because currently CBQN doesn't support garbage collection
## `)internalPrint expr`
Use the internal object printing system to show the expression result.
Use the internal object printing system to show the expression result. Mainly for debugging in situations where the BQN self-hosted formatter can't be used.

View File

@ -314,6 +314,10 @@ void setPrevImport(B path, i32 pos) {
bool had; i32 prev = mk_b2i(&prevImports, path, &had);
prevImports->a[prev].val = pos;
}
void clearImportCacheMap() {
if (prevImports!=NULL) free_b2i(prevImports);
prevImports = NULL;
}
static H_b2i* globalNames;
static B globalNameList;

View File

@ -635,6 +635,7 @@ B import_c2(B d, B w, B x) {
// defined in fns.c
i32 getPrevImport(B path);
void setPrevImport(B path, i32 pos);
void clearImportCacheMap(void);
static B importKeyList; // exists for GC roots as the hashmap doesn't
static B importValList;
@ -677,6 +678,13 @@ static void sys_gcFn() {
mm_visit(lastErrMsg);
#endif
}
void clearImportCache() {
if (importKeyList.u!=0) {
dec(importKeyList); importKeyList = m_f64(0);
dec(importValList); importValList = m_f64(0);
}
clearImportCacheMap();
}
static NFnDesc* fTypeDesc;

View File

@ -44,6 +44,7 @@ bool profiler_start(i64 hz);
bool profiler_stop(void);
void profiler_free(void);
void profiler_displayResults(void);
void clearImportCache(void);
i64 readInt(char** p) {
char* c = *p;
@ -129,6 +130,9 @@ void cbqn_runLine0(char* ln, i64 read) {
}
printf("No such variable found\n");
return;
} else if (isCmd(cmdS, &cmdE, "clearImportCache ")) {
clearImportCache();
return;
} else if (isCmd(cmdS, &cmdE, "vars")) {
B r = listVars(gsc);
if (q_N(r)) {