tebe6502 / Mad-Pascal

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

Index variable is not incremented without dummy call #91

Closed SignumTemporis closed 2 years ago

SignumTemporis commented 2 years ago

Issue description

An index variable is not incremented without calling some procedure first (line (1) in sample code). When line (1) is uncommented then it works as expected.

For FPC -MDelphi v3.2.2 it works as expected.

Mad-Pascal Compiler version ece71f6 Mad-Assembler version 40bfd80

Code to reproduce the issue

uses crt;

var t: array [0..1] of Byte;

procedure DoSomething(k: Byte);
var x1, x2: Byte;
begin
  x1 := t[k];
  // WriteLn('');   // (1)
  k := k + 1;
  x2 := t[k];

  WriteLn(x1, ' ', x2);
end;

begin
  t[0] := 1;
  t[1] := 3;

  DoSomething(0);

  ReadKey();
end.

Output

Expected

1 3

Actual

1 1
SignumTemporis commented 2 years ago

It behaves the same way with global variable.

uses crt;

var
  t: array [0..1] of Byte;
  k: Byte;

procedure DoSomething();
var x1, x2: Byte;
begin
  x1 := t[k];
  // WriteLn('');   // (1)
  k := k + 1;
  x2 := t[k];

  WriteLn(x1, ' ', x2);
end;

begin
  t[0] := 1;
  t[1] := 3;

  k := 0;
  DoSomething();

  ReadKey();
end.
tebe6502 commented 2 years ago

fixed

SignumTemporis commented 2 years ago

Works for me now.