Skip to content

Commit

Permalink
feat: Add default CompiledProgram
Browse files Browse the repository at this point in the history
We can use the empty program as initializer for fields that store
CompiledProgram, such as in the web IDE.
  • Loading branch information
uncomputable committed Sep 28, 2024
1 parent 976c6c4 commit d2f77b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::value::{UIntValue, Value};
use crate::{impl_eq_hash, parse};

/// Map of witness names to their expected type, as declared in the program.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct DeclaredWitnesses(HashMap<WitnessName, ResolvedType>);

impl DeclaredWitnesses {
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ pub struct CompiledProgram {
debug_symbols: DebugSymbols,
}

impl Default for CompiledProgram {
fn default() -> Self {
use simplicity::node::CoreConstructible;
Self {
simplicity: ProgNode::unit(&simplicity::types::Context::new()),
witness_types: DeclaredWitnesses::default(),
debug_symbols: DebugSymbols::default(),
}
}
}

impl CompiledProgram {
/// Parse and compile a Simfony program from the given string.
///
Expand Down

0 comments on commit d2f77b5

Please sign in to comment.