Jump to content
IGNORED

Mad Pascal


Recommended Posts

12 hours ago, Atlan_Roland said:

Mad Pascal Compiler version 1.6.7 [2023/04/04] for 6502
Compiling CITY.PAS
inc/npc_procedures.pas (184,10) Error: Assignments to formal parameters and open arrays are not possible

in the process of revision, not yet completed

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to use records in MP 1.6.6 and am getting several compiler failures.

 

Using this definition:

  TestRecord = packed record
    name: string[40];
    ref: byte;
    id: array [0..3] of byte;
    offset: array [0..3] of byte;
    width: array[0..3] of byte;
  end;

 

If I try to access the string or the arrays via a pointer (TestRecord^) it looks like the compiler adds an extra deference when trying to get to the data. In the case of the arrays it stops the compile because the resulting type is a mismatch. In the case of the string it uses name[0] and name[1] as a pointer rather than as string data.

 

Similar things happen when it's all constructed as an object. I also uncovered a compiler exception in this case and added a $define for it as well.

 

I've attached two test files with $defines to disable the bits that are compile errors. Both of them work correctly with the failures enabled when run via FPC.

 

objecttest.pas recordtest.pas

Link to comment
Share on other sites

11 hours ago, Heaven/TQA said:

what environment paths do I have to set? as the doc under usage doesn't give me a clue to be honest.

mp.exe filename.pas -ipath:<MadPascalPath>\lib
mads.exe filename.a65 -x -i:<MadPascalPath>\base
Link to comment
Share on other sites

  • 2 weeks later...

 

This doesn't work:

 

function xyz():integer;

var

   i:integer=0;

   j:byte=0;

begin

   ...

end;

 

According to documentation Mad Pascal works as FPC with -Delphi switch and above is not possible in Delphi.

 

Is there any other solution besides: 

 

function xyz():integer;

var

   i:integer;

   j:byte;

begin

   i:=0;

   j:=0;

   ...

end;

 

 

 

Link to comment
Share on other sites

8 hours ago, gz0000 said:

According to documentation Mad Pascal works as FPC with -Delphi switch and above is not possible in Delphi.

but it is possible in FPC

 -M<x>  Set language mode to <x>
      -Mfpc      Free Pascal dialect (default)
      -Mobjfpc   FPC mode with Object Pascal support
      -Mdelphi   Delphi 7 compatibility mode
      -Mtp       TP/BP 7.0 compatibility mode
      -Mmacpas   Macintosh Pascal dialects compatibility mode
      -Miso      ISO 7185 mode
      -Mextendedpascal ISO 10206 mode

 

Link to comment
Share on other sites

22 hours ago, tebe said:

Thank you for your help.

Maybe I wasn't specific enough - the following test code is OK for the first call, but not for other consecutive calls:

 

uses crt;
 
function xyz():word;
var
   val:word=0;
   val1:word=0;
   
begin
   repeat
      writeln('0. val1=',val1, ' val=', val);
      val1 := 10;
      Readkey;
      writeln('1. val1=',val1, ' val=', val);
      if (val1 <> 0) then val := 10;
      Readkey;
      writeln('2. val1=',val1, ' val=', val);
   until (val = val1);
   Readkey;
   writeln('3. val1=',val1, ' val=', val);
   xyz:=val;
end;

 

program test_local_vars_mp;

var
    k:byte;
    
begin
    for k:=0 to 255 do
       xyz();    
    repeat until keypressed;    
end.  

   

 

 

Am I doing something wrong? I haven't tried yet to analyze a65 or xex files. 

 

I am using Mad Pascal 1.6.4 with mads 2.1.0 build 8 (23 Dec 19).

 

mp.exe test_local_vars_mp.pas
mads.exe test_local_vars_mp.a65 -x -i:"c:\Mad-Pascal-1.6.4\base\" -o:test_local_vars_mp.xex -l:test_local_vars_mp.lst

 

test_local_vars_mp.png

test_local_vars_mp.lst test_local_vars_mp.xex test_local_vars_mp.a65 test_local_vars_mp.pas

Link to comment
Share on other sites

I don't know Pascal as such, but it does look like a little bug that the variables are not being re-initialised

 

I tried your code on a different compiler and it did as you expected, bit of a pain, but obviously a simple fix is:-

 

function xyz():word;
var
   val:word;
   val1:word;

begin
    val := 0;
    val1 := 0;
       repeat
      writeln('0. val1=',val1, ' val=', val);

 

etc...

Link to comment
Share on other sites

TGB, yes, you "fixed" it, but thats not the point.

The locals in the xyz() function should be re-initialized to 0 each time the function is entered. According to his output, they are not, and retain the 10 from the previous call. I think this is a bug.

Unless pascal explicitly doesn't do that, in which case I wonder why they have local vars at all.

Edited by danwinslow
Link to comment
Share on other sites

Scope, yes, but whats the point of allowing the declarative initialization if it's only going to be done once? The fact that the last value is retained makes it act more like global scope, even if the name scope is there. Not a pascal expert but seems kind of wrong.

Edited by danwinslow
  • Like 2
Link to comment
Share on other sites

28 minutes ago, danwinslow said:

but whats the point of allowing the declarative initialization if it's only going to be done once?

I think it's a derivative of the fact that global variables can be initialized this way and the memory for these variables is reserved at the end of the binary file, we save some lda/sta. As we can see this mechanism works for procedures and functions by chance, but it is indeed useless and misleading.

Link to comment
Share on other sites

Not sure if this applies, but reading some documentation on variables, doing this:-

 

function xyz():integer;

var

   i:integer=0;

   j:byte=0;

begin

   ...

end;

 

This method creates i and j as constants and they shouldn't be changed by you program, in theory should throw an error if you do.

If you did change the value, then there will be no initialization the second time in as the program has set the variables to constants

so there's no need to initialize again.

 

So the method is:-

 

function xyz():word;
var
   i:integer;
   j:integer;

begin
    i:= 0;
    j:= 0;
    ...

end;

 

The fact it works on some compilers may be just luck, I don't know enough about the language, but it does seem

reasonable considering what you are seeing.

Link to comment
Share on other sites

It shouldn't make them constants, constants go in a 'constant' block. Whether local var initialization should do anything and whether it should occur every time the function is entered is less clear, can't really get a direct answer after googling a bit.

This thread is probably relevant  - https://en.delphipraxis.net/topic/923-initialize-local-variables-at-declaration/

 

But anyway, as an outsider opinion I think it definitely should behave the way I was thinking - either make it happen each function call or don't allow it. There are various different implementations out there though, so maybe MadPascal allows compilation of such sources with the proviso that you might have to go back in and add your own direct initialization.

Edited by danwinslow
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...