tebe6502 / Mad-Pascal

Mad Pascal Compiler for 6502 (Atari XE/XL, C64, C4Plus, Neo6502)
122 stars 19 forks source link

Feature Request: `keep` modifier for procedures/functions #86

Closed zbyti closed 2 years ago

zbyti commented 2 years ago

keep as modifier could be a compiler directive - this would be useful not to remove unnecessary in his opinion procedures or functions and maybe even data.

procedure foo; keep;
begin
end;
zbyti commented 2 years ago

I made workaround for my VBI procedure here: https://github.com/zbyti/simple-games-easy-for-develop/blob/master/Mad%20Pascal/snake/src/game.inc

zbyti commented 2 years ago
procedure vbi; keep;
begin
  if not game_over then begin
    update_time;
    snake_step;
    if not fruit_on_board then put_fruit;
    if time_bcd = TIME_THOLD then game_over := true;
  end;
end;

//o-------------------------------------------------------------o

procedure prepare;
begin
  Move(pointer(CRT_CHARS_ADR), pointer(CHARSET_ADR), CHARSET_SIZE);
  Move(pointer(CRT_TITLE_ADR), pointer(SCREEN_ADR), SCREEN_SIZE);

  {*
    hack for the compiler, call vbi procedure
    in other case optimizer remove unused - from his point of view - code

    vbi;
  *}
end;

MadPascal/samples/vic-20/snake$ make
rm -f output/* bin/*
/home/zbyti/Programs/MadPascal/mp src/vic20.pas -t raw -code A009 -o output/vic20.a65
Mad Pascal Compiler version 1.6.6 [2022/04/12] for 6502
Compiling src/vic20.pas
src/vic20.pas (12) Note: Local const 'GAME_BLACK' not used
src/vic20.pas (14) Note: Local const 'GAME_RED' not used
src/vic20.pas (15) Note: Local const 'GAME_CYAN' not used
src/vic20.pas (16) Note: Local const 'GAME_PURPLE' not used
src/vic20.pas (18) Note: Local const 'GAME_BLUE' not used
src/vic20.pas (20) Note: Local const 'GAME_ORANGE' not used
src/game.inc (69) Note: Local absolutevar 'SF0B' not used
src/game.inc (70) Note: Local absolutevar 'SF1B' not used
49 lines compiled, 0.81 sec, 8017 tokens, 627 idents, 217 blocks, 6 types
8 note(s) issued
/home/zbyti/Programs/mads/mads output/vic20.a65 -x -i:/home/zbyti/Programs/MadPascal/base -o:output/vic20-core.bin
ZPAGE: $0000..$0053
RTLIB: $A07C..$A113
SYSTEM: $A12D..$A143
SYS_VIC20: $A144..$A28E
CODE: $A00C..$A548
DATA: $A55C..$A55E
$R RCDATA  $B912..$BBFF 'res/title_cbm.scr'
$R RCDATA  $BC00..$BFFF 'res/snake_cbm.fnt'
        .local +MAIN.UPDATE_TIME
vic20.a65 (1238) ERROR: Undeclared label MAIN.UPDATE_TIME (BANK=0)
        .local +MAIN.SNAKE_STEP
vic20.a65 (1244) ERROR: Undeclared label MAIN.SNAKE_STEP (BANK=0)
        m@INLINE
vic20.a65 (1239) ERROR: Undeclared macro M@INLINE (BANK=0)
vic20.a65 (1245) ERROR: Undeclared macro M@INLINE (BANK=0)
        jsr PUT_FRUIT
vic20.a65 (1252) ERROR: Undeclared label PUT_FRUIT (BANK=0)
Writing listing file...
make: *** [makefile:11: build-vic20] Error 2
zbyti commented 2 years ago

https://github.com/tebe6502/Mad-Pascal/pull/93

zbyti commented 2 years ago

https://github.com/tebe6502/Mad-Pascal/commit/05c00459bb2e6a074f8270a0b262e1aa9842ef9e