Linguagem de Programação Crystal

Attributes

Some types and methods can be annotated with attributes. The attribute list is fixed, but eventually (maybe) there will be user-defined attributes.

Tells the compiler how to link a C library. This is explained in the lib section.

ThreadLocal

The @[ThreadLocal] attribute can be applied to global variables and class variables. It makes them be thread local.

# One for each thread
@[ThreadLocal]
$values = [] of Int32

Packed

Allows marking a C struct as packed, which makes the alignment of the struct to be one byte, and that there is no padding between the elements. In non-packed structs, padding between field types is inserted according to the target system.

AlwaysInline

Gives a hint to the compiler to always inline a method:

@[AlwaysInline]
def foo
  1
end

NoInline

Tells the compiler to never inline a method call. This has no effect if the method yields.

@[NoInline]
def foo
  1
end

ReturnsTwice

Marks a method or lib fun as returning twice. The C setjmp is an example of such a function.

Raises

Marks a method or lib fun as potentially raising an exception. This is explained in the callbacks section.

CallConvention

Indicates the call convention of a lib fun. For example:

lib LibFoo
  @[CallConvention("X86_StdCall")]
  fun foo : Int32
end

The list of valid call conventions is:

  • C (the default)
  • Fast
  • Cold
  • WebKit_JS
  • AnyReg
  • X86_StdCall
  • X86_FastCall

They are explained here.

Flags

Marks an enum as a "flags enum", which changes the behaviour of some of its methods, like to_s.