Great project!
What I like about it, that you did not try to implement yet another Pascal compiler for the 6502, like UCSD Pascal.
The 6502 is not very compiler friendly.: lack of 16 bit registers, hardware stack with 8 bit stackpointer.
High level, block structured based, recursion able, languages require lots of memory, stacks, heaps, stack frames, variables on the stack. That means on the 6502 a software stack with zero page based stack pointer, and quite some code. Storing data stored on the stack also requires quite some code.
A solution often used on small machines with the 6502 is to generate compact code for virtual machine and the virtual machine implements an interpreteer for a stack machine. It works but is slow.
Trying to generate 6502 code leads to lots of code alas and memory is filled up quickly.
Instead you choose to design a language in the Pascal spirit but without no recursion, no blocks, dasta stored static
That i why I like your approach: no recursion, static variables.
I did a quick test (I am aware not all is implemented!)
program testprog;
var i : byte ;
l : byte absolute $F000 ;
procedure test (j: byte);
var k : byte ;
begin
k := j ;
j := k ;
end;
begin
asm
cld ;
end
i := 2 ;
test (i) ;
i := i + 1 ;
l := i ;
end.
;Code generated by P6502 compiler
processor 6502
;===RAM usage===
i EQU 0x005
l EQU 0xF000
j EQU 0x003
k EQU 0x004
;------ Work and Aux. Registers ------
;===Blocks of Code===
ORG $0000
$0000 4C 0F 00 JMP $000F
j $0003 DB ??
k $0004 DB ??
i $0005 DB ??
__test:
$0006 A5 03 LDA $03
$0008 85 04 STA $04
$000A A5 04 LDA $04
$000C 85 03 STA $03
$000E 60 RTS
__main_program__:
$000F D8 CLD
$0010 A9 02 LDA #$02
$0012 85 05 STA $05
$0014 A5 05 LDA $05
$0016 85 03 STA $03
$0018 20 06 00 JSR $0006
$001B E6 05 INC $05
$001D 85 05 STA $05
$001F A5 05 LDA $05
$0021 8D 00 F0 STA $F000
;--------------------
END
Great start! I like to see your progress!