Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC007] Add Seal and Unseal to the new AST primops #2101

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
11 changes: 8 additions & 3 deletions core/src/bytecode/ast/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,12 @@ impl From<&term::BinaryOp> for PrimOp {
term::BinaryOp::LabelAppendNote => PrimOp::LabelAppendNote,
term::BinaryOp::LabelLookupTypeVar => PrimOp::LabelLookupTypeVar,

op @ (term::BinaryOp::RecordInsert { .. }
| term::BinaryOp::Unseal
| term::BinaryOp::Seal) => panic!("didn't expect {op} at the parsing stage"),
term::BinaryOp::Seal => PrimOp::Seal,
term::BinaryOp::Unseal => PrimOp::Unseal,

term::BinaryOp::RecordInsert { .. } => {
panic!("didn't expect %record/insert% at the parsing stage")
}
}
}
}
Expand Down Expand Up @@ -1020,6 +1023,8 @@ impl FromAst<PrimOp> for TermPrimOp {
PrimOp::StringSplit => TermPrimOp::Binary(term::BinaryOp::StringSplit),
PrimOp::StringContains => TermPrimOp::Binary(term::BinaryOp::StringContains),
PrimOp::StringCompare => TermPrimOp::Binary(term::BinaryOp::StringCompare),
PrimOp::Seal => TermPrimOp::Binary(term::BinaryOp::Seal),
PrimOp::Unseal => TermPrimOp::Binary(term::BinaryOp::Unseal),
PrimOp::ContractArrayLazyApp => {
TermPrimOp::Binary(term::BinaryOp::ContractArrayLazyApp)
}
Expand Down
20 changes: 20 additions & 0 deletions core/src/bytecode/ast/primop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,22 @@ pub enum PrimOp {
/// 2. The right string.
StringCompare,

/// Seal a term with a sealing key (used by the implementation of polymorphic contracts).
///
/// # Argumens
///
/// 1. The sealing key.
/// 2. The term to seal.
Seal,

/// Unseal a term given the right sealing key. See [Self::Seal].
///
/// # Arguments
///
/// 1. The sealing key.
/// 2. The term to unseal.
Unseal,

/// Lazily apply a contract to an Array.
///
/// This simply inserts a contract into the array attributes.
Expand Down Expand Up @@ -1015,6 +1031,8 @@ impl fmt::Display for PrimOp {
StringSplit => write!(f, "string/split"),
StringContains => write!(f, "string/contains"),
StringCompare => write!(f, "string/compare"),
Seal => write!(f, "seal"),
Unseal => write!(f, "unseal"),
ContractArrayLazyApp => write!(f, "contract/array_lazy_apply"),
ContractRecordLazyApp => write!(f, "contract/record_lazy_apply"),
LabelWithMessage => write!(f, "label/with_message"),
Expand Down Expand Up @@ -1126,6 +1144,8 @@ impl PrimOp {
| StringSplit
| StringContains
| StringCompare
| Seal
| Unseal
| ContractArrayLazyApp
| ContractRecordLazyApp
| LabelWithMessage
Expand Down
Loading