gm2
[Top][All Lists]
Advanced

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

Re: [Gm2] Re: enumerated types and import rules


From: Izo
Subject: Re: [Gm2] Re: enumerated types and import rules
Date: Fri, 16 May 2003 08:34:00 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020903

Gaius Mulley wrote:

Hi,

hmm, upon further analysis, it appears (to me) that according to the
Interim Version of 4th Working Draft Modula-2 standard that one _must_
explicitly import an enumerated type to access the enumeration
elements. So the following code should not compile after all. [See
section 6.1.6.5 Closure].  Or have I misunderstood something?

Can anyone confirm that this is the same with the most up to date
standard. I will now order my copy :-)

It would also be good to confirm this with an ISO complient compiler.

Thanks,
Gaius



MODULE impf ;

IMPORT impb ;

CONST
  start = impb.red ;    (* should give an error? *)
  end   = impb.green ;  (* should give an error? *)

VAR
  a: ARRAY [start..end] OF CARDINAL ;
  b: impb.C ;           (* this should be ok *)
BEGIN
END impf.

-----------

DEFINITION MODULE impb ;

IMPORT impc ;

TYPE
  C = impc.C ;

END impb.

-----------

DEFINITION MODULE impc ;

TYPE
  C = (red, blue, green) ;

END impc.

As for ISO: GPM2 and XDS swallow it. Here are results:

GPM2: (ix86 assembly): impf.s

XDS: c crosscompile: impc.h, impb.h, impf.c

I.


 # assembly language output from DGEN -- module "impf"
 # code generator options: peep rVar 
        .file   "impf.mod"
        .data
        .align  2
.L001:  .byte   105,109,112,102,0

.stabs "impf.mod",100,0,0,.LLtext0
        .text
.LLtext0:
.stabs "__dgen_compiled.", 0x3c, 0, 0, 0

        .globl  Startimpf
 .stabs "INTEGER:t1=r1;0020000000000;0017777777777",128,0,0,0
 .stabs "CARDINAL:t3=r1;0;0037777777777",128,0,0,0
 .stabs "C_char:t2=r1;-128;127",128,0,0,0
 .stabs "BOOLEAN:t4=u1val:20=eFALSE:0,TRUE:1,,0,8;ord:1,0,8;;",128,0,0,0
 .stabs "C_void:t5=5",128,0,0,0
 .stabs "C_ptr:t6=*5",128,0,0,0
 .stabs "SHORTREAL:t7=r1;4;0",128,0,0,0
 .stabs "REAL:t8=r1;8;0",128,0,0,0
 .stabs "PROC:t9=*10=f5",128,0,0,0
 .stabs "CHAR:t11=r1;0;255",128,0,0,0
 .stabs "BYTE:t12=r1;0;255",128,0,0,0
 .stabs "WORD:t13",128,0,0,0
 .stabs "BITSET:t14=3",128,0,0,0
 .stabs "ADDRESS:t15=*5",128,0,0,0
 .stabs "Int16:t16=r1;-32768;32767",128,0,0,0
 .stabs "Card16:t17=r1;0;65535",128,0,0,0
 .stabs "Int8:t18=r1;-128;127",128,0,0,0
 .stabs "Card8:t19=r1;0;255",128,0,0,0
 .stabs "Int32:t20=r1;0020000000000;0017777777777",128,0,0,0
 .stabs "Card32:t21=r1;0;0037777777777",128,0,0,0
 .stabs "a:S22=ar1;0;2;3",40,0,0,a
        .lcomm  a,12
 .stabs "C:t23=u1val:24=ered:0,blue:1,green:2,,0,8;ord:1,0,8;;",128,0,0,0
 .stabs "b:S23",40,0,0,b
        .lcomm  b,1
        .data
        .align  2
_mNam:
        .byte   105,109,112,102,0
        .data
        .align  2
 .stabs "impf:F5",36,0,1,Startimpf

        .text
        .align  4
Startimpf:
        pushl   %ebp
        movl    %esp,%ebp
 # End of procedure prolog
.stabn  68,0,1,.L004-Startimpf
.L004:
        nop     
.stabn  68,0,13,.L005-Startimpf
.L005:
        movb    $0,b
.stabn  68,0,14,.L006-Startimpf
.L006:
        movzbl  b,%eax
        movl    a(,%eax,4),%eax
        movl    %eax,a+8
.stabn  68,0,15,.L007-Startimpf
.L007:
        leave
        ret     
.L003:
        .type   Startimpf,@function
        .size   Startimpf,.-Startimpf

/* Generated by XDS Modula-2 to ANSI C v4.20 translator */

#ifndef impc_H_
#define impc_H_
#ifndef X2C_H_
#include "X2C.h"
#endif

enum impc_C {impc_red, impc_blue, impc_green};



extern void impc_BEGIN(void);


#endif /* impc_H_ */
/* Generated by XDS Modula-2 to ANSI C v4.20 translator */

#ifndef impb_H_
#define impb_H_
#ifndef X2C_H_
#include "X2C.h"
#endif
#ifndef impc_H_
#include "impc.h"
#endif

typedef enum impc_C impb_C;


extern void impb_BEGIN(void);


#endif /* impb_H_ */
/* "@(#)impf.c May 16  8:28:12 1990" */
/* Generated by XDS Modula-2 to ANSI C v4.20 translator */

#define X2C_int32
#define X2C_index32
#ifndef X2C_H_
#include "X2C.h"
#endif
#define impf_C_
#ifndef impb_H_
#include "impb.h"
#endif
#ifndef impc_H_
#include "impc.h"
#endif

#define impf_start impc_red

#define impf_end impc_green

static unsigned long a[3];

static unsigned char b;


X2C_STACK_LIMIT(100000l)
extern int main(int argc, char **argv)
{
   X2C_BEGIN(&argc,argv,1,0l,8000000l);
   impb_BEGIN();
   b = impc_red;
   a[impc_green] = a[X2C_CHKINX(b,3)];
   X2C_EXIT();
   return 0;
}


reply via email to

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