tebe Posted April 6 Author Share Posted April 6 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 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted April 8 Share Posted April 8 On 4/2/2023 at 3:54 PM, tebe said: MP 1.6.7 (branch DEV) https://github.com/tebe6502/Mad-Pascal/tree/dev https://github.com/tebe6502/Mad-Pascal/tree/dev/samples/common I see you are develop more and more 😀👍 Quote Link to comment Share on other sites More sharing options...
Teapot Posted April 29 Share Posted April 29 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 Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted May 4 Share Posted May 4 ok... wanted to finally play around with mad pascal latest version... but how to i compile the samples? what environment paths do I have to set? as the doc under usage doesn't give me a clue to be honest. Quote Link to comment Share on other sites More sharing options...
tebe Posted May 5 Author Share Posted May 5 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 Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted May 5 Share Posted May 5 11 hours ago, tebe said: mp.exe filename.pas -ipath:<MadPascalPath>\lib mads.exe filename.a65 -x -i:<MadPascalPath>\base Aaah…. Thx btw I always wondered now why you used ipath: and i: and not both same 😉 Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted May 5 Share Posted May 5 11 hours ago, tebe said: mp.exe filename.pas -ipath:<MadPascalPath>\lib mads.exe filename.a65 -x -i:<MadPascalPath>\base works! Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted May 6 Share Posted May 6 Now another question regarding fixed point (shortreal)… any “fast” division possible? Or should I go the reciprocal mul way? and is there some 3d demo example except the cubes? Quote Link to comment Share on other sites More sharing options...
gz0000 Posted May 16 Share Posted May 16 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; Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 16 Share Posted May 16 6 hours ago, gz0000 said: Is there any other solution besides: function xyz():integer; var i:integer; j:byte; begin i:=0; j:=0; ... end; nope Quote Link to comment Share on other sites More sharing options...
tebe Posted May 16 Author Share Posted May 16 works without any problems func.a65 func.lst func.obx func.pas Quote Link to comment Share on other sites More sharing options...
tebe Posted May 16 Author Share Posted May 16 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 Quote Link to comment Share on other sites More sharing options...
gz0000 Posted May 17 Share Posted May 17 22 hours ago, tebe said: works without any problems func.a65 9.29 kB · 2 downloads func.lst 17.13 kB · 6 downloads func.obx 402 B · 1 download func.pas 181 B · 6 downloads 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.lst test_local_vars_mp.xex test_local_vars_mp.a65 test_local_vars_mp.pas Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted May 18 Share Posted May 18 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... Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 19 Share Posted May 19 On 5/17/2023 at 7:38 PM, gz0000 said: Maybe I wasn't specific enough - the following test code is OK for the first call exactly, because of that you should set the variables by yourself as you did Quote Link to comment Share on other sites More sharing options...
danwinslow Posted May 19 Share Posted May 19 (edited) 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 May 19 by danwinslow Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 19 Share Posted May 19 6 minutes ago, danwinslow said: Unless pascal explicitly doesn't do that, in which case I wonder why they have local vars at all. for scope Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 19 Share Posted May 19 1 Quote Link to comment Share on other sites More sharing options...
danwinslow Posted May 19 Share Posted May 19 (edited) 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 May 19 by danwinslow 2 Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 19 Share Posted May 19 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. Quote Link to comment Share on other sites More sharing options...
danwinslow Posted May 20 Share Posted May 20 Ah. Ok, thanks. The guy asking about it seemed to have some expectation of it working that way, so I kind of thought it was supposed to. Maybe it's kind of a language hole, and only works in variants that MadPascal is not implementing. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted May 20 Share Posted May 20 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. Quote Link to comment Share on other sites More sharing options...
danwinslow Posted May 20 Share Posted May 20 (edited) 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 May 20 by danwinslow Quote Link to comment Share on other sites More sharing options...
zbyti Posted May 20 Share Posted May 20 Gentlemen, remember, this is supposed to run on 8-bit and requires compromises to fit in 64KB and so on I've known about this case for almost two years, just report it on github and do a workaround I asure you @tebe also knows this issue/behavior Quote Link to comment Share on other sites More sharing options...
danwinslow Posted May 20 Share Posted May 20 yeah, I assumed as much, since he hasn't commented. I'm glad you've known about this, please pardon us for discussing it in your thread. Neither one of us was advocating for a change in MadPascal, I was just voicing an opinion. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.