Extended ScriptContext; added Option to builtins
This commit is contained in:
parent
72bf27d467
commit
6c5ec9bb25
|
@ -21,6 +21,7 @@ pub const LIST: &str = "List";
|
||||||
pub const NIL: &str = "Nil";
|
pub const NIL: &str = "Nil";
|
||||||
pub const RESULT: &str = "Result";
|
pub const RESULT: &str = "Result";
|
||||||
pub const STRING: &str = "String";
|
pub const STRING: &str = "String";
|
||||||
|
pub const OPTION: &str = "Option";
|
||||||
|
|
||||||
/// Build a prelude that can be injected
|
/// Build a prelude that can be injected
|
||||||
/// into a compiler pipeline
|
/// into a compiler pipeline
|
||||||
|
@ -224,6 +225,60 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Option(value, none)
|
||||||
|
let option_value = generic_var(id_gen.next());
|
||||||
|
let option_none = generic_var(id_gen.next());
|
||||||
|
|
||||||
|
prelude.types.insert(
|
||||||
|
OPTION.to_string(),
|
||||||
|
TypeConstructor {
|
||||||
|
location: Span::empty(),
|
||||||
|
parameters: vec![option_value.clone(), option_none.clone()],
|
||||||
|
tipo: option(option_value, option_none),
|
||||||
|
module: "".to_string(),
|
||||||
|
public: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
prelude.types_constructors.insert(
|
||||||
|
OPTION.to_string(),
|
||||||
|
vec!["Some".to_string(), "None".to_string()],
|
||||||
|
);
|
||||||
|
|
||||||
|
let some = generic_var(id_gen.next());
|
||||||
|
let none = generic_var(id_gen.next());
|
||||||
|
let _ = prelude.values.insert(
|
||||||
|
"Some".to_string(),
|
||||||
|
ValueConstructor::public(
|
||||||
|
function(vec![some.clone()], option(some, none)),
|
||||||
|
ValueConstructorVariant::Record {
|
||||||
|
module: "".into(),
|
||||||
|
name: "Some".to_string(),
|
||||||
|
field_map: None::<FieldMap>,
|
||||||
|
arity: 1,
|
||||||
|
location: Span::empty(),
|
||||||
|
constructors_count: 2,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let some = generic_var(id_gen.next());
|
||||||
|
let none = generic_var(id_gen.next());
|
||||||
|
let _ = prelude.values.insert(
|
||||||
|
"None".to_string(),
|
||||||
|
ValueConstructor::public(
|
||||||
|
function(vec![none.clone()], option(some, none)),
|
||||||
|
ValueConstructorVariant::Record {
|
||||||
|
module: "".into(),
|
||||||
|
name: "None".to_string(),
|
||||||
|
field_map: None::<FieldMap>,
|
||||||
|
arity: 0,
|
||||||
|
location: Span::empty(),
|
||||||
|
constructors_count: 2,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
prelude
|
prelude
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,6 +541,15 @@ pub fn result(a: Arc<Type>, e: Arc<Type>) -> Arc<Type> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn option(a: Arc<Type>, e: Arc<Type>) -> Arc<Type> {
|
||||||
|
Arc::new(Type::App {
|
||||||
|
public: true,
|
||||||
|
name: OPTION.to_string(),
|
||||||
|
module: "".to_string(),
|
||||||
|
args: vec![a, e],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn function(args: Vec<Arc<Type>>, ret: Arc<Type>) -> Arc<Type> {
|
pub fn function(args: Vec<Arc<Type>>, ret: Arc<Type>) -> Arc<Type> {
|
||||||
Arc::new(Type::Fn { ret, args })
|
Arc::new(Type::Fn { ret, args })
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,9 @@ pub type ScriptPurpose {
|
||||||
Certify(Certificate)
|
Certify(Certificate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type Redeemer =
|
||||||
|
Data
|
||||||
|
|
||||||
pub type BoundValue(value) {
|
pub type BoundValue(value) {
|
||||||
NegativeInfinity
|
NegativeInfinity
|
||||||
Finite(value)
|
Finite(value)
|
||||||
|
@ -32,20 +35,21 @@ pub type Interval(value) {
|
||||||
pub type Transaction {
|
pub type Transaction {
|
||||||
inputs: List(Input),
|
inputs: List(Input),
|
||||||
reference_inputs: List(Input),
|
reference_inputs: List(Input),
|
||||||
outputs: List(Nil),
|
outputs: List(Output),
|
||||||
fee: Value,
|
fee: Value,
|
||||||
mint: Value,
|
mint: Value,
|
||||||
certificates: List(Certificate),
|
certificates: List(Certificate),
|
||||||
withdrawals: List(Pair(StakeCredential, Int)),
|
withdrawals: List(Pair(StakeCredential, Int)),
|
||||||
validity_range: Interval(Int),
|
validity_range: Interval(Int),
|
||||||
extra_signatories: Nil,
|
extra_signatories: List(PublicKeyHash),
|
||||||
redeemers: List(Nil),
|
redeemers: List(Pair(ScriptPurpose, Redeemer)),
|
||||||
datums: List(Pair(Hash(Data), Data)),
|
datums: List(Pair(Hash(Data), Data)),
|
||||||
id: TransactionId,
|
id: TransactionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TransactionId =
|
pub type TransactionId = {
|
||||||
Hash(Transaction)
|
hash: Hash(Transaction)
|
||||||
|
}
|
||||||
|
|
||||||
pub type Input {
|
pub type Input {
|
||||||
output_reference: OutputReference,
|
output_reference: OutputReference,
|
||||||
|
@ -60,17 +64,45 @@ pub type OutputReference {
|
||||||
pub type PolicyId =
|
pub type PolicyId =
|
||||||
ByteArray
|
ByteArray
|
||||||
|
|
||||||
pub type StakeCredential =
|
pub type StakeCredential = {
|
||||||
Nil
|
StakeHash(Credential)
|
||||||
|
StakePointer(Int, Int, Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Credential = {
|
||||||
|
PublicKeyCredential(PublicKeyHash)
|
||||||
|
ScriptCredential(ScriptHash)
|
||||||
|
}
|
||||||
|
|
||||||
pub type VerificationKey =
|
pub type VerificationKey =
|
||||||
Nil
|
Nil
|
||||||
|
|
||||||
|
pub type ScriptHash =
|
||||||
|
ByteArray
|
||||||
|
|
||||||
|
pub type PublicKeyHash =
|
||||||
|
Hash(VerificationKey)
|
||||||
|
|
||||||
pub type PoolId =
|
pub type PoolId =
|
||||||
Hash(VerificationKey)
|
Hash(VerificationKey)
|
||||||
|
|
||||||
pub type Output =
|
pub type Output = {
|
||||||
Nil
|
address: Address,
|
||||||
|
value: Value,
|
||||||
|
datum: DatumOption,
|
||||||
|
reference_script: Option(ScriptHash),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Address = {
|
||||||
|
payment_credential: Credential,
|
||||||
|
stake_credential: Option(StakeCredential),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DatumOption = {
|
||||||
|
NoDatum
|
||||||
|
DatumHash(Hash(Data))
|
||||||
|
Datum(Data)
|
||||||
|
}
|
||||||
|
|
||||||
pub type AssetName =
|
pub type AssetName =
|
||||||
ByteArray
|
ByteArray
|
||||||
|
|
Loading…
Reference in New Issue