What is wrong with this code?

Topics related to the use of Oberon language features
Locked
4GlCoder
Posts: 27
Joined: Fri Jul 22, 2011 2:47 pm

What is wrong with this code?

Post by 4GlCoder » Wed Sep 21, 2011 1:38 pm

I'm trying to separate some code from a camera library:

Code: Select all

MODULE IRLib;

IMPORT Out;

TYPE
  camlib* = POINTER TO RECORD 
    freq* : INTEGER;
    shutterNow* : PROCEDURE(self : camlib)
  END;

  CanonCam* = POINTER TO RECORD(camlib)
    shutterDelayed* : PROCEDURE(self : camlib)
  END;

PROCEDURE CanonShutterNow(self : CanonCam);
BEGIN
  Out.String("Click now."); Out.Ln
END CanonShutterNow;

PROCEDURE CanonShutterDelayed(self : CanonCam);
BEGIN 
  Out.String("Delayed ... click"); Out.Ln
END CanonShutterDelayed;

PROCEDURE CanonInit*(self : CanonCam);
BEGIN
  self.freq := 33;
  self.shutterNow := CanonShutterNow;
  self.shutterDelayed := CanonShutterDelayed
END CanonInit;

PROCEDURE CanonExample;
VAR
  D5 : CanonCam;
  i : INTEGER;
BEGIN
  NEW(D5);
  CanonInit(D5);
  i := 0;
  REPEAT
    D5.shutterNow(D5);
    D5.shutterDelayed(D5);
    INC(i)
  UNTIL i > 3
END CanonExample;

END IRLib.
This compiles fine! Now I move the CanonExample procedure above to it's own module:

Code: Select all

MODULE TestIRLib;

IMPORT IRLib;

PROCEDURE CanonExample;
VAR
  D5 : IRLib.CanonCam;
  i : INTEGER;
BEGIN
  NEW(D5);
  IRLib.CanonInit(D5);
  i := 0;
  REPEAT
    D5.shutterNow(D5);
    D5.shutterDelayed(D5);
    INC(i)
  UNTIL i > 3
END CanonExample;

END TestIRLib.
But now i'm getting compile errors..

Code: Select all

Oberon-07 LPC2000 ARM Compiler v3.4.1
  compiling TestIRLib

  Line  Col
    14   22:  incompatible types
    formal parameter: 
    15   26:  incompatible types
    formal parameter: 
What am I doing wrong ?

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: What is wrong with this code?

Post by cfbsoftware » Thu Sep 22, 2011 8:30 am

This is most likely related to the restriction described in the section titled "Extending imported types" in Section titled "Oberon-07 Language Differences and Restrictions" in the Astrobe documentation.

The solution is to split the definition of CamLib into two parts:

Code: Select all

TYPE
  CamLib* = POINTER TO CamLibDesc;
  CamLibDesc* = RECORD
    freq* : INTEGER;
    shutterNow* : PROCEDURE(self: CamLib)
  END;

4GlCoder
Posts: 27
Joined: Fri Jul 22, 2011 2:47 pm

Re: What is wrong with this code?

Post by 4GlCoder » Fri Sep 23, 2011 12:21 pm

Yeah that brought back the dejavu...

Thanks reminding me, Camera library now completely separated from the examples

Locked