@@ -59,48 +59,48 @@ fn emit_header(code: &mut String, project_name: &str) {
5959 code,
6060 "// Generated by betlangiser — ternary probabilistic modelling"
6161 )
62- . unwrap ( ) ;
63- writeln ! ( code, "// Project: {}" , project_name) . unwrap ( ) ;
64- writeln ! ( code, "// SPDX-License-Identifier: PMPL-1.0-or-later" ) . unwrap ( ) ;
65- writeln ! ( code) . unwrap ( ) ;
66- writeln ! ( code, "module {} where" , sanitize_identifier( project_name) ) . unwrap ( ) ;
67- writeln ! ( code) . unwrap ( ) ;
62+ . expect ( "TODO: handle error" ) ;
63+ writeln ! ( code, "// Project: {}" , project_name) . expect ( "TODO: handle error" ) ;
64+ writeln ! ( code, "// SPDX-License-Identifier: PMPL-1.0-or-later" ) . expect ( "TODO: handle error" ) ;
65+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
66+ writeln ! ( code, "module {} where" , sanitize_identifier( project_name) ) . expect ( "TODO: handle error" ) ;
67+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
6868}
6969
7070/// Emit distribution declarations — each variable gets a `let` binding
7171/// with its Betlang distribution constructor and type annotation.
7272fn emit_distribution_declarations ( code : & mut String , variables : & [ ParsedVariable ] ) {
73- writeln ! ( code, "// --- Distribution Declarations ---" ) . unwrap ( ) ;
74- writeln ! ( code) . unwrap ( ) ;
73+ writeln ! ( code, "// --- Distribution Declarations ---" ) . expect ( "TODO: handle error" ) ;
74+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
7575
7676 for var in variables {
7777 let info = distribution_info ( & var. distribution ) ;
7878 let btype = betlang_type ( & var. distribution ) ;
7979
80- writeln ! ( code, "/// {} — {}" , var. name, info. description) . unwrap ( ) ;
81- writeln ! ( code, "/// Sampling method: {}" , info. sampling_method) . unwrap ( ) ;
82- writeln ! ( code, "/// Support: {}" , info. support) . unwrap ( ) ;
80+ writeln ! ( code, "/// {} — {}" , var. name, info. description) . expect ( "TODO: handle error" ) ;
81+ writeln ! ( code, "/// Sampling method: {}" , info. sampling_method) . expect ( "TODO: handle error" ) ;
82+ writeln ! ( code, "/// Support: {}" , info. support) . expect ( "TODO: handle error" ) ;
8383 writeln ! (
8484 code,
8585 "let {} : {} = {}" ,
8686 var. name, btype, info. betlang_constructor
8787 )
88- . unwrap ( ) ;
89- writeln ! ( code) . unwrap ( ) ;
88+ . expect ( "TODO: handle error" ) ;
89+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
9090 }
9191}
9292
9393/// Emit propagation rule declarations — each variable is annotated with
9494/// how arithmetic operations on it should propagate uncertainty.
9595fn emit_propagation_rules ( code : & mut String , variables : & [ ParsedVariable ] ) {
96- writeln ! ( code, "// --- Propagation Rules ---" ) . unwrap ( ) ;
97- writeln ! ( code) . unwrap ( ) ;
96+ writeln ! ( code, "// --- Propagation Rules ---" ) . expect ( "TODO: handle error" ) ;
97+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
9898
9999 for var in variables {
100100 let rule = propagation_rule ( & var. distribution ) ;
101- writeln ! ( code, "@propagation({}, \" {}\" )" , var. name, rule) . unwrap ( ) ;
101+ writeln ! ( code, "@propagation({}, \" {}\" )" , var. name, rule) . expect ( "TODO: handle error" ) ;
102102 }
103- writeln ! ( code) . unwrap ( ) ;
103+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
104104}
105105
106106/// Emit ternary logic helper functions for Bernoulli variables.
@@ -109,32 +109,32 @@ fn emit_propagation_rules(code: &mut String, variables: &[ParsedVariable]) {
109109/// - A ternary evaluation function that maps sampled proportions to Kleene truth values
110110/// - AND/OR/NOT combinators for ternary logic chains
111111fn emit_ternary_helpers ( code : & mut String , variables : & [ ParsedVariable ] ) {
112- writeln ! ( code, "// --- Ternary Logic (Kleene Algebra) ---" ) . unwrap ( ) ;
113- writeln ! ( code) . unwrap ( ) ;
114-
115- writeln ! ( code, "/// Kleene strong three-valued AND" ) . unwrap ( ) ;
116- writeln ! ( code, "let ternary_and(a: Ternary, b: Ternary) -> Ternary =" ) . unwrap ( ) ;
117- writeln ! ( code, " match (a, b) with" ) . unwrap ( ) ;
118- writeln ! ( code, " | (False, _) | (_, False) -> False" ) . unwrap ( ) ;
119- writeln ! ( code, " | (True, True) -> True" ) . unwrap ( ) ;
120- writeln ! ( code, " | _ -> Unknown" ) . unwrap ( ) ;
121- writeln ! ( code) . unwrap ( ) ;
122-
123- writeln ! ( code, "/// Kleene strong three-valued OR" ) . unwrap ( ) ;
124- writeln ! ( code, "let ternary_or(a: Ternary, b: Ternary) -> Ternary =" ) . unwrap ( ) ;
125- writeln ! ( code, " match (a, b) with" ) . unwrap ( ) ;
126- writeln ! ( code, " | (True, _) | (_, True) -> True" ) . unwrap ( ) ;
127- writeln ! ( code, " | (False, False) -> False" ) . unwrap ( ) ;
128- writeln ! ( code, " | _ -> Unknown" ) . unwrap ( ) ;
129- writeln ! ( code) . unwrap ( ) ;
130-
131- writeln ! ( code, "/// Kleene strong three-valued NOT" ) . unwrap ( ) ;
132- writeln ! ( code, "let ternary_not(a: Ternary) -> Ternary =" ) . unwrap ( ) ;
133- writeln ! ( code, " match a with" ) . unwrap ( ) ;
134- writeln ! ( code, " | True -> False" ) . unwrap ( ) ;
135- writeln ! ( code, " | False -> True" ) . unwrap ( ) ;
136- writeln ! ( code, " | Unknown -> Unknown" ) . unwrap ( ) ;
137- writeln ! ( code) . unwrap ( ) ;
112+ writeln ! ( code, "// --- Ternary Logic (Kleene Algebra) ---" ) . expect ( "TODO: handle error" ) ;
113+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
114+
115+ writeln ! ( code, "/// Kleene strong three-valued AND" ) . expect ( "TODO: handle error" ) ;
116+ writeln ! ( code, "let ternary_and(a: Ternary, b: Ternary) -> Ternary =" ) . expect ( "TODO: handle error" ) ;
117+ writeln ! ( code, " match (a, b) with" ) . expect ( "TODO: handle error" ) ;
118+ writeln ! ( code, " | (False, _) | (_, False) -> False" ) . expect ( "TODO: handle error" ) ;
119+ writeln ! ( code, " | (True, True) -> True" ) . expect ( "TODO: handle error" ) ;
120+ writeln ! ( code, " | _ -> Unknown" ) . expect ( "TODO: handle error" ) ;
121+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
122+
123+ writeln ! ( code, "/// Kleene strong three-valued OR" ) . expect ( "TODO: handle error" ) ;
124+ writeln ! ( code, "let ternary_or(a: Ternary, b: Ternary) -> Ternary =" ) . expect ( "TODO: handle error" ) ;
125+ writeln ! ( code, " match (a, b) with" ) . expect ( "TODO: handle error" ) ;
126+ writeln ! ( code, " | (True, _) | (_, True) -> True" ) . expect ( "TODO: handle error" ) ;
127+ writeln ! ( code, " | (False, False) -> False" ) . expect ( "TODO: handle error" ) ;
128+ writeln ! ( code, " | _ -> Unknown" ) . expect ( "TODO: handle error" ) ;
129+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
130+
131+ writeln ! ( code, "/// Kleene strong three-valued NOT" ) . expect ( "TODO: handle error" ) ;
132+ writeln ! ( code, "let ternary_not(a: Ternary) -> Ternary =" ) . expect ( "TODO: handle error" ) ;
133+ writeln ! ( code, " match a with" ) . expect ( "TODO: handle error" ) ;
134+ writeln ! ( code, " | True -> False" ) . expect ( "TODO: handle error" ) ;
135+ writeln ! ( code, " | False -> True" ) . expect ( "TODO: handle error" ) ;
136+ writeln ! ( code, " | Unknown -> Unknown" ) . expect ( "TODO: handle error" ) ;
137+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
138138
139139 // Per-variable ternary evaluators.
140140 for var in variables {
@@ -144,41 +144,41 @@ fn emit_ternary_helpers(code: &mut String, variables: &[ParsedVariable]) {
144144 "/// Evaluate '{}' as ternary: True if p >= 0.9, False if p <= 0.1, else Unknown" ,
145145 var. name
146146 )
147- . unwrap ( ) ;
147+ . expect ( "TODO: handle error" ) ;
148148 writeln ! (
149149 code,
150150 "let {}_ternary(observed: Float) -> Ternary =" ,
151151 var. name
152152 )
153- . unwrap ( ) ;
154- writeln ! ( code, " if observed >= 0.9 then True" ) . unwrap ( ) ;
155- writeln ! ( code, " else if observed <= 0.1 then False" ) . unwrap ( ) ;
156- writeln ! ( code, " else Unknown" ) . unwrap ( ) ;
157- writeln ! ( code) . unwrap ( ) ;
153+ . expect ( "TODO: handle error" ) ;
154+ writeln ! ( code, " if observed >= 0.9 then True" ) . expect ( "TODO: handle error" ) ;
155+ writeln ! ( code, " else if observed <= 0.1 then False" ) . expect ( "TODO: handle error" ) ;
156+ writeln ! ( code, " else Unknown" ) . expect ( "TODO: handle error" ) ;
157+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
158158 }
159159 }
160160}
161161
162162/// Emit the simulation configuration block.
163163fn emit_simulation_config ( code : & mut String , config : & AbiSimConfig ) {
164- writeln ! ( code, "// --- Simulation Configuration ---" ) . unwrap ( ) ;
165- writeln ! ( code) . unwrap ( ) ;
166- writeln ! ( code, "@config(samples = {})" , config. samples) . unwrap ( ) ;
167- writeln ! ( code, "@config(confidence = {})" , config. confidence) . unwrap ( ) ;
164+ writeln ! ( code, "// --- Simulation Configuration ---" ) . expect ( "TODO: handle error" ) ;
165+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
166+ writeln ! ( code, "@config(samples = {})" , config. samples) . expect ( "TODO: handle error" ) ;
167+ writeln ! ( code, "@config(confidence = {})" , config. confidence) . expect ( "TODO: handle error" ) ;
168168 if let Some ( seed) = config. seed {
169- writeln ! ( code, "@config(seed = {})" , seed) . unwrap ( ) ;
169+ writeln ! ( code, "@config(seed = {})" , seed) . expect ( "TODO: handle error" ) ;
170170 }
171- writeln ! ( code, "@config(output = \" {}\" )" , config. output_format) . unwrap ( ) ;
172- writeln ! ( code) . unwrap ( ) ;
171+ writeln ! ( code, "@config(output = \" {}\" )" , config. output_format) . expect ( "TODO: handle error" ) ;
172+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
173173}
174174
175175/// Emit the main `simulate` entry point that runs the Monte Carlo simulation.
176176fn emit_entry_point ( code : & mut String , variables : & [ ParsedVariable ] , config : & AbiSimConfig ) {
177- writeln ! ( code, "// --- Entry Point ---" ) . unwrap ( ) ;
178- writeln ! ( code) . unwrap ( ) ;
179- writeln ! ( code, "/// Run the Monte Carlo simulation." ) . unwrap ( ) ;
180- writeln ! ( code, "let simulate() -> SimulationResults =" ) . unwrap ( ) ;
181- writeln ! ( code, " let results = {{" ) . unwrap ( ) ;
177+ writeln ! ( code, "// --- Entry Point ---" ) . expect ( "TODO: handle error" ) ;
178+ writeln ! ( code) . expect ( "TODO: handle error" ) ;
179+ writeln ! ( code, "/// Run the Monte Carlo simulation." ) . expect ( "TODO: handle error" ) ;
180+ writeln ! ( code, "let simulate() -> SimulationResults =" ) . expect ( "TODO: handle error" ) ;
181+ writeln ! ( code, " let results = {{" ) . expect ( "TODO: handle error" ) ;
182182
183183 for var in variables {
184184 let info = distribution_info ( & var. distribution ) ;
@@ -187,11 +187,11 @@ fn emit_entry_point(code: &mut String, variables: &[ParsedVariable], config: &Ab
187187 " {}: sample({}, {})," ,
188188 var. name, info. betlang_constructor, config. samples
189189 )
190- . unwrap ( ) ;
190+ . expect ( "TODO: handle error" ) ;
191191 }
192192
193- writeln ! ( code, " }}" ) . unwrap ( ) ;
194- writeln ! ( code, " report(results, confidence={})" , config. confidence) . unwrap ( ) ;
193+ writeln ! ( code, " }}" ) . expect ( "TODO: handle error" ) ;
194+ writeln ! ( code, " report(results, confidence={})" , config. confidence) . expect ( "TODO: handle error" ) ;
195195}
196196
197197/// Sanitize a project name into a valid Betlang module identifier.
@@ -266,7 +266,7 @@ mod tests {
266266 } ,
267267 ] ;
268268 let m = make_manifest ( "risk-model" , vars) ;
269- let code = generate_betlang_code ( & m) . unwrap ( ) ;
269+ let code = generate_betlang_code ( & m) . expect ( "TODO: handle error" ) ;
270270
271271 // Header present.
272272 assert ! ( code. contains( "Generated by betlangiser" ) ) ;
@@ -309,7 +309,7 @@ mod tests {
309309 expression: None ,
310310 } ] ;
311311 let m = make_manifest ( "no-bernoulli" , vars) ;
312- let code = generate_betlang_code ( & m) . unwrap ( ) ;
312+ let code = generate_betlang_code ( & m) . expect ( "TODO: handle error" ) ;
313313
314314 // No ternary helpers when there are no Bernoulli variables.
315315 assert ! ( !code. contains( "ternary_and" ) ) ;
@@ -390,7 +390,7 @@ mod tests {
390390 } ,
391391 ] ;
392392 let m = make_manifest ( "all-dists" , vars) ;
393- let code = generate_betlang_code ( & m) . unwrap ( ) ;
393+ let code = generate_betlang_code ( & m) . expect ( "TODO: handle error" ) ;
394394
395395 // All five variables declared.
396396 assert ! ( code. contains( "let a :" ) ) ;
@@ -416,7 +416,7 @@ mod tests {
416416 } ] ;
417417 let mut m = make_manifest ( "seeded" , vars) ;
418418 m. simulation . seed = Some ( 42 ) ;
419- let code = generate_betlang_code ( & m) . unwrap ( ) ;
419+ let code = generate_betlang_code ( & m) . expect ( "TODO: handle error" ) ;
420420 assert ! ( code. contains( "@config(seed = 42)" ) ) ;
421421 }
422422}
0 commit comments