Recent

Author Topic: MODE ISO:Wrong number of parameters specified for call to "<Procedure Variable>"  (Read 2957 times)

helbig

  • New Member
  • *
  • Posts: 29
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?

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
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!
« Last Edit: September 22, 2020, 04:39:38 pm by Thaddy »
Specialize a type, not a var.

helbig

  • New Member
  • *
  • Posts: 29
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.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
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.
« Last Edit: September 22, 2020, 06:32:59 pm by Thaddy »
Specialize a type, not a var.

helbig

  • New Member
  • *
  • Posts: 29
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.

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
[…] How can I catch a signal within ISO MODE?
  • Don’t make a = signalHandler(1) comparison. fpSignal returns nil on error, or the previous signal handler.
  • Your catch procedure has the wrong signature. It has to be a signalHandler. Furthermore, it demanded a cdecl which in turn didn’t like the interrupt.
  • In ISO mode, or if {$modeSwitch classicProcVars+}, routine pointers are obtained without the @-address-operator.
  • You didn’t initialize your interrupt variable before accessing it.
  • Please don’t shout, the compiler will understand just as well if write at a normal loudness. :P
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.
« Last Edit: September 22, 2020, 08:40:30 pm by Kays »
Yours Sincerely
Kai Burghardt

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
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.

helbig

  • New Member
  • *
  • Posts: 29
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.  

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Do you use any -Fa parameters?

helbig

  • New Member
  • *
  • Posts: 29
Yes, -FaBaseUnix

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Yes, -FaBaseUnix

Then that is where fpsignal comes from. But that also makes it unix specific.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
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 or $X 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. ;)

helbig

  • New Member
  • *
  • Posts: 29
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

hansotten

  • Jr. Member
  • **
  • Posts: 88
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
« Last Edit: September 24, 2020, 12:34:46 pm by hansotten »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
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 )
« Last Edit: September 24, 2020, 01:16:31 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018