fix fucked execptr after pushing input

master
Ondřej Hruška 3 years ago
parent 7bc96a8f58
commit b7443ca9d4
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      src/fh_builtins_meta.c
  2. 14
      src/fh_input.c
  3. 2
      src/fh_parse.c
  4. 2
      testfiles/combinedtest.f
  5. 7
      testfiles/rescan.f

@ -601,7 +601,6 @@ static enum fh_error w_evaluate(struct fh_thread_s *fh, const struct fh_word_s *
enum fh_error rv; enum fh_error rv;
uint32_t addr, count; uint32_t addr, count;
TRY(ds_pop_addr_len(fh, &addr, &count)); TRY(ds_pop_addr_len(fh, &addr, &count));
fh_runtime_start(fh, fh_create_input_from_string(fh_str_at(fh, addr), count, fh->input->cwd)); fh_runtime_start(fh, fh_create_input_from_string(fh_str_at(fh, addr), count, fh->input->cwd));
return FH_OK; return FH_OK;
} }

@ -20,6 +20,7 @@ enum fh_error fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newi
newinput->previous = oldinput; newinput->previous = oldinput;
} }
fh->execptr = MAGICADDR_EXEC_INTERACTIVE;
fh->inputlen = 0; fh->inputlen = 0;
fh->inputptr = 0; fh->inputptr = 0;
@ -86,17 +87,17 @@ void fh_input_memmove_leftovers(struct fh_thread_s *fh)
// something is left // something is left
uint32_t remains = fh->inputlen - fh->inputptr; uint32_t remains = fh->inputlen - fh->inputptr;
if (remains > 0) { if (remains > 0) {
LOG("Refill, reuse %d bytes left in buffer", remains); //LOG("Refill, reuse %d bytes left in buffer", remains);
memmove(inputbuf_at(fh, 0), inputbuf_at(fh, fh->inputptr), remains); memmove(inputbuf_at(fh, 0), inputbuf_at(fh, fh->inputptr), remains);
fh->inputptr = 0; fh->inputptr = 0;
fh->inputlen = remains; fh->inputlen = remains;
} else { } else {
LOG("Refill, nothing reused (1)"); //LOG("Refill, nothing reused (1)");
fh->inputptr = 0; fh->inputptr = 0;
fh->inputlen = 0; fh->inputlen = 0;
} }
} else { } else {
LOG("Refill, nothing reused (2)"); //LOG("Refill, nothing reused (2)");
fh->inputptr = 0; fh->inputptr = 0;
fh->inputlen = 0; fh->inputlen = 0;
} }
@ -108,11 +109,11 @@ static bool file_refill(struct fh_thread_s *fh, struct fh_input_spec_s *spec)
fh_input_memmove_leftovers(fh); fh_input_memmove_leftovers(fh);
uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen - 1; uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen - 1;
char *wp = (char *) inputbuf_at(fh, fh->inputptr); char *wp = (char *) inputbuf_at(fh, fh->inputptr);
LOG("spec %p, fgets %d", spec, space_left); //LOG("spec %p, fgets %d", spec, space_left);
if (fgets(wp, (int) space_left, fis->file)) { if (fgets(wp, (int) space_left, fis->file)) {
spec->linenum++; spec->linenum++;
fh->inputlen = strnlen(wp, INPUT_BUFFER_SIZE); fh->inputlen = strnlen(wp, INPUT_BUFFER_SIZE);
LOG("read %d bytes from file", fh->inputlen); //LOG("read %d bytes from file", fh->inputlen);
return true; return true;
} else { } else {
return fh->inputptr > fh->inputlen; // return false only if there is nothing left return fh->inputptr > fh->inputlen; // return false only if there is nothing left
@ -174,6 +175,7 @@ struct fh_input_spec_s *fh_create_input_from_filestruct(FILE *f, const char *cwd
return NULL; return NULL;
} }
LOG("Input for FILE, cwd: %s", cwd);
fis->spec.free_self = free_filespec; fis->spec.free_self = free_filespec;
fis->spec.refill_input_buffer = file_refill; fis->spec.refill_input_buffer = file_refill;
fis->file = f; fis->file = f;
@ -221,6 +223,8 @@ struct fh_input_spec_s *fh_create_input_from_string(char *str, size_t len, const
return NULL; return NULL;
} }
LOG("Evaluating: \"%.*s\"", (int)len, str);
sis->spec.free_self = free_strspec; sis->spec.free_self = free_strspec;
sis->spec.refill_input_buffer = str_refill; sis->spec.refill_input_buffer = str_refill;
sis->str = str; sis->str = str;

@ -234,7 +234,7 @@ enum fh_error fh_runtime_start(struct fh_thread_s *fh, struct fh_input_spec_s *i
} }
while (1) { while (1) {
LOG("Refill input buffer"); //LOG("Refill input buffer");
if (fh->input->refill_input_buffer(fh, fh->input)) { if (fh->input->refill_input_buffer(fh, fh->input)) {
// discard spaces at the end // discard spaces at the end
while (isspace(fh->heap[INPUTBUF_ADDR + fh->inputlen - 1]) && fh->inputlen > 0) { while (isspace(fh->heap[INPUTBUF_ADDR + fh->inputlen - 1]) && fh->inputlen > 0) {

@ -870,10 +870,8 @@ T{ 2 SCANS !
345 RESCAN? 345 RESCAN?
-> 345 345 }T -> 345 345 }T
1 debug
: GS2 5 SCANS ! S" 123 RESCAN?" EVALUATE ; : GS2 5 SCANS ! S" 123 RESCAN?" EVALUATE ;
T{ GS2 -> 123 123 123 123 123 }T T{ GS2 -> 123 123 123 123 123 }T
xx
: GS3 WORD COUNT SWAP C@ ; : GS3 WORD COUNT SWAP C@ ;
T{ BL GS3 HELLO -> 5 CHAR H }T T{ BL GS3 HELLO -> 5 CHAR H }T

@ -0,0 +1,7 @@
VARIABLE SCANS
: RESCAN? -1 SCANS +! SCANS @ IF 0 >IN ! THEN ;
1 debug
: GS2 1 SCANS ! S" 123 RESCAN?" EVALUATE ;
GS2
??
Loading…
Cancel
Save