chore: trying to fix test 5

This commit is contained in:
rvcas 2022-12-14 00:11:10 -05:00 committed by KtorZ
parent 6635a918b5
commit b71315ba2f
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 102 additions and 20 deletions

View File

@ -66,10 +66,8 @@ impl UntypedModule {
}
}
pub type TypedDefinition = Definition<Arc<Type>, TypedExpr, String, String>;
pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>;
pub type TypedFunction = Function<Arc<Type>, TypedExpr>;
pub type UntypedFunction = Function<(), UntypedExpr>;
#[derive(Debug, Clone, PartialEq)]
pub struct Function<T, Expr> {
@ -84,6 +82,9 @@ pub struct Function<T, Expr> {
pub end_position: usize,
}
pub type TypedTypeAlias = TypeAlias<Arc<Type>>;
pub type UntypedTypeAlias = TypeAlias<()>;
#[derive(Debug, Clone, PartialEq)]
pub struct TypeAlias<T> {
pub alias: String,
@ -95,6 +96,9 @@ pub struct TypeAlias<T> {
pub tipo: T,
}
pub type TypedDataType = DataType<Arc<Type>>;
pub type UntypedDataType = DataType<()>;
#[derive(Debug, Clone, PartialEq)]
pub struct DataType<T> {
pub constructors: Vec<RecordConstructor<T>>,
@ -107,6 +111,9 @@ pub struct DataType<T> {
pub typed_parameters: Vec<T>,
}
pub type TypedUse = Use<String>;
pub type UntypedUse = Use<()>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Use<PackageName> {
pub as_name: Option<String>,
@ -116,6 +123,9 @@ pub struct Use<PackageName> {
pub unqualified: Vec<UnqualifiedImport>,
}
pub type TypedModuleConstant = ModuleConstant<Arc<Type>, String>;
pub type UntypedModuleConstant = ModuleConstant<(), ()>;
#[derive(Debug, Clone, PartialEq)]
pub struct ModuleConstant<T, ConstantRecordTag> {
pub doc: Option<String>,
@ -127,6 +137,9 @@ pub struct ModuleConstant<T, ConstantRecordTag> {
pub tipo: T,
}
pub type TypedDefinition = Definition<Arc<Type>, TypedExpr, String, String>;
pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>;
#[derive(Debug, Clone, PartialEq)]
pub enum Definition<T, Expr, ConstantRecordTag, PackageName> {
Fn(Function<T, Expr>),

View File

@ -16,8 +16,8 @@ use uplc::{
use crate::{
air::Air,
ast::{
ArgName, AssignmentKind, BinOp, Clause, Constant, DataType, Function, Pattern, Span,
TypedArg,
ArgName, AssignmentKind, BinOp, Clause, Constant, Pattern, Span, TypedArg, TypedDataType,
TypedFunction,
},
expr::TypedExpr,
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
@ -64,9 +64,9 @@ pub struct ClauseProperties {
pub struct CodeGenerator<'a> {
defined_functions: HashMap<FunctionAccessKey, ()>,
functions: &'a HashMap<FunctionAccessKey, &'a Function<Arc<tipo::Type>, TypedExpr>>,
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a DataType<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>,
// imports: &'a HashMap<(String, String), &'a Use<String>>,
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
module_types: &'a HashMap<String, TypeInfo>,
@ -76,9 +76,9 @@ pub struct CodeGenerator<'a> {
impl<'a> CodeGenerator<'a> {
pub fn new(
functions: &'a HashMap<FunctionAccessKey, &'a Function<Arc<tipo::Type>, TypedExpr>>,
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a DataType<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>,
// imports: &'a HashMap<(String, String), &'a Use<String>>,
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
module_types: &'a HashMap<String, TypeInfo>,
@ -176,12 +176,20 @@ impl<'a> CodeGenerator<'a> {
}
TypedExpr::Var {
constructor, name, ..
} => {
if let ValueConstructorVariant::ModuleConstant { literal, .. } =
&constructor.variant
{
} => match &constructor.variant {
ValueConstructorVariant::ModuleConstant { literal, .. } => {
constants_ir(literal, ir_stack, scope);
} else {
}
ValueConstructorVariant::ModuleFn {
builtin: Some(builtin),
..
} => {
ir_stack.push(Air::Builtin {
scope,
func: *builtin,
});
}
_ => {
ir_stack.push(Air::Var {
scope,
constructor: constructor.clone(),
@ -189,7 +197,7 @@ impl<'a> CodeGenerator<'a> {
variant_name: String::new(),
});
}
}
},
TypedExpr::Fn { args, body, .. } => {
let mut func_body = vec![];
let mut func_scope = scope.clone();
@ -1558,9 +1566,8 @@ impl<'a> CodeGenerator<'a> {
let tipo = constructor.tipo;
let args_type = match tipo.as_ref() {
Type::Fn { args, .. } => args,
_ => todo!(),
Type::Fn { args, .. } | Type::App { args, .. } => args,
_ => unreachable!(),
};
if let Some(field_map) = field_map.clone() {

View File

@ -13,8 +13,11 @@ pub mod script;
pub mod telemetry;
use aiken_lang::{
ast::{Definition, Function, ModuleKind, TypedDefinition, TypedFunction},
builtins,
ast::{
Annotation, DataType, Definition, Function, ModuleKind, RecordConstructor,
RecordConstructorArg, Span, TypedDataType, TypedDefinition, TypedFunction,
},
builtins::{self, generic_var},
tipo::TypeInfo,
uplc::{CodeGenerator, DataTypeKey, FunctionAccessKey},
IdGenerator,
@ -387,6 +390,16 @@ where
let mut imports = HashMap::new();
let mut constants = HashMap::new();
let option_data_type = make_option();
data_types.insert(
DataTypeKey {
module_name: "".to_string(),
defined_type: "Option".to_string(),
},
&option_data_type,
);
for module in checked_modules.values() {
for def in module.ast.definitions() {
match def {
@ -463,6 +476,16 @@ where
let mut imports = HashMap::new();
let mut constants = HashMap::new();
let option_data_type = make_option();
data_types.insert(
DataTypeKey {
module_name: "".to_string(),
defined_type: "Option".to_string(),
},
&option_data_type,
);
// let mut indices_to_remove = Vec::new();
let mut scripts = Vec::new();
@ -558,6 +581,8 @@ where
continue;
}
println!("{}", script.program.to_pretty());
match script.program.eval(initial_budget) {
(Ok(result), remaining_budget, _) => {
let eval_info = EvalInfo {
@ -744,3 +769,40 @@ fn is_aiken_path(path: &Path, dir: impl AsRef<Path>) -> bool {
.expect("is_aiken_path(): to_str"),
)
}
fn make_option() -> TypedDataType {
DataType {
constructors: vec![
RecordConstructor {
location: Span::empty(),
name: "Some".to_string(),
arguments: vec![RecordConstructorArg {
label: None,
annotation: Annotation::Var {
location: Span::empty(),
name: "a".to_string(),
},
location: Span::empty(),
tipo: generic_var(0),
doc: None,
}],
documentation: None,
sugar: false,
},
RecordConstructor {
location: Span::empty(),
name: "None".to_string(),
arguments: vec![],
documentation: None,
sugar: false,
},
],
doc: None,
location: Span::empty(),
name: "Option".to_string(),
opaque: false,
parameters: vec!["a".to_string()],
public: true,
typed_parameters: vec![generic_var(0)],
}
}