Skip to content

Commit 2b9eb81

Browse files
committed
Minor optimizations to the parser.
Removed unneeded CLC instructions and simplify EXIT loop handling.
1 parent d81d160 commit 2b9eb81

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/actions.asm

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ xit: rts
418418
dec label_ptr+1
419419
sta (label_ptr), y ; Store to (label_ptr - 1)
420420
inc label_ptr+1
421-
clc
421+
; clc ; Already clear
422422
xit: rts
423423
.endproc
424424

@@ -435,7 +435,7 @@ xit: rts
435435
.proc next_laddr
436436
loop:
437437
lda tmp1
438-
clc
438+
; clc ; Always called with C=0
439439
adc #4
440440
bcc comp
441441
inc tmp1+1
@@ -524,7 +524,8 @@ cloop: bmi xit_label_err
524524
sta (tmp1), y
525525

526526
; Continue searching the address list
527-
next: jsr next_laddr
527+
; here C=0 always
528+
jsr next_laddr
528529
bcc cloop
529530

530531
; No more entries, adds our address as a "definition" (A = 128)
@@ -540,14 +541,14 @@ nfound:
540541

541542
; Check if we have a valid name - this exits on error!
542543
jsr label_search
543-
bcs xit_label_err
544+
bcs xit
544545

545546
; Check if type is compatible
546547
cmp tmp3
547548
beq start_searching
548549
::xit_label_err:
549550
sec
550-
rts
551+
xit: rts
551552

552553
; Get EXEC label address and store - this is split because we first parse the
553554
; label (and create it if needed), then parse arguments and at last emit the
@@ -564,8 +565,10 @@ cloop:
564565
; Check label status
565566
; 0 == label not defined, 1 == label defined, 128 == label address
566567
; Found, get address from label and emit
568+
; here C=0 always
567569
bmi emit_addr
568-
next:
570+
571+
; here C=0 always
569572
jsr next_laddr
570573
bcc cloop
571574
; Not found, add to the label address list
@@ -607,7 +610,7 @@ check_var:
607610
.endproc ; Fall through
608611
; Emits address into codep, relocating if necessary.
609612
.proc emit_addr
610-
clc
613+
; clc ; get_codep clears carry and emit_addr is called with C=0
611614
adc reloc_addr
612615
pha
613616
txa
@@ -630,7 +633,7 @@ check_var:
630633
ldx var_sp
631634
sta var_stk, x
632635
inc var_sp
633-
clc
636+
; clc ; Already clear
634637
rts
635638
.endproc
636639

@@ -751,8 +754,11 @@ ok:
751754
inx
752755
bmi loop_error
753756

757+
; Keep new loop_sp in stack
758+
txa
759+
pha
760+
754761
; Move all stack 3 positions up
755-
stx loop_sp
756762
move:
757763
dex
758764
lda loop_stk-3, x
@@ -761,15 +767,15 @@ comp_y: cpx #$FC
761767
bne move
762768

763769
; Store our new stack entry
764-
lda loop_sp
765-
pha
766-
ldy comp_y+1
767-
sty loop_sp
770+
; X is the new slot
771+
stx loop_sp
768772
lda #LT_EXIT
769773
jsr push_codep
774+
775+
; Restore new loop_sp
770776
pla
771777
sta loop_sp
772-
clc
778+
; clc ; push_codep clears C
773779
rts
774780
.endproc
775781

src/parse.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ pexit_ok:
359359
jmp parse_line
360360

361361
; Calls a machine-language subroutine
362+
; NOTE: we always call ML subs with carry clear (C=0)
362363
pcall_ml:
363364
jsr call_ax1
364365
bcc ploop

0 commit comments

Comments
 (0)