Home | About | Partners | Contact Us

SourceForge Logo

Quick Links
Building XL
XL Mailing List

Understanding XL
Conceptual overview
XL examples
Inside XL
Concept Programming

In depth
Browse GIT
SourceForge Info

Other projects
GNU Project
The Mozart Project

XLR: Extensible Language and Runtime

The art of turning ideas into code


Prev: Language extensions


One concern with language extensions is the creationg of multiple dialects. Not only do people need to learn the dialects (in particular their semantics), it is also difficult to identify in the code where a particular dialect is being used. These problems are the reason that the development of Moka was suspended: Moka extended Java, but Java had no "hooks" that could be used to signal where extensions were being used.

For totally new concepts, the typical approach is to invent a new notation. For instance, the tasking extension to XL uses the task word as an anchor for the translation mechanism. Similarly, functions are implemented by recognizing parse trees containing the word function at just the right place. Such concepts do require dialects of their own.

But many concepts are really minor variations of a more important concept, or very specific to a particular domain, or specify minor implementation details. It is desirable to have a specific notation for those. For this case, XL uses a dedicated notation, called a pragma. By convention, a pragma is any text enclosed between curly braces. For instance, {inline} is a pragma.

Pragmas should be used for operations that slightly alter the semantics of the code, but not enough to deserve a new notation. In particular, most low-level optimization or implementation details can be specified with pragmas. For instance, {inline} specifies that a function should be inlined; {byref} and {byval} can be used to force arguments to passed by reference or by value; {C name} indicates that a subroutine should use the C calling conventions and name as a linkage name.

// Examples of pragmas {inline} {C "__quick"} function Quick({byref} X : integer)

Historic note: In the old C++ implementation, pragmas were the main mechanism to invoke compiler plug-ins. In the XL compiler, the translation statements play that role. The pragmas form remains as a convention, the special rule being that there is a top-level translation rule that ignores unrecognized pragmas with a warning (whereas an unrecognized form would generate a compiler error).

Prev: Language extensions


Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)