Skip to content

Language Specification (12) : Pragma Facilities

Benjamin Kowarsch edited this page Jan 12, 2024 · 3 revisions

Pragma Facilities

Pragmas are non-semantic directives — instructions to the language processor to control or influence the compilation process but do not alter the semantics of the compiling source code.

There are two kinds:

  • language defined pragmas
  • implementation defined pragmas.

Pragma Symbol Naming

  • Pragma symbols of language defined pragmas are always in all-uppercase
  • Pragma symbols of implementation defined pragmas may not be in all-uppercase
  • The implementation prefix matches constant Impl.ShortName
  • Implementation prefix and implementation defined pragma symbols follow the syntax of StdIdent

Language Defined Pragmas

There are five language defined pragmas.

Pragma INLINE

An INLINE pragma may be placed before the semicolon that terminates a procedure header. It represents a request to inline calls to a procedure so marked. The request is a mandate for functions that return a property. Other requests may be declined, but should generally be fulfilled within reason*. When a request is declined, a compile time informational message is issued.

InlinePragma := ’<*’ INLINE ’*>’ ;
(*Macro*) PROCEDURE colour ( point : Point ) : Colour <*INLINE*>;

[*] The implementors of a compiler backend generally know better when to optimise than the users of their product.

Pragma DEPRECATED

A DEPRECATED pragma may follow the identifier of a constant, type, variable, procedure or function definition or declaration and marks the identifier deprecated. When such an identifier is used, a compile time warning is issued. A compiler switch may be provided to promote the warning to an error.

deprecatedPragma := ’<*’ DEPRECATED ’*>’ ;
PROCEDURE Foo <*DEPRECATED*> ( bar : Bar );

Pragma PRIVATETO

A PRIVATETO pragma may follow the identifier in the header of a definition module and marks the module for private use by modules listed in its body. When such a module is imported by any module not listed, a compile time warning is issued. A compiler switch may be provided to promote the warning to an error.

privateToPragma := ’<*’ PRIVATETO '=' identList ’*>’ ;
DEFINITION MODULE Filesys0 <*PRIVATETO=Filesys*>;

Pragma FFI

An FFI pragma may follow the module identifier in the header of a definition module and establishes the calling convention of the specified foreign API, language and its execution environment for the module.

FFIPragma := ’<*’ FFI ’=’ ForeignAPISpecifier ’*>’ ;

ForeignAPISpecifier := ’"C"’ | ’"CLR"’ | ’"JVM"’ ;
(* Interface to the C stdio library *)
DEFINITION MODULE CStdIO <*FFI="C"*>;

Pragma FFIDENT

An FFIDENT pragma may follow the identifier of a constant, type, variable, procedure or function definition or declaration to map the identifier to the foreign API identifier specified in the pragma body.

FFIdentPramga := ’<*’ FFIDENT ’=’ ForeignIdentifier ’*>’ ;

alias ForeignIdentifier = QuotedLiteral ;
(* Interface to an OpenVMS SMG library routine *)
PROCEDURE PasteVirtualDisplay <*FFIDENT="SMG$PASTE_VIRTUAL_DISPLAY"*>
  ( displayID, pasteboardID : INTEGER; row, column : INTEGER ) : CARDINAL;

Implementation Defined Pragmas

Implementation defined pragmas are specific to a language processor and should therefore be ignored by other language processors. An implementation defined pragma may be preceded with an implementation specific prefix in order to distinguish it from other implementation defined pragmas for other processors that may use the same pragma symbol. When a processor does not understand an implementation defined pragma it will emit an informational, warning, error or fatal error message depending on the pragma’s message mode suffix.

ImplDefinedPragma :=
  ’<*’ ( implPrefix ’.’ )? pragmaSymbol ( ’=’ constExpr )? ’|’ ctMsgMode ’*>’ ;

alias implPrefix, pragmaSymbol = <implementation-defined> ; /* follows StdIdent syntax */

ctMsgMode := INFO | WARN | ERROR | FATAL ;

Use of an implementation defined pragma of a fictional compiler is shown below:

<*JollyM2.UnrollLoops=TRUE|WARN*>
FOR plane IN array DO
  FOR row IN plane
    DO FOR col IN row DO
      ...
    END (* FOR *)
  END (* FOR *)
END; (* FOR *)
<*JollyM2.UnrollLoops=FALSE|WARN*>
Clone this wiki locally