feat: rename ir to air
This commit is contained in:
parent
24d724e10e
commit
ed3d143477
|
@ -7,10 +7,8 @@ use crate::{
|
||||||
tipo::{Type, ValueConstructor},
|
tipo::{Type, ValueConstructor},
|
||||||
};
|
};
|
||||||
|
|
||||||
// []
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum IR {
|
pub enum Air {
|
||||||
Int {
|
Int {
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
value: String,
|
value: String,
|
||||||
|
@ -236,78 +234,41 @@ pub enum IR {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IR {
|
impl Air {
|
||||||
pub fn scope(&self) -> Vec<u64> {
|
pub fn scope(&self) -> Vec<u64> {
|
||||||
match self {
|
match self {
|
||||||
IR::Int { scope, .. }
|
Air::Int { scope, .. }
|
||||||
| IR::String { scope, .. }
|
| Air::String { scope, .. }
|
||||||
| IR::ByteArray { scope, .. }
|
| Air::ByteArray { scope, .. }
|
||||||
| IR::Var { scope, .. }
|
| Air::Var { scope, .. }
|
||||||
| IR::List { scope, .. }
|
| Air::List { scope, .. }
|
||||||
| IR::Tail { scope, .. }
|
| Air::Tail { scope, .. }
|
||||||
| IR::ListAccessor { scope, .. }
|
| Air::ListAccessor { scope, .. }
|
||||||
| IR::ListExpose { scope, .. }
|
| Air::ListExpose { scope, .. }
|
||||||
| IR::Call { scope, .. }
|
| Air::Call { scope, .. }
|
||||||
| IR::Builtin { scope, .. }
|
| Air::Builtin { scope, .. }
|
||||||
| IR::BinOp { scope, .. }
|
| Air::BinOp { scope, .. }
|
||||||
| IR::Assignment { scope, .. }
|
| Air::Assignment { scope, .. }
|
||||||
| IR::DefineFunc { scope, .. }
|
| Air::DefineFunc { scope, .. }
|
||||||
| IR::DefineConst { scope, .. }
|
| Air::DefineConst { scope, .. }
|
||||||
| IR::DefineConstrFields { scope, .. }
|
| Air::DefineConstrFields { scope, .. }
|
||||||
| IR::DefineConstrFieldAccess { scope, .. }
|
| Air::DefineConstrFieldAccess { scope, .. }
|
||||||
| IR::Lam { scope, .. }
|
| Air::Lam { scope, .. }
|
||||||
| IR::When { scope, .. }
|
| Air::When { scope, .. }
|
||||||
| IR::Clause { scope, .. }
|
| Air::Clause { scope, .. }
|
||||||
| IR::ListClause { scope, .. }
|
| Air::ListClause { scope, .. }
|
||||||
| IR::ClauseGuard { scope, .. }
|
| Air::ClauseGuard { scope, .. }
|
||||||
| IR::Discard { scope }
|
| Air::Discard { scope }
|
||||||
| IR::Finally { scope }
|
| Air::Finally { scope }
|
||||||
| IR::If { scope, .. }
|
| Air::If { scope, .. }
|
||||||
| IR::Constr { scope, .. }
|
| Air::Constr { scope, .. }
|
||||||
| IR::Fields { scope, .. }
|
| Air::Fields { scope, .. }
|
||||||
| IR::RecordAccess { scope, .. }
|
| Air::RecordAccess { scope, .. }
|
||||||
| IR::FieldsExpose { scope, .. }
|
| Air::FieldsExpose { scope, .. }
|
||||||
| IR::Todo { scope, .. }
|
| Air::Todo { scope, .. }
|
||||||
| IR::Record { scope, .. }
|
| Air::Record { scope, .. }
|
||||||
| IR::RecordUpdate { scope, .. }
|
| Air::RecordUpdate { scope, .. }
|
||||||
| IR::Negate { scope, .. } => scope.to_vec(),
|
| Air::Negate { scope, .. } => scope.to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// pub fn get(r: Int) -> This{g: Int}{
|
|
||||||
// This{ g: r }
|
|
||||||
// }
|
|
||||||
//let x = get(rdmr) when datum is { Hold(h, thing: f) -> h > x.g, Sell{price} -> x.g == price }
|
|
||||||
|
|
||||||
// [ When(3) datum_var Clause(2) FieldsExpose(3) datum_var h_field_var f_field_var Binop(Greater, 2) h_var FieldAccess(2) x_var g_field Finally(2) Binop(2, EqualsInteger) FieldAccess x_var g_field_var ]
|
|
||||||
|
|
||||||
// [ Assignment(2) ]
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var ]
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var Call(2) ]
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var Call(2) func_get_var ]
|
|
||||||
// ^Mark this index function insertion
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var Call(2) func_get_var rdmr_var When(4)]
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var Call(2) func_get_var ]
|
|
||||||
|
|
||||||
// (var rdmr)
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var Call(2) ]
|
|
||||||
|
|
||||||
// (var func_get)
|
|
||||||
|
|
||||||
// arg stack [ (var rdmr)]
|
|
||||||
|
|
||||||
// [ Assignment(2) x_var ]
|
|
||||||
|
|
||||||
// [(var func_get) (var rdmr)]
|
|
||||||
|
|
||||||
// [ Assignment(2)]
|
|
||||||
|
|
||||||
// (var x)
|
|
||||||
|
|
||||||
// arg stack [ [(var func_get) (var rdmr)] ]
|
|
|
@ -3,11 +3,11 @@ use std::sync::{
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub mod air;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
pub mod builtins;
|
pub mod builtins;
|
||||||
pub mod expr;
|
pub mod expr;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod ir;
|
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod pretty;
|
pub mod pretty;
|
||||||
pub mod tipo;
|
pub mod tipo;
|
||||||
|
|
|
@ -13,19 +13,19 @@ use uplc::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
air::Air,
|
||||||
ast::{
|
ast::{
|
||||||
ArgName, AssignmentKind, BinOp, Clause, Constant, DataType, Function, Pattern, Span,
|
ArgName, AssignmentKind, BinOp, Clause, Constant, DataType, Function, Pattern, Span,
|
||||||
TypedArg,
|
TypedArg,
|
||||||
},
|
},
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
ir::IR,
|
|
||||||
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
|
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct FuncComponents {
|
pub struct FuncComponents {
|
||||||
ir: Vec<IR>,
|
ir: Vec<Air>,
|
||||||
dependencies: Vec<FunctionAccessKey>,
|
dependencies: Vec<FunctionAccessKey>,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
|
@ -100,12 +100,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
self.build_ir(&body, &mut ir_stack, scope);
|
self.build_ir(&body, &mut ir_stack, scope);
|
||||||
|
|
||||||
println!("INITIAL: {ir_stack:#?}");
|
|
||||||
|
|
||||||
self.define_ir(&mut ir_stack);
|
self.define_ir(&mut ir_stack);
|
||||||
|
|
||||||
println!("AFTER FUNCTION DEFINITIONS: {ir_stack:#?}");
|
|
||||||
|
|
||||||
let mut term = self.uplc_code_gen(&mut ir_stack);
|
let mut term = self.uplc_code_gen(&mut ir_stack);
|
||||||
|
|
||||||
if self.needs_field_access {
|
if self.needs_field_access {
|
||||||
|
@ -134,24 +130,22 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let mut interner = Interner::new();
|
let mut interner = Interner::new();
|
||||||
|
|
||||||
println!("{}", program.to_pretty());
|
|
||||||
|
|
||||||
interner.program(&mut program);
|
interner.program(&mut program);
|
||||||
|
|
||||||
program
|
program
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build_ir(&mut self, body: &TypedExpr, ir_stack: &mut Vec<IR>, scope: Vec<u64>) {
|
pub(crate) fn build_ir(&mut self, body: &TypedExpr, ir_stack: &mut Vec<Air>, scope: Vec<u64>) {
|
||||||
match body {
|
match body {
|
||||||
TypedExpr::Int { value, .. } => ir_stack.push(IR::Int {
|
TypedExpr::Int { value, .. } => ir_stack.push(Air::Int {
|
||||||
scope,
|
scope,
|
||||||
value: value.to_string(),
|
value: value.to_string(),
|
||||||
}),
|
}),
|
||||||
TypedExpr::String { value, .. } => ir_stack.push(IR::String {
|
TypedExpr::String { value, .. } => ir_stack.push(Air::String {
|
||||||
scope,
|
scope,
|
||||||
value: value.to_string(),
|
value: value.to_string(),
|
||||||
}),
|
}),
|
||||||
TypedExpr::ByteArray { bytes, .. } => ir_stack.push(IR::ByteArray {
|
TypedExpr::ByteArray { bytes, .. } => ir_stack.push(Air::ByteArray {
|
||||||
scope,
|
scope,
|
||||||
bytes: bytes.to_vec(),
|
bytes: bytes.to_vec(),
|
||||||
}),
|
}),
|
||||||
|
@ -172,7 +166,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
TypedExpr::Var {
|
TypedExpr::Var {
|
||||||
constructor, name, ..
|
constructor, name, ..
|
||||||
} => {
|
} => {
|
||||||
ir_stack.push(IR::Var {
|
ir_stack.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: constructor.clone(),
|
constructor: constructor.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
|
@ -185,7 +179,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tipo,
|
tipo,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
ir_stack.push(IR::List {
|
ir_stack.push(Air::List {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
count: if tail.is_some() {
|
count: if tail.is_some() {
|
||||||
elements.len() + 1
|
elements.len() + 1
|
||||||
|
@ -210,7 +204,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypedExpr::Call { fun, args, .. } => {
|
TypedExpr::Call { fun, args, .. } => {
|
||||||
ir_stack.push(IR::Call {
|
ir_stack.push(Air::Call {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
count: args.len() + 1,
|
count: args.len() + 1,
|
||||||
});
|
});
|
||||||
|
@ -227,7 +221,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
TypedExpr::BinOp {
|
TypedExpr::BinOp {
|
||||||
name, left, right, ..
|
name, left, right, ..
|
||||||
} => {
|
} => {
|
||||||
ir_stack.push(IR::BinOp {
|
ir_stack.push(Air::BinOp {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
name: *name,
|
name: *name,
|
||||||
count: 2,
|
count: 2,
|
||||||
|
@ -249,9 +243,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tipo,
|
tipo,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut define_vec: Vec<IR> = vec![];
|
let mut define_vec: Vec<Air> = vec![];
|
||||||
let mut value_vec: Vec<IR> = vec![];
|
let mut value_vec: Vec<Air> = vec![];
|
||||||
let mut pattern_vec: Vec<IR> = vec![];
|
let mut pattern_vec: Vec<Air> = vec![];
|
||||||
|
|
||||||
let mut value_scope = scope.clone();
|
let mut value_scope = scope.clone();
|
||||||
value_scope.push(self.id_gen.next());
|
value_scope.push(self.id_gen.next());
|
||||||
|
@ -304,7 +298,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let mut scope = scope.clone();
|
let mut scope = scope.clone();
|
||||||
scope.push(self.id_gen.next());
|
scope.push(self.id_gen.next());
|
||||||
|
|
||||||
// holds when clause pattern IR
|
// holds when clause pattern Air
|
||||||
let mut clause_subject_vec = vec![];
|
let mut clause_subject_vec = vec![];
|
||||||
|
|
||||||
// reset complex clause setting per clause back to default
|
// reset complex clause setting per clause back to default
|
||||||
|
@ -331,7 +325,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
format!("__tail_{}", clause_properties.current_index - 1)
|
format!("__tail_{}", clause_properties.current_index - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clause is first in IR pattern vec
|
// Clause is first in Air pattern vec
|
||||||
if subject.tipo().is_list() {
|
if subject.tipo().is_list() {
|
||||||
let next_tail = if index == clauses.len() - 1 {
|
let next_tail = if index == clauses.len() - 1 {
|
||||||
None
|
None
|
||||||
|
@ -339,7 +333,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Some(format!("__tail_{}", clause_properties.current_index))
|
Some(format!("__tail_{}", clause_properties.current_index))
|
||||||
};
|
};
|
||||||
|
|
||||||
pattern_vec.push(IR::ListClause {
|
pattern_vec.push(Air::ListClause {
|
||||||
scope,
|
scope,
|
||||||
tipo: subject.tipo().clone(),
|
tipo: subject.tipo().clone(),
|
||||||
tail_name: subject_name,
|
tail_name: subject_name,
|
||||||
|
@ -349,7 +343,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
clause_properties.current_index += 1;
|
clause_properties.current_index += 1;
|
||||||
} else {
|
} else {
|
||||||
pattern_vec.push(IR::Clause {
|
pattern_vec.push(Air::Clause {
|
||||||
scope,
|
scope,
|
||||||
tipo: subject.tipo().clone(),
|
tipo: subject.tipo().clone(),
|
||||||
subject_name,
|
subject_name,
|
||||||
|
@ -364,7 +358,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let mut final_scope = scope.clone();
|
let mut final_scope = scope.clone();
|
||||||
final_scope.push(self.id_gen.next());
|
final_scope.push(self.id_gen.next());
|
||||||
pattern_vec.push(IR::Finally {
|
pattern_vec.push(Air::Finally {
|
||||||
scope: final_scope.clone(),
|
scope: final_scope.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -380,14 +374,14 @@ impl<'a> CodeGenerator<'a> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if needs_subject_var || clause_properties.needs_constr_var {
|
if needs_subject_var || clause_properties.needs_constr_var {
|
||||||
ir_stack.push(IR::Lam {
|
ir_stack.push(Air::Lam {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
name: constr_var.clone(),
|
name: constr_var.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.build_ir(&subject, ir_stack, scope.clone());
|
self.build_ir(&subject, ir_stack, scope.clone());
|
||||||
|
|
||||||
ir_stack.push(IR::When {
|
ir_stack.push(Air::When {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
subject_name,
|
subject_name,
|
||||||
tipo: subject.tipo(),
|
tipo: subject.tipo(),
|
||||||
|
@ -396,7 +390,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let mut scope = scope;
|
let mut scope = scope;
|
||||||
scope.push(self.id_gen.next());
|
scope.push(self.id_gen.next());
|
||||||
|
|
||||||
ir_stack.push(IR::Var {
|
ir_stack.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
subject.tipo(),
|
subject.tipo(),
|
||||||
|
@ -407,7 +401,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
name: constr_var,
|
name: constr_var,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ir_stack.push(IR::When {
|
ir_stack.push(Air::When {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
subject_name,
|
subject_name,
|
||||||
tipo: subject.tipo(),
|
tipo: subject.tipo(),
|
||||||
|
@ -434,11 +428,11 @@ impl<'a> CodeGenerator<'a> {
|
||||||
branch_scope.push(self.id_gen.next());
|
branch_scope.push(self.id_gen.next());
|
||||||
|
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
if_ir.push(IR::If {
|
if_ir.push(Air::If {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if_ir.push(IR::If {
|
if_ir.push(Air::If {
|
||||||
scope: branch_scope.clone(),
|
scope: branch_scope.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -461,7 +455,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
} => {
|
} => {
|
||||||
self.needs_field_access = true;
|
self.needs_field_access = true;
|
||||||
|
|
||||||
ir_stack.push(IR::RecordAccess {
|
ir_stack.push(Air::RecordAccess {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
index: *index,
|
index: *index,
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
|
@ -482,7 +476,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(func) = func {
|
if let Some(func) = func {
|
||||||
ir_stack.push(IR::Var {
|
ir_stack.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
func.return_type.clone(),
|
func.return_type.clone(),
|
||||||
|
@ -504,7 +498,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
ValueConstructorVariant::ModuleFn { builtin, .. } => {
|
ValueConstructorVariant::ModuleFn { builtin, .. } => {
|
||||||
let builtin = builtin.unwrap();
|
let builtin = builtin.unwrap();
|
||||||
|
|
||||||
ir_stack.push(IR::Builtin {
|
ir_stack.push(Air::Builtin {
|
||||||
func: builtin,
|
func: builtin,
|
||||||
scope,
|
scope,
|
||||||
});
|
});
|
||||||
|
@ -518,7 +512,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TypedExpr::Todo { label, tipo, .. } => {
|
TypedExpr::Todo { label, tipo, .. } => {
|
||||||
ir_stack.push(IR::Todo {
|
ir_stack.push(Air::Todo {
|
||||||
scope,
|
scope,
|
||||||
label: label.clone(),
|
label: label.clone(),
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
|
@ -533,15 +527,15 @@ impl<'a> CodeGenerator<'a> {
|
||||||
fn when_ir(
|
fn when_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
||||||
pattern_vec: &mut Vec<IR>,
|
pattern_vec: &mut Vec<Air>,
|
||||||
values: &mut Vec<IR>,
|
values: &mut Vec<Air>,
|
||||||
tipo: &Type,
|
tipo: &Type,
|
||||||
clause_properties: &mut ClauseProperties,
|
clause_properties: &mut ClauseProperties,
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
) {
|
) {
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern::Int { value, .. } => {
|
Pattern::Int { value, .. } => {
|
||||||
pattern_vec.push(IR::Int {
|
pattern_vec.push(Air::Int {
|
||||||
scope,
|
scope,
|
||||||
value: value.clone(),
|
value: value.clone(),
|
||||||
});
|
});
|
||||||
|
@ -550,15 +544,15 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
Pattern::String { .. } => todo!(),
|
Pattern::String { .. } => todo!(),
|
||||||
Pattern::Var { name, .. } => {
|
Pattern::Var { name, .. } => {
|
||||||
pattern_vec.push(IR::Discard {
|
pattern_vec.push(Air::Discard {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
});
|
});
|
||||||
pattern_vec.push(IR::Lam {
|
pattern_vec.push(Air::Lam {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
pattern_vec.push(IR::Var {
|
pattern_vec.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
tipo.clone().into(),
|
tipo.clone().into(),
|
||||||
|
@ -573,11 +567,11 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Pattern::VarUsage { .. } => todo!(),
|
Pattern::VarUsage { .. } => todo!(),
|
||||||
Pattern::Assign { name, pattern, .. } => {
|
Pattern::Assign { name, pattern, .. } => {
|
||||||
let mut new_vec = vec![];
|
let mut new_vec = vec![];
|
||||||
new_vec.push(IR::Lam {
|
new_vec.push(Air::Lam {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
});
|
});
|
||||||
new_vec.push(IR::Var {
|
new_vec.push(Air::Var {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
tipo.clone().into(),
|
tipo.clone().into(),
|
||||||
|
@ -601,7 +595,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Pattern::Discard { .. } => {
|
Pattern::Discard { .. } => {
|
||||||
pattern_vec.push(IR::Discard { scope });
|
pattern_vec.push(Air::Discard { scope });
|
||||||
pattern_vec.append(values);
|
pattern_vec.append(values);
|
||||||
}
|
}
|
||||||
Pattern::List { elements, tail, .. } => {
|
Pattern::List { elements, tail, .. } => {
|
||||||
|
@ -619,7 +613,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
clause_properties.is_complex_clause = true;
|
clause_properties.is_complex_clause = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern_vec.push(IR::Discard {
|
pattern_vec.push(Air::Discard {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -674,7 +668,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.find(|(_, dt)| &dt.name == constr_name)
|
.find(|(_, dt)| &dt.name == constr_name)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut new_vec = vec![IR::Var {
|
let mut new_vec = vec![Air::Var {
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
tipo.clone().into(),
|
tipo.clone().into(),
|
||||||
ValueConstructorVariant::LocalVariable {
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
@ -688,7 +682,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
// if only one constructor, no need to check
|
// if only one constructor, no need to check
|
||||||
if data_type.constructors.len() > 1 {
|
if data_type.constructors.len() > 1 {
|
||||||
// push constructor Index
|
// push constructor Index
|
||||||
pattern_vec.push(IR::Int {
|
pattern_vec.push(Air::Int {
|
||||||
value: index.to_string(),
|
value: index.to_string(),
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
});
|
});
|
||||||
|
@ -729,8 +723,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
fn when_recursive_ir(
|
fn when_recursive_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
||||||
pattern_vec: &mut Vec<IR>,
|
pattern_vec: &mut Vec<Air>,
|
||||||
values: &mut Vec<IR>,
|
values: &mut Vec<Air>,
|
||||||
clause_properties: ClauseProperties,
|
clause_properties: ClauseProperties,
|
||||||
_tipo: &Type,
|
_tipo: &Type,
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
|
@ -742,7 +736,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Pattern::VarUsage { .. } => todo!(),
|
Pattern::VarUsage { .. } => todo!(),
|
||||||
Pattern::Assign { .. } => todo!(),
|
Pattern::Assign { .. } => todo!(),
|
||||||
Pattern::Discard { .. } => {
|
Pattern::Discard { .. } => {
|
||||||
pattern_vec.push(IR::Discard { scope });
|
pattern_vec.push(Air::Discard { scope });
|
||||||
|
|
||||||
pattern_vec.append(values);
|
pattern_vec.append(values);
|
||||||
}
|
}
|
||||||
|
@ -763,7 +757,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
// let mut var_vec = vec![];
|
// let mut var_vec = vec![];
|
||||||
// let item_name = format!("list_item_id_{}", self.id_gen.next());
|
// let item_name = format!("list_item_id_{}", self.id_gen.next());
|
||||||
// names.push(item_name.clone());
|
// names.push(item_name.clone());
|
||||||
// var_vec.push(IR::Var {
|
// var_vec.push(Air::Var {
|
||||||
// constructor: ValueConstructor::public(
|
// constructor: ValueConstructor::public(
|
||||||
// Type::App {
|
// Type::App {
|
||||||
// public: true,
|
// public: true,
|
||||||
|
@ -820,13 +814,13 @@ impl<'a> CodeGenerator<'a> {
|
||||||
format!("__tail_{}", elements.len() - 2)
|
format!("__tail_{}", elements.len() - 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
pattern_vec.push(IR::ListExpose {
|
pattern_vec.push(Air::ListExpose {
|
||||||
scope,
|
scope,
|
||||||
tail_head_names,
|
tail_head_names,
|
||||||
tail: Some((tail_var, tail_name)),
|
tail: Some((tail_var, tail_name)),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pattern_vec.push(IR::ListExpose {
|
pattern_vec.push(Air::ListExpose {
|
||||||
scope,
|
scope,
|
||||||
tail_head_names,
|
tail_head_names,
|
||||||
tail: None,
|
tail: None,
|
||||||
|
@ -916,7 +910,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let data_type = self.data_types.get(&data_type_key).unwrap();
|
let data_type = self.data_types.get(&data_type_key).unwrap();
|
||||||
|
|
||||||
if data_type.constructors.len() > 1 {
|
if data_type.constructors.len() > 1 {
|
||||||
nested_pattern.push(IR::ClauseGuard {
|
nested_pattern.push(Air::ClauseGuard {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
subject_name: constr_var_name.clone(),
|
subject_name: constr_var_name.clone(),
|
||||||
|
@ -952,7 +946,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.collect::<Vec<(String, String, usize, bool)>>();
|
.collect::<Vec<(String, String, usize, bool)>>();
|
||||||
|
|
||||||
if !arguments_index.is_empty() {
|
if !arguments_index.is_empty() {
|
||||||
pattern_vec.push(IR::FieldsExpose {
|
pattern_vec.push(Air::FieldsExpose {
|
||||||
count: arguments_index.len() + 2,
|
count: arguments_index.len() + 2,
|
||||||
indices: arguments_index
|
indices: arguments_index
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1006,7 +1000,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let data_type = self.data_types.get(&data_type_key).unwrap();
|
let data_type = self.data_types.get(&data_type_key).unwrap();
|
||||||
|
|
||||||
if data_type.constructors.len() > 1 {
|
if data_type.constructors.len() > 1 {
|
||||||
nested_pattern.push(IR::ClauseGuard {
|
nested_pattern.push(Air::ClauseGuard {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
subject_name: constr_var_name.clone(),
|
subject_name: constr_var_name.clone(),
|
||||||
|
@ -1040,7 +1034,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.collect::<Vec<(String, usize, bool)>>();
|
.collect::<Vec<(String, usize, bool)>>();
|
||||||
|
|
||||||
if !arguments_index.is_empty() {
|
if !arguments_index.is_empty() {
|
||||||
pattern_vec.push(IR::FieldsExpose {
|
pattern_vec.push(Air::FieldsExpose {
|
||||||
count: arguments_index.len() + 2,
|
count: arguments_index.len() + 2,
|
||||||
indices: arguments_index
|
indices: arguments_index
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1065,8 +1059,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
fn assignment_ir(
|
fn assignment_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: &Pattern<tipo::PatternConstructor, Arc<Type>>,
|
pattern: &Pattern<tipo::PatternConstructor, Arc<Type>>,
|
||||||
pattern_vec: &mut Vec<IR>,
|
pattern_vec: &mut Vec<Air>,
|
||||||
value_vec: &mut Vec<IR>,
|
value_vec: &mut Vec<Air>,
|
||||||
_tipo: &Type,
|
_tipo: &Type,
|
||||||
kind: AssignmentKind,
|
kind: AssignmentKind,
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
|
@ -1075,7 +1069,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Pattern::Int { .. } => todo!(),
|
Pattern::Int { .. } => todo!(),
|
||||||
Pattern::String { .. } => todo!(),
|
Pattern::String { .. } => todo!(),
|
||||||
Pattern::Var { name, .. } => {
|
Pattern::Var { name, .. } => {
|
||||||
pattern_vec.push(IR::Assignment {
|
pattern_vec.push(Air::Assignment {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
kind,
|
kind,
|
||||||
scope,
|
scope,
|
||||||
|
@ -1099,8 +1093,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
fn pattern_ir(
|
fn pattern_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
pattern: &Pattern<tipo::PatternConstructor, Arc<tipo::Type>>,
|
||||||
pattern_vec: &mut Vec<IR>,
|
pattern_vec: &mut Vec<Air>,
|
||||||
values: &mut Vec<IR>,
|
values: &mut Vec<Air>,
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
) {
|
) {
|
||||||
match pattern {
|
match pattern {
|
||||||
|
@ -1110,7 +1104,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Pattern::VarUsage { .. } => todo!(),
|
Pattern::VarUsage { .. } => todo!(),
|
||||||
Pattern::Assign { .. } => todo!(),
|
Pattern::Assign { .. } => todo!(),
|
||||||
Pattern::Discard { .. } => {
|
Pattern::Discard { .. } => {
|
||||||
pattern_vec.push(IR::Discard { scope });
|
pattern_vec.push(Air::Discard { scope });
|
||||||
|
|
||||||
pattern_vec.append(values);
|
pattern_vec.append(values);
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1121,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let mut var_vec = vec![];
|
let mut var_vec = vec![];
|
||||||
let item_name = format!("list_item_id_{}", self.id_gen.next());
|
let item_name = format!("list_item_id_{}", self.id_gen.next());
|
||||||
names.push(item_name.clone());
|
names.push(item_name.clone());
|
||||||
var_vec.push(IR::Var {
|
var_vec.push(Air::Var {
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
Type::App {
|
Type::App {
|
||||||
public: true,
|
public: true,
|
||||||
|
@ -1157,7 +1151,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern_vec.push(IR::ListAccessor {
|
pattern_vec.push(Air::ListAccessor {
|
||||||
names,
|
names,
|
||||||
tail: tail.is_some(),
|
tail: tail.is_some(),
|
||||||
scope,
|
scope,
|
||||||
|
@ -1232,7 +1226,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
self.pattern_ir(
|
self.pattern_ir(
|
||||||
a,
|
a,
|
||||||
&mut nested_pattern,
|
&mut nested_pattern,
|
||||||
&mut vec![IR::Var {
|
&mut vec![Air::Var {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
tipo.clone(),
|
tipo.clone(),
|
||||||
|
@ -1257,7 +1251,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.collect::<Vec<(String, String, usize, bool)>>();
|
.collect::<Vec<(String, String, usize, bool)>>();
|
||||||
|
|
||||||
if !arguments_index.is_empty() {
|
if !arguments_index.is_empty() {
|
||||||
pattern_vec.push(IR::FieldsExpose {
|
pattern_vec.push(Air::FieldsExpose {
|
||||||
count: arguments_index.len() + 2,
|
count: arguments_index.len() + 2,
|
||||||
indices: arguments_index
|
indices: arguments_index
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1296,7 +1290,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
self.pattern_ir(
|
self.pattern_ir(
|
||||||
a,
|
a,
|
||||||
&mut nested_pattern,
|
&mut nested_pattern,
|
||||||
&mut vec![IR::Var {
|
&mut vec![Air::Var {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
tipo.clone(),
|
tipo.clone(),
|
||||||
|
@ -1320,7 +1314,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.collect::<Vec<(String, usize, bool)>>();
|
.collect::<Vec<(String, usize, bool)>>();
|
||||||
|
|
||||||
if !arguments_index.is_empty() {
|
if !arguments_index.is_empty() {
|
||||||
pattern_vec.push(IR::FieldsExpose {
|
pattern_vec.push(Air::FieldsExpose {
|
||||||
count: arguments_index.len() + 2,
|
count: arguments_index.len() + 2,
|
||||||
indices: arguments_index
|
indices: arguments_index
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1342,7 +1336,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uplc_code_gen(&mut self, ir_stack: &mut Vec<IR>) -> Term<Name> {
|
fn uplc_code_gen(&mut self, ir_stack: &mut Vec<Air>) -> Term<Name> {
|
||||||
let mut arg_stack: Vec<Term<Name>> = vec![];
|
let mut arg_stack: Vec<Term<Name>> = vec![];
|
||||||
|
|
||||||
while let Some(ir_element) = ir_stack.pop() {
|
while let Some(ir_element) = ir_stack.pop() {
|
||||||
|
@ -1352,25 +1346,25 @@ impl<'a> CodeGenerator<'a> {
|
||||||
arg_stack[0].clone()
|
arg_stack[0].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_uplc(&mut self, ir: IR, arg_stack: &mut Vec<Term<Name>>) {
|
fn gen_uplc(&mut self, ir: Air, arg_stack: &mut Vec<Term<Name>>) {
|
||||||
match ir {
|
match ir {
|
||||||
IR::Int { value, .. } => {
|
Air::Int { value, .. } => {
|
||||||
let integer = value.parse().unwrap();
|
let integer = value.parse().unwrap();
|
||||||
|
|
||||||
let term = Term::Constant(UplcConstant::Integer(integer));
|
let term = Term::Constant(UplcConstant::Integer(integer));
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::String { value, .. } => {
|
Air::String { value, .. } => {
|
||||||
let term = Term::Constant(UplcConstant::String(value));
|
let term = Term::Constant(UplcConstant::String(value));
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::ByteArray { bytes, .. } => {
|
Air::ByteArray { bytes, .. } => {
|
||||||
let term = Term::Constant(UplcConstant::ByteString(bytes));
|
let term = Term::Constant(UplcConstant::ByteString(bytes));
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Var {
|
Air::Var {
|
||||||
name, constructor, ..
|
name, constructor, ..
|
||||||
} => match constructor.variant {
|
} => match constructor.variant {
|
||||||
ValueConstructorVariant::LocalVariable { .. } => arg_stack.push(Term::Var(Name {
|
ValueConstructorVariant::LocalVariable { .. } => arg_stack.push(Term::Var(Name {
|
||||||
|
@ -1495,10 +1489,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IR::Discard { .. } => {
|
Air::Discard { .. } => {
|
||||||
arg_stack.push(Term::Constant(UplcConstant::Unit));
|
arg_stack.push(Term::Constant(UplcConstant::Unit));
|
||||||
}
|
}
|
||||||
IR::List {
|
Air::List {
|
||||||
count, tipo, tail, ..
|
count, tipo, tail, ..
|
||||||
} => {
|
} => {
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
|
@ -1550,8 +1544,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IR::Tail { .. } => todo!(),
|
Air::Tail { .. } => todo!(),
|
||||||
IR::ListAccessor { names, tail, .. } => {
|
Air::ListAccessor { names, tail, .. } => {
|
||||||
let value = arg_stack.pop().unwrap();
|
let value = arg_stack.pop().unwrap();
|
||||||
let mut term = arg_stack.pop().unwrap();
|
let mut term = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
@ -1601,7 +1595,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::ListExpose {
|
Air::ListExpose {
|
||||||
tail_head_names,
|
tail_head_names,
|
||||||
tail,
|
tail,
|
||||||
..
|
..
|
||||||
|
@ -1653,7 +1647,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Call { count, .. } => {
|
Air::Call { count, .. } => {
|
||||||
if count >= 2 {
|
if count >= 2 {
|
||||||
let mut term = arg_stack.pop().unwrap();
|
let mut term = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
@ -1670,14 +1664,14 @@ impl<'a> CodeGenerator<'a> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IR::Builtin { func, .. } => {
|
Air::Builtin { func, .. } => {
|
||||||
let mut term = Term::Builtin(func);
|
let mut term = Term::Builtin(func);
|
||||||
for _ in 0..func.force_count() {
|
for _ in 0..func.force_count() {
|
||||||
term = Term::Force(term.into());
|
term = Term::Force(term.into());
|
||||||
}
|
}
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::BinOp { name, tipo, .. } => {
|
Air::BinOp { name, tipo, .. } => {
|
||||||
let left = arg_stack.pop().unwrap();
|
let left = arg_stack.pop().unwrap();
|
||||||
let right = arg_stack.pop().unwrap();
|
let right = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
@ -1951,7 +1945,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
};
|
};
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Assignment { name, .. } => {
|
Air::Assignment { name, .. } => {
|
||||||
let right_hand = arg_stack.pop().unwrap();
|
let right_hand = arg_stack.pop().unwrap();
|
||||||
let lam_body = arg_stack.pop().unwrap();
|
let lam_body = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
@ -1969,7 +1963,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::DefineFunc {
|
Air::DefineFunc {
|
||||||
func_name,
|
func_name,
|
||||||
params,
|
params,
|
||||||
recursive,
|
recursive,
|
||||||
|
@ -2078,10 +2072,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IR::DefineConst { .. } => todo!(),
|
Air::DefineConst { .. } => todo!(),
|
||||||
IR::DefineConstrFields { .. } => todo!(),
|
Air::DefineConstrFields { .. } => todo!(),
|
||||||
IR::DefineConstrFieldAccess { .. } => todo!(),
|
Air::DefineConstrFieldAccess { .. } => todo!(),
|
||||||
IR::Lam { name, .. } => {
|
Air::Lam { name, .. } => {
|
||||||
let arg = arg_stack.pop().unwrap();
|
let arg = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
let mut term = arg_stack.pop().unwrap();
|
let mut term = arg_stack.pop().unwrap();
|
||||||
|
@ -2099,7 +2093,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
};
|
};
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::When {
|
Air::When {
|
||||||
subject_name, tipo, ..
|
subject_name, tipo, ..
|
||||||
} => {
|
} => {
|
||||||
let subject = arg_stack.pop().unwrap();
|
let subject = arg_stack.pop().unwrap();
|
||||||
|
@ -2135,7 +2129,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Clause {
|
Air::Clause {
|
||||||
tipo,
|
tipo,
|
||||||
subject_name,
|
subject_name,
|
||||||
complex_clause,
|
complex_clause,
|
||||||
|
@ -2250,7 +2244,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
IR::ListClause {
|
Air::ListClause {
|
||||||
tail_name,
|
tail_name,
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
..
|
..
|
||||||
|
@ -2311,7 +2305,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::ClauseGuard {
|
Air::ClauseGuard {
|
||||||
subject_name, tipo, ..
|
subject_name, tipo, ..
|
||||||
} => {
|
} => {
|
||||||
let condition = arg_stack.pop().unwrap();
|
let condition = arg_stack.pop().unwrap();
|
||||||
|
@ -2386,10 +2380,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Finally { .. } => {
|
Air::Finally { .. } => {
|
||||||
let _clause = arg_stack.pop().unwrap();
|
let _clause = arg_stack.pop().unwrap();
|
||||||
}
|
}
|
||||||
IR::If { .. } => {
|
Air::If { .. } => {
|
||||||
let condition = arg_stack.pop().unwrap();
|
let condition = arg_stack.pop().unwrap();
|
||||||
let then = arg_stack.pop().unwrap();
|
let then = arg_stack.pop().unwrap();
|
||||||
let mut term = arg_stack.pop().unwrap();
|
let mut term = arg_stack.pop().unwrap();
|
||||||
|
@ -2414,9 +2408,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::Constr { .. } => todo!(),
|
Air::Constr { .. } => todo!(),
|
||||||
IR::Fields { .. } => todo!(),
|
Air::Fields { .. } => todo!(),
|
||||||
IR::RecordAccess { index, tipo, .. } => {
|
Air::RecordAccess { index, tipo, .. } => {
|
||||||
let constr = arg_stack.pop().unwrap();
|
let constr = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
let mut term = Term::Apply {
|
let mut term = Term::Apply {
|
||||||
|
@ -2459,7 +2453,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
IR::FieldsExpose { indices, .. } => {
|
Air::FieldsExpose { indices, .. } => {
|
||||||
self.needs_field_access = true;
|
self.needs_field_access = true;
|
||||||
|
|
||||||
let constr_var = arg_stack.pop().unwrap();
|
let constr_var = arg_stack.pop().unwrap();
|
||||||
|
@ -2697,16 +2691,16 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(body);
|
arg_stack.push(body);
|
||||||
}
|
}
|
||||||
IR::Todo { .. } => {
|
Air::Todo { .. } => {
|
||||||
arg_stack.push(Term::Error);
|
arg_stack.push(Term::Error);
|
||||||
}
|
}
|
||||||
IR::Record { .. } => todo!(),
|
Air::Record { .. } => todo!(),
|
||||||
IR::RecordUpdate { .. } => todo!(),
|
Air::RecordUpdate { .. } => todo!(),
|
||||||
IR::Negate { .. } => todo!(),
|
Air::Negate { .. } => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn define_ir(&mut self, ir_stack: &mut Vec<IR>) {
|
pub(crate) fn define_ir(&mut self, ir_stack: &mut Vec<Air>) {
|
||||||
let mut func_components = IndexMap::new();
|
let mut func_components = IndexMap::new();
|
||||||
let mut func_index_map = IndexMap::new();
|
let mut func_index_map = IndexMap::new();
|
||||||
|
|
||||||
|
@ -2745,7 +2739,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.dependencies
|
.dependencies
|
||||||
.extend(depend_comp.dependencies.clone());
|
.extend(depend_comp.dependencies.clone());
|
||||||
|
|
||||||
let mut temp_ir = vec![IR::DefineFunc {
|
let mut temp_ir = vec![Air::DefineFunc {
|
||||||
scope: func_scope.clone(),
|
scope: func_scope.clone(),
|
||||||
func_name: dependency.function_name.clone(),
|
func_name: dependency.function_name.clone(),
|
||||||
module_name: dependency.module_name.clone(),
|
module_name: dependency.module_name.clone(),
|
||||||
|
@ -2767,7 +2761,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
for (index, ir) in ir_stack.clone().into_iter().enumerate().rev() {
|
for (index, ir) in ir_stack.clone().into_iter().enumerate().rev() {
|
||||||
match ir {
|
match ir {
|
||||||
IR::Var { constructor, .. } => {
|
Air::Var { constructor, .. } => {
|
||||||
if let ValueConstructorVariant::ModuleFn { .. } = &constructor.variant {}
|
if let ValueConstructorVariant::ModuleFn { .. } = &constructor.variant {}
|
||||||
}
|
}
|
||||||
a => {
|
a => {
|
||||||
|
@ -2788,7 +2782,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let funt_comp = func_components.get(item.0).unwrap();
|
let funt_comp = func_components.get(item.0).unwrap();
|
||||||
|
|
||||||
full_func_ir.push(IR::DefineFunc {
|
full_func_ir.push(Air::DefineFunc {
|
||||||
scope: item.1.clone(),
|
scope: item.1.clone(),
|
||||||
func_name: item.0.function_name.clone(),
|
func_name: item.0.function_name.clone(),
|
||||||
module_name: item.0.module_name.clone(),
|
module_name: item.0.module_name.clone(),
|
||||||
|
@ -2809,7 +2803,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
fn define_recurse_ir(
|
fn define_recurse_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
ir_stack: &[IR],
|
ir_stack: &[Air],
|
||||||
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
||||||
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
||||||
recursion_func_map: IndexMap<FunctionAccessKey, ()>,
|
recursion_func_map: IndexMap<FunctionAccessKey, ()>,
|
||||||
|
@ -2825,7 +2819,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let function_ir = function_components.ir.clone();
|
let function_ir = function_components.ir.clone();
|
||||||
|
|
||||||
for ir in function_ir.clone() {
|
for ir in function_ir.clone() {
|
||||||
if let IR::Var {
|
if let Air::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
variant:
|
variant:
|
||||||
|
@ -2886,14 +2880,14 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
fn process_define_ir(
|
fn process_define_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
ir_stack: &[IR],
|
ir_stack: &[Air],
|
||||||
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
||||||
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
||||||
) {
|
) {
|
||||||
let mut to_be_defined_map: IndexMap<FunctionAccessKey, Vec<u64>> = IndexMap::new();
|
let mut to_be_defined_map: IndexMap<FunctionAccessKey, Vec<u64>> = IndexMap::new();
|
||||||
for ir in ir_stack.iter().rev() {
|
for ir in ir_stack.iter().rev() {
|
||||||
match ir {
|
match ir {
|
||||||
IR::Var {
|
Air::Var {
|
||||||
scope, constructor, ..
|
scope, constructor, ..
|
||||||
} => {
|
} => {
|
||||||
if let ValueConstructorVariant::ModuleFn {
|
if let ValueConstructorVariant::ModuleFn {
|
||||||
|
@ -2926,7 +2920,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let mut func_calls = vec![];
|
let mut func_calls = vec![];
|
||||||
|
|
||||||
for ir in func_ir.clone() {
|
for ir in func_ir.clone() {
|
||||||
if let IR::Var {
|
if let Air::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
variant:
|
variant:
|
||||||
|
@ -3012,16 +3006,16 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constants_ir(literal: &Constant<Arc<Type>, String>, ir_stack: &mut Vec<IR>, scope: Vec<u64>) {
|
fn constants_ir(literal: &Constant<Arc<Type>, String>, ir_stack: &mut Vec<Air>, scope: Vec<u64>) {
|
||||||
match literal {
|
match literal {
|
||||||
Constant::Int { value, .. } => {
|
Constant::Int { value, .. } => {
|
||||||
ir_stack.push(IR::Int {
|
ir_stack.push(Air::Int {
|
||||||
scope,
|
scope,
|
||||||
value: value.clone(),
|
value: value.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Constant::String { value, .. } => {
|
Constant::String { value, .. } => {
|
||||||
ir_stack.push(IR::String {
|
ir_stack.push(Air::String {
|
||||||
scope,
|
scope,
|
||||||
value: value.clone(),
|
value: value.clone(),
|
||||||
});
|
});
|
||||||
|
@ -3030,7 +3024,7 @@ fn constants_ir(literal: &Constant<Arc<Type>, String>, ir_stack: &mut Vec<IR>, s
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
Constant::List { elements, tipo, .. } => {
|
Constant::List { elements, tipo, .. } => {
|
||||||
ir_stack.push(IR::List {
|
ir_stack.push(Air::List {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
count: elements.len(),
|
count: elements.len(),
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
|
@ -3042,11 +3036,11 @@ fn constants_ir(literal: &Constant<Arc<Type>, String>, ir_stack: &mut Vec<IR>, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant::Record { .. } => {
|
Constant::Record { .. } => {
|
||||||
// ir_stack.push(IR::Record { scope, });
|
// ir_stack.push(Air::Record { scope, });
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
Constant::ByteArray { bytes, .. } => {
|
Constant::ByteArray { bytes, .. } => {
|
||||||
ir_stack.push(IR::ByteArray {
|
ir_stack.push(Air::ByteArray {
|
||||||
scope,
|
scope,
|
||||||
bytes: bytes.clone(),
|
bytes: bytes.clone(),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue