Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use simplicity::jet::Elements;
use crate::debug::{CallTracker, DebugSymbols, TrackedCallName};
use crate::driver::{FileScoped, SymbolTable, MAIN_MODULE, MAIN_STR};
use crate::error::{Error, RichError, Span, WithSpan};
use crate::jet::JetHL;
use crate::num::{NonZeroPow2Usize, Pow2Usize};
use crate::parse::MatchPattern;
use crate::pattern::Pattern;
Expand Down Expand Up @@ -1266,14 +1267,16 @@ impl AbstractSyntaxTree for Call {
let name = CallName::analyze(from, ty, scope)?;
let args = match name.clone() {
CallName::Jet(jet) => {
let args_tys = crate::jet::source_type(jet)
let args_tys = jet
.source_type()
.iter()
.map(AliasedType::resolve_builtin)
.collect::<Result<Vec<ResolvedType>, AliasName>>()
.map_err(Error::UndefinedAlias)
.with_span(from)?;
check_argument_types(from.args(), &args_tys).with_span(from)?;
let out_ty = crate::jet::target_type(jet)
let out_ty = jet
.target_type()
.resolve_builtin()
.map_err(Error::UndefinedAlias)
.with_span(from)?;
Expand Down Expand Up @@ -1440,10 +1443,8 @@ impl AbstractSyntaxTree for CallName {
) -> Result<Self, RichError> {
match from.name() {
parse::CallName::Jet(name) => match Elements::from_str(name.as_inner()) {
Ok(Elements::CheckSigVerify | Elements::Verify) | Err(_) => {
Err(Error::JetDoesNotExist(name.clone())).with_span(from)
}
Ok(jet) => Ok(Self::Jet(jet)),
Ok(jet) if !jet.is_disabled() => Ok(Self::Jet(jet)),
_ => Err(Error::JetDoesNotExist(name.clone())).with_span(from),
},
parse::CallName::UnwrapLeft(right_ty) => scope
.resolve(right_ty)
Expand Down
3 changes: 2 additions & 1 deletion src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ast::{
};
use crate::debug::CallTracker;
use crate::error::{Error, RichError, Span, WithSpan};
use crate::jet::JetHL;
use crate::named::{self, CoreExt, PairBuilder};
use crate::num::{NonZeroPow2Usize, Pow2Usize};
use crate::pattern::{BasePattern, Pattern};
Expand Down Expand Up @@ -410,7 +411,7 @@ impl Call {
args.comp(&body).with_span(self)
}
CallName::Assert => {
let jet = ProgNode::jet(scope.ctx(), Elements::Verify);
let jet = ProgNode::jet(scope.ctx(), Elements::verify());
scope.with_debug_symbol(args, &jet, self)
}
CallName::Panic => {
Expand Down
30 changes: 28 additions & 2 deletions src/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ use crate::types::UIntType::*;
use crate::types::*;

use simplicity::jet::Elements;
use simplicity::jet::Jet;

pub trait JetHL<J: Jet> {
fn source_type(&self) -> Vec<AliasedType>;
fn target_type(&self) -> AliasedType;
fn verify() -> J;
fn is_disabled(&self) -> bool;
}

impl JetHL<Elements> for Elements {
fn source_type(&self) -> Vec<AliasedType> {
source_type(*self)
}

fn target_type(&self) -> AliasedType {
target_type(*self)
}

fn verify() -> Elements {
Elements::Verify
}

fn is_disabled(&self) -> bool {
matches!(self, Elements::CheckSigVerify | Elements::Verify)
}
}

fn tuple<A: Into<AliasedType>, I: IntoIterator<Item = A>>(elements: I) -> AliasedType {
AliasedType::tuple(elements.into_iter().map(A::into))
Expand Down Expand Up @@ -1044,7 +1070,7 @@ mod tests {
fn compatible_source_type() {
for jet in Elements::ALL {
let resolved_ty = ResolvedType::tuple(
source_type(jet)
jet.source_type()
.into_iter()
.map(|t| t.resolve_builtin().unwrap()),
);
Expand All @@ -1059,7 +1085,7 @@ mod tests {
#[test]
fn compatible_target_type() {
for jet in Elements::ALL {
let resolved_ty = target_type(jet).resolve_builtin().unwrap();
let resolved_ty = jet.target_type().resolve_builtin().unwrap();
let structural_ty = StructuralType::from(&resolved_ty);
let simplicity_ty = jet.target_ty().to_final();

Expand Down
6 changes: 3 additions & 3 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use simplicity::{Ihr, RedeemNode, Value as SimValue};
use crate::array::Unfolder;
use crate::debug::{DebugSymbols, TrackedCallName};
use crate::either::Either;
use crate::jet::{source_type, target_type};
use crate::jet::JetHL;
use crate::str::AliasName;
use crate::types::AliasedType;
use crate::value::StructuralValue;
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<'a> DefaultTracker<'a> {
match output.clone() {
NodeOutput::Success(mut output_frame) => {
let target_ty = &node.arrow().target;
let jet_target_ty = resolve_jet_type(&target_type(jet));
let jet_target_ty = resolve_jet_type(&jet.target_type());

// Skip the leading bit when the frame has extra padding.
// This occurs because some jets (like eq_64 etc.) are wrapped in AssertL (a Case combinator),
Expand Down Expand Up @@ -331,7 +331,7 @@ impl ExecTracker<Elements> for DefaultTracker<'_> {

/// Parses jet input arguments from the bit machine's read frame.
fn parse_jet_arguments(jet: Elements, input_frame: &mut FrameIter) -> Result<Vec<Value>, String> {
let source_types = source_type(jet);
let source_types = jet.source_type();
if source_types.is_empty() {
return Ok(vec![]);
}
Expand Down