indent REPL

This commit is contained in:
dzaima 2021-06-27 21:22:06 +03:00
parent a4446716bf
commit 1ffd3a207a

View File

@ -54,6 +54,7 @@ int main(int argc, char* argv[]) {
} }
#endif #endif
bool startREPL = argc==1; bool startREPL = argc==1;
bool silentREPL = false;
if (!startREPL) { if (!startREPL) {
i32 i = 1; i32 i = 1;
while (i!=argc) { while (i!=argc) {
@ -70,7 +71,8 @@ int main(int argc, char* argv[]) {
"-p code: execute the argument as BQN and print its result pretty-printed\n" "-p code: execute the argument as BQN and print its result pretty-printed\n"
"-o code: execute the argument as BQN and print its raw result\n" "-o code: execute the argument as BQN and print its raw result\n"
"-M num : set maximum heap size to num megabytes\n" "-M num : set maximum heap size to num megabytes\n"
"-r : start the REPL after all further arguments\n" "-r : start the REPL after executing all arguments\n"
"-s : start a silent REPL\n"
, argv[0]); , argv[0]);
exit(0); exit(0);
} else { } else {
@ -112,10 +114,8 @@ int main(int argc, char* argv[]) {
mm_heapMax = am*1024*1024; mm_heapMax = am*1024*1024;
break; break;
} }
case 'r': { case 'r': { startREPL = true; break; }
startREPL = true; case 's': { startREPL = true; silentREPL = true; break; }
break;
}
} }
} }
} }
@ -152,8 +152,9 @@ int main(int argc, char* argv[]) {
while (true) { // exit by evaluating an empty expression while (true) { // exit by evaluating an empty expression
char* ln = NULL; char* ln = NULL;
size_t gl = 0; size_t gl = 0;
if (!silentREPL) printf(" ");
i64 read = getline(&ln, &gl, stdin); i64 read = getline(&ln, &gl, stdin);
if (read<=0 || ln[0]==0 || ln[0]==10) break; if (read<=0 || ln[0]==0 || ln[0]==10) { if(!silentREPL) putchar('\n'); break; }
Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), inc(bi_emptySVec), gsc, true); Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), inc(bi_emptySVec), gsc, true);
free(ln); free(ln);