zasm: indicate include lineno in errors
This commit is contained in:
parent
8def8e7c38
commit
2c80924df9
@ -58,8 +58,10 @@
|
|||||||
.equ IO_PC IO_IN_INCLUDE+1
|
.equ IO_PC IO_IN_INCLUDE+1
|
||||||
; Current lineno in top-level file
|
; Current lineno in top-level file
|
||||||
.equ IO_LINENO IO_PC+2
|
.equ IO_LINENO IO_PC+2
|
||||||
|
; Current lineno in include file
|
||||||
|
.equ IO_INC_LINENO IO_LINENO+2
|
||||||
; Line number (can be top-level or include) when ioSavePos was last called.
|
; Line number (can be top-level or include) when ioSavePos was last called.
|
||||||
.equ IO_SAVED_LINENO IO_LINENO+2
|
.equ IO_SAVED_LINENO IO_INC_LINENO+2
|
||||||
.equ IO_RAMEND IO_SAVED_LINENO+2
|
.equ IO_RAMEND IO_SAVED_LINENO+2
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
@ -81,6 +83,17 @@ ioGetC:
|
|||||||
ld de, IO_INCLUDE_HDL
|
ld de, IO_INCLUDE_HDL
|
||||||
call fsGetC
|
call fsGetC
|
||||||
pop de
|
pop de
|
||||||
|
cp 0x0a ; newline
|
||||||
|
jr nz, .notNewline
|
||||||
|
; We have newline. Increase lineno and return (the rest of the
|
||||||
|
; processing below isn't needed.
|
||||||
|
push hl
|
||||||
|
ld hl, IO_INC_LINENO
|
||||||
|
inc (hl)
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
|
||||||
|
.notNewline:
|
||||||
or a ; cp 0
|
or a ; cp 0
|
||||||
ret nz ; not zero, all good
|
ret nz ; not zero, all good
|
||||||
; We reached EOF. What we do depends on whether we're in Local Pass
|
; We reached EOF. What we do depends on whether we're in Local Pass
|
||||||
@ -212,10 +225,21 @@ ioOpenInclude:
|
|||||||
call fsOpen
|
call fsOpen
|
||||||
ld a, 1
|
ld a, 1
|
||||||
ld (IO_IN_INCLUDE), a
|
ld (IO_IN_INCLUDE), a
|
||||||
|
ld hl, 0
|
||||||
|
ld (IO_INC_LINENO), hl
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Return current lineno in HL
|
; Return current lineno in HL and, if in an include, its lineno in DE.
|
||||||
|
; If not in an include, DE is set to 0
|
||||||
ioLineNo:
|
ioLineNo:
|
||||||
|
push af
|
||||||
ld hl, (IO_LINENO)
|
ld hl, (IO_LINENO)
|
||||||
|
ld de, 0
|
||||||
|
call ioInInclude
|
||||||
|
jr z, .end
|
||||||
|
ld de, (IO_INC_LINENO)
|
||||||
|
.end:
|
||||||
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ zasmMain:
|
|||||||
ld (ZASM_FIRST_PASS), a
|
ld (ZASM_FIRST_PASS), a
|
||||||
call zasmParseFile
|
call zasmParseFile
|
||||||
.end:
|
.end:
|
||||||
jp ioLineNo ; --> HL, returns
|
jp ioLineNo ; --> HL, --> DE, returns
|
||||||
|
|
||||||
; Sets Z according to whether we're in first pass.
|
; Sets Z according to whether we're in first pass.
|
||||||
zasmIsFirstPass:
|
zasmIsFirstPass:
|
||||||
|
@ -42,6 +42,10 @@ int main()
|
|||||||
i++;
|
i++;
|
||||||
c = getchar();
|
c = getchar();
|
||||||
}
|
}
|
||||||
|
if (!i) {
|
||||||
|
fprintf(stderr, "No input, aborting\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
Z80RESET(&cpu);
|
Z80RESET(&cpu);
|
||||||
cpu.ioRead = io_read;
|
cpu.ioRead = io_read;
|
||||||
cpu.ioWrite = io_write;
|
cpu.ioWrite = io_write;
|
||||||
|
Binary file not shown.
@ -191,7 +191,17 @@ int main()
|
|||||||
int res = cpu.R1.br.A;
|
int res = cpu.R1.br.A;
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
int lineno = cpu.R1.wr.HL;
|
int lineno = cpu.R1.wr.HL;
|
||||||
fprintf(stderr, "Error %d on line %d\n", res, lineno);
|
int inclineno = cpu.R1.wr.DE;
|
||||||
|
if (inclineno) {
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"Error %d on line %d, include line %d\n",
|
||||||
|
res,
|
||||||
|
lineno,
|
||||||
|
inclineno);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Error %d on line %d\n", res, lineno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user