save replxx history more
This commit is contained in:
parent
983452b409
commit
07fa4a066b
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
bool please_tail_call_err = true;
|
bool please_tail_call_err = true;
|
||||||
|
|
||||||
|
void before_exit(void);
|
||||||
bool inErr;
|
bool inErr;
|
||||||
NORETURN NOINLINE void err(char* s) {
|
NORETURN NOINLINE void err(char* s) {
|
||||||
if (inErr) {
|
if (inErr) {
|
||||||
@ -21,6 +22,7 @@ NORETURN NOINLINE void err(char* s) {
|
|||||||
vm_pstLive(); fflush(stderr); fflush(stdout);
|
vm_pstLive(); fflush(stderr); fflush(stdout);
|
||||||
print_vmStack(); fflush(stderr);
|
print_vmStack(); fflush(stderr);
|
||||||
fputs("CBQN interpreter entered unexpected state, exiting.\n", stderr);
|
fputs("CBQN interpreter entered unexpected state, exiting.\n", stderr);
|
||||||
|
before_exit();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -513,6 +513,7 @@ B bqn_execFile(B path, B args) { // consumes both
|
|||||||
return bqn_exec(path_chars(inc(path)), path, args);
|
return bqn_exec(path_chars(inc(path)), path, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void before_exit(void);
|
||||||
void bqn_exit(i32 code) {
|
void bqn_exit(i32 code) {
|
||||||
#ifdef DUMP_ON_EXIT
|
#ifdef DUMP_ON_EXIT
|
||||||
cbqn_heapDump();
|
cbqn_heapDump();
|
||||||
@ -520,6 +521,7 @@ void bqn_exit(i32 code) {
|
|||||||
rtWrap_print();
|
rtWrap_print();
|
||||||
CTR_FOR(CTR_PRINT)
|
CTR_FOR(CTR_PRINT)
|
||||||
print_allocStats();
|
print_allocStats();
|
||||||
|
before_exit();
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/main.c
16
src/main.c
@ -226,6 +226,16 @@ static NOINLINE void repl_init() {
|
|||||||
completion_impl(inp, res, true, dist);
|
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() {
|
static void cbqn_init_replxx() {
|
||||||
build_theme(theme0_built, theme0);
|
build_theme(theme0_built, theme0);
|
||||||
sysvalNames = emptyHVec();
|
sysvalNames = emptyHVec();
|
||||||
@ -239,6 +249,8 @@ static NOINLINE void repl_init() {
|
|||||||
gc_add(sysvalNames);
|
gc_add(sysvalNames);
|
||||||
gc_add(sysvalNamesNorm);
|
gc_add(sysvalNamesNorm);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void before_exit() { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -656,6 +668,8 @@ int main(int argc, char* argv[]) {
|
|||||||
dec(p2);
|
dec(p2);
|
||||||
gc_add(tag(TOBJ(histfile), OBJ_TAG));
|
gc_add(tag(TOBJ(histfile), OBJ_TAG));
|
||||||
replxx_history_load(replxx, histfile);
|
replxx_history_load(replxx, histfile);
|
||||||
|
global_replxx = replxx;
|
||||||
|
global_histfile = histfile;
|
||||||
|
|
||||||
replxx_set_ignore_case(replxx, true);
|
replxx_set_ignore_case(replxx, true);
|
||||||
replxx_set_highlighter_callback(replxx, highlighter_replxx, NULL);
|
replxx_set_highlighter_callback(replxx, highlighter_replxx, NULL);
|
||||||
@ -668,8 +682,8 @@ int main(int argc, char* argv[]) {
|
|||||||
if (errno==0) printf("\n");
|
if (errno==0) printf("\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cbqn_runLine((char*)ln, strlen(ln));
|
|
||||||
replxx_history_add(replxx, ln);
|
replxx_history_add(replxx, ln);
|
||||||
|
cbqn_runLine((char*)ln, strlen(ln));
|
||||||
replxx_history_save(replxx, histfile);
|
replxx_history_save(replxx, histfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/vm.c
2
src/vm.c
@ -1594,6 +1594,7 @@ NOINLINE void printErrMsg(B msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void before_exit(void);
|
||||||
NOINLINE NORETURN void throwImpl(bool rethrow) {
|
NOINLINE NORETURN void throwImpl(bool rethrow) {
|
||||||
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
|
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
|
||||||
// while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n");
|
// 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;
|
Env* envEnd = envStart+envPrevHeight;
|
||||||
unwindEnv(envStart-1);
|
unwindEnv(envStart-1);
|
||||||
vm_pst(envCurr+1, envEnd);
|
vm_pst(envCurr+1, envEnd);
|
||||||
|
before_exit();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
#else
|
#else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user