OxL Reference

kw comptime

Reserved keyword

The list of words: §1.4

Syntax

ebnf
Fn          = [ "comptime" [ "literal" ] | "unsafe" ] "fn" Ident [ Generics ] "(" [ Params ] ")"
              [ "->" Type ] [ Effects ] [ Where ] { Contract } ( Block | "=>" Expr ) ;
ebnf
Primary     = Literal | Path | "it" | "self" | "(" Expr { "," Expr } ")" | ListLit | MapLit
            | StructLit | Lambda | Block | If | Match | For | While | Loop | Scope | Select | Query
            | "spawn" ( Postfix | Block ) | "await" Unary | "atomic" [ "(" Args ")" ] Block
            | "return" [ Expr ] | "fail" Expr | "yield" Expr | "respond" Expr | "break" [ Label ] [ Expr ]
            | "continue" [ Label ] | "emit" Path "(" Expr ")" | "unsafe" Block | "blocking" Block
            | "comptime" Block | "." Ident [ "(" [ Args ] ")" ] ;

Grammar: App. A

Defined in

Examples

oxl
attr Audit { level: Level = Level.Info }

comptime fn Audit.apply(d: Decl, a: Audit) -> Decl | CompileError {
  d.wrapBody(body => quote { log.at($a.level, "call {$d.name}"); $body })
}

— 15.4 User-defined attributes and code generation

oxl
comptime fn toCsvRow<T>(x: &T) -> String {
  var out = String.new()
  inline for f in reflect(T).fields where f.visible {
    out.push("{x.[f]},")
  }
  out
}

— 15.2 Reflection

Related diagnostics

comptime-error, not-comptime, impl-foreign-type, unknown-method, prefix-literal

See also