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::{
|
||||
ast::{ModuleKind, Span},
|
||||
tipo::{
|
||||
fields::FieldMap, Type, TypeConstructor, TypeInfo, TypeVar, ValueConstructor,
|
||||
self, fields::FieldMap, Type, TypeConstructor, TypeInfo, TypeVar, ValueConstructor,
|
||||
ValueConstructorVariant,
|
||||
},
|
||||
IdGenerator,
|
||||
|
@ -336,7 +336,13 @@ pub fn from_default_function(
|
|||
|
||||
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::Trace => {
|
||||
let ret = generic_var(id_gen.next());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use vec1::Vec1;
|
||||
use uplc::builtins::DefaultFunction;
|
||||
|
||||
use crate::{
|
||||
ast::{
|
||||
|
@ -40,12 +40,19 @@ pub enum IR {
|
|||
// },
|
||||
List {
|
||||
count: usize,
|
||||
tipo: Arc<Type>,
|
||||
tail: bool,
|
||||
},
|
||||
|
||||
Tail {
|
||||
count: usize,
|
||||
},
|
||||
|
||||
ListAccessor {
|
||||
names: Vec<String>,
|
||||
tail: bool,
|
||||
},
|
||||
|
||||
// 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]
|
||||
|
||||
|
@ -54,13 +61,18 @@ pub enum IR {
|
|||
count: usize,
|
||||
},
|
||||
|
||||
Builtin {
|
||||
func: DefaultFunction,
|
||||
},
|
||||
|
||||
BinOp {
|
||||
name: BinOp,
|
||||
count: usize,
|
||||
tipo: Arc<Type>,
|
||||
},
|
||||
|
||||
Assignment {
|
||||
count: usize,
|
||||
name: String,
|
||||
kind: AssignmentKind,
|
||||
},
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{cell::RefCell, collections::HashMap, ops::Deref, sync::Arc};
|
||||
|
||||
use uplc::builtins::DefaultFunction;
|
||||
use uplc::{ast::Type as UplcType, builtins::DefaultFunction};
|
||||
|
||||
use crate::{
|
||||
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`.
|
||||
/// Returns None if the type is not a `Type::App` or is an incorrect `Type:App`
|
||||
///
|
||||
|
@ -290,6 +327,13 @@ impl TypeVar {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_list(&self) -> bool {
|
||||
match self {
|
||||
Self::Link { tipo } => tipo.is_list(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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},
|
||||
builtins,
|
||||
tipo::TypeInfo,
|
||||
uplc::{CodeGenerator, DataTypeKey, FunctionAccessKey},
|
||||
uplc::{DataTypeKey, FunctionAccessKey},
|
||||
uplc_two::CodeGenerator,
|
||||
IdGenerator,
|
||||
};
|
||||
use miette::NamedSource;
|
||||
|
@ -372,6 +373,7 @@ impl Project {
|
|||
&data_types,
|
||||
// &imports,
|
||||
// &constants,
|
||||
&self.module_types,
|
||||
);
|
||||
|
||||
let program = generator.generate(body, arguments);
|
||||
|
|
|
@ -49,8 +49,9 @@ pub type Datum {
|
|||
}
|
||||
|
||||
pub fn spend(datum: Datum, _rdmr: Nil, _ctx: Nil) -> Bool {
|
||||
when datum is {
|
||||
Sell -> True
|
||||
Buy -> False
|
||||
}
|
||||
let x = [[[2, 9], [7]], [[4]], [[6]]]
|
||||
|
||||
let [[[a, g], d], b, ..] = x
|
||||
|
||||
True
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue