@@ -6,7 +6,7 @@ use simplicityhl::ast::ElementsJetHinter;
66use simplicityhl:: version:: SimcDirective ;
77use simplicityhl:: {
88 resolution:: DependencyMapBuilder , source:: CanonPath , source:: CanonSourceFile , AbiMeta ,
9- CompiledProgram ,
9+ TemplateProgram ,
1010} ;
1111use simplicityhl:: { UnstableFeature , UnstableFeatures } ;
1212use std:: path:: Path ;
@@ -132,24 +132,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
132132 UnstableFeatures :: new ( features. copied ( ) )
133133 } ) ;
134134
135+ // Argument values are resolved against the program's parameter types,
136+ // so the file is parsed here and resolved once the template is built.
135137 #[ cfg( feature = "serde" ) ]
136- let args_opt: simplicityhl:: Arguments = match matches. get_one :: < String > ( "args_file" ) {
137- None => simplicityhl:: Arguments :: default ( ) ,
138- Some ( args_file) => {
139- let args_path = Path :: new ( & args_file) ;
140- let args_text = std:: fs:: read_to_string ( args_path) . map_err ( |e| e. to_string ( ) ) ?;
141- serde_json:: from_str :: < simplicityhl:: Arguments > ( & args_text) ?
142- }
143- } ;
138+ let unresolved_args: Option < simplicityhl:: UnresolvedValues > =
139+ match matches. get_one :: < String > ( "args_file" ) {
140+ None => None ,
141+ Some ( args_file) => {
142+ let args_path = Path :: new ( & args_file) ;
143+ let args_text = std:: fs:: read_to_string ( args_path) . map_err ( |e| e. to_string ( ) ) ?;
144+ Some ( serde_json:: from_str ( & args_text) ?)
145+ }
146+ } ;
144147 #[ cfg( not( feature = "serde" ) ) ]
145- let args_opt : simplicityhl :: Arguments = if matches. contains_id ( "args_file" ) {
148+ if matches. contains_id ( "args_file" ) {
146149 return Err (
147150 "Program was compiled without the 'serde' feature and cannot process .args files."
148151 . into ( ) ,
149152 ) ;
150- } else {
151- simplicityhl:: Arguments :: default ( )
152- } ;
153+ }
153154
154155 let dep_args = matches
155156 . get_many :: < String > ( "dependencies" )
@@ -195,14 +196,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
195196 } ;
196197
197198 let source = CanonSourceFile :: new ( main_path. clone ( ) , std:: sync:: Arc :: from ( main_text) ) ;
198- let compiled = match CompiledProgram :: new_with_dep (
199+ let template = match TemplateProgram :: new_with_dep (
199200 source,
200201 & dependencies,
201202 & unstable_features,
202- args_opt,
203- include_debug_symbols,
204203 Box :: new ( ElementsJetHinter :: new ( ) ) ,
205204 ) {
205+ Ok ( program) => program,
206+ Err ( e) => {
207+ // `Display` is message-only; render for source snippets with
208+ // file and line pointers, as the single-file path does.
209+ eprintln ! ( "{}" , e. render_to_string( ) ) ;
210+ std:: process:: exit ( 1 ) ;
211+ }
212+ } ;
213+
214+ #[ cfg( feature = "serde" ) ]
215+ let args_opt: simplicityhl:: Arguments = match unresolved_args {
216+ None => simplicityhl:: Arguments :: default ( ) ,
217+ Some ( unresolved) => unresolved. resolve ( template. parameters ( ) ) ?,
218+ } ;
219+ #[ cfg( not( feature = "serde" ) ) ]
220+ let args_opt = simplicityhl:: Arguments :: default ( ) ;
221+
222+ let compiled = match template. instantiate ( args_opt, include_debug_symbols) {
206223 Ok ( program) => program,
207224 Err ( e) => {
208225 eprintln ! ( "{}" , e) ;
@@ -216,8 +233,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
216233 . map ( |wit_file| -> Result < simplicityhl:: WitnessValues , String > {
217234 let wit_path = Path :: new ( wit_file) ;
218235 let wit_text = std:: fs:: read_to_string ( wit_path) . map_err ( |e| e. to_string ( ) ) ?;
219- let witness = serde_json:: from_str :: < simplicityhl:: WitnessValues > ( & wit_text) . unwrap ( ) ;
220- Ok ( witness)
236+ let unresolved = serde_json:: from_str :: < simplicityhl:: UnresolvedValues > ( & wit_text)
237+ . map_err ( |e| e. to_string ( ) ) ?;
238+ unresolved. resolve ( compiled. witness_types ( ) )
221239 } )
222240 . transpose ( ) ?;
223241 #[ cfg( not( feature = "serde" ) ) ]
0 commit comments