Op Types Reference
Every operation in a DUUMBI program is a node in the semantic graph with a @type from the duumbi: namespace. This page documents all ops with their Cranelift IR mapping and JSON-LD usage.
Arithmetic
Section titled “Arithmetic”| Op | Cranelift IR | Description |
|---|---|---|
Const | iconst | Integer constant (i64) |
ConstF64 | f64const | Float constant (f64) |
ConstBool | iconst (i8) | Boolean constant |
Add | iadd / fadd | Addition |
Sub | isub / fsub | Subtraction |
Mul | imul / fmul | Multiplication |
Div | sdiv / fdiv | Division |
// Const: integer literal{ "@type": "duumbi:Const", "value": 42 }
// ConstF64: floating-point literal{ "@type": "duumbi:ConstF64", "value": 3.14 }
// Add: binary arithmetic (works on i64 and f64){ "@type": "duumbi:Add", "duumbi:left": { "@id": "duumbi:main/main/entry/0" }, "duumbi:right": { "@id": "duumbi:main/main/entry/1" }}Control flow
Section titled “Control flow”| Op | Cranelift IR | Description |
|---|---|---|
Compare | icmp / fcmp | Comparison (returns bool) |
Branch | brif | Conditional branch |
Call | call | Function call |
Return | return | Return from function |
Match | brif on discriminant | Pattern match (Result/Option) |
// Compare: comparison operators (eq, ne, lt, le, gt, ge){ "@type": "duumbi:Compare", "duumbi:op": "le", "duumbi:left": { "@id": "duumbi:main/fib/entry/0" }, "duumbi:right": { "@type": "duumbi:Const", "value": 1 }}
// Branch: if-else{ "@type": "duumbi:Branch", "duumbi:condition": { "@id": "duumbi:main/fib/entry/1" }, "duumbi:then_block": "duumbi:main/fib/then", "duumbi:else_block": "duumbi:main/fib/else"}
// Call: function call with arguments{ "@type": "duumbi:Call", "duumbi:function": "fibonacci", "duumbi:args": [{ "@id": "duumbi:main/fib/else/0" }]}
// Match: pattern matching on Result/Option{ "@type": "duumbi:Match", "duumbi:value": { "@id": "duumbi:main/main/entry/3" }, "duumbi:ok_block": "duumbi:main/main/ok_arm", "duumbi:err_block": "duumbi:main/main/err_arm"}Variables
Section titled “Variables”| Op | Cranelift IR | Description |
|---|---|---|
Load | use_var | Load variable value |
Store | def_var | Store to variable |
// Store: assign a value to a variable{ "@type": "duumbi:Store", "duumbi:name": "counter", "duumbi:value": { "@type": "duumbi:Const", "value": 0 }}
// Load: read a variable{ "@type": "duumbi:Load", "duumbi:name": "counter" }| Op | Cranelift IR | Description |
|---|---|---|
Print | call duumbi_print_* | Print i64, f64, or bool |
PrintString | call duumbi_print_string | Print string |
// Print: output an integer to stdout{ "@type": "duumbi:Print", "duumbi:value": { "@id": "duumbi:main/main/entry/2" }}String operations
Section titled “String operations”| Op | Runtime function | Description |
|---|---|---|
ConstString | duumbi_string_new | Create string constant |
StringConcat | duumbi_string_concat | Concatenate strings |
StringEquals | duumbi_string_equals | String equality |
StringCompare | duumbi_string_compare | Lexicographic comparison |
StringLength | duumbi_string_len | String length |
StringSlice | duumbi_string_slice | Substring extraction |
StringContains | duumbi_string_contains | Substring search |
StringFind | duumbi_string_find | Find index of substring |
StringFromI64 | duumbi_string_from_i64 | Integer to string |
// ConstString: create a string literal{ "@type": "duumbi:ConstString", "value": "hello, world" }
// StringConcat: join two strings{ "@type": "duumbi:StringConcat", "duumbi:left": { "@id": "duumbi:main/main/entry/0" }, "duumbi:right": { "@id": "duumbi:main/main/entry/1" }}
// StringSlice: extract substring (start, end indices){ "@type": "duumbi:StringSlice", "duumbi:value": { "@id": "duumbi:main/main/entry/0" }, "duumbi:start": 0, "duumbi:end": 5}Array operations
Section titled “Array operations”| Op | Runtime function | Description |
|---|---|---|
ArrayNew | duumbi_array_new | Create empty array |
ArrayPush | duumbi_array_push | Push element |
ArrayGet | duumbi_array_get | Get element by index |
ArraySet | duumbi_array_set | Set element by index |
ArrayLength | duumbi_array_len | Array length |
// ArrayNew: create typed empty array{ "@type": "duumbi:ArrayNew", "duumbi:element_type": "i64" }
// ArrayPush: append element (mutates array){ "@type": "duumbi:ArrayPush", "duumbi:array": { "@id": "duumbi:main/main/entry/0" }, "duumbi:value": { "@type": "duumbi:Const", "value": 42 }}Struct operations
Section titled “Struct operations”| Op | Runtime function | Description |
|---|---|---|
StructNew | duumbi_struct_new | Create struct |
FieldGet | duumbi_struct_field_get | Get field value |
FieldSet | duumbi_struct_field_set | Set field value |
// StructNew: create a named struct{ "@type": "duumbi:StructNew", "duumbi:struct_name": "Point", "duumbi:fields": { "x": { "@type": "duumbi:Const", "value": 10 }, "y": { "@type": "duumbi:Const", "value": 20 } }}
// FieldGet: access a field{ "@type": "duumbi:FieldGet", "duumbi:value": { "@id": "duumbi:main/main/entry/0" }, "duumbi:field": "x"}Ownership operations
Section titled “Ownership operations”| Op | Runtime function | Description |
|---|---|---|
Alloc | duumbi_alloc | Allocate value |
Move | pointer copy | Transfer ownership |
Borrow | pointer copy | Immutable borrow (&T) |
BorrowMut | pointer copy | Mutable borrow (&mut T) |
Drop | duumbi_*_free | Deallocate |
See the Ownership Model guide for detailed rules and examples.
// Alloc: allocate a heap value{ "@type": "duumbi:Alloc", "duumbi:value": { "@type": "duumbi:ConstString", "value": "hello" }}
// Borrow: create an immutable reference{ "@type": "duumbi:Borrow", "duumbi:source": { "@id": "duumbi:main/main/entry/0" }}
// Drop: deallocate when done{ "@type": "duumbi:Drop", "duumbi:value": { "@id": "duumbi:main/main/entry/0" }}Error handling
Section titled “Error handling”| Op | Runtime function | Description |
|---|---|---|
ResultOk | duumbi_result_new_ok | Create Ok value |
ResultErr | duumbi_result_new_err | Create Err value |
ResultIsOk | duumbi_result_is_ok | Check if Ok |
ResultUnwrap | duumbi_result_unwrap | Unwrap Ok value |
ResultUnwrapErr | duumbi_result_unwrap_err | Unwrap Err value |
OptionSome | duumbi_option_new_some | Create Some value |
OptionNone | duumbi_option_new_none | Create None |
OptionIsSome | duumbi_option_is_some | Check if Some |
OptionUnwrap | duumbi_option_unwrap | Unwrap Some value |
// ResultOk: wrap a value in Ok{ "@type": "duumbi:ResultOk", "duumbi:value": { "@type": "duumbi:Const", "value": 42 }}
// Match: pattern match on Result — exhaustive handling required{ "@type": "duumbi:Match", "duumbi:value": { "@id": "duumbi:main/main/entry/0" }, "duumbi:ok_block": "duumbi:main/main/ok_arm", "duumbi:err_block": "duumbi:main/main/err_arm"}See the Error Codes reference for all validation errors.