make progress on list deconstruction with IR
This commit is contained in:
parent
2a00b896fc
commit
abe29a3883
|
@ -7,7 +7,7 @@ use uplc::builtins::DefaultFunction;
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{ModuleKind, Span},
|
ast::{ModuleKind, Span},
|
||||||
tipo::{
|
tipo::{
|
||||||
fields::FieldMap, Type, TypeConstructor, TypeInfo, TypeVar, ValueConstructor,
|
self, fields::FieldMap, Type, TypeConstructor, TypeInfo, TypeVar, ValueConstructor,
|
||||||
ValueConstructorVariant,
|
ValueConstructorVariant,
|
||||||
},
|
},
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
|
@ -336,7 +336,13 @@ pub fn from_default_function(
|
||||||
|
|
||||||
Some((tipo, 1))
|
Some((tipo, 1))
|
||||||
}
|
}
|
||||||
DefaultFunction::IfThenElse => None,
|
DefaultFunction::IfThenElse => {
|
||||||
|
let ret = generic_var(id_gen.next());
|
||||||
|
|
||||||
|
let tipo = function(vec![bool(), ret.clone(), ret.clone()], ret);
|
||||||
|
|
||||||
|
Some((tipo, 3))
|
||||||
|
}
|
||||||
DefaultFunction::ChooseUnit => None,
|
DefaultFunction::ChooseUnit => None,
|
||||||
DefaultFunction::Trace => {
|
DefaultFunction::Trace => {
|
||||||
let ret = generic_var(id_gen.next());
|
let ret = generic_var(id_gen.next());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use vec1::Vec1;
|
use uplc::builtins::DefaultFunction;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
|
@ -40,12 +40,19 @@ pub enum IR {
|
||||||
// },
|
// },
|
||||||
List {
|
List {
|
||||||
count: usize,
|
count: usize,
|
||||||
|
tipo: Arc<Type>,
|
||||||
|
tail: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
Tail {
|
Tail {
|
||||||
count: usize,
|
count: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ListAccessor {
|
||||||
|
names: Vec<String>,
|
||||||
|
tail: bool,
|
||||||
|
},
|
||||||
|
|
||||||
// func(x, other(y))
|
// func(x, other(y))
|
||||||
//[ Define(3) x definition *lam_body* -> [ (x [ (func [ func x [ (y [ other y ]) *definition* ] ]) *definition* ]) *definition* ], Define func -> [ (func [ func x [ (y [ other y ]) *definition* ] ]) *definition* ] , Call func -> [ func x [ (y [ other y ]) *definition* ] ], Var x -> x, Define y -> [ (y [ other y ]) *definition* ], Call other -> [ other y ], Var y -> y]
|
//[ Define(3) x definition *lam_body* -> [ (x [ (func [ func x [ (y [ other y ]) *definition* ] ]) *definition* ]) *definition* ], Define func -> [ (func [ func x [ (y [ other y ]) *definition* ] ]) *definition* ] , Call func -> [ func x [ (y [ other y ]) *definition* ] ], Var x -> x, Define y -> [ (y [ other y ]) *definition* ], Call other -> [ other y ], Var y -> y]
|
||||||
|
|
||||||
|
@ -54,13 +61,18 @@ pub enum IR {
|
||||||
count: usize,
|
count: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Builtin {
|
||||||
|
func: DefaultFunction,
|
||||||
|
},
|
||||||
|
|
||||||
BinOp {
|
BinOp {
|
||||||
name: BinOp,
|
name: BinOp,
|
||||||
count: usize,
|
count: usize,
|
||||||
|
tipo: Arc<Type>,
|
||||||
},
|
},
|
||||||
|
|
||||||
Assignment {
|
Assignment {
|
||||||
count: usize,
|
name: String,
|
||||||
kind: AssignmentKind,
|
kind: AssignmentKind,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{cell::RefCell, collections::HashMap, ops::Deref, sync::Arc};
|
use std::{cell::RefCell, collections::HashMap, ops::Deref, sync::Arc};
|
||||||
|
|
||||||
use uplc::builtins::DefaultFunction;
|
use uplc::{ast::Type as UplcType, builtins::DefaultFunction};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Constant, DefinitionLocation, ModuleKind, Span, TypedConstant},
|
ast::{Constant, DefinitionLocation, ModuleKind, Span, TypedConstant},
|
||||||
|
@ -127,6 +127,43 @@ impl Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_list(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::App { module, name, .. } if "List" == name && module.is_empty() => true,
|
||||||
|
Self::Var { tipo } => tipo.borrow().is_list(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_uplc_type(&self) -> UplcType {
|
||||||
|
if self.is_int() {
|
||||||
|
UplcType::Integer
|
||||||
|
} else if self.is_bytearray() {
|
||||||
|
UplcType::ByteString
|
||||||
|
} else if self.is_string() {
|
||||||
|
UplcType::String
|
||||||
|
} else if self.is_bool() {
|
||||||
|
UplcType::Bool
|
||||||
|
} else if self.is_list() {
|
||||||
|
let args_type = match self {
|
||||||
|
Self::App {
|
||||||
|
module, name, args, ..
|
||||||
|
} if "List" == name && module.is_empty() => args[0].clone(),
|
||||||
|
Self::Var { tipo } => {
|
||||||
|
if let TypeVar::Link { tipo } = tipo.borrow().clone() {
|
||||||
|
tipo
|
||||||
|
} else {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => todo!(),
|
||||||
|
};
|
||||||
|
UplcType::List(Box::new(args_type.get_uplc_type()))
|
||||||
|
} else {
|
||||||
|
UplcType::Data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the args for the type if the type is a specific `Type::App`.
|
/// Get the args for the type if the type is a specific `Type::App`.
|
||||||
/// Returns None if the type is not a `Type::App` or is an incorrect `Type:App`
|
/// Returns None if the type is not a `Type::App` or is an incorrect `Type:App`
|
||||||
///
|
///
|
||||||
|
@ -290,6 +327,13 @@ impl TypeVar {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_list(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Link { tipo } => tipo.is_list(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,8 @@ use aiken_lang::{
|
||||||
ast::{Definition, Function, ModuleKind, TypedFunction},
|
ast::{Definition, Function, ModuleKind, TypedFunction},
|
||||||
builtins,
|
builtins,
|
||||||
tipo::TypeInfo,
|
tipo::TypeInfo,
|
||||||
uplc::{CodeGenerator, DataTypeKey, FunctionAccessKey},
|
uplc::{DataTypeKey, FunctionAccessKey},
|
||||||
|
uplc_two::CodeGenerator,
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
};
|
};
|
||||||
use miette::NamedSource;
|
use miette::NamedSource;
|
||||||
|
@ -372,6 +373,7 @@ impl Project {
|
||||||
&data_types,
|
&data_types,
|
||||||
// &imports,
|
// &imports,
|
||||||
// &constants,
|
// &constants,
|
||||||
|
&self.module_types,
|
||||||
);
|
);
|
||||||
|
|
||||||
let program = generator.generate(body, arguments);
|
let program = generator.generate(body, arguments);
|
||||||
|
|
|
@ -49,8 +49,9 @@ pub type Datum {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spend(datum: Datum, _rdmr: Nil, _ctx: Nil) -> Bool {
|
pub fn spend(datum: Datum, _rdmr: Nil, _ctx: Nil) -> Bool {
|
||||||
when datum is {
|
let x = [[[2, 9], [7]], [[4]], [[6]]]
|
||||||
Sell -> True
|
|
||||||
Buy -> False
|
let [[[a, g], d], b, ..] = x
|
||||||
}
|
|
||||||
|
True
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue