Python and GNU Modula-2

Cours informatique Modula-2, tutoriel & guide de travaux pratiques en pdf.

Python and GNU Modula-2

GNU Modula-2 can easily be compiled to produce Python modules
-fswig option automatically generates a swig interface file
three command lines will transform an implementation module into a Python module see the gravity demo
slide 5 gaius

GNU Modula-2 overview

PIM [234] and ISO compliant
afull set of PIM libraries are available
afull set of ISO libraries are available command line switches to force dialect and libraries
twocategories of language extensions firstly,followthe tradition of other GCC front ends: -fcpp,inlining of built-in functions/constants and access to assembly language secondly,alloweasy access to C libraries
enhances a number of language features: sets can be declared from anyordinal type abstract data types are not restricted to a pointer type procedures, types, variables, enumerations, constants, composite types may be declared in anyorder

Goals of GNU Modula-2

to fold the gm2 source code into the gcc tree at a convenient time in the future
exploit the features of GCC
libraries PIM library compatibility areimplementation of the Logitech (PIM) libraries are available Ulm (PIM) are also available
an easy interface to C
listen to the requests of the users

Extensions: access to C

-fcpp will invoke the C preprocessor in traditional mode using assembler as a base language useful to turn on/offdebugging code
similar to the Fortran front end

Easy access to C libraries

DEFINITION MODULE FOR « C » libc ;
EXPORT UNQUALIFIED printf ;
PROCEDURE printf (a: ARRAY OF CHAR; …) ;
END libc.
when using DEFINITION MODULE FOR « C » pointers are mapped onto: SYSTEM.ADDRESS ARRAY OF is mapped onto void * all other types are mapped onto their C counterparts

Extensions: access to assembly language

PROCEDURE Example (i, j: CARDINAL) : CARDINAL ; VAR k: CARDINAL ; BEGIN ASM VOLATILE (« movl %1,%eax; \ addl %2,%eax; movl %eax,%0″ : »=g » (k) (* outputs *) : »g » (i), « g » (j) (* inputs *) : »eax ») ; (* we trash *) RETURN( k ) END Example ;

LIRE AUSSI :  Support de cours Python et le web

Extensions: access to GCC built-ins

DEFINITION MODULE MathLib0 ;
CONST pi =3.1415926535897932384626433832795028841972; exp1=2.7182818284590452353602874713526624977572;
PROCEDURE __BUILTIN__ sqrt (x: REAL) : REAL ; PROCEDURE __BUILTIN__ sqrtl (x: LONGREAL) : LONGREAL ; PROCEDURE __BUILTIN__ sqrts (x: SHORTREAL) : SHORTREAL ;
PROCEDURE exp (x: REAL) : REAL ; PROCEDURE exps (x: SHORTREAL) : SHORTREAL ;
IMPLEMENTATION MODULE MathLib0 ;
IMPORT cbuiltin, libm ;
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sqrt)) sqrt (x: REAL): REAL; BEGIN RETURN cbuiltin.sqrt (x) END sqrt ;
PROCEDURE exp (x: REAL) : REAL ; BEGIN RETURN libm.exp (x) END exp ;

Structure of GNU Modula-2

it was constructed using a similar structure as other front ends
the GNU Modula-2 front end is written in C and Modula-2
conceptually it removesthe C front end and replaces GCC with a Modula-2 front end
leaving the middle and back end alone
it uses flex and a Modula-2 parser generator to construct a top down recursive descent parser with error recovery uses flex to build a dynamic buffer of all source tokens uses three passes to resolveall imports, exports, enumerated types, abstract data types, constants and generate quadruples each front end Modula-2 symbol table entry is translated into treesand finally the quadruples are translated into gimple statement which are presented to the middle end front end ensures that only legalsymbols and legalsource are ever passed to GCC gimple.

Some of the compiler options

extensive runtime checking available: -findex, -frange, -fcase, -freturn, -fwholediv and -fnil
language dialect can be selected via: -fpim, -fpim2, -fpim3, -fpim4 and -fiso
-fpim, -fpim2, -fpim3, -fpim4 and -fiso also modify the library search path
-fmakeall compiles the module, all dependant modules and performs the link
-fextended-opaque allows opaque types to be implemented via anytype (not just a pointer type)

Python and GNU Modula-2Télécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *