consumer_open_entry_reuse.tri (2538B)
1 -- Is SCP code reusable across two real configurations, without recompiling 2 -- a different entry for each initial state? Reference execution remains the 3 -- independent oracle; this probe does not treat shape as authentication. 4 !import "prelude" !Local 5 !import "io" !Local 6 !import "consumers.base-source" B 7 !import "consumers.structural" S 8 !import "consumers.lexical-worker" L 9 10 load path = do onOk_ 11 source <- readFile path 12 pure (bindResult (B.compileBaseSource source) 13 (named _ : ok (snd (snd named)) t)) 14 initial rules state = S.makeConsumer state rules 15 entry worker = snd (snd worker) 16 inputs = ["#skip" "" "alpha" " beta"] 17 check filterRules dataLineRules nonemptyRules = 18 let dataLineIR = initial dataLineRules t in 19 let nonemptyIR = initial nonemptyRules t in 20 let dataLine = resultOr t (L.lCompile dataLineIR) in 21 let nonempty = resultOr t (L.lCompile nonemptyIR) in 22 let authoredData = initial filterRules dataLineIR in 23 let authoredNonempty = initial filterRules nonemptyIR in 24 let compiledData = L.lCompile (initial filterRules dataLine) in 25 let compiledNonempty = L.lCompile (initial filterRules nonempty) in 26 let dataWorker = resultOr t compiledData in 27 let nonemptyWorker = resultOr t compiledNonempty in 28 let sharedEntry = entry dataWorker in 29 let linkedData = L.lWorker dataLine sharedEntry in 30 let linkedNonempty = L.lWorker nonempty sharedEntry in 31 foldl and? true [ 32 (resultIsOk (L.lCompile dataLineIR)) 33 (resultIsOk (L.lCompile nonemptyIR)) 34 (resultIsOk compiledData) 35 (resultIsOk compiledNonempty) 36 (equal? sharedEntry (entry nonemptyWorker)) 37 (equal? linkedData dataWorker) 38 (equal? linkedNonempty nonemptyWorker) 39 (equal? (S.runConsumer authoredData inputs) (ok ["alpha" " beta"] t)) 40 (equal? (S.runConsumer authoredNonempty inputs) 41 (ok ["#skip" "alpha" " beta"] t)) 42 (equal? (L.lRunChecked linkedData inputs) 43 (S.runConsumer authoredData inputs)) 44 (equal? (L.lRunChecked linkedNonempty inputs) 45 (S.runConsumer authoredNonempty inputs)) 46 (equal? (L.lRunOpenChecked linkedNonempty inputs dataLine) 47 (S.runConsumer authoredData inputs))] 48 scenario = do onOk_ 49 filterRules <- load "lib/consumer/filter.scp" 50 dataLineRules <- load "demos/consumers/data-lines/data-line.scp" 51 nonemptyRules <- load "lib/consumer/nonempty.scp" 52 pure (ok (check filterRules dataLineRules nonemptyRules) t) 53 main = io (onResult_ scenario 54 (_ : putStrLn "open-entry-LOAD-FAIL") 55 (passed : putStrLn (matchBool "open-entry-ok" "open-entry-DIFFER" 56 passed))) 57 main