Skip to content

Types

Nospace adds two commands for dealing with types explicitly, Cast and Assert. Type commands have no runtime behavior and are instead used to help Nospace statically analyse for type errors.

Type commands use the prefix.

Type Names

Similar to labels, type names are a sequence of s and s terminated by a .

The following primitive type names are reserved:

  • Never (‌‌‍)
  • Any (‌​)
  • Unknown (‌​​)
  • Int (​​)
  • Char (​‌‍)

Any other name is considered a custom type.

Cast

The Cast command is used to tell Nospace that the top item of the stack is the provided type.

Syntax

CommandUnobsfucated
Nospace⁠​WJ, ZWSP
Whitespace--
NossemblyCast-

Parameters

The Cast must be provided with a type name indicating the type to cast the top item of the stack to.

Stack parameters

The Cast command has no runtime behavior and as such takes no stack parameters.

Example

​​​‌‍⁠​​‌‌‌‌‍

Assert

The Assert command will throw a compile-time error if none of the possible types on the top of the stack are compatible with the specified type name.

Syntax

CommandUnobsfucated
Nospace⁠‌WJ, ZWNJ
Whitespace--
NossemblyAssert-

Parameters

The Assert must be provided with a type name indicating the type which the top item in the stack should be compared to.

Stack parameters

The Assert command has no runtime behavior and as such takes no stack parameters.

Example

Example where the type constraint is satisfied:

​​​‌‍⁠​​‌‌‌‌‍⁠‌​‌‌‌‌‍

Example where the type constraint is not satisfied:

​​​‌‍⁠​​‌‌‌‌‍⁠‌​‌​​​​‍
TypeError: Attempted to assert type "MyType2", but the top item of the stack is of type "MyType".