forked from mirrors/ubasic
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:
parent
9c45ed4588
commit
f9ea3c6e6b
4 changed files with 123 additions and 4 deletions
14
tokenizer.c
14
tokenizer.c
|
|
@ -167,12 +167,19 @@ get_next_token(void)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tokenizer_init(const char *program)
|
||||
tokenizer_goto(const char *program)
|
||||
{
|
||||
ptr = program;
|
||||
current_token = get_next_token();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tokenizer_init(const char *program)
|
||||
{
|
||||
tokenizer_goto(program);
|
||||
current_token = get_next_token();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
tokenizer_token(void)
|
||||
{
|
||||
|
|
@ -254,3 +261,8 @@ tokenizer_variable_num(void)
|
|||
return *ptr - 'a';
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
char const *
|
||||
tokenizer_pos(void)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue