Special Attributes for Island

In addition to normal Custom Attributes on Island, the Elements compiler provides support for the special, predefined attribute classes, resulting in specific code or data generated in the executable to to adjust the compiler behavior.

Island Only

These attributes or aspects are available for the Island platform only. They're defined in the Island RTL.

VersionResource

Windows only:Defines the parameters for the PE version resource. Assembly level attribute, has these properties which are the direct equivalent to their version property.

  • Copyright: String
  • Description: String
  • FileVersion: String
  • CompanyName: String
  • ProductName: String
  • LegalTrademarks: String
  • Title: String
  • Version: String

StaticAddress

For low level targets, this places a static field to be equivalent to a memory address, when reading from it or writing to it, it will directly write to that memory address. Takes 1 IntPtr parameter containing the memory address.

InlineAsm

When defined on an external method, it's body becomes a pure inline asm function. This attribute takes 4 parameters: asm containing the AT&T style asm. Constraints containing a clang compatible constraints string. SideEffects boolean to define if the asm blcok has side effects and align if it needs to be aligned.

CallingConvention

For i386 only, ignored on all other cpu types. Overrides the calling convention, takes 1 parameter of type CallingConvention and can be Default, FastCall, Stdcall or Cdecl.

SymbolName

Overrides the name of a method or static field, takes a string parameter. By default Island uses name mangling to ensure methods don't have the same name, with this attribute a custom name can be provided. Useful for interop with other languages. Note that the compiler still applies some rules like adding an underscore before it, or adding @number after it for stdcall on Windows, these rules can be overriden by prefixing the symbol name with ascii character 1 (SymbolName(#1'MySymbol')).

DisableOptimizations

When applied to a method all optimizations in that function are disabled, even if the project is optimized.

DisableInlining

When applied to a method, this won't be inlined by the optimizer.

InReg

i386 only, ignored elsewhere. Can be set on a method, in which case it's first parameter will pass via EAX instead of on the stack.

ThreadLocal

Can be set on a static field, when set this field will have it's own copy for every thread instead of being a static.

SectionName

Overrides the PE/ELF section a method or field will be defined in. Takes a string parameter containing the new section name.

NoReturn

marks a method as not returning for optimization purposes.

Weak

Marks a method or field as weak. When the linker encounters weak symbols it will merge them instead of fail, and a non weak version will take prescendence over a weak one.

LinkOnce

Like Weak, but linkonce symbols can be discarded if they are not referenced.

Used

Can be applied to a type, method or static field and forces the compiler to link this symbol in, even if it's not referenced.

Naked

When set on a method no prologue/epilogue, like a stackframe will be emitted for this method. Generally only combined with asm.

DllImport

For all platforms, Imports a symbol from the given dynamic library. Takes a dllname as a parameter. Optionally an EntryPoint named argument can be set to define which symbol to look for.

DllExport

For all platforms, exports a method, static field or type from the given dynamic library. This can also be set globally by setting the ExportAllTypes option. When used on methods or fields, the SymbolName attribute can be used to override the name which it gets exported with.

Union

Changes a struct to work like a union, all fields are located at offset 0 and overlap eachother. The size of the struct is the size of the largest field.

Packed

Changes the packing of the struct from the platform default to byte aligned.