Language reference
This section documents all Quadrate keywords and built-in instructions.
Quick navigation
- Keywords - Language keywords like
fn,if,for,struct - Stack Operations -
dup,drop,swap,rot, etc. - Arithmetic -
+,-,*,/,% - Comparison -
==,!=,<,>,<=,>= - Bitwise -
and,or,xor,not,shl,shr - Arrays - Array creation and manipulation
- Generics - Generic functions with
<T> - Type Casting -
cast<T> - Input/Output -
print,nl,read - Error Handling -
panic - Threading -
spawn,wait,detach - Miscellaneous -
call
Types
Quadrate has four basic types:
| Type | Description | Example |
|---|---|---|
i64 |
64-bit signed integer | 42, -17 |
f64 |
64-bit floating-point | 3.14, -0.5 |
str |
String | "hello" |
ptr |
Pointer | Struct instances, arrays |
Stack signatures
Function signatures use (inputs -- outputs) notation:
fn add(a:i64 b:i64 -- sum:i64) { + }
- Before
--: Values consumed from stack (bottom to top) - After
--: Values produced on stack (bottom to top)
Fallible functions
Functions that can fail are marked with !:
fn divide(a:i64 b:i64 -- result:i64)! {
// Can signal error
}
Call with if-else to handle errors:
10 2 divide if {
// success
} else {
drop2 // error
}