tricu

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

linked-reference.tri (1873B)


      1 !import prelude *
      2 !import consumers_structural as S
      3 !export *
      4 -- Independent reference execution for explicitly registered compiled entries.
      5 -- Registry rows are (exact entry tree, authored consumer). Entries are matched
      6 -- as opaque values, NEVER invoked or decompiled. No compiler/validator import,
      7 -- recursive dependency discovery, or fallback for unregistered code exists.
      8 
      9 lrPair? value = triage false (_ : false) (_ _ : true) value
     10 lrWorker? value = (lazyBool
     11   (_ : and? (equal? (fst value) "scp-worker.v1") (lrPair? (snd value)))
     12   (_ : false) (lrPair? value))
     13 lrInitial worker = lazyBool (_ : fst (snd worker)) (_ : t) (lrWorker? worker)
     14 lrFind_ self registry code = (lazyList (_ : nothing)
     15   (row rest : lazyBool (_ : just (snd row)) (_ : self rest code)
     16     (equal? (fst row) code)) registry)
     17 lrFind registry code = y lrFind_ registry code
     18 lrInvoke registry worker input state run = (lazyBool
     19   (_ : lazyMaybe (_ : err "unregistered reference entry" t)
     20     (authored : run input authored state registry)
     21     (lrFind registry (snd (snd worker))))
     22   (_ : err "invalid reference worker descriptor" t) (lrWorker? worker))
     23 lrRun_ self input consumer state registry = (lazyMaybe
     24   (_ : err "no matching consumer rule" t)
     25   (selection : matchPair (output bindings :
     26     S.evalOutputUsing output bindings
     27       (nextInput nextState : self nextInput consumer nextState registry)
     28       (worker argument initial : lrInvoke registry worker argument initial self)
     29       lrInitial) selection)
     30   (S.chooseRule (snd consumer) input state))
     31 runLinkedReference registry worker input = (lrInvoke registry worker input
     32   (lrInitial worker) (input consumer state registry :
     33     y lrRun_ input consumer state registry))
     34 -- Adapter for the unit compiler's rows; registration remains explicit.
     35 linkedReferenceRows rows = (map (row : pair (fst (snd row))
     36   (fst (snd (snd row)))) rows)