#include #include #include #include #include "../include/arboricx.h" static uint8_t *read_file(const char *path, size_t *out_len) { FILE *f = fopen(path, "rb"); if (!f) return NULL; fseek(f, 0, SEEK_END); *out_len = ftell(f); fseek(f, 0, SEEK_SET); uint8_t *buf = malloc(*out_len); fread(buf, 1, *out_len, f); fclose(f); return buf; } int main() { arb_ctx_t *ctx = arboricx_init(); if (!ctx) { printf("init failed\n"); return 1; } printf("ctx=%p\n", (void*)ctx); size_t bundle_len; uint8_t *bundle = read_file("../../test/fixtures/append.arboricx", &bundle_len); if (!bundle) { printf("bundle not found\n"); return 1; } printf("bundle size=%zu\n", bundle_len); clock_t t0 = clock(); uint32_t term = arb_load_bundle(ctx, bundle, bundle_len, "append"); clock_t t1 = clock(); printf("load_bundle took %.3f ms, term=%u\n", (double)(t1 - t0) * 1000.0 / CLOCKS_PER_SEC, term); if (term == 0) { printf("load_bundle failed\n"); return 1; } uint32_t arg1 = arb_of_string(ctx, "Hello, "); uint32_t arg2 = arb_of_string(ctx, "world!"); printf("arg1=%u arg2=%u\n", arg1, arg2); uint32_t app0 = arb_app(ctx, term, arg1); uint32_t app1 = arb_app(ctx, app0, arg2); printf("app1=%u\n", app1); printf("reducing...\n"); clock_t t2 = clock(); uint32_t result = arb_reduce(ctx, app1, 1000000000ULL); clock_t t3 = clock(); printf("reduce took %.3f ms, result=%u\n", (double)(t3 - t2) * 1000.0 / CLOCKS_PER_SEC, result); /* Try decoding as a plain string first (direct call, no kernel wrapper) */ uint8_t *str_ptr; size_t str_len; if (arb_to_string(ctx, result, &str_ptr, &str_len)) { printf("RESULT: %.*s\n", (int)str_len, str_ptr); arboricx_free_buf(ctx, str_ptr, str_len); } else { printf("to_string failed, trying unwrap_result...\n"); int ok; uint32_t value, rest; if (!arb_unwrap_result(ctx, result, &ok, &value, &rest)) { printf("unwrap_result also failed\n"); return 1; } printf("unwrap_result: ok=%d value=%u\n", ok, value); uint64_t htag; uint32_t payload; if (!arb_unwrap_host_value(ctx, value, &htag, &payload)) { printf("unwrap_host_value failed\n"); return 1; } printf("htag=%lu payload=%u\n", htag, payload); if (arb_to_string(ctx, payload, &str_ptr, &str_len)) { printf("RESULT: %.*s\n", (int)str_len, str_ptr); arboricx_free_buf(ctx, str_ptr, str_len); } } free(bundle); arboricx_free(ctx); printf("done\n"); return 0; }