Lazarus

Programming => General => Topic started by: helbig on September 22, 2020, 03:59:39 pm

Title: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 22, 2020, 03:59:39 pm
Hi,
this little beauty is not accepted by FPC:
{$MODE ISO}
program interupt(input, output);
   var interrupt: integer;

   procedure catch; interrupt;
   begin
      interrupt:=999;
   end;
begin
   if FPSIGNAL(SIGINT,SIGNALHANDLER(@CATCH))=SIGNALHANDLER(1) then
   writeln('Error:', fpGetErrno);
   while interrupt = 0 do ;
   writeln(interrupt);
end.

$ fpc -Fabaseunix interrupt.p
interrupt.p(10,45) Error: Wrong number of parameters specified for call to "<Procedure Variable>"
interrupt.p(15) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode

But without MODE ISO it compiles fine! And the signal will be caught!

How can I catch a signal within ISO MODE?
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: Thaddy on September 22, 2020, 04:31:32 pm
Code: Pascal  [Select][+][-]
  1. FPSIGNAL(SIGINT,SIGNALHANDLER(@CATCH))=SIGNALHANDLER(1)
Is not ISO compliant code.
Try
Code: Pascal  [Select][+][-]
  1. FPSIGNAL(SIGINT,SIGNALHANDLER(@CATCH))=@SIGNALHANDLER(1)

I am not even sure that is allowed in ISO mode, It is very restrictive and misses much of the features of modern pascal.
I will test it later against a compiler/interpreter that is known to be 100% compatible (P5 by Scott Franco/Moore).If that fails it is likely a bug, but I think you need to take the pointer address.

Scott visits this forum sometimes and Florian himself has a keen interest.

Does your code compile in P5? then it is a bug, otherwise it is not!
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 22, 2020, 04:49:30 pm
No, the "@" before SIGNALHANDLER did not help out. I need the ISO MODE for compiling Donald Knuth's typesetting system TeX. (TeX-FPC). It needs 32bit integer, gotos, ISO-IO-procedures, (get and put) and some extensions to ISO Pascal.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: Thaddy on September 22, 2020, 06:19:00 pm
No, the "@" before SIGNALHANDLER did not help out. I need the ISO MODE for compiling Donald Knuth's typesetting system TeX. (TeX-FPC). It needs 32bit integer, gotos, ISO-IO-procedures, (get and put) and some extensions to ISO Pascal.
Where can I find TeX-FPC? We don't need it, btw.
And are you sure *very* sure that it should compile in ISO mode? (32 bit does not help)
And try {$mode extendedpascal} for code that has ISO extensions. Note the official extensions are also a standard and FPC tries to support it too.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 22, 2020, 07:16:49 pm
Here is a link to TeX-FPC:
https://ctan.org/tex-archive/systems/unix/tex-fpc
The program was written 1982 in Stanford and is adapted to a certain Pascal Compiler, called Pascal H.
2009 I changed it to work with the GNU Pascal Compiler (TeX-GPC) and 2019 I published an adaption to Free Pascal. For me, the ISO Mode turned out to be the mode with the least surprises. In the 1970s, I worked a lot with ISO Pascal but never with Turbo Pascal.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: Kays on September 22, 2020, 08:34:54 pm
[…] How can I catch a signal within ISO MODE?
Code: Pascal  [Select][+][-]
  1. {$mode ISO}
  2. program interruptTest(input, output);
  3.  
  4. var
  5.         lastInterrupt: integer;
  6.  
  7. procedure catchSignal(signal: longInt); cDecl;
  8. begin
  9.         lastInterrupt := 999;
  10. end;
  11.  
  12. begin
  13.         lastInterrupt := 0;
  14.        
  15.         if not assigned(FPSignal(SigInt, catchSignal)) then
  16.         begin
  17.                 writeLn('Error: ', fpGetErrno());
  18.                 halt(1);
  19.         end;
  20.        
  21.         while lastInterrupt = 0 do
  22.         begin
  23.         end;
  24.        
  25.         writeLn(lastInterrupt);
  26. end.
