chore: trying to fix test 5
This commit is contained in:
parent
6635a918b5
commit
b71315ba2f
|
@ -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 TypedFunction = Function<Arc<Type>, TypedExpr>;
|
||||||
|
pub type UntypedFunction = Function<(), UntypedExpr>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Function<T, Expr> {
|
pub struct Function<T, Expr> {
|
||||||
|
@ -84,6 +82,9 @@ pub struct Function<T, Expr> {
|
||||||
pub end_position: usize,
|
pub end_position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypedTypeAlias = TypeAlias<Arc<Type>>;
|
||||||
|
pub type UntypedTypeAlias = TypeAlias<()>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct TypeAlias<T> {
|
pub struct TypeAlias<T> {
|
||||||
pub alias: String,
|
pub alias: String,
|
||||||
|
@ -95,6 +96,9 @@ pub struct TypeAlias<T> {
|
||||||
pub tipo: T,
|
pub tipo: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypedDataType = DataType<Arc<Type>>;
|
||||||
|
pub type UntypedDataType = DataType<()>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct DataType<T> {
|
pub struct DataType<T> {
|
||||||
pub constructors: Vec<RecordConstructor<T>>,
|
pub constructors: Vec<RecordConstructor<T>>,
|
||||||
|
@ -107,6 +111,9 @@ pub struct DataType<T> {
|
||||||
pub typed_parameters: Vec<T>,
|
pub typed_parameters: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypedUse = Use<String>;
|
||||||
|
pub type UntypedUse = Use<()>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Use<PackageName> {
|
pub struct Use<PackageName> {
|
||||||
pub as_name: Option<String>,
|
pub as_name: Option<String>,
|
||||||
|
@ -116,6 +123,9 @@ pub struct Use<PackageName> {
|
||||||
pub unqualified: Vec<UnqualifiedImport>,
|
pub unqualified: Vec<UnqualifiedImport>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypedModuleConstant = ModuleConstant<Arc<Type>, String>;
|
||||||
|
pub type UntypedModuleConstant = ModuleConstant<(), ()>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ModuleConstant<T, ConstantRecordTag> {
|
pub struct ModuleConstant<T, ConstantRecordTag> {
|
||||||
pub doc: Option<String>,
|
pub doc: Option<String>,
|
||||||
|
@ -127,6 +137,9 @@ pub struct ModuleConstant<T, ConstantRecordTag> {
|
||||||
pub tipo: T,
|
pub tipo: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type TypedDefinition = Definition<Arc<Type>, TypedExpr, String, String>;
|
||||||
|
pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Definition<T, Expr, ConstantRecordTag, PackageName> {
|
pub enum Definition<T, Expr, ConstantRecordTag, PackageName> {
|
||||||
Fn(Function<T, Expr>),
|
Fn(Function<T, Expr>),
|
||||||
|
|
|
@ -16,8 +16,8 @@ use uplc::{
|
||||||
use crate::{
|
use crate::{
|
||||||
air::Air,
|
air::Air,
|
||||||
ast::{
|
ast::{
|
||||||
ArgName, AssignmentKind, BinOp, Clause, Constant, DataType, Function, Pattern, Span,
|
ArgName, AssignmentKind, BinOp, Clause, Constant, Pattern, Span, TypedArg, TypedDataType,
|
||||||
TypedArg,
|
TypedFunction,
|
||||||
},
|
},
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
|
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
|
||||||
|
@ -64,9 +64,9 @@ pub struct ClauseProperties {
|
||||||
|
|
||||||
pub struct CodeGenerator<'a> {
|
pub struct CodeGenerator<'a> {
|
||||||
defined_functions: HashMap<FunctionAccessKey, ()>,
|
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>>>,
|
// 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>>,
|
// imports: &'a HashMap<(String, String), &'a Use<String>>,
|
||||||
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
|
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
|
||||||
module_types: &'a HashMap<String, TypeInfo>,
|
module_types: &'a HashMap<String, TypeInfo>,
|
||||||
|
@ -76,9 +76,9 @@ pub struct CodeGenerator<'a> {
|
||||||
|
|
||||||
impl<'a> CodeGenerator<'a> {
|
impl<'a> CodeGenerator<'a> {
|
||||||
pub fn new(
|
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>>>,
|
// 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>>,
|
// imports: &'a HashMap<(String, String), &'a Use<String>>,
|
||||||
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
|
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
|
||||||
module_types: &'a HashMap<String, TypeInfo>,
|
module_types: &'a HashMap<String, TypeInfo>,
|
||||||
|
@ -176,12 +176,20 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
TypedExpr::Var {
|
TypedExpr::Var {
|
||||||
constructor, name, ..
|
constructor, name, ..
|
||||||
} => {
|
} => match &constructor.variant {
|
||||||
if let ValueConstructorVariant::ModuleConstant { literal, .. } =
|
ValueConstructorVariant::ModuleConstant { literal, .. } => {
|
||||||
&constructor.variant
|
|
||||||
{
|
|
||||||
constants_ir(literal, ir_stack, scope);
|
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 {
|
ir_stack.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: constructor.clone(),
|
constructor: constructor.clone(),
|
||||||
|
@ -189,7 +197,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
variant_name: String::new(),
|
variant_name: String::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
TypedExpr::Fn { args, body, .. } => {
|
TypedExpr::Fn { args, body, .. } => {
|
||||||
let mut func_body = vec![];
|
let mut func_body = vec![];
|
||||||
let mut func_scope = scope.clone();
|
let mut func_scope = scope.clone();
|
||||||
|
@ -1558,9 +1566,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let tipo = constructor.tipo;
|
let tipo = constructor.tipo;
|
||||||
|
|
||||||
let args_type = match tipo.as_ref() {
|
let args_type = match tipo.as_ref() {
|
||||||
Type::Fn { args, .. } => args,
|
Type::Fn { args, .. } | Type::App { args, .. } => args,
|
||||||
|
_ => unreachable!(),
|
||||||
_ => todo!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(field_map) = field_map.clone() {
|
if let Some(field_map) = field_map.clone() {
|
||||||
|
|
|
@ -13,8 +13,11 @@ pub mod script;
|
||||||
pub mod telemetry;
|
pub mod telemetry;
|
||||||
|
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{Definition, Function, ModuleKind, TypedDefinition, TypedFunction},
|
ast::{
|
||||||
builtins,
|
Annotation, DataType, Definition, Function, ModuleKind, RecordConstructor,
|
||||||
|
RecordConstructorArg, Span, TypedDataType, TypedDefinition, TypedFunction,
|
||||||
|
},
|
||||||
|
builtins::{self, generic_var},
|
||||||
tipo::TypeInfo,
|
tipo::TypeInfo,
|
||||||
uplc::{CodeGenerator, DataTypeKey, FunctionAccessKey},
|
uplc::{CodeGenerator, DataTypeKey, FunctionAccessKey},
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
|
@ -387,6 +390,16 @@ where
|
||||||
let mut imports = HashMap::new();
|
let mut imports = HashMap::new();
|
||||||
let mut constants = 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 module in checked_modules.values() {
|
||||||
for def in module.ast.definitions() {
|
for def in module.ast.definitions() {
|
||||||
match def {
|
match def {
|
||||||
|
@ -463,6 +476,16 @@ where
|
||||||
let mut imports = HashMap::new();
|
let mut imports = HashMap::new();
|
||||||
let mut constants = 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 indices_to_remove = Vec::new();
|
||||||
let mut scripts = Vec::new();
|
let mut scripts = Vec::new();
|
||||||
|
|
||||||
|
@ -558,6 +581,8 @@ where
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{}", script.program.to_pretty());
|
||||||
|
|
||||||
match script.program.eval(initial_budget) {
|
match script.program.eval(initial_budget) {
|
||||||
(Ok(result), remaining_budget, _) => {
|
(Ok(result), remaining_budget, _) => {
|
||||||
let eval_info = EvalInfo {
|
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"),
|
.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)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue