From 4d8283e14b0365038b01df4fab5dee75035007ed Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 25 Aug 2019 11:18:13 +0200 Subject: Remove number of branches in executor --- src/compiler.c | 10 ++++++++++ src/tokenizer.c | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/compiler.c b/src/compiler.c index 3ccb86a..dbc1498 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -482,3 +482,13 @@ int amal_compiler_internal_load_file(amal_compiler *self, const char *filepath, return 0; } + +Tokenizer* amal_compiler_find_tokenizer_by_code_reference(amal_compiler *self, const char *code_ref) { + Parser **parser = buffer_begin(&self->parsers); + Parser **parser_end = buffer_end(&self->parsers); + for(; parser != parser_end; ++parser) { + if(tokenizer_contains_code_reference(&(*parser)->tokenizer, code_ref)) + return &(*parser)->tokenizer; + } + return NULL; +} diff --git a/src/tokenizer.c b/src/tokenizer.c index 82ea0f6..fd516f6 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -768,3 +768,7 @@ int tokenizer_get_code_reference_index(Tokenizer *self, const char *ref) { return -1; return ref - self->code.data; } + +bool tokenizer_contains_code_reference(Tokenizer *self, const char *code_ref) { + return code_ref >= self->code.data && code_ref < self->code.data + self->code.size; +} -- cgit v1.2.3