Pragmatic directives: Difference between revisions
Content added Content deleted
(Added XPL0 description.) |
|||
Line 326: | Line 326: | ||
::similar to <tt>trace all</tt> for the clauses in a <tt>method</tt> with the addition that the results of all ''expression'' evaluations and any results assigned to a variable by an assignment, <tt>loop</tt>, or <tt>parse</tt> instruction are also traced. |
::similar to <tt>trace all</tt> for the clauses in a <tt>method</tt> with the addition that the results of all ''expression'' evaluations and any results assigned to a variable by an assignment, <tt>loop</tt>, or <tt>parse</tt> instruction are also traced. |
||
:and ''varlist'' provides a list of variables which will be monitored during execution. |
:and ''varlist'' provides a list of variables which will be monitored during execution. |
||
=={{header|Nim}}== |
|||
Nim provides a great number of directives known as pragmas. It is not possible to describe them here. A pragma (or list of pragmas) starts with <code>{.</code> and ends with <code>.}</code>. It may possess arguments. Here are some kinds of pragmas: |
|||
:– pragmas such as <code>pure</code> applicable to types; |
|||
:– pragmas such as <code>noSideEffect</code>, <code>compileTime</code> applicable to procedures; |
|||
:– compilation option pragmas, especially to disable or enable runtime checks; |
|||
:– <code>push</code> and <code>pop</code> pragmas to deactivate/reactivate options; |
|||
:– pragmas for objects, such as <code>inheritable</code> or <code>final</code>; |
|||
:– pragmas such as <code>linearScanEnd</code> or <code>computedGoto</code> which change the way the code is generated; |
|||
:– pragmas for variables such as <code>register</code> or <code>global</code>; |
|||
:– pragmas such as <code>hint</code> to make the compiler output a message at compilation; |
|||
:– pragmas such as <code>used</code> to avoid a warning message (here when a variable is not used); |
|||
:– <code>experimental</code> pragma to activate experimental features; |
|||
:– <code>deprecated</code> pragma to mark a type, procedure, etc. as deprecated with emission of a warning at compile time; |
|||
:– pragmas to interface with other languages: <code>importc</code>, <code>extern</code>, <code>bycopy</code>, <code>byref</code>, <code>varargs</code>, etc. |
|||
:– pragmas to declare the calling convention of a procedure: <code>nimcall</code>, <code>closure</code>, <code>stdcall</code>, <code>cdecl</code>, <code>inline</code>, etc. |
|||
:– implementation specific pragmas: <code>bitsize</code>, <code>align</code>, <code>volatile</code>, etc. |
|||
:- pragmas for templates such as <code>inject</code>, <code>gensym</code>; |
|||
:– thread pragmas; |
|||
:– pragma <code>pragma</code> which allows the users to define their own pragmas. |
|||
And here are some examples: |
|||
<lang Nim>{.checks: off, optimization: speed.} # Checks are deactivated and code is generated for speed. |
|||
# Define a type Color as pure which implies that value names are declared in their own scope |
|||
# and may/should be accessed with their type qualifier (as Color.Red). |
|||
type Color {.pure.} = enum Red, Green, Blue |
|||
# Declare a procedure to inline if possible. |
|||
proc odd(x: int): bool {.inline.} = (x and 1) != 0 |
|||
# Declaration of a C external procedure. |
|||
proc printf(formatstr: cstring) {.header: "<stdio.h>", importc: "printf", varargs.} |
|||
# Declaration of a deprecated procedure. If not used, no warning will be emitted. |
|||
proc notUsed(x: int) {.used, deprecated.} = echo x |
|||
# Declaration of a type with an alignment constraint. |
|||
type SseType = object |
|||
sseData {.align(16).}: array[4, float32] |
|||
# Declaration of a procedure containing a variable to store in register, if possible, and a variable to store as global. |
|||
proc p() = |
|||
var x {.register.}: int |
|||
var y {.global.} = "abcdef" |
|||
{.push checks: on.} |
|||
# From here, checks are activated. |
|||
... |
|||
{.pop.} |
|||
# From here, checks are deactivated again. |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |