checkpoint commit
This commit is contained in:
parent
28697586f2
commit
6950b66b55
|
@ -469,7 +469,7 @@ pub struct RecordAccessor {
|
||||||
pub tipo: Arc<Type>,
|
pub tipo: Arc<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum PatternConstructor {
|
pub enum PatternConstructor {
|
||||||
Record {
|
Record {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
@ -88,7 +88,7 @@ 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, TypedExpr)>,
|
||||||
uplc_data_holder_lookup: IndexMap<(String, String, String), (ScopeLevels, TypedExpr)>,
|
uplc_data_holder_lookup: IndexMap<(String, String, String), (ScopeLevels, TypedExpr)>,
|
||||||
uplc_when_lookup: IndexMap<(String, String, String), (ScopeLevels, TypedExpr)>,
|
uplc_when_lookup: IndexMap<(String, String, String), ScopeLevels>,
|
||||||
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
||||||
type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
|
type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
|
||||||
|
@ -413,6 +413,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(ValueConstructorVariant::Record { .. }, Type::App { .. }) => {}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
TypedExpr::Fn {
|
TypedExpr::Fn {
|
||||||
|
@ -465,7 +466,6 @@ impl<'a> CodeGenerator<'a> {
|
||||||
for subject in subjects {
|
for subject in subjects {
|
||||||
self.recurse_scope_level(subject, scope_level.clone());
|
self.recurse_scope_level(subject, scope_level.clone());
|
||||||
}
|
}
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
//if statements increase scope due to branching.
|
//if statements increase scope due to branching.
|
||||||
TypedExpr::If {
|
TypedExpr::If {
|
||||||
|
@ -626,9 +626,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
value: &TypedExpr,
|
value: &TypedExpr,
|
||||||
scope_level: ScopeLevels,
|
scope_level: ScopeLevels,
|
||||||
) {
|
) {
|
||||||
match pattern {
|
match dbg!(pattern) {
|
||||||
Pattern::Int { .. } | Pattern::String { .. } | Pattern::Var { .. } => {
|
Pattern::Int { .. } | Pattern::String { .. } | Pattern::Var { .. } => {
|
||||||
self.recurse_scope_level(value, scope_level);
|
self.recurse_scope_level(value, scope_level.scope_increment_sequence(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern::VarUsage {
|
Pattern::VarUsage {
|
||||||
|
@ -648,28 +648,83 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tail,
|
tail,
|
||||||
} => todo!(),
|
} => todo!(),
|
||||||
Pattern::Constructor {
|
Pattern::Constructor {
|
||||||
location,
|
name: constructor_name,
|
||||||
name,
|
|
||||||
arguments,
|
|
||||||
module,
|
|
||||||
constructor,
|
|
||||||
with_spread,
|
|
||||||
tipo,
|
tipo,
|
||||||
|
arguments,
|
||||||
|
constructor,
|
||||||
|
module,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
self.recurse_scope_level(value, scope_level);
|
self.recurse_scope_level(value, scope_level.scope_increment_sequence(1));
|
||||||
|
|
||||||
match &**tipo {
|
match &**tipo {
|
||||||
Type::App {
|
Type::App { module, name, .. } => {
|
||||||
public,
|
if let Some(val) = self.uplc_when_lookup.get(&(
|
||||||
module,
|
module.to_string(),
|
||||||
name,
|
name.clone(),
|
||||||
args,
|
constructor_name.clone(),
|
||||||
} => todo!(),
|
)) {
|
||||||
|
if scope_level.is_less_than(&val, false) {
|
||||||
|
self.uplc_when_lookup.insert(
|
||||||
|
(module.to_string(), name.clone(), constructor_name.clone()),
|
||||||
|
scope_level,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.uplc_when_lookup.insert(
|
||||||
|
(module.to_string(), name.clone(), constructor_name.clone()),
|
||||||
|
scope_level,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Type::Fn { .. } => {
|
||||||
|
let mapping_index = match constructor {
|
||||||
|
tipo::PatternConstructor::Record { name, field_map } => {
|
||||||
|
if let Some(fields_mapping) = field_map {
|
||||||
|
fields_mapping.fields.clone()
|
||||||
|
} else {
|
||||||
|
HashMap::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut args = arguments.clone();
|
||||||
|
let local_var_name = "";
|
||||||
|
// arguments.iter().map(|x| {
|
||||||
|
// let name = match &x.value {
|
||||||
|
// Pattern::Var { location, name } => {
|
||||||
|
// if let Some(val) = self.uplc_data_holder_lookup.get(&(
|
||||||
|
// module.to_string(),
|
||||||
|
// .clone(),
|
||||||
|
// label.clone(),
|
||||||
|
// )) {
|
||||||
|
// if current_scope.is_less_than(&val.0, false) {
|
||||||
|
// self.uplc_data_holder_lookup.insert(
|
||||||
|
// (
|
||||||
|
// module.to_string(),
|
||||||
|
// current_var_name.clone(),
|
||||||
|
// label.clone(),
|
||||||
|
// ),
|
||||||
|
// (current_scope.clone(), a.clone()),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// self.uplc_data_holder_lookup.insert(
|
||||||
|
// (
|
||||||
|
// module.to_string(),
|
||||||
|
// current_var_name.clone(),
|
||||||
|
// label.clone(),
|
||||||
|
// ),
|
||||||
|
// (current_scope.clone(), a.clone()),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// _ => todo!(),
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// self.data_types.get();
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -867,7 +922,58 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tipo,
|
tipo,
|
||||||
subjects,
|
subjects,
|
||||||
clauses,
|
clauses,
|
||||||
} => todo!(),
|
} => {
|
||||||
|
let mut current_clauses = clauses.clone();
|
||||||
|
let mut new_current_clauses: Vec<(Vec<usize>, TypedExpr)> = current_clauses
|
||||||
|
.iter()
|
||||||
|
.map(|clause| {
|
||||||
|
let mut final_keys = Vec::new();
|
||||||
|
for pattern in clause.pattern.clone() {
|
||||||
|
let key = match pattern {
|
||||||
|
Pattern::Constructor { name, tipo, .. } => {
|
||||||
|
let key = match &*tipo {
|
||||||
|
Type::App { module, name, .. } => {
|
||||||
|
(module.clone(), name.clone())
|
||||||
|
}
|
||||||
|
Type::Fn { args, ret } => todo!(),
|
||||||
|
Type::Var { tipo } => todo!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let dt = self.data_types.get(&key).unwrap();
|
||||||
|
|
||||||
|
let index = dt.constructors.iter().position(|c| name == c.name);
|
||||||
|
|
||||||
|
// index.unwrap()
|
||||||
|
index.unwrap()
|
||||||
|
}
|
||||||
|
_ => todo!(),
|
||||||
|
};
|
||||||
|
final_keys.push(key);
|
||||||
|
}
|
||||||
|
(final_keys, clause.then.clone())
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let mut term = self.recurse_code_gen(
|
||||||
|
&new_current_clauses.remove(new_current_clauses.len() - 1).1,
|
||||||
|
scope_level.scope_increment_sequence(1),
|
||||||
|
);
|
||||||
|
|
||||||
|
for subject in subjects {}
|
||||||
|
|
||||||
|
// for clause in new_current_clauses.iter().rev() {
|
||||||
|
// let branch_term =
|
||||||
|
// self.recurse_code_gen(&clause.1, scope_level.scope_increment_sequence(1));
|
||||||
|
|
||||||
|
// for index in clause.0 {
|
||||||
|
// term = Term::Apply {
|
||||||
|
// function: Term::Var { text: "co" },
|
||||||
|
// argument: (),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
//if statements increase scope due to branching.
|
//if statements increase scope due to branching.
|
||||||
TypedExpr::If {
|
TypedExpr::If {
|
||||||
branches,
|
branches,
|
||||||
|
|
|
@ -16,8 +16,8 @@ pub fn spend(datum: sample.Datum, rdmr: Redeemer, ctx: spend.ScriptContext) -> B
|
||||||
let b = datum.rdmr
|
let b = datum.rdmr
|
||||||
|
|
||||||
when b is {
|
when b is {
|
||||||
sample.Buy -> True
|
sample.Buy | sample.Sell -> 1 == 1
|
||||||
sample.Sell -> False
|
sample.Sell -> 5 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue