changeset 56:f741bb544a04

Clean up labels in tokenization routine
author William Astle <lost@l-w.ca>
date Thu, 22 Dec 2022 23:44:25 -0700
parents 1568fa902257
children 6a4c342ac12b
files src/lwbasic.s
diffstat 1 files changed, 66 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwbasic.s	Thu Dec 22 23:08:49 2022 -0700
+++ b/src/lwbasic.s	Thu Dec 22 23:44:25 2022 -0700
@@ -1498,55 +1498,53 @@
                 ldy #tokebuff                   ; point to destination buffer
                 pshs y                          ; set return value
 tokenize0       lda ,x+                         ; get input character
-                bne tokenize1                   ; brif not end of input
-tokenize0a      sta ,y+                         ; blank out final byte in result
-tokenize0b      tfr y,d                         ; get end address to accumulator
+                bne tokenize3                   ; brif not end of input
+tokenize1       sta ,y+                         ; blank out final byte in result
+tokenize2       tfr y,d                         ; get end address to accumulator
                 subd #tokebuff                  ; subtract out start; gives length of result
                 puls x,pc                       ; set return pointer and return
-tokenize1       tst tok_skipkw                  ; are we in the middle of a "not token"?
-                beq tokenize3a                  ; brif not
+tokenize3       tst tok_skipkw                  ; are we in the middle of a "not token"?
+                beq tokenize6                   ; brif not
                 jsr setcifalpha                 ; is it alpha
-                bcs tokenize2                   ; brif so - store it and continue
+                bcs tokenize4                   ; brif so - store it and continue
                 jsr setcifdigit                 ; is it numeric?
-                bcc tokenize3                   ; brif not
-tokenize2       sta ,y+                         ; save output character
+                bcc tokenize5                   ; brif not
+tokenize4       sta ,y+                         ; save output character
                 bra tokenize0                   ; check for another
-tokenize3       clr tok_skipkw                  ; clear the "not token" flag
-tokenize3a      cmpa #'"                        ; is it a string?
-                bne tokenize5                   ; brif not
+tokenize5       clr tok_skipkw                  ; clear the "not token" flag
+tokenize6       cmpa #'"                        ; is it a string?
+                bne tokenize8                   ; brif not
                 sta ,y+                         ; save string delimiter
-tokenize4       lda ,x+                         ; get input character
-                beq tokenize0a                  ; brif end of input
+tokenize7       lda ,x+                         ; get input character
+                beq tokenize1                   ; brif end of input
                 sta ,y+                         ; save it in output
                 cmpa #'"                        ; end of string?
-                bne tokenize4                   ; brif not
+                bne tokenize7                   ; brif not
                 bra tokenize0                   ; brif 
-tokenize5       cmpa #':                        ; end of statement?
-                bne tokenize6                   ; brif not
+tokenize8       cmpa #':                        ; end of statement?
+                bne tokenize9                   ; brif not
                 clr tok_skipdt                  ; reset "in data" flag
-                bra tokenize2                   ; stash it and continue
-tokenize6       cmpa #0x20                      ; is it a space?
-                beq tokenize2                   ; brif so - stash it unmodified
+                bra tokenize4                   ; stash it and continue
+tokenize9       cmpa #0x20                      ; is it a space?
+                beq tokenize4                   ; brif so - stash it unmodified
                 tst tok_skipdt                  ; are we "in data"?
-                bne tokenize2                   ; brif so - don't tokenize it
+                bne tokenize4                   ; brif so - don't tokenize it
                 cmpa #'?                        ; PRINT shortcut?
-                bne tokenize6a                  ; brif not
+                bne tokenize10                  ; brif not
                 lda #tok_print                  ; load token for PRINT
-                bra tokenize2                   ; move stash it and move on
-tokenize6a      cmpa #''                        ; ' shortcut for remark?
-                bne tokenize9                   ; brif not
+                bra tokenize4                   ; move stash it and move on
+tokenize10      cmpa #''                        ; ' shortcut for remark?
+                bne tokenize12                  ; brif not
                 ldd #':*256+tok_apos            ; put token for ' and an implied colon
                 std ,y++                        ; stash it
-tokenize8       lda ,x+                         ; fetch byte from input
+tokenize11      lda ,x+                         ; fetch byte from input
                 sta ,y+                         ; stash in output
-                bne tokenize8                   ; brif not end of input
-                bra tokenize0b                  ; go finish up
-tokenize9       jsr setcifdigit                 ; is it a digit?
-                bcs tokenize2                   ; brif so - pass it through
+                bne tokenize11                  ; brif not end of input
+                bra tokenize2                   ; go finish up
+tokenize12      jsr setcifdigit                 ; is it a digit?
+                bcs tokenize4                   ; brif so - pass it through
                 tsta                            ; is the high bit set?
                 bmi tokenize0                   ; ignore it if so
-
-; do longest match dictionary lookup here
                 ldu #primarydict                ; point to keyword table
                 leax -1,x                       ; back up input to start of potential token
                 clr tok_kwtype                  ; set secondary table flag to primary table
@@ -1554,69 +1552,69 @@
                 clr tok_kwmatch+1
                 clr tok_kwmatchl                ; set length matched
                 pshs x                          ; save start of input token
