On this page:
phase?
phase
phase-level
phase-shift
7.2.1 Execution Phases
execution-phase?
execution-phase
execution-phase-level
execution-phase-shift
runtime-phase
compile-phase
compile-phase-for
template-phase
template-phase-for
meta-compile-phase
7.2.2 The Label Phase
label-phase?
label-phase
7.7

7.2 Phases

 (require rebellion/module/phase) package: rebellion

"One program’s run-time is another program’s compile-time."

procedure

(phase? v)  boolean?

  v : any/c
A predicate for phases.

procedure

(phase level)  phase?

  level : (or/c exact-integer? #f)
Constructs a phase at level, where #f is the level of the label phase.

Examples:
> (phase 0)

(execution-phase 0)

> (phase 1)

(execution-phase 1)

> (phase -1)

(execution-phase -1)

> (phase #f)

#<label-phase>

procedure

(phase-level ph)  (or/c exact-integer? #f)

  ph : phase?
Returns the level of ph, where #f is the level of the label phase.

Examples:

procedure

(phase-shift ph relative-levels)  phase?

  ph : phase?
  relative-levels : exact-integer?
Shifts ph by relative-levels, where shifting the label phase does nothing.

Examples:
> (phase-shift runtime-phase 1)

(execution-phase 1)

> (phase-shift meta-compile-phase -2)

(execution-phase 0)

> (phase-shift label-phase 5)

#<label-phase>

7.2.1 Execution Phases

procedure

(execution-phase? v)  boolean?

  v : any/c
A predicate for execution phases, which are phases at levels where code is actually executed. The only phase where code isn’t executed is the label phase. Implies phase? and is mutually exclusive with label-phase?.

procedure

(execution-phase level)  execution-phase?

  level : exact-integer?
Equivalent to (phase level), but restricted to construct only execution phases.

Equivalent to (phase-level ph), but restricted to operate only on execution phases.

procedure

(execution-phase-shift ph relative-levels)  exact-integer?

  ph : execution-phase?
  relative-levels : exact-integer?
Equivalent to (phase-shift ph relative-levels), but restricted to operate only on execution phases.

Examples:
> (execution-phase-shift runtime-phase 2)

(execution-phase 2)

> (execution-phase-shift label-phase 5)

execution-phase-shift: contract violation

  expected: execution-phase?

  given: #<label-phase>

  in: the 1st argument of

      (->

       execution-phase?

       exact-integer?

       execution-phase?)

  contract from:

      <pkgs>/rebellion/private/phase.rkt

  blaming: top-level

   (assuming the contract is correct)

  at: <pkgs>/rebellion/private/phase.rkt:16.3

value

runtime-phase : phase? = (phase 0)

The runtime phase, where expressions are evaluated while the program is running.

value

compile-phase : phase? = (phase 1)

The compile phase, where expressions are evaluated while compiling code in the runtime phase.

procedure

(compile-phase-for ph)  execution-phase?

  ph : execution-phase?
Returns the phase of code run when compiling code in ph, effectively shifting ph up by one.

Examples:
> (compile-phase-for runtime-phase)

(execution-phase 1)

> (compile-phase-for compile-phase)

(execution-phase 2)

> (compile-phase-for template-phase)

(execution-phase 0)

value

template-phase : phase? = (phase -1)

The template phase, where expressions are evaluated in code generated by the runtime phase.

Returns the phase of code generated by code in ph, effectively shifting ph down by one.

Examples:
> (template-phase-for runtime-phase)

(execution-phase -1)

> (template-phase-for compile-phase)

(execution-phase 0)

> (template-phase-for meta-compile-phase)

(execution-phase 1)

value

meta-compile-phase : phase? = (phase 2)

The meta-compile phase, where expressions are evaluated while compiling code that is itself in the compile phase.

7.2.2 The Label Phase

procedure

(label-phase? v)  boolean?

  v : any/c
A predicate for the label phase, where no code is executed. Implies phase? and is mutually exclusive with execution-phase?.

value

label-phase : phase? = (phase #f)

The label phase, where expressions are evaluated in code that examines only the bindings of other code without actually running it, such as documentation.