lboasso / oberonc

An Oberon-07 compiler for the JVM
MIT License
147 stars 17 forks source link

Compile errors when importing a file #23

Closed rbatllet closed 1 year ago

rbatllet commented 1 year ago

I found it's impossible to compile the Rectangles.Mod file. These are the errors detected:

Rectangles.Mod:22:28: undef
Rectangles.Mod:26:11: not a function
Rectangles.Mod:31:20: illegal assignment
Rectangles.Mod:32:21: undef
Rectangles.Mod:33:20: undef
Rectangles.Mod:35:0: undef
Rectangles.Mod:35:15: compilation FAILED

It seems that the elements that supposedly have been exported are not really exported.

Figures.Mod

MODULE Figures; (* Abstract module *)

TYPE
   Figure*    = POINTER TO FigureDesc;
   Interface* = POINTER TO InterfaceDesc;

   InterfaceDesc* = RECORD
      draw*  : PROCEDURE (f : Figure);
      clear* : PROCEDURE (f : Figure);
      mark*  : PROCEDURE (f : Figure);
      move*  : PROCEDURE (f : Figure; dx, dy : INTEGER);
   END;

   FigureDesc* = RECORD
      if : Interface;
   END;

PROCEDURE Init* (f : Figure; if : Interface);
BEGIN
   f.if := if
END Init;

PROCEDURE Draw* (f : Figure);
BEGIN
   f.if.draw(f)
END Draw;

(* Other procedures here *)

END Figures.

Rectangles.Mod

MODULE Rectangles;

IMPORT Figures;

TYPE
   Rectangle* = POINTER TO RectangleDesc;

   RectangleDesc* = RECORD
      (Figures.FigureDesc)
      x, y, w, h : INTEGER;
   END;

VAR
   if : Figures.Interface;

PROCEDURE New* (VAR r : Rectangle);
BEGIN
   NEW(r);
   Figures.Init(r, if)
END New;

PROCEDURE Draw* (f : Figure);
   VAR
      r : Rectangle;
BEGIN
   r := f(Rectangle); (* f AS Rectangle *)
   (* ... *)
END Draw;

(* Other procedures here *)

BEGIN (* Module initialisation *)
   NEW(if);
   if.draw  := Draw;
   if.clear := Clear;
   if.mark  := Mark;
   if.move  := Move
END Rectangles.
lboasso commented 1 year ago

Hello @rbatllet! Thanks for giving oberonc a try! Sorry for my late reply but this notification got lost among my emails.

There is a mistake in your source code: after importing a module (ex. Figures), any exported symbol from that module must be qualified (Figures.Figure). For example, in Rectangles.Mod, this line PROCEDURE Draw* (f : Figure); should be instead PROCEDURE Draw* (f : Figures.Figure);

Cheers, Luca