Expressions and macros

An expression is a document. The example builds an expression program once and evaluates it with an input document. The macro example expands an expression before compilation and evaluation.

Example

Build an expression and evaluate it

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c838 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_expr_build(expression, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 42

Reusing programs

A program keeps the expression that you built, independently of any one evaluation.

  • You can evaluate one program concurrently with separate input documents.
  • Keep the program until its evaluations finish.
  • Then release it under the ownership rule of its operation.

Operations

OperationReturnsSummary
stardust_expr_buildStatus. program through outputbuild(expression) borrows the expression document and returns an owned program.
stardust_macro_buildStatus. program through outputbuild_macro(title, authored, arguments) binds AST arguments into an unstored macro and returns an owned program.
stardust_macro_expandStatus. document through outputexpand_macro(title, authored, arguments) returns the expanded expression document without building it.
stardust_expr_evaluateStatus. document through outputprogram.evaluate(input) returns an independent owned result document.
stardust_expr_program_releasevoidRelease the program handle.
stardust_db_expression_buildStatus. program through outputBuild an owned program from a path or inline expression, expanding stored macros.

stardust_expr_build

c132 B
uint32_t stardust_expr_build(const stardust_document *source, stardust_expr_build_explain *explain, stardust_expr_program **output);
c109 B
uint32_t stardust_expr_program_error(const stardust_expr_program *program, stardust_diagnostic_view *output);

Parameters

stardust_expr_build

ParameterTypeOwnershipDefaultMeaning
sourceconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
explainstardust_expr_build_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_expr_program **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_expr_program_error

ParameterTypeOwnershipDefaultMeaning
programconst stardust_expr_program *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_COMPILE_FAILEDthe expression does not compile
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Notes

Expression documents.

Examples

Build an expression and evaluate its input

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c838 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_expr_build(expression, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 42

Inspect one measured cost stage

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9
c446 B
stardust_document *expression = NULL;
stardust_expr_build_explain explain = {0};
stardust_expr_program *program = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_expr_build(expression, &explain, &program);
stardust_expr_program_release(program);
stardust_document_release(expression);
if (status != STARDUST_OK) return status;
stardust_cost result = explain.total;
TRON108 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04BC 6172656E615F62 79746573txt "arena_bytes"
1002 00000000000000 00i64 0
190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
233C 637075txt "cpu"
2702 0C000000000000 00i64 12
300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
3A4C 77616C6Ctxt "wall"
3F02 0D000000000000 00i64 13
480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
5207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48

Explain expression compilation

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9
c454 B
stardust_document *expression = NULL;
stardust_expr_build_explain explain = {0};
stardust_expr_program *program = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_expr_build(expression, &explain, &program);
stardust_expr_program_release(program);
stardust_document_release(expression);
if (status != STARDUST_OK) return status;
stardust_expr_build_explain result = explain;
TRON486 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 6172656E615F62 79746573txt "arena_bytes"
01002 00000000000000 00i64 0
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0233C 637075txt "cpu"
02702 02000000000000 00i64 2
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 02000000000000 00i64 2
0480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
05207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48
064BC 6172656E615F62 79746573txt "arena_bytes"
07002 00000000000000 00i64 0
0790F 0A 64000000 7000 0000map leaf, size 10: @64 → @70
0833C 637075txt "cpu"
08702 08000000000000 00i64 8
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 07000000000000 00i64 7
0A80F 0A 9A000000 9F00 0000map leaf, size 10: @9A → @9F
0B207 12 21800000 7900 0000 90000000 A800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @79 → @90 → @A8
0C4BC 6172656E615F62 79746573txt "arena_bytes"
0D002 00000000000000 00i64 0
0D90F 0A C4000000 D000 0000map leaf, size 10: @C4 → @D0
0E33C 637075txt "cpu"
0E702 0C000000000000 00i64 12
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 0D000000000000 00i64 13
1080F 0A FA000000 FF00 0000map leaf, size 10: @FA → @FF
11207 12 21800000 D900 0000 F0000000 0801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @D9 → @F0 → @108
12414 12 707265706172 655F657870726573 73696F6Etxt "prepare_expression"
1380F 0A 24010000 5200 0000map leaf, size 10: @124 → @52
1427C 636F6D70696C65txt "compile"
14A0F 0A 42010000 B200 0000map leaf, size 10: @142 → @B2
15414 10 737461676573 5F636F6D706C6574 6564txt "stages_completed"
16602 02000000000000 00i64 2
16F0F 0A 54010000 6601 0000map leaf, size 10: @154 → @166
179EC 6172656E615F63 61706163697479txt "arena_capacity"
18802 00000100000000 00i64 65536
1910F 0A 79010000 8801 0000map leaf, size 10: @179 → @188
19B5C 746F74616Ctxt "total"
1A10F 0A 9B010000 1201 0000map leaf, size 10: @19B → @112
1AB9C 63616368655F68 6974txt "cache_hit"
1B509bit true
1B60F 0A AB010000 B501 0000map leaf, size 10: @1AB → @1B5
1C007 1E D2480000 3801 0000 4A010000 6F01 0000 91010000 A101 0000 B6010000map branch, size 30, depth 0 (root), slots 1, 4, 6, 7, 11, 14: @138 → @14A → @16F → @191 → @1A1 → @1B6

Also calls: stardust_expr_program_error

stardust_macro_build

c155 B
uint32_t stardust_macro_build(stardust_bytes title, const stardust_document *authored, const stardust_document *arguments, stardust_expr_program **output);
c109 B
uint32_t stardust_expr_program_error(const stardust_expr_program *program, stardust_diagnostic_view *output);

Parameters

stardust_macro_build

ParameterTypeOwnershipDefaultMeaning
titlestardust_bytesValueRequiredThe diagnostic title of this unstored macro.
authoredconst stardust_document *Borrowed handleRequiredThe native authored macro definition with its declared parameters and expression body.
argumentsconst stardust_document *Borrowed handleRequiredNative AST arguments bound to the macro's declared parameters before expansion.
outputstardust_expr_program **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_expr_program_error

ParameterTypeOwnershipDefaultMeaning
programconst stardust_expr_program *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe arguments include an undeclared macro parameter
STARDUST_INVALID_DEFINITIONthe macro is invalid or expands recursively
STARDUST_NOT_FOUNDthe macro refers to an unknown macro
STARDUST_COMPILE_FAILEDthe expansion does not compile
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Notes

Macro documents.

Examples

Bind an unstored macro and evaluate it

macro_text holds this document:

TRON135 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 696E707574txt "input"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
176C 696E73657274txt "insert"
1E5C 696E707574txt "input"
240F 0A 17000000 1E00 0000map leaf, size 10: @17 → @1E
2E1C 2Btxt "+"
3002 01000000000000 00i64 1
390E 15 00 0700 030000 00 2E000000 240000 00 30000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2E → @24 → @30
4E6C 706172616D73txt "params"
550F 0A 4E000000 0A00 0000map leaf, size 10: @4E → @A
5F7C 657870616E6473txt "expands"
670F 0A 5F000000 3900 0000map leaf, size 10: @5F → @39
7107 0E 00050000 5500 0000 67000000map branch, size 14, depth 0 (root), slots 8, 10: @55 → @67

arguments_text holds this document:

TRON68 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Atxt "*"
067C 3F616D6F756E74txt "?amount"
0E02 02000000000000 00i64 2
170E 15 00 0700 030000 00 04000000 060000 00 0E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @E
2C5C 696E707574txt "input"
320F 0A 2C000000 1700 0000map leaf, size 10: @2C → @17

input_text holds this document:

TRON38 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 616D6F756E74txt "amount"
0B02 0A000000000000 00i64 10
140F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
c1.1 kB
stardust_document *authored = NULL;
stardust_document *arguments = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
stardust_bytes title = {(const uint8_t *)"twice-plus-one", 14};
uint32_t status = stardust_parse(macro_text, STARDUST_TRON, &authored);
if (status == STARDUST_OK) status = stardust_parse(arguments_text, STARDUST_TRON, &arguments);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_macro_build(title, authored, arguments, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(arguments);
stardust_document_release(authored);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 15000000000000 00i64 21

Also calls: stardust_expr_program_error

stardust_macro_expand

c152 B
uint32_t stardust_macro_expand(stardust_bytes title, const stardust_document *authored, const stardust_document *arguments, stardust_document **output);
c97 B
uint32_t stardust_document_error(const stardust_document *doc, stardust_diagnostic_view *output);

Parameters

stardust_macro_expand

ParameterTypeOwnershipDefaultMeaning
titlestardust_bytesValueRequiredThe diagnostic title of this unstored macro.
authoredconst stardust_document *Borrowed handleRequiredThe native authored macro definition with its declared parameters and expression body.
argumentsconst stardust_document *Borrowed handleRequiredNative AST arguments bound to the macro's declared parameters before expansion.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_error

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe arguments include an undeclared macro parameter
STARDUST_INVALID_DEFINITIONthe macro is invalid or expands recursively
STARDUST_NOT_FOUNDthe macro refers to an unknown macro
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Notes

Macro documents.

Examples

Expand an unstored macro as a native document

macro_text holds this document:

TRON135 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 696E707574txt "input"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
176C 696E73657274txt "insert"
1E5C 696E707574txt "input"
240F 0A 17000000 1E00 0000map leaf, size 10: @17 → @1E
2E1C 2Btxt "+"
3002 01000000000000 00i64 1
390E 15 00 0700 030000 00 2E000000 240000 00 30000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2E → @24 → @30
4E6C 706172616D73txt "params"
550F 0A 4E000000 0A00 0000map leaf, size 10: @4E → @A
5F7C 657870616E6473txt "expands"
670F 0A 5F000000 3900 0000map leaf, size 10: @5F → @39
7107 0E 00050000 5500 0000 67000000map branch, size 14, depth 0 (root), slots 8, 10: @55 → @67

arguments_text holds this document:

TRON68 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Atxt "*"
067C 3F616D6F756E74txt "?amount"
0E02 02000000000000 00i64 2
170E 15 00 0700 030000 00 04000000 060000 00 0E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @E
2C5C 696E707574txt "input"
320F 0A 2C000000 1700 0000map leaf, size 10: @2C → @17
c587 B
stardust_document *authored = NULL;
stardust_document *arguments = NULL;
stardust_document *result = NULL;
stardust_bytes title = {(const uint8_t *)"twice-plus-one", 14};
uint32_t status = stardust_parse(macro_text, STARDUST_TRON, &authored);
if (status == STARDUST_OK) status = stardust_parse(arguments_text, STARDUST_TRON, &arguments);
if (status == STARDUST_OK) status = stardust_macro_expand(title, authored, arguments, &result);
stardust_document_release(arguments);
stardust_document_release(authored);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON84 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Atxt "*"
067C 3F616D6F756E74txt "?amount"
0E02 02000000000000 00i64 2
170E 15 00 0700 030000 00 04000000 060000 00 0E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @E
2C1C 2Btxt "+"
2E02 01000000000000 00i64 1
370E 15 00 0700 030000 00 2C000000 170000 00 2E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2C → @17 → @2E

Also calls: stardust_document_error

stardust_expr_evaluate

c163 B
uint32_t stardust_expr_evaluate(stardust_expr_program *program, const stardust_document *variables, stardust_expr_eval_explain *explain, stardust_result **output);
c92 B
uint32_t stardust_result_take_document(stardust_result *result, stardust_document **output);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_expr_evaluate

ParameterTypeOwnershipDefaultMeaning
programstardust_expr_program *Borrowed handleRequiredKeep the handle alive until the call returns.
variablesconst stardust_document *Borrowed handleNULLKeep the handle alive until the call returns.
explainstardust_expr_eval_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_take_document

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_EVALUATION_FAILEDthe expression fails on the input
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Notes

Expression evaluation.

Examples

Build an expression and evaluate its input

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c838 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_expr_build(expression, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 42

Explain expression evaluation

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c762 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *output = NULL;
stardust_expr_eval_explain explain = {0};
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_expr_build(expression, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, &explain, &output);
stardust_result_release(output);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) return status;
stardust_expr_eval_explain result = explain;
TRON634 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 6172656E615F62 79746573txt "arena_bytes"
01002 00000000000000 00i64 0
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0233C 637075txt "cpu"
02702 02000000000000 00i64 2
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 02000000000000 00i64 2
0480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
05207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48
064BC 6172656E615F62 79746573txt "arena_bytes"
07002 00000000000000 00i64 0
0790F 0A 64000000 7000 0000map leaf, size 10: @64 → @70
0833C 637075txt "cpu"
08702 16000000000000 00i64 22
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 16000000000000 00i64 22
0A80F 0A 9A000000 9F00 0000map leaf, size 10: @9A → @9F
0B207 12 21800000 7900 0000 90000000 A800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @79 → @90 → @A8
0C4BC 6172656E615F62 79746573txt "arena_bytes"
0D002 00000000000000 00i64 0
0D90F 0A C4000000 D000 0000map leaf, size 10: @C4 → @D0
0E33C 637075txt "cpu"
0E702 02000000000000 00i64 2
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 02000000000000 00i64 2
1080F 0A FA000000 FF00 0000map leaf, size 10: @FA → @FF
11207 12 21800000 D900 0000 F0000000 0801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @D9 → @F0 → @108
124BC 6172656E615F62 79746573txt "arena_bytes"
Show all 59 nodes
Offset (hex)Bytes (hex)Meaning
13002 00000000000000 00i64 0
1390F 0A 24010000 3001 0000map leaf, size 10: @124 → @130
1433C 637075txt "cpu"
14702 1C000000000000 00i64 28
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 1D000000000000 00i64 29
1680F 0A 5A010000 5F01 0000map leaf, size 10: @15A → @15F
17207 12 21800000 3901 0000 50010000 6801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @139 → @150 → @168
184EC 646F63756D656E 745F6279746573txt "document_bytes"
19302 2A000000000000 00i64 42
19C0F 0A 84010000 9301 0000map leaf, size 10: @184 → @193
1A614 11 707265706172 655F766172696162 6C6573txt "prepare_variables"
1B90F 0A A6010000 5200 0000map leaf, size 10: @1A6 → @52
1C314 10 737461676573 5F636F6D706C6574 6564txt "stages_completed"
1D502 03000000000000 00i64 3
1DE0F 0A C3010000 D501 0000map leaf, size 10: @1C3 → @1D5
1E8EC 6172656E615F63 61706163697479txt "arena_capacity"
1F702 00000100000000 00i64 65536
2000F 0A E8010000 F701 0000map leaf, size 10: @1E8 → @1F7
20AEC 61646F70745F64 6F63756D656E74txt "adopt_document"
2190F 0A 0A020000 1201 0000map leaf, size 10: @20A → @112
22307 0E 14000000 0002 0000 19020000map branch, size 14, depth 1, slots 2, 4: @200 → @219
2318C 6576616C756174 65txt "evaluate"
23A0F 0A 31020000 B200 0000map leaf, size 10: @231 → @B2
2445C 746F74616Ctxt "total"
24A0F 0A 44020000 7201 0000map leaf, size 10: @244 → @172
25407 1E E20A0000 9C01 0000 B9010000 DE01 0000 23020000 3A02 0000 4A020000map branch, size 30, depth 0 (root), slots 1, 5, 6, 7, 9, 11: @19C → @1B9 → @1DE → @223 → @23A → @24A
Offset (hex)Bytes (hex)Meaning

Also calls: stardust_result_take_document, stardust_result_error, stardust_result_release

stardust_expr_program_release

c67 B
void stardust_expr_program_release(stardust_expr_program *program);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
programstardust_expr_program *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Examples

Build an expression and evaluate its input

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c838 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_expr_build(expression, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 42

stardust_db_expression_build

c159 B
uint32_t stardust_db_expression_build(stardust_db *db, const stardust_db_source *source, stardust_expr_build_explain *explain, stardust_expr_program **output);
c109 B
uint32_t stardust_expr_program_error(const stardust_expr_program *program, stardust_diagnostic_view *output);

Parameters

stardust_db_expression_build

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
sourceconst stardust_db_source *Borrowed inputRequiredAn inline native definition or a stored definition path.
explainstardust_expr_build_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_expr_program **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_expr_program_error

ParameterTypeOwnershipDefaultMeaning
programconst stardust_expr_program *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_NOT_FOUNDno expression is stored at the path
STARDUST_INVALID_DEFINITIONa macro it calls is invalid or expands recursively
STARDUST_COMPILE_FAILEDthe expanded expression does not compile
STARDUST_CLOSEDthe database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Notes

The program keeps the expression and macros selected at build time and survives database closure. Build again to use later definition changes.

Expression documents.

Examples

Build an expression with the database's macros and evaluate it

expression_text holds this document:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c936 B
stardust_document *expression = NULL;
stardust_document *input = NULL;
stardust_expr_program *program = NULL;
stardust_result *evaluated = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &expression);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = expression};
if (status == STARDUST_OK) status = stardust_parse(input_text, STARDUST_TRON, &input);
if (status == STARDUST_OK) status = stardust_db_expression_build(db, &source, NULL, &program);
if (status == STARDUST_OK) status = stardust_expr_evaluate(program, input, NULL, &evaluated);
if (status == STARDUST_OK) status = stardust_result_take_document(evaluated, &result);
stardust_result_release(evaluated);
stardust_expr_program_release(program);
stardust_document_release(input);
stardust_document_release(expression);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 42

Also calls: stardust_expr_program_error