Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-07

Changing compiler modes

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I am trying to merge a bunch of my pascal units into a single unit, to avoid circular references. This is quite a challenge because they are not all compiled with the same mode.

Some units use {$Mode TP}
And I can't compile some of the procedures from that unit in other modes because I use features that only work in Turbo Pascal mode, like modifying a for loop variable from inside the loop.   I also have issues with the curly brace {   I can't use it as a literal character like MyChar:='{'; because it thinks it's starting comment and it's very strict in not allowing nested comments with curly braces like this
Case RunExt of
{ #134:   {F12}
      Thing1;}
 #3: {Ctrl C}
       Thing2;
End;
But then I have other procedures that just won't work in Turbo Pascal mode, because I have used  % to specify binary numbers like this:
My_Binary_Number := %10011001;  and that just give me an error in Turbo Pascal mode.. I could just change them to hex, but there are hundreds of them.

I'm wondering if there is some way that I can have some procedures compiled with {$Mode FPC} and others with {$Mode TP} I see something about {$ModeSwitch EXCEPTIONS} here: https://wiki.freepascal.org/Compiler_Mode but I can't get that to work.. it doesn't say much about it... If I put that in I still can't change mode for individual procedures.

Alternatively, is there any way to force it to allow circular unit references? I'm sure there is a technical reason why it's not allowed, but I thought I might as well ask. I have SO MANY duplicate functions because I need them in more than one unit and it's just to prevent creating circular unit references; I'm hoping to avoid a massive re-write to solve all the issues I have with one mode ore the other... that would take years to accomplish.

Any help or suggestions are greatly appreciated.

James

Reply by email

