gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with Procedure Type


From: Fischlin Andreas
Subject: Re: Problems with Procedure Type
Date: Mon, 28 Jun 2021 07:19:45 +0000

Dear Derek,

Just a few comments on your code regardless of any difficulties you may have encountered:

DEFINITION MODULE Test_Suite;
  TYPE Test_Suite;
  TYPE Run_Type;
  PROCEDURE construct(VAR instance: Test_Suite; run_proc_instance: Run_Type);
  PROCEDURE run(instance: Test_Suite);
END Test_Suite.

DEFINITION MODULE Test_Suite;
  TYPE Test_SuiteOpaque;
  TYPE Run_Type;
  PROCEDURE Construct(VAR instance: Test_SuiteOpaque; run_proc_instance: Run_Type);
  PROCEDURE Run(instance: Test_SuiteOpaque);
END Test_Suite.

I makes no sense and is actually against M2 syntax to use the identifier of a module for any other purpose, here defining an opaque type. I hope any attempt to compile such a code is not accepted. Then it is advisable to capitalise types and procedures while starting identifiers of variables and constants in lower case. Makes recognition of type much easier throughout the code. All my comments on the definition module apply of course in analogy also to the implementation module where you made the same mistake.

All the best.

Sincerely yours,
Andreas Fischlin


ETH Zurich
Prof. em. Dr. Andreas Fischlin
IPCC Vice-Chair WGII
Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics
CHN E 24
Universitaetstrasse 16
8092 Zurich
SWITZERLAND


+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 595-4050 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________









On 27/06/2021, at 07:21, Derek Wyss <dwyss@my.hpu.edu> wrote:

Hello,

I'm attempting to follow along Kent Beck's book Test-Driven Development in creating a simple unit test framework. I've run into a problem with Procedure Types. I can't get my program to compile. When I comment out all of the stuff having to do with the Procedure Type I'm using, it will compile. Otherwise, I get this message:

tez@cibolo:~/Desktop/Modula-2/mtunit$ gm2 Test_Suite.mod
Test_Suite.mod:36:15: error: unimplemented identifier(s) in EXPORT list of DEFINITION MODULE Test_Suite
the implementation module fails to implement the following exported identifier(s)
   36 | END Test_Suite.
      | 

I'm not sure what I'm doing wrong. I tried declaring my Procedure Type like so:
  TYPE Run_Type = PROC;
  TYP Run_Type = PROCEDURE ();
But none of those seem to work. I can't think of anything else to try. I'm using whatever version of the compiler that you currently get with the Debian package.

tez@cibolo:~/Desktop/Modula-2/mtunit$ gm2 -v
Using built-in specs.
COLLECT_GCC=gm2
COLLECT_LTO_WRAPPER=/usr/lib/gm2/libexec/gcc/x86_64-linux-gnu/10.2.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --enable-languages=c,c++,m2 --prefix=/opt/gm2 --libexecdir=/usr/lib/gm2/libexec --infodir=/opt/gm2/share/info --mandir=/opt/gm2/share/man --enable-threads=posix --enable-clocale=gnu --disable-multilib --disable-bootstrap --enable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --enable-long-longx
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20200915 (GCC)

tez@cibolo:~/Desktop/Modula-2/mtunit$ gm2 --version
gm2 (GCC) 10.2.1 20200915
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Any helpful hints would be appreciated. The code to both of my modules is listed below.

Thanks,

Derek

DEFINITION MODULE Test_Suite;
  TYPE Test_Suite;
  TYPE Run_Type;
  PROCEDURE construct(VAR instance: Test_Suite; run_proc_instance: Run_Type);
  PROCEDURE run(instance: Test_Suite);
END Test_Suite.


IMPLEMENTATION MODULE Test_Suite;

  IMPORT Storage;

  (* DECLARATIONS *********************************************************** *)
  TYPE Run_Type = PROCEDURE;

  TYPE Chronicle = RECORD
                     it_was_run: BOOLEAN;
                     run_proc: Run_Type;
                   END;

  TYPE Test_Suite = POINTER TO Chronicle;

  (* ------------------------------------------------------------------------ *)
  PROCEDURE construct(VAR instance: Test_Suite; run_proc_instance: Run_Type);
 
    VAR chronicle_instance : Chronicle;
   
  BEGIN
    Storage.ALLOCATE(instance, SIZE(Chronicle));

    instance^ := chronicle_instance;
    instance^.run_proc := run_proc_instance;
    instance^.it_was_run := FALSE;

  END construct;

  (* ------------------------------------------------------------------------ *)
  PROCEDURE run(instance: Test_Suite);
  BEGIN
    instance^.it_was_run := TRUE;
    instance^.run_proc;
  END run;

END Test_Suite.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]