Surprisingly though, … = nil does not work. I can’t explain you why, but not assigned(…) is identical to an equal-comparison.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: PascalDragon on September 23, 2020, 09:43:23 am
Surprisingly though, … = nil does not work. I can’t explain you why, but not assigned(…) is identical to an equal-comparison.

It also fails in e.g. mode Delphi. I wonder why the compiler handles that differently... would you report a bug, please? :)

By the way: FPSignal is only available on *nix systems. For e.g. Windows and OS/2 you can use SysSetCtrlBreakHandler. For other platforms you'll have to determine a platform dependent mechanism.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 23, 2020, 09:50:56 am
Thank you, Kai.
Most important: Your program does compile and installs the signal handler.

First: The comparison nil = does not and should not compile since it is not ISO-Pascal! But the error message is not very enlightening!
Error: Wrong number of parameters specified for call to "<Procedure Variable>"

Second: FPSignal returns a previously installed signal handler or nil, if there was no signal handler installed. So expect the return value nil if it is successfull.

Third: The compiler, even in ISO Mode, lets you call FPSignal as a procedure!

Thanks a lot, you really helped me!

Finally: May I ask you to check my (mis)use of Free Pascal in http://mirrors.ctan.org/systems/unix/tex-fpc/tex-fpc.pdf
This is from January 2019. The edition I am preparing will have all the features of the TeX-GPC program. The last one is the signal handler!

Greetings, Wolfgang

Code: Pascal  [Select][+][-]
  1. {$MODE ISO}
  2. program interupt(input, output);
  3.    var interrupt: integer;
  4.  
  5.    procedure catch; interrupt;
  6.    begin
  7.       interrupt:=999;
  8.    end;
  9. begin
  10.    FPSignal(sigint,SignalHandler(CATCH));
  11.    if fpGetErrno <> 0 then
  12.       writeln('Error:', fPGetErrno);
  13.    interrupt := 0;
  14.    while interrupt = 0 do ;
  15.    writeln(interrupt);
  16. end
  17.  
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: marcov on September 23, 2020, 10:44:04 am
Do you use any -Fa parameters?
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 23, 2020, 11:01:04 am
Yes, -FaBaseUnix
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: marcov on September 23, 2020, 11:33:21 am
Yes, -FaBaseUnix

Then that is where fpsignal comes from. But that also makes it unix specific.
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: PascalDragon on September 23, 2020, 09:55:58 pm
First: The comparison nil = does not and should not compile since it is not ISO-Pascal! But the error message is not very enlightening!
Error: Wrong number of parameters specified for call to "<Procedure Variable>"

Well, ISO-Pascal doesn't support procedure variable types, only procedural parameters, so in that sense the whole call would be invalid for ISO-Pascal. It can however be considered an extension and thus the check against Nil should work (it doesn't work in mode Delphi either, so something is fishy...)

Third: The compiler, even in ISO Mode, lets you call FPSignal as a procedure!

The $ExtendedSyntax (https://www.freepascal.org/docs-html/current/prog/progsu124.html#x132-1330001.3.40) or $X (https://www.freepascal.org/docs-html/current/prog/progsu124.html#x132-1330001.3.40) switch is enabled by default independent of the mode.

Finally: May I ask you to check my (mis)use of Free Pascal in http://mirrors.ctan.org/systems/unix/tex-fpc/tex-fpc.pdf
This is from January 2019. The edition I am preparing will have all the features of the TeX-GPC program. The last one is the signal handler!

I have not read the whole document yet, but I noticed your remark regarding else-clause for the case-statement: you can also use otherwise which would even be compatible to Extended Pascal. ;)
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 24, 2020, 11:50:38 am
Hi PascalDragon,