Michael Van Canneyt
to James Richters
James Richters wrote 20 lines
I am trying to merge a bunch of my pascal units into a single unit, to avoid circular references. This is quite a challenge because they are not all compiled with the same mode. Some units use {$Mode TP} And I can't compile some of the procedures from that unit in other modes because I use features that only work in Turbo Pascal mode, like modifying a for loop variable from inside the loop. I also have issues with the curly brace { I can't use it as a literal character like MyChar:='{'; because it thinks it's starting comment and it's very strict in not allowing nested comments with curly braces like this Case RunExt of { #134: {F12} Thing1;} #3: {Ctrl C} Thing2; End; But then I have other procedures that just won't work in Turbo Pascal mode, because I have used % to specify binary numbers like this: My_Binary_Number := %10011001; and that just give me an error in Turbo Pascal mode.. I could just change them to hex, but there are hundreds of them. I'm wondering if there is some way that I can have some procedures compiled with {$Mode FPC} and others with {$Mode TP} I see something about {$ModeSwitch EXCEPTIONS} here: https://wiki.freepascal.org/Compiler_Mode but I can't get that to work.. it doesn't say much about it... If I put that in I still can't change mode for individual procedures.

You can't switch modes between procedure, because a mode implicitly alters the uses clause, and for this reason can only occur before the uses clause.

Some mode-specific features can be switched on or off on a per-feature basis, but this is not so for all features, and they are also global (i.e. can be set only once for a unit).

Alternatively, is there any way to force it to allow circular unit references?

Only from interface to implementation.

If you have such a strange set of units, I would recommend a rewrite in each case: it doesn't sound like a 'healthy' code base...

Michael.

Reply by email

James Richters
to Michael Van Canneyt

I see how {$ModeSwitch } work now.. I have far more code that only works in {$Mode TP} so I supposed I'll have to just re-write things to stay compatible with that.

Is there a {$Modeswitch } feature I can turn on to allow the % to specify binary numbers when in {$Mode TP}?

James

Earlier message 44 lines
-----Original Message----- From: fpc-pascal On Behalf Of Michael Van Canneyt Sent: Monday, July 1, 2019 10:31 AM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] Changing compiler modes On Mon, 1 Jul 2019, James Richters wrote: > I am trying to merge a bunch of my pascal units into a single unit, to avoid circular references. This is quite a challenge because they are not all compiled with the same mode. > > Some units use {$Mode TP} And I can't compile some of the procedures > from that unit in other modes because I use features that only work in > Turbo Pascal mode, like modifying a for loop variable from inside the > loop. I also have issues with the curly brace { I can't use it as a > literal character like MyChar:='{'; because it thinks it's starting > comment and it's very strict in not allowing nested comments with > curly braces like this Case RunExt of { #134: {F12} > Thing1;} > #3: {Ctrl C} > Thing2; > End; > > But then I have other procedures that just won't work in Turbo Pascal mode, because I have used % to specify binary numbers like this: > My_Binary_Number := %10011001; and that just give me an error in Turbo Pascal mode.. I could just change them to hex, but there are hundreds of them. > > I'm wondering if there is some way that I can have some procedures compiled with {$Mode FPC} and others with {$Mode TP} > I see something about {$ModeSwitch EXCEPTIONS} here: https://wiki.freepascal.org/Compiler_Mode but I can't get that to work.. > it doesn't say much about it... If I put that in I still can't change mode for individual procedures. You can't switch modes between procedure, because a mode implicitly alters the uses clause, and for this reason can only occur before the uses clause. Some mode-specific features can be switched on or off on a per-feature basis, but this is not so for all features, and they are also global (i.e. can be set only once for a unit). > Alternatively, is there any way to force it to allow circular unit references? Only from interface to implementation. If you have such a strange set of units, I would recommend a rewrite in each case: it doesn't sound like a 'healthy' code base... Michael.

Reply by email

Michael Van Canneyt
to James Richters
James Richters wrote
I see how {$ModeSwitch } work now.. I have far more code that only works in {$Mode TP} so I supposed I'll have to just re-write things to stay compatible with that. Is there a {$Modeswitch } feature I can turn on to allow the % to specify binary numbers when in {$Mode TP}?

No. Here is a list of available modeswitches:

https://www.freepascal.org/docs-html/current/prog/progsu105.html#x113-1140001.3.22

Michael.

Reply by email

James Richters
to Michael Van Canneyt

Thanks for the link to the list of mode switches. I'm still trying to figure out how I can best restructure.. I'll probably need to re-write a bunch of stuff to make things all work in the same mode. I'm thinking of making it all work in fpc mode.

Do any of these happen to allow modifying a For loop variable, which works in {$Mode TP}

For X := 1 to 10 do
   Begin
       If somethingmakesmewanttoexit then
            X:=10;
       If somethinmakesmewanttoskipthenextthing then
           Inc(X);
   End;

James

Earlier message 19 lines
-----Original Message----- From: fpc-pascal On Behalf Of Michael Van Canneyt Sent: Monday, July 1, 2019 10:49 AM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] Changing compiler modes On Mon, 1 Jul 2019, James Richters wrote: > I see how {$ModeSwitch } work now.. I have far more code that only works in {$Mode TP} so I supposed I'll have to just re-write things to stay compatible with that. > > Is there a {$Modeswitch } feature I can turn on to allow the % to specify binary numbers when in {$Mode TP}? No. Here is a list of available modeswitches: https://www.freepascal.org/docs-html/current/prog/progsu105.html#x113-1140001.3.22 Michael.

Reply by email

Michael Van Canneyt
to James Richters
James Richters wrote 11 lines
Thanks for the link to the list of mode switches. I'm still trying to figure out how I can best restructure.. I'll probably need to re-write a bunch of stuff to make things all work in the same mode. I'm thinking of making it all work in fpc mode. Do any of these happen to allow modifying a For loop variable, which works in {$Mode TP} For X := 1 to 10 do Begin If somethingmakesmewanttoexit then X:=10; If somethinmakesmewanttoskipthenextthing then Inc(X); End;

Not to my knowledge.

Michael.

Reply by email