Changing compiler modes

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing compiler modes

Zaaphod
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Michael Van Canneyt


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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Zaaphod
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

-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Michael Van Canneyt
Sent: Monday, July 1, 2019 10:31 AM
To: FPC-Pascal users discussions <[hidden email]>
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.
_______________________________________________
fpc-pascal maillist  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Michael Van Canneyt


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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Zaaphod
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
-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Michael Van Canneyt
Sent: Monday, July 1, 2019 10:49 AM
To: FPC-Pascal users discussions <[hidden email]>
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.
_______________________________________________
fpc-pascal maillist  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Michael Van Canneyt


On Mon, 1 Jul 2019, James Richters wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Changing compiler modes

Bo Berglund
In reply to this post by Zaaphod
On Mon, 1 Jul 2019 13:37:54 -0400, "James Richters"
<[hidden email]> wrote:

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

Why not:
For X := 1 to 10 do
   Begin
       If somethingmakesmewanttoexit then
            break;
       If somethinmakesmewanttoskipthenextthing then
           continue;
       Regularprocessing;
   End;



--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal