Skip to content

Commit 2399539

Browse files
committed
Split parsing of labels and starting of PROC/DATA loops.
This fixes creation of variables starting with "DATA".
1 parent fe10570 commit 2399539

5 files changed

Lines changed: 30 additions & 26 deletions

File tree

src/actions.asm

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ xit: rts
463463

464464
::laddr_search_num = cpnum + 1
465465
::laddr_search_start:
466+
::last_label_num = *+1
467+
ldx #0
466468
lda laddr_buf
467469
ldy laddr_buf+1
468470
sty tmp1+1
@@ -500,12 +502,10 @@ xit: rts
500502
xit: rts
501503
.endproc
502504

503-
; Label definition search/create
505+
; Pushes the PROC/DATA loop, search, create a label and define the location
504506
.proc E_LABEL_DEF
505-
506-
; Search and create the label
507-
jsr E_LABEL_CREATE
508-
bcs add_laddr_list::xit ; Label already defined
507+
lda #LT_PROC_DATA
508+
jsr push_codep
509509

510510
; Search in the label list
511511
jsr laddr_search_start
@@ -531,7 +531,7 @@ cloop: bmi xit_label_err
531531
; No more entries, adds our address as a "definition" (A = 128)
532532
nfound:
533533
lda #128
534-
jmp add_laddr_list
534+
bmi add_laddr_list
535535
.endproc
536536

537537
; Label search on use
@@ -542,6 +542,7 @@ nfound:
542542
; Check if we have a valid name - this exits on error!
543543
jsr label_search
544544
bcs xit
545+
stx last_label_num
545546

546547
; Check if type is compatible
547548
cmp tmp3
@@ -554,7 +555,6 @@ xit: rts
554555
; label (and create it if needed), then parse arguments and at last emit the
555556
; call address
556557
::E_DO_EXEC:
557-
ldx #0
558558

559559
; Emits a label, searching the label address in the label list
560560
start_searching:
@@ -581,24 +581,18 @@ ret: rts
581581
; Label search and create if not exists
582582
.proc E_LABEL_CREATE
583583
jsr label_search
584-
bcc check_var
584+
stx last_label_num
585+
; Already defined, just store index
586+
bcc ret
585587

586588
do_create:
587589
; Create a new label
588590
ldx #label_ptr - prog_ptr
589591
jsr name_new
590-
ldx label_count
591592
inc label_count
592593
clc
593-
set_var:
594-
stx E_DO_EXEC+1
595-
rts
594+
ret: rts
596595

597-
; Check if label is PROC, error if not
598-
check_var:
599-
beq set_var
600-
sec
601-
rts
602596
.endproc
603597

604598
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

src/basic.syn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,13 @@ DATA_END:
596596

597597
DATA_VAR: new data array name
598598
DATA_TYPE
599-
emit { TOK_JUMP, LT_PROC_DATA } E_PUSH_LT E_LABEL_DEF "()" DATA_TYPE
599+
E_LABEL_CREATE "()" emit { TOK_JUMP } E_LABEL_DEF DATA_TYPE
600600

601601
# DLI support - builds a machine code routine and store the address to
602602
# display list interrupt handler:
603603
DLI_COMMAND: 'SET', label
604604
# Define a new DLI with given name
605-
"Set" emit { TOK_JUMP, LT_PROC_DATA } E_PUSH_LT \
605+
"Set" E_LABEL_CREATE emit { TOK_JUMP } \
606606
E_LABEL_DEF emit { VT_ARRAY_BYTE } E_LABEL_SET_TYPE \
607607
emit { 72, 138, 72, 166, COLRSH } EQUAL \
608608
DLI_LDA emit { 141, &WSYNC } DLI_STA DLI_CODES
@@ -711,7 +711,7 @@ PARSE_LINE_COMMAND: statement
711711
"PAuse" PAUSE_OPT emit TOK_PAUSE
712712
"INC" VAR_WORD_LVALUE_SADDR emit TOK_INC
713713
"DEc" VAR_WORD_LVALUE_SADDR emit TOK_DEC
714-
"PRoc" emit { TOK_JUMP, LT_PROC_DATA } E_PUSH_LT E_LABEL_DEF emit LT_PROC_2 E_PUSH_LT OPT_PROC_VAR
714+
"PRoc" E_LABEL_CREATE emit { TOK_JUMP } E_LABEL_DEF emit LT_PROC_2 E_PUSH_LT OPT_PROC_VAR
715715
"ENDProc" E_POP_PROC_2 emit TOK_RET E_POP_PROC_DATA
716716
EXEC_CALL E_LABEL_CREATE OPT_EXEC_PARAM emit { TOK_CALL } E_DO_EXEC
717717
"DAta" DATA_VAR DATA_END

src/compiler/parser.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +577,15 @@ bool SMB_E_NUMBER_FP(parse &s)
577577

578578
bool SMB_E_LABEL_DEF(parse &s)
579579
{
580+
auto l = s.push_loop(LT_PROC_DATA);
581+
s.remove_last();
582+
s.push_proc(l);
583+
580584
s.debug("E_LABEL_DEF");
581585
auto &v = s.labels;
582-
std::string name;
583-
if( !s.get_ident(name) )
584-
return false;
585-
if( v.find(name) == v.end() )
586-
v[name] = labelType();
586+
auto name = s.last_label;
587587
if( v[name].is_defined() )
588588
return false;
589-
s.last_label = name;
590589
s.current_params = 0;
591590
s.add_text(name);
592591
s.emit_label("fb_lbl_" + name);

testsuite/tests/err-vdata.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
' Test for error parsing variables that start with DATA
2+
? "Start"
3+
X=1234
4+
DATAVAR=DPEEK(&X)
5+
? DATAVAR
6+

testsuite/tests/err-vdata.chk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Name: Test for error parsing variables that start with DATA
2+
Test: run
3+
Output:
4+
Start
5+
1234

0 commit comments

Comments
 (0)