clean up some unused parts in created hashmaps
This commit is contained in:
parent
b450c41438
commit
d11b8858ba
|
@ -84,7 +84,7 @@ impl Default for ScopeLevels {
|
||||||
|
|
||||||
pub struct CodeGenerator<'a> {
|
pub struct CodeGenerator<'a> {
|
||||||
uplc_function_holder: Vec<(String, Term<Name>)>,
|
uplc_function_holder: Vec<(String, Term<Name>)>,
|
||||||
uplc_function_holder_lookup: IndexMap<(String, String), (ScopeLevels, TypedExpr)>,
|
uplc_function_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
uplc_data_holder_lookup: IndexMap<(String, String, String), (ScopeLevels, TypedExpr)>,
|
uplc_data_holder_lookup: IndexMap<(String, String, String), (ScopeLevels, TypedExpr)>,
|
||||||
uplc_data_constr_lookup: IndexMap<(String, String), ScopeLevels>,
|
uplc_data_constr_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
|
@ -232,6 +232,34 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
(ValueConstructorVariant::Record { .. }, Type::App { .. }) => {}
|
(ValueConstructorVariant::Record { .. }, Type::App { .. }) => {}
|
||||||
(ValueConstructorVariant::Record { .. }, Type::Fn { .. }) => {}
|
(ValueConstructorVariant::Record { .. }, Type::Fn { .. }) => {}
|
||||||
|
(ValueConstructorVariant::ModuleFn { name, module, .. }, Type::Fn { .. }) => {
|
||||||
|
if self
|
||||||
|
.uplc_function_holder_lookup
|
||||||
|
.get(&(module.to_string(), name.to_string()))
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
let func_def = self
|
||||||
|
.functions
|
||||||
|
.get(&(module.to_string(), name.to_string()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self.recurse_scope_level(
|
||||||
|
&func_def.body,
|
||||||
|
scope_level.scope_increment(func_def.arguments.len() as i32 + 1),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.uplc_function_holder_lookup
|
||||||
|
.insert((module, name), scope_level);
|
||||||
|
} else if scope_level.is_less_than(
|
||||||
|
self.uplc_function_holder_lookup
|
||||||
|
.get(&(module.to_string(), name.to_string()))
|
||||||
|
.unwrap(),
|
||||||
|
false,
|
||||||
|
) {
|
||||||
|
self.uplc_function_holder_lookup
|
||||||
|
.insert((module, name), scope_level);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
TypedExpr::Fn { .. } => todo!(),
|
TypedExpr::Fn { .. } => todo!(),
|
||||||
|
@ -361,7 +389,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.insert((module, current_var_name), current_scope);
|
.insert((module, current_var_name), current_scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a @ TypedExpr::ModuleSelect { constructor, .. } => match constructor {
|
TypedExpr::ModuleSelect { constructor, .. } => match constructor {
|
||||||
ModuleValueConstructor::Record { .. } => todo!(),
|
ModuleValueConstructor::Record { .. } => todo!(),
|
||||||
ModuleValueConstructor::Fn { module, name, .. } => {
|
ModuleValueConstructor::Fn { module, name, .. } => {
|
||||||
if self
|
if self
|
||||||
|
@ -379,22 +407,16 @@ impl<'a> CodeGenerator<'a> {
|
||||||
scope_level.scope_increment(func_def.arguments.len() as i32 + 1),
|
scope_level.scope_increment(func_def.arguments.len() as i32 + 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.uplc_function_holder_lookup.insert(
|
self.uplc_function_holder_lookup
|
||||||
(module.to_string(), name.to_string()),
|
.insert((module.to_string(), name.to_string()), scope_level);
|
||||||
(scope_level, a.clone()),
|
|
||||||
);
|
|
||||||
} else if scope_level.is_less_than(
|
} else if scope_level.is_less_than(
|
||||||
&self
|
self.uplc_function_holder_lookup
|
||||||
.uplc_function_holder_lookup
|
|
||||||
.get(&(module.to_string(), name.to_string()))
|
.get(&(module.to_string(), name.to_string()))
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
.0,
|
|
||||||
false,
|
false,
|
||||||
) {
|
) {
|
||||||
self.uplc_function_holder_lookup.insert(
|
self.uplc_function_holder_lookup
|
||||||
(module.to_string(), name.to_string()),
|
.insert((module.to_string(), name.to_string()), scope_level);
|
||||||
(scope_level, a.clone()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModuleValueConstructor::Constant { .. } => todo!(),
|
ModuleValueConstructor::Constant { .. } => todo!(),
|
||||||
|
@ -424,7 +446,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
// name: constructor_name,
|
// name: constructor_name,
|
||||||
tipo,
|
tipo,
|
||||||
// arguments,
|
// arguments,
|
||||||
// constructor,
|
constructor: _constructor,
|
||||||
// module,
|
// module,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
|
@ -526,7 +548,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
if name == "True" || name == "False" {
|
if name == "True" || name == "False" {
|
||||||
Term::Constant(Constant::Bool(name == "True"))
|
Term::Constant(Constant::Bool(name == "True"))
|
||||||
} else {
|
} else {
|
||||||
match dbg!(constructor.variant.clone()) {
|
match constructor.variant.clone() {
|
||||||
ValueConstructorVariant::LocalVariable { .. } => Term::Var(Name {
|
ValueConstructorVariant::LocalVariable { .. } => Term::Var(Name {
|
||||||
text: name.to_string(),
|
text: name.to_string(),
|
||||||
unique: 0.into(),
|
unique: 0.into(),
|
||||||
|
@ -1211,14 +1233,11 @@ impl<'a> CodeGenerator<'a> {
|
||||||
scope_level: ScopeLevels,
|
scope_level: ScopeLevels,
|
||||||
) -> Term<Name> {
|
) -> Term<Name> {
|
||||||
let mut term = current_term;
|
let mut term = current_term;
|
||||||
|
|
||||||
|
// attempt to insert function definitions where needed
|
||||||
for func in self.uplc_function_holder_lookup.clone().keys() {
|
for func in self.uplc_function_holder_lookup.clone().keys() {
|
||||||
if scope_level.is_less_than(
|
if scope_level.is_less_than(
|
||||||
&self
|
self.uplc_function_holder_lookup.clone().get(func).unwrap(),
|
||||||
.uplc_function_holder_lookup
|
|
||||||
.clone()
|
|
||||||
.get(func)
|
|
||||||
.unwrap()
|
|
||||||
.0,
|
|
||||||
false,
|
false,
|
||||||
) {
|
) {
|
||||||
let func_def = self
|
let func_def = self
|
||||||
|
@ -1370,14 +1389,14 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
// Pull out all uplc data holder and data usage, filter by Scope Level, Sort By Scope Depth, Then Apply
|
// Pull out all uplc data holder and data usage, filter by Scope Level, Sort By Scope Depth, Then Apply
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
let mut data_holder: Vec<((String, String, String), (bool, ScopeLevels, u64))> = self
|
let mut data_holder: Vec<((String, String, String), (ScopeLevels, i128))> = self
|
||||||
.uplc_data_usage_holder_lookup
|
.uplc_data_usage_holder_lookup
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|record_scope| scope_level.is_less_than(record_scope.1, false))
|
.filter(|record_scope| scope_level.is_less_than(record_scope.1, false))
|
||||||
.map(|((module, name), scope)| {
|
.map(|((module, name), scope)| {
|
||||||
(
|
(
|
||||||
(module.to_string(), name.to_string(), "".to_string()),
|
(module.to_string(), name.to_string(), "".to_string()),
|
||||||
(true, scope.clone(), 0),
|
(scope.clone(), -1),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1393,27 +1412,27 @@ impl<'a> CodeGenerator<'a> {
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
(module.to_string(), name.to_string(), label.to_string()),
|
(module.to_string(), name.to_string(), label.to_string()),
|
||||||
(false, scope.clone(), *index),
|
(scope.clone(), *index as i128),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<((String, String, String), (bool, ScopeLevels, u64))>>(),
|
.collect::<Vec<((String, String, String), (ScopeLevels, i128))>>(),
|
||||||
);
|
);
|
||||||
data_holder.sort_by(|b, d| {
|
data_holder.sort_by(|item1, item2| {
|
||||||
if b.1 .1.is_less_than(&d.1 .1, true) {
|
if item1.1 .0.is_less_than(&item2.1 .0, true) {
|
||||||
Ordering::Less
|
Ordering::Less
|
||||||
} else if d.1 .1.is_less_than(&b.1 .1, true) {
|
} else if item2.1 .0.is_less_than(&item1.1 .0, true) {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
} else if b.1 .0 && !d.1 .0 {
|
} else if item1.1 .1 < item2.1 .1 {
|
||||||
Ordering::Less
|
Ordering::Less
|
||||||
} else if d.1 .0 && !b.1 .0 {
|
} else if item2.1 .1 < item1.1 .1 {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
Ordering::Equal
|
Ordering::Equal
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (key @ (module, name, label), (is_data_usage, _, index)) in data_holder.iter().rev() {
|
for (key @ (module, name, label), (_, index)) in data_holder.iter().rev() {
|
||||||
if *is_data_usage {
|
if index < &0 {
|
||||||
term = Term::Apply {
|
term = Term::Apply {
|
||||||
function: Term::Lambda {
|
function: Term::Lambda {
|
||||||
parameter_name: Name {
|
parameter_name: Name {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub type Signer {
|
pub type Signer {
|
||||||
hash: Int,
|
hash: ByteArray,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ScriptContext {
|
pub type ScriptContext {
|
||||||
|
|
|
@ -16,13 +16,28 @@ pub type Reen {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn twice(f: fn(Int) -> Int, x: Int) -> Int {
|
||||||
|
f(f(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_one(x: Int) -> Int {
|
||||||
|
x + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_two(x: Int) -> Int {
|
||||||
|
twice(add_one, x)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn spend(
|
pub fn spend(
|
||||||
datum: sample.Datum,
|
datum: sample.Datum,
|
||||||
rdmr: Redeemer,
|
rdmr: Redeemer,
|
||||||
ctx: spend.ScriptContext,
|
ctx: spend.ScriptContext,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
1 % 2 != 3 || 5 / 4 - 2 != 0
|
let x = rdmr.signer
|
||||||
|
let z = datum.sc.signer.hash
|
||||||
|
let y = datum.sc
|
||||||
|
let a = datum.fin
|
||||||
|
|
||||||
|
a > 0 && z == x
|
||||||
|
|
||||||
True
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue