Implemented line indexing for faster jumps/looping.

This required adding the ability to to get and set the
tokenizer's current position pointer from outside of it with
tokenizer_pos and tokenizer_goto (c.f. tokenizer_init).
The index itself is stored as a linked list, which makes it ripe
for further optimization. It is accessed with index_* routines.
The interpreter resorts to running the old, slower jump procedure
when jumping forward (to a line that hasn't been index).

New goto test.
This commit is contained in:
Danyil Bohdan 2013-12-22 16:15:40 +02:00
parent 9c45ed4588
commit f9ea3c6e6b
4 changed files with 123 additions and 4 deletions

13
tests.c
View file

@ -38,11 +38,21 @@ static const char program_let[] =
"10 let a = 42\n\
20 end\n";
static const char program_goto[] =
"10 goto 50\n\
20 goto 40\n\
30 goto 60\n\
40 goto 30\n\
50 goto 20\n\
60 let c = 108\n\
70 end\n";
static const char program_loop[] =
"10 for i = 0 to 126\n\
20 for j = 0 to 126\n\
30 for k = 0 to 10\n\
40 let a = i * j * k\n\
rem 45 print a, i, j, k\n\
50 next k\n\
60 next j\n\
70 next i\n\
@ -90,6 +100,9 @@ main(void)
run(program_let);
assert(ubasic_get_variable(0) == 42);
run(program_goto);
assert(ubasic_get_variable(2) == 108);
run(program_loop);
assert(ubasic_get_variable(0) == (VARIABLE_TYPE)(126 * 126 * 10));