Skip to content

Commit

Permalink
fix minor scope issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Dec 4, 2022
1 parent 5927265 commit d7ff170
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions crates/lang/src/uplc.rs
Expand Up @@ -83,7 +83,7 @@ impl Default for ScopeLevels {
}
}

#[derive(Clone, Eq, PartialEq, Hash)]
#[derive(Clone, Eq, Debug, PartialEq, Hash)]
pub struct ConstrFieldKey {
pub local_var: String,
pub field_name: String,
Expand All @@ -103,7 +103,7 @@ pub struct FunctionAccessKey {
pub function_name: String,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ConstrConversionInfo {
local_var: String,
field: Option<String>,
Expand All @@ -112,7 +112,7 @@ pub struct ConstrConversionInfo {
returning_type: String,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ScopedExpr {
scope: ScopeLevels,
expr: TypedExpr,
Expand Down Expand Up @@ -169,6 +169,13 @@ impl<'a> CodeGenerator<'a> {
}
});

println!("DATA HOLDER LOOKUP{:#?}", self.uplc_data_holder_lookup);

println!(
"DATA USAGE HOLDER {:#?}",
self.uplc_data_usage_holder_lookup
);

let mut term = self.recurse_code_gen(&body, ScopeLevels::new());

// Apply constr exposer to top level.
Expand Down Expand Up @@ -250,7 +257,7 @@ impl<'a> CodeGenerator<'a> {
}

pub(crate) fn recurse_scope_level(&mut self, body: &TypedExpr, scope_level: ScopeLevels) {
match body {
match dbg!(body) {
TypedExpr::Int { .. } => {}
TypedExpr::String { .. } => {}
TypedExpr::ByteArray { .. } => {}
Expand Down Expand Up @@ -330,7 +337,7 @@ impl<'a> CodeGenerator<'a> {
}
}
TypedExpr::Call { fun, args, .. } => {
self.recurse_scope_level(fun, scope_level.scope_increment(1));
self.recurse_scope_level(fun, scope_level.clone());

for (index, arg) in args.iter().enumerate() {
self.recurse_scope_level(
Expand All @@ -343,13 +350,11 @@ impl<'a> CodeGenerator<'a> {
self.recurse_scope_level(left, scope_level.clone());
self.recurse_scope_level(right, scope_level);
}
TypedExpr::Assignment { value, pattern, .. } => self.recurse_scope_level_pattern(
pattern,
value,
scope_level.scope_increment(1),
&[],
),
TypedExpr::Trace { .. } => todo!(),
TypedExpr::Assignment { value, pattern, .. } => {
self.recurse_scope_level_pattern(pattern, value, scope_level, &[])
}
TypedExpr::Trace {..} => todo!(),
TypedExpr::Try { .. } => todo!(),
TypedExpr::When {
subjects, clauses, ..
} => {
Expand Down Expand Up @@ -600,7 +605,7 @@ impl<'a> CodeGenerator<'a> {
}
};

let module = module.clone().unwrap();
let module = module.clone().unwrap_or_default();
// TODO: support multiple subjects
let (var_name, tipo) = match &vars[0] {
TypedExpr::Var {
Expand Down Expand Up @@ -780,8 +785,8 @@ impl<'a> CodeGenerator<'a> {
let mut term = self
.recurse_code_gen(exp, scope_level.scope_increment_sequence(i as i32 + 1));

term = self
.maybe_insert_def(term, scope_level.scope_increment_sequence(i as i32 + 1));
term =
self.maybe_insert_def(term, scope_level.scope_increment_sequence(i as i32));

self.uplc_function_holder
.push((String::new(), term.clone()));
Expand Down Expand Up @@ -1590,7 +1595,8 @@ impl<'a> CodeGenerator<'a> {
}
Pattern::List { .. } => None,
Pattern::Discard { .. } => None,
_ => todo!(),
Pattern::Int { .. } => None,
rest => todo!("{rest:?}"),
};

if let Some(key) = key {
Expand Down Expand Up @@ -1655,7 +1661,14 @@ impl<'a> CodeGenerator<'a> {

(index.unwrap_or(dt.constructors.len()), current_term)
}
_ => todo!(),
Pattern::Discard { .. } => (
dt.constructors.len(),
self.recurse_code_gen(
&clause.then,
scope_level.scope_increment_sequence(1),
),
),
rest => todo!("{rest:?}"),
};
pair
})
Expand Down Expand Up @@ -1753,7 +1766,7 @@ impl<'a> CodeGenerator<'a> {
// Skip first type since we know we have a list
let tipo = match subject {
TypedExpr::Var { constructor, .. } => &constructor.tipo,
_ => todo!(),
rest => todo!("{rest:?}"),
};
let mut current_tipo = match (**tipo).clone() {
Type::App { args, .. } => (*args[0]).clone(),
Expand Down Expand Up @@ -2672,6 +2685,9 @@ impl<'a> CodeGenerator<'a> {
}
});

println!("SCOPE LEVEL IS {scope_level:#?}");
println!("DATA HOLDER COMBINED {:#?}", data_holder);

for ConstrConversionInfo {
local_var,
field,
Expand Down

0 comments on commit d7ff170

Please sign in to comment.