Types
XXML is a statically typed language with a rich type system including primitives, classes, enumerations, and generics.
Primitive Types
| Type | Description | Example |
|---|---|---|
Integer | 64-bit signed integer | Integer::Constructor(42) |
String | UTF-8 string | String::Constructor("Hello") |
Bool | Boolean (true/false) | Bool::Constructor(true) |
None | No value (void equivalent) | Used for methods with no return |
Type Declarations
Property Types
Properties are declared with their type and ownership modifier:
xxml
Property <name> Types String^;
Property <age> Types Integer^;
Property <active> Types Bool^;Parameter Types
Parameters include ownership modifiers that control how values are passed:
xxml
Parameter <value> Types Integer% // Copy - receives independent copy
Parameter <message> Types String& // Reference - borrows without ownership
Parameter <data> Types T^ // Owned - takes ownershipReturn Types
xxml
Method <getName> Returns String^ Parameters ()
Method <calculate> Returns Integer^ Parameters (Parameter <x> Types Integer%)
Method <process> Returns None Parameters ()Ownership Modifiers
Every type reference includes an ownership modifier:
^Owned
Unique ownership, manages lifetime
&Reference
Borrowed, non-owning access
%Copy
Independent value copy
xxml
// Owned - this variable owns the data
Instantiate String^ As <ownedString> = String::Constructor("Hello");
// Reference - borrows without owning
Method <print> Returns None Parameters (Parameter <msg> Types String&) Do
{
Run Console::printLine(msg);
}
// Copy - creates independent copy
Method <process> Returns Integer^ Parameters (Parameter <value> Types Integer%) Do
{
Return value.multiply(Integer::Constructor(2));
}Note
See the Ownership page for detailed information on ownership semantics.
Native Types
XXML provides low-level native types for FFI and system programming:
xxml
NativeType<"int64"> // 64-bit integer
NativeType<"ptr"> // Raw pointer
NativeType<"float64"> // 64-bit floatWarning
Native types bypass XXML's safety guarantees. Use them carefully when interfacing with C libraries or system calls.
Enumerations
Enumerations define a set of named integer constants:
enums.xxml
[ Enumeration <Color>
Value <RED> = 1;
Value <GREEN> = 2;
Value <BLUE> = 3;
]
[ Enumeration <Key>
Value <SPACE> = 32;
Value <A> = 65;
Value <B>; // Auto-increment: 66
Value <C>; // Auto-increment: 67
]
// Usage
If (keyCode.equals(Key::SPACE)) -> {
Run Console::printLine(String::Constructor("Space pressed"));
}Generic Types
Types can be parameterized with type arguments:
xxml
// Generic class
[ Class <Box> <T Constrains None> Final Extends None
[ Public <>
Property <value> Types T^;
]
]
// Using generic types
Instantiate Collections::List<Integer>^ As <numbers> =
Collections::List@Integer::Constructor();
Instantiate Collections::HashMap<String, Integer>^ As <ages> =
Collections::HashMap@String, Integer::Constructor();Tip
Note the different syntax: use
<Type> for type declarations and @Type for constructor calls.Function Types
Function references use the F(ReturnType)(ParamTypes...) syntax:
xxml
// Function that takes Integer& and returns Integer^
F(Integer^)(Integer&)
// Function that takes no params and returns String^
F(String^)()
// Function that takes two params
F(Integer^)(Integer&, Integer&)
// Usage with lambda
Instantiate F(Integer^)(Integer&)^ As <doubler> = [ Lambda [] Returns Integer^ Parameters (
Parameter <n> Types Integer&
) {
Return n.multiply(Integer::Constructor(2));
}];Type Summary
| Category | Syntax | Example |
|---|---|---|
| Primitive | TypeName | Integer^, String& |
| Generic | Type<T> | List<Integer>^ |
| Function | F(Ret)(Params) | F(Integer^)(String&)^ |
| Native | NativeType<"name"> | NativeType<"int64"> |
Next Steps
Learn more about ownership semantics and generic programming.