Types and Values
Raml's type system is built around a single scalar type (bs) and compound types (structs).
Overview
This section covers the basics — enough to start writing Raml programs.
Bitstream Type (bs)
bs (bitstream) is the sole scalar type in Raml. It holds variable-length data — strings, binary patterns, or integers. When no type is specified, the type defaults to bs:
msg = "hello" // bs containing string data
bs data = "binary" // explicit type
x = "text" // x is bs
y = 42 // y is also bs (inferred)
bs variables are automatically converted to uint32_t when passed as numeric arguments to methods or functions.
Pointer Types
Pointer types are formed by appending # to a named type:
node# np // pointer to a node object
Three Declaration Forms
| Form | Example | Notes |
|---|---|---|
| Inferred | x y z = 10 | Multiple variables, inferred type |
| Explicit | bs data = "hello" | Explicit bitstream type |
| Inferred | value = 42 | Type inferred from expression (defaults to bs) |
Literals
42 // decimal integer
0xFF // hexadecimal (255)
0b1010 // binary (10)
"hello" // double-quoted string
'world' // single-quoted string
"""multi
line""" // triple-quoted (multi-line)
Escape sequences inside strings: \", \', \\, \n, \t.
The = symbol doubles as a truthy literal in conditions:
if x =:
print "x is truthy"
Deep Dive
This section covers the internals — type mapping to C, formal inference rules, edge cases, and implementation details.
C Type Mapping
In the generated C code, bs maps to a bs_t struct with data and len fields. Integer literals passed to numeric arguments are converted via raml_bs_to_uint32().
Type Inference Rules
| Context | Inferred Type |
|---|---|
| Integer literal in assignment | bs |
| String literal | bs |
keyboard call | bs |
load call | bs |
| Arithmetic expression | bs |
| Comparison expression | bs |
| Variable reference | Same as declared type |
| Method/function return | Type of last expression |
Design note: All variables default to bs unless explicitly typed as a named struct type. bs variables are automatically converted to uint32_t when passed as numeric arguments.
Pointer Type Formation
Pointer types are constructed by applying the # suffix to a named type:
node# np = @n // pointer to node
node## pp = @np // pointer to pointer
Named Types and Object Layout
Object types are referenced by their declaration name:
counter:
value
:start:
c = make counter 0 // c has type counter
In the C codegen, each object becomes a struct with fields laid out sequentially, prefixed by the struct name:
typedef struct {
uint64_t value; // field at offset 0
} counter_t;
Edge Cases
- Empty bitstreams: A bitstream with no data (
bs x = "") has.len = 0and.data = NULL.