This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Note: Compile Time Evaluation Overview
Alex Rønne Petersen edited this page Jun 6, 2013
·
5 revisions
Compile-time evaluation (CTE) is the process of executing Flect code during the compilation process. Why might we need such functionality? There are two primary use cases:
- It can be used to generate the code in a macro. In other words, it lets programmers perform more sophisticated operations on syntax trees than plain quoting and unquoting. Think parser generators, regular expression compilers, and so on.
- It enables the value of a
glob
(or other kind of global variable) to be computed from highly sophisticated, almost-arbitrary code rather than just from plain arithmetic expressions.
The idea is to let the programmer use the same language that they use to write their programs to also write metaprogramming code (instead of using some external language like Perl to generate Flect code).
CTE is triggered in a few places in the language:
- When evaluating the value of an
enum
declaration's field. - When evaluating the initializer of a
glob
declaration. - When evaluating the initializer of a
tls
declaration. - When expanding the body of a
macro
declaration. - When evaluating the result of the
macro
expression. - When evaluating the operand of the
unquote
expression.
CTE has some termination problems which are described in Note: CTE Cycles. Certain code has to be disallowed during CTE for the sake of portability and ease of implementation (see Note: Illegal Code in CTE).
- Home
- Introduction
- Motivation
- Features
- Tutorial
- Library
- FAQ
- General
- Interoperability
- Syntax
- Type System
- Macros and CTE
- Specification
- Introduction
- Lexical
- Common Grammar Elements
- Modules and Bundles
- Type System
- Declarations
- Expressions
- Macros
- Compile-Time Evaluation
- Memory Management
- Application Binary Interface
- Foreign Function Interface
- Unit Testing
- Documentation Comments
- Style
- Indentation
- Braces
- Spacing
- Naming