2222 .export E_REM, E_EOL, E_NUMBER_WORD, E_NUMBER_BYTE
2323 .export E_PUSH_LT, E_POP_LOOP, E_POP_REPEAT
2424 .export E_POP_IF, E_ELSEIF, E_EXIT_LOOP
25- .export E_POP_WHILE, E_POP_FOR, E_POP_PROC_1 , E_POP_PROC_2, E_POP_DATA
25+ .export E_POP_WHILE, E_POP_FOR, E_POP_PROC_DATA , E_POP_PROC_2
2626 .export E_CONST_STRING
2727 .export E_VAR_CREATE, E_VAR_WORD, E_VAR_SEARCH
28- .export E_VAR_SET_TYPE
28+ .export E_VAR_SET_TYPE, E_LABEL_SET_TYPE
2929 .export E_LABEL, E_LABEL_DEF
3030 .export E_PUSH_VAR, E_POP_VAR
31- .exportzp VT_WORD, VT_STRING, VT_FLOAT
31+ .exportzp VT_WORD, VT_STRING, VT_FLOAT, VT_UNDEF
3232 .exportzp VT_ARRAY_WORD, VT_ARRAY_BYTE, VT_ARRAY_STRING, VT_ARRAY_FLOAT
33- .exportzp LT_PROC_1 , LT_PROC_2, LT_DATA , LT_DO_LOOP, LT_REPEAT, LT_WHILE_1, LT_WHILE_2, LT_FOR_1, LT_FOR_2, LT_EXIT, LT_IF, LT_ELSE, LT_ELIF
33+ .exportzp LT_PROC_DATA , LT_PROC_2, LT_DO_LOOP, LT_REPEAT, LT_WHILE_1, LT_WHILE_2, LT_FOR_1, LT_FOR_2, LT_EXIT, LT_IF, LT_ELSE, LT_ELIF
3434 .importzp loop_sp, bpos, bptr, tmp1, tmp2, tmp3, opos
3535 ; From runtime.asm
3636 .import read_word
3737 ; From vars.asm
3838 .import var_search, name_new
39- .import label_search
39+ .import list_search
4040 .importzp var_namelen, label_count, var_count
4141 ; From alloc.asm
4242 .import alloc_laddr
43- .importzp prog_ptr, laddr_ptr, laddr_buf, var_ptr, label_ptr
43+ .importzp prog_ptr, laddr_ptr, laddr_buf, var_ptr, label_ptr, label_buf
4444 ; From parser.asm
4545 .import parser_error, parser_skipws, parser_emit_byte, parser_inc_opos
4646 ; From error.asm
@@ -87,8 +87,7 @@ read_fp = AFP
8787 ; ; EXIT? PUSH?
8888 ; ; bit-7 bit-6
8989 LT_EXIT ; error yes
90- LT_PROC_1 ; error yes
91- LT_DATA ; error yes
90+ LT_PROC_DATA ; error yes
9291 LT_FOR_2 ; yes yes
9392 LT_LAST_JUMP = 63
9493 LT_PROC_2 ; yes no
@@ -402,13 +401,16 @@ no_float:
402401xit: rts
403402.endproc
404403
405- ; Support for labels (PROC/EXEC)
404+ ; Support for labels (DATA/ PROC/EXEC)
406405; ------------------------------
407406;
408407; We keep two lists:
409408; - label_buf/ptr: a list of all the labels, sorted by the label number.
410409; one byte for each character in the name, last byte with
411410; bit 7 set.
411+ ; After the name there is one byte with the label type,
412+ ; same as var-types.
413+ ;
412414; - laddr_buf/ptr: a list with each label reference:
413415; byte 0: the label number,
414416; byte 1: the type of reference,
@@ -433,14 +435,15 @@ xit: rts
433435;
434436; Label definition search/create
435437.proc E_LABEL_DEF
438+ lda #0 ; Type of label: undefined
436439 jsr label_create
437440
438441 ; Fills all undefined labels with current position:
439442 bcs nfound
440443
441444 ; If we found a *definition* for the label, error out (label already
442445 ; defined).
443- cloop: bmi error
446+ cloop: bmi xit_label_err
444447
445448 ; Write current codep to AX
446449 jsr patch_codep
@@ -460,25 +463,52 @@ nfound:
460463 jsr add_laddr_list
461464 ; Ok, advance parsing pointer with the label length
462465 bcc advance_varn
463-
464- error: sec
465466 rts
466467.endproc
467468
469+ ; Sets the type of the last label defined
470+ .proc E_LABEL_SET_TYPE
471+ jsr get_last_tok ; Get variable TYPE from last token
472+
473+ ldy #$FF
474+ dec label_ptr+1
475+ sta (label_ptr), y ; Store to (label_ptr - 1)
476+ inc label_ptr+1
477+ clc
478+ xit: rts
479+ .endproc
480+
468481 ; Create a label if not exists and starts searching in the label
469482 ; address list.
470483 ;
471484 ; This jumps to next_laddr, so it returns the same values.
472485.proc label_create
473486 ; Check if we have a valid name - this exits on error!
474- jsr label_search
475- bcc xit
487+ sta tmp3 ; Store label type
488+ ldx #label_buf - prog_ptr
489+ ldy label_count
490+ jsr list_search
491+ bcs do_create
492+ ; Check if type is compatible
493+ cmp tmp3
494+ beq no_create ; Yes, search address
495+ xit_pop_2: ; Exit from caller with error
496+ pla
497+ pla
498+ ::xit_label_err:
499+ sec
500+ rts
501+
502+ do_create:
503+ ; See if we need to create it
504+ lda tmp3
505+ bne xit_pop_2
476506 ; Create a new label
477507 ldx #label_ptr - prog_ptr
478508 jsr name_new
479509 ldx label_count
480510 inc label_count
481- xit :
511+ no_create :
482512 lda laddr_buf
483513 ldy laddr_buf+1
484514 sty tmp1+1
@@ -560,6 +590,7 @@ xit: rts
560590
561591; Label search / create (on use)
562592.proc E_LABEL
593+ jsr get_last_tok ; Get label TYPE from last token
563594 jsr label_create
564595 ; Emits a label, searching the label address in the label list
565596 bcs nfound
@@ -691,7 +722,7 @@ retry: dey
691722 bmi loop_error
692723 lda loop_stk, y
693724 bmi retry ; FOR(2)/WHILE(2)/IF/ELSE/ELIF are > 127
694- cmp #LT_DATA+ 1 ; PROC(1)/DATA
725+ cmp #LT_PROC_DATA+ 1 ; PROC(1)/DATA
695726 bcc loop_error
696727ok:
697728 ; Store slot
@@ -788,14 +819,9 @@ no_elif:
788819 rts
789820.endproc
790821
791- .proc E_POP_DATA
792- ; Pop saved position, store
793- lda #LT_DATA
794- .byte $2C ; Skip 2 bytes over next "LDA"
795- .endproc ; Fall through
796- .proc E_POP_PROC_1
822+ .proc E_POP_PROC_DATA
797823 ; Pop saved "jump to end" position
798- lda #LT_PROC_1
824+ lda #LT_PROC_DATA
799825.endproc ; Fall through
800826
801827.proc pop_patch_codep
0 commit comments