-tokenize10x     clr tok_kwnum                   ; clear keyword number
-tokenize10      ldb ,u                          ; are we at the end of the table?
-                bne tokenize11                  ; brif not
+tokenize13      clr tok_kwnum                   ; clear keyword number
+tokenize14      ldb ,u                          ; are we at the end of the table?
+                bne tokenize16                  ; brif not
                 ldu #secondarydict              ; point to secondary token dictionary
                 com tok_kwtype                  ; flip to secondary token flag
-                bne tokenize10x                 ; brif we haven't already done the secondaries
+                bne tokenize13                  ; brif we haven't already done the secondaries
                 puls x                          ; get back input pointer
                 ldb tok_kwmatchl                ; get length of best match
-                beq tokenize10y                 ; brif we don't have a match
+                beq tokenize15                  ; brif we don't have a match
                 abx                             ; move input pointer past matched token
                 ldd tok_kwmatch                 ; get matched token number
                 tsta                            ; is it a primary?
-                beq tokenize17                  ; brif so
-                bra tokenize16                  ; go stash two byte token
-tokenize10y     com tok_skipkw                  ; set "not token flag"
+                beq tokenize24                  ; brif so
+                bra tokenize23                  ; go stash two byte token
+tokenize15      com tok_skipkw                  ; set "not token flag"
                 lda ,x+                         ; get character
-                bra tokenize2                   ; stash it and continue
-tokenize11      ldx ,s                          ; get back start of input token
+                bra tokenize4                   ; stash it and continue
+tokenize16      ldx ,s                          ; get back start of input token
                 clra                            ; initalize match length counter
-tokenize12      inca                            ; bump length counter
+tokenize17      inca                            ; bump length counter
                 ldb ,x+                         ; get input character
                 cmpb #'z                        ; is it above lower case Z?
-                bhi tokenize13                  ; brif so
+                bhi tokenize18                  ; brif so
                 cmpb #'a                        ; is it below lower case A?
-                blo tokenize13                  ; brif so
+                blo tokenize18                  ; brif so
                 subb #0x20                      ; convert to upper case
-tokenize13      subb ,u+                        ; does it match?
-                beq tokenize12                  ; brif so - check another
+tokenize18      subb ,u+                        ; does it match?
+                beq tokenize17                  ; brif so - check another
                 cmpb #0x80                      ; did it match with high bit set?
-                beq tokenize15                  ; brif so - exact match
+                beq tokenize21                  ; brif so - exact match
                 leau -1,u                       ; back up to current test character
-tokenize14      ldb ,u+                         ; end of token?
-                bpl tokenize14                  ; brif not
-tokenize14a     inc tok_kwnum                   ; bump token counter
-                bra tokenize10                  ; go check another one
-tokenize15      cmpa tok_kwmatchl               ; is it a longer match?
-                bls tokenize14a                 ; brif not, ignore it
+tokenize19      ldb ,u+                         ; end of token?
+                bpl tokenize19                  ; brif not
+tokenize20      inc tok_kwnum                   ; bump token counter
+                bra tokenize14                  ; go check another one
+tokenize21      cmpa tok_kwmatchl               ; is it a longer match?
+                bls tokenize20                  ; brif not, ignore it
                 sta tok_kwmatchl                ; save new match length
                 ldd tok_kwtype                  ; get the matched token count
                 orb #0x80                       ; set token flag
                 std tok_kwmatch                 ; save matched token
-                bra tokenize14a                 ; keep looking through the tables
-tokenize18      lda #':                         ; for putting implied colons in
-tokenize16      std ,y++                        ; put output into buffer
+                bra tokenize20                  ; keep looking through the tables
+tokenize22      lda #':                         ; for putting implied colons in
+tokenize23      std ,y++                        ; put output into buffer
                 jmp tokenize0                   ; go handle more input
-tokenize17      cmpb #tok_else                  ; is it ELSE?
-                beq tokenize18                  ; brif so - stash it with colon
+tokenize24      cmpb #tok_else                  ; is it ELSE?
+                beq tokenize22                  ; brif so - stash it with colon
                 cmpb #tok_data                  ; is it DATA?
-                bne tokenize18a                 ; brif not
+                bne tokenize26                  ; brif not
                 stb tok_skipdt                  ; set "in data" flag
-tokenize20      stb ,y+                         ; stash token
+tokenize25      stb ,y+                         ; stash token
                 jmp tokenize0                   ; go handle more
-tokenize18a     cmpb #tok_rem                   ; is it REM?
-                beq tokenize19                  ; brif so
+tokenize26      cmpb #tok_rem                   ; is it REM?
+                beq tokenize28                  ; brif so
                 cmpb #tok_apos                  ; apostrophe REM?
-                bne tokenize20                  ; brif not - stash token and continue
+                bne tokenize25                  ; brif not - stash token and continue
                 lda #':                         ; stash the implied colon
                 sta ,y+
-                bra tokenize19
-tokenize19a     ldb ,x+                         ; fetch next input character
-tokenize19      stb ,y+                         ; stash the character
-                bne tokenize19a                 ; brif not end of input - do another
-                jmp tokenize0b                  ; stash end of buffer and handle cleanup
+                bra tokenize28
+tokenize27      ldb ,x+                         ; fetch next input character
+tokenize28      stb ,y+                         ; stash the character
+                bne tokenize27                  ; brif not end of input - do another
+                jmp tokenize2                   ; stash end of buffer and handle cleanup
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Keyword dictionaries and jump tables. These are defined by several macros which ensure that each command or function
 ; entry has an associated jump table entry. These macros are: