Recent

Author Topic: NEW procedure and (old style) variant records (Initial ISO Pascal standard)  (Read 3878 times)

pahhur

  • Newbie
  • Posts: 5

Is there by any chance an option to fpc to instruct the compiler
to understand the initial ISO Pascal standard, especially the
NEW procedure with old style variant records:

Given a

TYPE
v = ^x;
x = RECORD
            n: INTEGER;
            CASE BOOLEAN OF
                TRUE:  (x0: REAL);
                FALSE: (x1, x2: INTEGER)
         END;

and a variable

VAR a: v;

then

    NEW(a,TRUE);

and

   NEW (a,FALSE);

should be possible, and both allocating exactly for the given variant only
(N. Wirth, Pascal User Manual and report, Iso Pascal Standard, 11.4.2, page 191); same applies to DISPOSE.

I have several thousand lines of old code here that
i need to compile.

The compiler right now reports:

Error: Pointer to object expected
Error: Illegal expression

for every NEW or DISPOSE statement that uses this old syntax.




marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
This works, but you have to enable ISO mode (passing -Miso on the cmdline)

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
or add ($mode iso} or {$mode extendedpascal} at the top of your program.
Note that since both ISO modes do not support units, the exception is you can not use this when you also use units. only whole programs.
The ISO modes are very strict and almost 99.999% compliant which is both excellent and - when you do not read the  standards - sometimes frustrating.
These two are the only modes that do not transparently mix and match with other modes because of units..

But Marco is right: it works when you specify one of the ISO modes either on the command line or by the above in source.

It seems you are familiar with the standards, so these two answers should be clear to you

Note that the extendedpascal mode is 3.2.0 + I believe, because it is not in the online documentation yet.

Florian and  Scott Franco (a.k.a. Scott Moore) have interactively discussed the standards and Florian implemented almost all if not all missing parts for both standards, (and I tested a bit fun)
 
http://pascal-central.com/standards.html
(by Scott Franco, who also visits this forum now and then)


 
« Last Edit: May 15, 2020, 10:11:54 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

pahhur

  • Newbie
  • Posts: 5
Thanks to both of you. That enables the NEW syntax. However, when I use
DISPOSE, I still get an error message:

variant.pas(16,14) Fatal: Syntax error, ")" expected but "," found

at the DISPOSE line.


(* variant.pas *)
PROGRAM variants;

TYPE v = ^x;
     x = RECORD
            n: INTEGER;
            CASE BOOLEAN OF
                TRUE:  (x0: REAL);
                FALSE: (x1, x2: INTEGER)
         END;

VAR a: v;
BEGIN
    NEW(a,FALSE);
    a^.x1 := 5;
    a^.x2 := 42;
    DISPOSE(a,FALSE);
    NEW(a,TRUE);
    a^.n := 10;
    a^.x0 := 5.0
END.
(*------------------------------------------*)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
I tested with a recent snapshot, and it is still a problem.

If this is ISO pascal, please file a bug.

jamie

  • Hero Member
  • *****
  • Posts: 6128
I've never seen that format before but what ever...

if there are several thousands lines then maybe an overloaded version of what ever will do...

but I guess that may not exist... in this mode..
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Hi!

Too young for New and Dispose?

This is not only ISO Standard but also german  DIN-Norm 66256 - since 1983.
Germans are only happy when they got a DIN-Norm for everything.

Winni


jamie

  • Hero Member
  • *****
  • Posts: 6128
I must of missed the boat, because I started coding in 1975 but had the chance of working with old computers which then would rather seem to start becoming antiques.

 I also do electronics and back then I had a collection of old surplus tube flip flips. Enough of those and I could make up a 4 bit register! ... ;)
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Hi!

I was so happy when I could get rid of the tubes in 1967 because they sold the transistor BC 107 for 1.50 German Marks ! Since then I worked only with tubes for guitar power amplifiers - good old EL 34 is simply the best! And for guitar electronics you took the germanium transistor  AC 151 : germanium has less noise than silicium.

Keep on rockin'

Winni

jamie

  • Hero Member
  • *****
  • Posts: 6128
Ah the Selenium diodes, can't beat the smell of those when they burnt up!  :D
anyways I don't think we use the term silicium anymore, out dated like the rest of us!

Speaking of guitar amps, I was working on a cheap low end Fender today. One of those what we call a government project. When you break away from your normal duties and use the companies resources to fix something for your boss, totally unrelated to your normal job.

 Yes, I know about the EL tubes ;)



 
« Last Edit: May 16, 2020, 03:45:16 am by jamie »
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
I tested with a recent snapshot, and it is still a problem.

If this is ISO pascal, please file a bug.
It is ISO Pascal and it is a bug, so should be reported indeed.
See the definition by Scott Franco, who describes the standard here:
http://www.standardpascal.org/iso7185rules.html#Dynamic%20allocation

Funny that that never came up during the tests. Probably because even he does not use the construct in his code.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
I filed a bug, refering to the original example above.

The issue is critical, because it allows the compiler to decide memory layout. (New() must match Dispose() when the extra parameters are used, so memory can be saved.)
It seems this feature of the ISO modes is hardly used, btw, but it is part of the standard indeed.

[addition]
If records are defined like this, with an array of const type thing as second parameter(s), the compiler just allocates the part(s) of a record that are needed, but a Dispose must exactly match the New() in such cases.

Frankly, I did not even know that existed...
« Last Edit: May 16, 2020, 11:58:59 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
A lot of ISO code that we tested with comes from GPC or was adapted for GPC.

If GPC is a bit permissive in some aspects, I can imagine it being only found later.

From what I remember, many more recent compilers don't really allocate reduced memory, and therefore don't really need the variant at deallocation either, just like FPC doesn't require any size with freemem (while TP did). It is maintained in the heapmanager.
« Last Edit: May 16, 2020, 02:18:00 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Florian chose a sane solution: fixed by parsing, not by implementing.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Florian chose a sane solution: fixed by parsing, not by implementing.

Yeah, but dispose should also be fixed by parse. Even if the parameter is ignored, it is still a compatibility issue.

...ah ok, you had seen the commit.

Quote
r45519 florian 2020-05-27 23:10:55 +0200 (Wed, 27 May 2020)
* allow in iso mode constants selecting the branch to dispose of a variant record (no functional effect though), resolves 0037085
« Last Edit: May 28, 2020, 10:49:23 am by marcov »

 

TinyPortal © 2005-2018