tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

arboricx.h (2728B)


      1 #ifndef ARBORICX_H
      2 #define ARBORICX_H
      3 
      4 #include <stddef.h>
      5 #include <stdint.h>
      6 
      7 #ifdef __cplusplus
      8 extern "C" {
      9 #endif
     10 
     11 typedef struct arb_ctx arb_ctx_t;
     12 
     13 /* Context lifecycle */
     14 arb_ctx_t* arboricx_init(void);
     15 void arboricx_free(arb_ctx_t* ctx);
     16 void arboricx_free_buf(arb_ctx_t* ctx, uint8_t* ptr, size_t len);
     17 
     18 /* Tree construction */
     19 uint32_t arb_leaf(arb_ctx_t* ctx);
     20 uint32_t arb_stem(arb_ctx_t* ctx, uint32_t child);
     21 uint32_t arb_fork(arb_ctx_t* ctx, uint32_t left, uint32_t right);
     22 uint32_t arb_app(arb_ctx_t* ctx, uint32_t func, uint32_t arg);
     23 
     24 /* Reduction */
     25 uint32_t arb_reduce(arb_ctx_t* ctx, uint32_t root, uint64_t fuel);
     26 
     27 /* Codec constructors */
     28 uint32_t arb_of_number(arb_ctx_t* ctx, uint64_t n);
     29 uint32_t arb_of_string(arb_ctx_t* ctx, const char* s);
     30 uint32_t arb_of_bytes(arb_ctx_t* ctx, const uint8_t* bytes, size_t len);
     31 uint32_t arb_of_list(arb_ctx_t* ctx, const uint32_t* items, size_t len);
     32 
     33 /* Codec destructors (return 1 on success, 0 on failure) */
     34 int arb_to_number(arb_ctx_t* ctx, uint32_t root, uint64_t* out);
     35 int arb_to_string(arb_ctx_t* ctx, uint32_t root, uint8_t** out_ptr, size_t* out_len);
     36 int arb_to_bytes(arb_ctx_t* ctx, uint32_t root, uint8_t** out_ptr, size_t* out_len);
     37 int arb_to_bool(arb_ctx_t* ctx, uint32_t root, int* out);
     38 
     39 /* Result unwrapping (return 1 on success, 0 on failure) */
     40 int arb_unwrap_result(arb_ctx_t* ctx, uint32_t root, int* out_ok, uint32_t* out_value, uint32_t* out_rest);
     41 int arb_unwrap_host_value(arb_ctx_t* ctx, uint32_t root, uint64_t* out_tag, uint32_t* out_payload);
     42 
     43 /* Tree inspection (Layer 1 — for custom IO drivers and non-POSIX hosts) */
     44 int arb_is_leaf(arb_ctx_t* ctx, uint32_t root);
     45 int arb_is_stem(arb_ctx_t* ctx, uint32_t root);
     46 int arb_is_fork(arb_ctx_t* ctx, uint32_t root);
     47 int arb_is_app(arb_ctx_t* ctx, uint32_t root);
     48 int arb_get_stem_child(arb_ctx_t* ctx, uint32_t root, uint32_t* out);
     49 int arb_get_fork_children(arb_ctx_t* ctx, uint32_t root,
     50                           uint32_t* out_left, uint32_t* out_right);
     51 int arb_get_app_func_arg(arb_ctx_t* ctx, uint32_t root,
     52                          uint32_t* out_func, uint32_t* out_arg);
     53 
     54 /* IO driver (Layer 2 — POSIX interaction-tree runtime) */
     55 typedef struct {
     56     int allow_read_all;
     57     int allow_write_all;
     58 } arb_io_perms_t;
     59 
     60 uint32_t arb_run_io(arb_ctx_t* ctx, uint32_t program, const arb_io_perms_t* perms);
     61 
     62 /* Kernel entrypoints */
     63 uint32_t arb_kernel_root(arb_ctx_t* ctx);
     64 
     65 /* Native bundle loading (fast path — bypasses the Tricu kernel) */
     66 uint32_t arb_load_bundle(arb_ctx_t* ctx, const uint8_t* bytes, size_t len, const char* name);
     67 uint32_t arb_load_bundle_default(arb_ctx_t* ctx, const uint8_t* bytes, size_t len);
     68 
     69 #ifdef __cplusplus
     70 }
     71 #endif
     72 
     73 #endif /* ARBORICX_H */