thanks for the hint: But FPC 3.2.0 in ISO mode does not accept the case label "otherwise":
Code: Pascal  [Select][+][-]
  1. $ cat ow.p
  2. {$MODE ISO}
  3. program ow;
  4. begin
  5.     case 5 of
  6.         1, 2, 3: ;
  7.         otherwise:
  8.     end
  9. end.
  10. $ fpc ow.p
  11. ow.p(6,6) Error: Identifier not found "otherwise"
  12. ow.p(6,15) Error: Constant Expression expected
  13. ow.p(9) Fatal: There were 2 errors compiling module, stopping
  14. Fatal: Compilation aborted
  15. Error: /usr/local/bin/ppcx64 returned an error exitcode
  16.  

Greetings Wolfgang
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: hansotten on September 24, 2020, 12:27:44 pm
With  {$mode ISO}

else is allowed, otherwise is not

According to the wiki  the planned {$mode extendedPascal} will allow otherwise

but it is not yet implemented in the current Freepascal/Lazarus version. And work on it is halted since 2019 according bugreport https://bugs.freepascal.org/view.php?id=32549
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: Thaddy on September 24, 2020, 12:46:43 pm
Apart from the fact that the presented code has a bug anyway (missing close for otherwise i.e. missing ; ), ISO/IEC 7185 :1990 a.k.a. the standard, does not contain otherwise as a selector switch for case as far as I can see.
http://www.pascal-central.com/docs/iso7185.pdf and http://www.pascal-central.com/docs/iso10206.pdf  for reference.

I know some dialects support it. A workaround is like so:
Code: Pascal  [Select][+][-]
  1. {$MODE ISO}{$macro on}{$define otherwise:=else}
  2. program ow;
  3. begin
  4.     case 5 of
  5.         1, 2, 3: ;
  6.         otherwise;
  7.     end
  8. end.

Try P5 to test if it is supposed to be supported. Scott Franco (a.k.a. Scott Moore) maybe can shed some light on it. He knows everything about both ISO modes and wrote P5. He is also a forum member.

See: https://github.com/tangentstorm/pascal/tree/master/p5 (compiles with FPC)
and: https://sourceforge.net/p/pascalp5/wiki/Home/

I know Florian also uses that for conformance testing.
Afaik, P5 is the only known open source version that is fully standards compliant, although FPC comes very close (99.9%)

( Also note that very old Pascal code is not necessarily ISO!  e.g. UCSD Pascal is not in any way ISO compliant, nor is the abandonwared GNU Pascal )
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: helbig on September 24, 2020, 01:06:04 pm
Hi Thaddy,
I do not think, that the last case has to be closed by a semicolon.
This compiles w/o a flaw! The semicolon before the "end" is optional, not mandatory.
The semicolon seperates cases, it is not a part of a case.
Code: Pascal  [Select][+][-]
  1. {$MODE ISO}
  2. program ow;
  3. begin
  4.    case 5 of
  5.       1, 2, 3:
  6.    end
  7. end.
  8.  
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: Thaddy on September 24, 2020, 01:23:10 pm
Well, I do not have P5 at hand right now, (I am busy) but for sure it should fail that code since you specify two paths in the original code.
Also, a case should have defined execution paths and it is not the colon, but the semi-colon that separates the paths.
Try P5 yourself, it is a 30 seconds or less compile even on slow hardware..
Title: Re: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"
Post by: PascalDragon on September 24, 2020, 01:50:35 pm
Hi PascalDragon,

thanks for the hint: But FPC 3.2.0 in ISO mode does not accept the case label "otherwise":

Ehm... right... we've disabled non-supported keywords for ISO-Pascal, but the else keyword is still available thus it also works...

Anyway, I've enabled the otherwise keyword for mode ExtendedPascal in revision 46943 (https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=46943) as it should be.

but it is not yet implemented in the current Freepascal/Lazarus version. And work on it is halted since 2019 according bugreport https://bugs.freepascal.org/view.php?id=32549

It's a work in progress, but not a high priority one, especially as quite some parts of the language are involved.
TinyPortal © 2005-2018