From 944b4c8bf65795d7bf5e7ecb672d22bdcd1a199d Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Sun, 25 Feb 2018 22:14:11 -0300 Subject: [PATCH] Optimize variable/label search, a few bytes less. --- src/actions.asm | 5 +---- src/vars.asm | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/actions.asm b/src/actions.asm index 7253c40..1b599eb 100644 --- a/src/actions.asm +++ b/src/actions.asm @@ -34,7 +34,7 @@ ; From runtime.asm .import read_word ; From vars.asm - .import var_search, name_new, var_getlen + .import var_search, name_new .import label_search .importzp var_namelen, label_count, var_count ; From alloc.asm @@ -342,7 +342,6 @@ xrts: rts lda #VT_WORD sta tmp3 ; Store variable type ; Check if we have a valid name - this exits on error! - jsr var_getlen ; Search existing var jsr var_search bcs exit @@ -357,7 +356,6 @@ exit: ; Creates a new variable, with no type (the type will be set by parser next) .proc E_VAR_CREATE ; Check if we have a valid name - this exits on error! - jsr var_getlen ; Search existing var jsr var_search bcc E_VAR_WORD::not_found ; Exit with error if already exists @@ -529,7 +527,6 @@ xit: rts .proc label_create ; Check if we have a valid name - this exits on error! - jsr var_getlen jsr label_search bcc xit ; Create a new label diff --git a/src/vars.asm b/src/vars.asm index 0ce1297..2da227c 100644 --- a/src/vars.asm +++ b/src/vars.asm @@ -19,7 +19,7 @@ ; Handles a list of names (variables or labels) ; -------------------------------------------- - .export var_getlen, var_search, label_search, name_new + .export var_search, label_search, name_new .exportzp var_namelen, label_count ; From interpreter.asm @@ -82,8 +82,9 @@ char_ok: ; Inputs: ; (INBUFF + CIX) : Variable name, from parsing code, terminated in any invalid char .proc label_search + jsr var_getlen ldx #label_buf - prog_ptr - ldy #label_count + ldy label_count bne list_search .endproc @@ -91,9 +92,10 @@ char_ok: ; Inputs: ; (INBUFF + CIX) : Variable name, from parsing code, terminated in any invalid char .proc var_search + jsr var_getlen ; Pointer to var list to "var" ldx #var_buf - prog_ptr - ldy #var_count + ldy var_count .endproc ; Fall through ; Search a list of names - used for variables or labels @@ -115,7 +117,7 @@ search_loop: ldy #0 lda (var),y cmp len - bne next_var + bne next_var_len ; Compare data tay @@ -129,6 +131,7 @@ next_var: ; Advance pointer to next var ldy #0 lda (var),y +next_var_len: clc adc #2 ; No carry, as len is max 128 adc var @@ -139,7 +142,7 @@ next_var: search_start: inx ::search_count= * + 1 - cpx $12 + cpx #0 bne search_loop not_found: @@ -207,17 +210,15 @@ exit_2: ; Copy length and name of var/label ldy #0 lda len - sta (var),y loop: - lda (name),y - iny sta (var),y + lda (name),y cpy len - bne loop + iny + bcc loop ; Set type to 0 initially lda #0 - iny sta (var), y rts .endproc