remove some warnings and start on when

This commit is contained in:
Kasey White 2022-11-06 18:31:02 -05:00 committed by Lucas
parent 805bf19081
commit 28697586f2
2 changed files with 58 additions and 63 deletions

View File

@ -9,7 +9,9 @@ use uplc::{
}; };
use crate::{ use crate::{
ast::{DataType, Function, ModuleConstant, Pattern, TypeAlias, TypedArg, Use}, ast::{
BinOp, DataType, Function, ModuleConstant, Pattern, TypeAlias, TypedArg, TypedPattern, Use,
},
expr::TypedExpr, expr::TypedExpr,
tipo::{self, ModuleValueConstructor, Type, ValueConstructorVariant}, tipo::{self, ModuleValueConstructor, Type, ValueConstructorVariant},
}; };
@ -86,6 +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_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>>>,
@ -106,6 +109,7 @@ impl<'a> CodeGenerator<'a> {
uplc_function_holder: Vec::new(), uplc_function_holder: Vec::new(),
uplc_function_holder_lookup: IndexMap::new(), uplc_function_holder_lookup: IndexMap::new(),
uplc_data_holder_lookup: IndexMap::new(), uplc_data_holder_lookup: IndexMap::new(),
uplc_when_lookup: IndexMap::new(),
uplc_data_usage_holder_lookup: IndexMap::new(), uplc_data_usage_holder_lookup: IndexMap::new(),
functions, functions,
type_aliases, type_aliases,
@ -447,10 +451,7 @@ impl<'a> CodeGenerator<'a> {
pattern, pattern,
} => todo!(), } => todo!(),
TypedExpr::When { TypedExpr::When {
location, subjects, clauses, ..
tipo,
subjects,
clauses,
} => { } => {
for clause in clauses { for clause in clauses {
for pattern in clause.pattern.iter() { for pattern in clause.pattern.iter() {
@ -458,9 +459,12 @@ impl<'a> CodeGenerator<'a> {
pattern, pattern,
&clause.then, &clause.then,
scope_level.scope_increment_sequence(1), scope_level.scope_increment_sequence(1),
) );
} }
} }
for subject in subjects {
self.recurse_scope_level(subject, scope_level.clone());
}
todo!() todo!()
} }
//if statements increase scope due to branching. //if statements increase scope due to branching.
@ -488,7 +492,7 @@ impl<'a> CodeGenerator<'a> {
let mut current_var_name = "".to_string(); let mut current_var_name = "".to_string();
let mut module = "".to_string(); let mut module = "".to_string();
let mut current_record = *record.clone(); let mut current_record = *record.clone();
let mut current_scope = scope_level.clone(); let mut current_scope = scope_level;
while !is_var { while !is_var {
match current_record.clone() { match current_record.clone() {
TypedExpr::Var { TypedExpr::Var {
@ -599,7 +603,7 @@ impl<'a> CodeGenerator<'a> {
); );
} }
} }
ModuleValueConstructor::Constant { literal, location } => todo!(), ModuleValueConstructor::Constant { .. } => todo!(),
}, },
TypedExpr::Todo { TypedExpr::Todo {
location, location,
@ -616,9 +620,9 @@ impl<'a> CodeGenerator<'a> {
} }
} }
fn recurse_scope_level_pattern<Constructor, Type>( fn recurse_scope_level_pattern(
&mut self, &mut self,
pattern: &Pattern<Constructor, Type>, pattern: &TypedPattern,
value: &TypedExpr, value: &TypedExpr,
scope_level: ScopeLevels, scope_level: ScopeLevels,
) { ) {
@ -653,6 +657,18 @@ impl<'a> CodeGenerator<'a> {
tipo, tipo,
} => { } => {
self.recurse_scope_level(value, scope_level); self.recurse_scope_level(value, scope_level);
match &**tipo {
Type::App {
public,
module,
name,
args,
} => todo!(),
_ => todo!(),
};
// self.data_types.get();
todo!() todo!()
} }
} }
@ -667,10 +683,7 @@ impl<'a> CodeGenerator<'a> {
TypedExpr::ByteArray { bytes, .. } => { TypedExpr::ByteArray { bytes, .. } => {
Term::Constant(Constant::ByteString(bytes.clone())) Term::Constant(Constant::ByteString(bytes.clone()))
} }
TypedExpr::Sequence { TypedExpr::Sequence { expressions, .. } => {
location,
expressions,
} => {
for (i, exp) in expressions.iter().enumerate().rev() { for (i, exp) in expressions.iter().enumerate().rev() {
let mut term = self let mut term = self
.recurse_code_gen(exp, scope_level.scope_increment_sequence(i as i32 + 1)); .recurse_code_gen(exp, scope_level.scope_increment_sequence(i as i32 + 1));
@ -685,19 +698,17 @@ impl<'a> CodeGenerator<'a> {
self.uplc_function_holder.pop().unwrap().1 self.uplc_function_holder.pop().unwrap().1
} }
TypedExpr::Pipeline { TypedExpr::Pipeline {
location, expressions: _expressions,
expressions, ..
} => todo!(), } => todo!(),
TypedExpr::Var { TypedExpr::Var {
location, constructor, name, ..
constructor,
name,
} => { } => {
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 constructor.variant.clone() { match constructor.variant.clone() {
ValueConstructorVariant::LocalVariable { location } => Term::Var(Name { ValueConstructorVariant::LocalVariable { .. } => Term::Var(Name {
text: name.to_string(), text: name.to_string(),
unique: 0.into(), unique: 0.into(),
}), }),
@ -739,12 +750,7 @@ impl<'a> CodeGenerator<'a> {
elements, elements,
tail, tail,
} => todo!(), } => todo!(),
TypedExpr::Call { TypedExpr::Call { fun, args, .. } => {
location,
tipo,
fun,
args,
} => {
let mut term = let mut term =
self.recurse_code_gen(fun, scope_level.scope_increment(args.len() as i32 + 1)); self.recurse_code_gen(fun, scope_level.scope_increment(args.len() as i32 + 1));
@ -760,24 +766,15 @@ impl<'a> CodeGenerator<'a> {
term term
} }
TypedExpr::BinOp { TypedExpr::BinOp {
location, name, left, right, ..
tipo,
name,
left,
right,
} => { } => {
let left_term = self.recurse_code_gen(left, scope_level.clone()); let left_term = self.recurse_code_gen(left, scope_level.clone());
let right_term = self.recurse_code_gen(right, scope_level); let right_term = self.recurse_code_gen(right, scope_level);
println!("NAME IS {name:#?}"); println!("NAME IS {name:#?}");
match name { match name {
Eq => match &*left.tipo() { BinOp::Eq => match &*left.tipo() {
Type::App { Type::App { name, .. } => match name.as_str() {
public,
module,
name,
args,
} => match name.as_str() {
"Int" => Term::Apply { "Int" => Term::Apply {
function: Term::Apply { function: Term::Apply {
function: Term::Builtin(DefaultFunction::EqualsInteger).into(), function: Term::Builtin(DefaultFunction::EqualsInteger).into(),
@ -801,30 +798,24 @@ impl<'a> CodeGenerator<'a> {
Type::Fn { args, ret } => todo!(), Type::Fn { args, ret } => todo!(),
Type::Var { tipo } => todo!(), Type::Var { tipo } => todo!(),
}, },
And => todo!(), BinOp::And => todo!(),
Or => todo!(), BinOp::Or => todo!(),
NotEq => todo!(), BinOp::NotEq => todo!(),
LtInt => todo!(), BinOp::LtInt => todo!(),
LtEqInt => todo!(), BinOp::LtEqInt => todo!(),
GtEqInt => todo!(), BinOp::GtEqInt => todo!(),
GtInt => todo!(), BinOp::GtInt => todo!(),
AddInt => todo!(), BinOp::AddInt => todo!(),
SubInt => todo!(), BinOp::SubInt => todo!(),
MultInt => todo!(), BinOp::MultInt => todo!(),
DivInt => todo!(), BinOp::DivInt => todo!(),
ModInt => todo!(), BinOp::ModInt => todo!(),
} }
} }
TypedExpr::Assignment { TypedExpr::Assignment { value, pattern, .. } => match pattern {
location, Pattern::Int { .. } => todo!(),
tipo, Pattern::String { .. } => todo!(),
value, Pattern::Var { name, .. } => Term::Apply {
pattern,
kind,
} => match pattern {
Pattern::Int { location, value } => todo!(),
Pattern::String { location, value } => todo!(),
Pattern::Var { location, name } => Term::Apply {
function: Term::Lambda { function: Term::Lambda {
parameter_name: Name { parameter_name: Name {
text: name.to_string(), text: name.to_string(),
@ -848,7 +839,7 @@ impl<'a> CodeGenerator<'a> {
location, location,
pattern, pattern,
} => todo!(), } => todo!(),
Pattern::Discard { name, location } => todo!(), Pattern::Discard { .. } => todo!(),
Pattern::List { Pattern::List {
location, location,
elements, elements,

View File

@ -14,6 +14,10 @@ pub fn spend(datum: sample.Datum, rdmr: Redeemer, ctx: spend.ScriptContext) -> B
let x = datum.sc.signer let x = datum.sc.signer
let a = datum.sc.signer.hash let a = datum.sc.signer.hash
let b = datum.rdmr let b = datum.rdmr
let c = 1
c == 1 when b is {
sample.Buy -> True
sample.Sell -> False
}
} }