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
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() {