save replxx history more

This commit is contained in:
dzaima 2022-10-19 22:59:55 +03:00
parent 983452b409
commit 07fa4a066b
4 changed files with 21 additions and 1 deletions

View File

@ -7,6 +7,7 @@
bool please_tail_call_err = true;
void before_exit(void);
bool inErr;
NORETURN NOINLINE void err(char* s) {
if (inErr) {
@ -21,6 +22,7 @@ NORETURN NOINLINE void err(char* s) {
vm_pstLive(); fflush(stderr); fflush(stdout);
print_vmStack(); fflush(stderr);
fputs("CBQN interpreter entered unexpected state, exiting.\n", stderr);
before_exit();
#ifdef DEBUG
__builtin_trap();
#endif

View File

@ -513,6 +513,7 @@ B bqn_execFile(B path, B args) { // consumes both
return bqn_exec(path_chars(inc(path)), path, args);
}
void before_exit(void);
void bqn_exit(i32 code) {
#ifdef DUMP_ON_EXIT
cbqn_heapDump();
@ -520,6 +521,7 @@ void bqn_exit(i32 code) {
rtWrap_print();
CTR_FOR(CTR_PRINT)
print_allocStats();
before_exit();
exit(code);
}

View File

@ -226,6 +226,16 @@ static NOINLINE void repl_init() {
completion_impl(inp, res, true, dist);
}
static Replxx* global_replxx;
static char* global_histfile;
void before_exit() {
if (global_replxx!=NULL && global_histfile!=NULL) {
replxx_history_save(global_replxx, global_histfile);
replxx_end(global_replxx);
global_replxx = NULL;
}
}
static void cbqn_init_replxx() {
build_theme(theme0_built, theme0);
sysvalNames = emptyHVec();
@ -239,6 +249,8 @@ static NOINLINE void repl_init() {
gc_add(sysvalNames);
gc_add(sysvalNamesNorm);
}
#else
void before_exit() { }
#endif
@ -656,6 +668,8 @@ int main(int argc, char* argv[]) {
dec(p2);
gc_add(tag(TOBJ(histfile), OBJ_TAG));
replxx_history_load(replxx, histfile);
global_replxx = replxx;
global_histfile = histfile;
replxx_set_ignore_case(replxx, true);
replxx_set_highlighter_callback(replxx, highlighter_replxx, NULL);
@ -668,8 +682,8 @@ int main(int argc, char* argv[]) {
if (errno==0) printf("\n");
break;
}
cbqn_runLine((char*)ln, strlen(ln));
replxx_history_add(replxx, ln);
cbqn_runLine((char*)ln, strlen(ln));
replxx_history_save(replxx, histfile);
}
}

View File

@ -1594,6 +1594,7 @@ NOINLINE void printErrMsg(B msg) {
}
void before_exit(void);
NOINLINE NORETURN void throwImpl(bool rethrow) {
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
// while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n");
@ -1619,6 +1620,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
Env* envEnd = envStart+envPrevHeight;
unwindEnv(envStart-1);
vm_pst(envCurr+1, envEnd);
before_exit();
#ifdef DEBUG
__builtin_trap();
#else