chore: fix some stuff after rebase
This commit is contained in:
parent
6c6aefd1c4
commit
3787cce275
|
@ -105,7 +105,7 @@ pub struct DataType<T> {
|
||||||
pub typed_parameters: Vec<T>,
|
pub typed_parameters: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Use<PackageName> {
|
pub struct Use<PackageName> {
|
||||||
pub as_name: Option<String>,
|
pub as_name: Option<String>,
|
||||||
pub location: Span,
|
pub location: Span,
|
||||||
|
@ -141,21 +141,21 @@ pub enum Definition<T, Expr, ConstantRecordTag, PackageName> {
|
||||||
impl<A, B, C, E> Definition<A, B, C, E> {
|
impl<A, B, C, E> Definition<A, B, C, E> {
|
||||||
pub fn location(&self) -> Span {
|
pub fn location(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
Definition::Fn { location, .. }
|
Definition::Fn(Function { location, .. })
|
||||||
| Definition::Use { location, .. }
|
| Definition::Use(Use { location, .. })
|
||||||
| Definition::TypeAlias { location, .. }
|
| Definition::TypeAlias(TypeAlias { location, .. })
|
||||||
| Definition::DataType { location, .. }
|
| Definition::DataType(DataType { location, .. })
|
||||||
| Definition::ModuleConstant { location, .. } => *location,
|
| Definition::ModuleConstant(ModuleConstant { location, .. }) => *location,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_doc(&mut self, new_doc: String) {
|
pub fn put_doc(&mut self, new_doc: String) {
|
||||||
match self {
|
match self {
|
||||||
Definition::Use { .. } => (),
|
Definition::Use { .. } => (),
|
||||||
Definition::Fn { doc, .. }
|
Definition::Fn(Function { doc, .. })
|
||||||
| Definition::TypeAlias { doc, .. }
|
| Definition::TypeAlias(TypeAlias { doc, .. })
|
||||||
| Definition::DataType { doc, .. }
|
| Definition::DataType(DataType { doc, .. })
|
||||||
| Definition::ModuleConstant { doc, .. } => {
|
| Definition::ModuleConstant(ModuleConstant { doc, .. }) => {
|
||||||
let _ = std::mem::replace(doc, Some(new_doc));
|
let _ = std::mem::replace(doc, Some(new_doc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ use vec1::Vec1;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
Annotation, Arg, ArgName, AssignmentKind, BinOp, CallArg, ClauseGuard, Constant,
|
Annotation, Arg, ArgName, AssignmentKind, BinOp, CallArg, ClauseGuard, Constant, DataType,
|
||||||
Definition, Pattern, RecordConstructor, RecordConstructorArg, RecordUpdateSpread, Span,
|
Definition, Function, ModuleConstant, Pattern, RecordConstructor, RecordConstructorArg,
|
||||||
TypedArg, TypedConstant, UnqualifiedImport, UntypedArg, UntypedClause, UntypedClauseGuard,
|
RecordUpdateSpread, Span, TypeAlias, TypedArg, TypedConstant, UnqualifiedImport,
|
||||||
UntypedDefinition, UntypedModule, UntypedPattern, UntypedRecordUpdateArg, CAPTURE_VARIABLE,
|
UntypedArg, UntypedClause, UntypedClauseGuard, UntypedDefinition, UntypedModule,
|
||||||
|
UntypedPattern, UntypedRecordUpdateArg, Use, CAPTURE_VARIABLE,
|
||||||
},
|
},
|
||||||
docvec,
|
docvec,
|
||||||
expr::UntypedExpr,
|
expr::UntypedExpr,
|
||||||
|
@ -205,7 +206,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
|
|
||||||
fn definition<'a>(&mut self, definition: &'a UntypedDefinition) -> Document<'a> {
|
fn definition<'a>(&mut self, definition: &'a UntypedDefinition) -> Document<'a> {
|
||||||
match definition {
|
match definition {
|
||||||
Definition::Fn {
|
Definition::Fn(Function {
|
||||||
name,
|
name,
|
||||||
arguments: args,
|
arguments: args,
|
||||||
body,
|
body,
|
||||||
|
@ -213,17 +214,17 @@ impl<'comments> Formatter<'comments> {
|
||||||
return_annotation,
|
return_annotation,
|
||||||
end_position,
|
end_position,
|
||||||
..
|
..
|
||||||
} => self.definition_fn(public, name, args, return_annotation, body, *end_position),
|
}) => self.definition_fn(public, name, args, return_annotation, body, *end_position),
|
||||||
|
|
||||||
Definition::TypeAlias {
|
Definition::TypeAlias(TypeAlias {
|
||||||
alias,
|
alias,
|
||||||
parameters: args,
|
parameters: args,
|
||||||
annotation: resolved_type,
|
annotation: resolved_type,
|
||||||
public,
|
public,
|
||||||
..
|
..
|
||||||
} => self.type_alias(*public, alias, args, resolved_type),
|
}) => self.type_alias(*public, alias, args, resolved_type),
|
||||||
|
|
||||||
Definition::DataType {
|
Definition::DataType(DataType {
|
||||||
name,
|
name,
|
||||||
parameters,
|
parameters,
|
||||||
public,
|
public,
|
||||||
|
@ -231,14 +232,14 @@ impl<'comments> Formatter<'comments> {
|
||||||
location,
|
location,
|
||||||
opaque,
|
opaque,
|
||||||
..
|
..
|
||||||
} => self.data_type(*public, *opaque, name, parameters, constructors, location),
|
}) => self.data_type(*public, *opaque, name, parameters, constructors, location),
|
||||||
|
|
||||||
Definition::Use {
|
Definition::Use(Use {
|
||||||
module,
|
module,
|
||||||
as_name,
|
as_name,
|
||||||
unqualified,
|
unqualified,
|
||||||
..
|
..
|
||||||
} => "use "
|
}) => "use "
|
||||||
.to_doc()
|
.to_doc()
|
||||||
.append(Document::String(module.join("/")))
|
.append(Document::String(module.join("/")))
|
||||||
.append(if unqualified.is_empty() {
|
.append(if unqualified.is_empty() {
|
||||||
|
@ -264,13 +265,13 @@ impl<'comments> Formatter<'comments> {
|
||||||
nil()
|
nil()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Definition::ModuleConstant {
|
Definition::ModuleConstant(ModuleConstant {
|
||||||
public,
|
public,
|
||||||
name,
|
name,
|
||||||
annotation,
|
annotation,
|
||||||
value,
|
value,
|
||||||
..
|
..
|
||||||
} => {
|
}) => {
|
||||||
let head = pub_(*public).append("const ").append(name.as_str());
|
let head = pub_(*public).append("const ").append(name.as_str());
|
||||||
let head = match annotation {
|
let head = match annotation {
|
||||||
None => head,
|
None => head,
|
||||||
|
|
|
@ -10,7 +10,6 @@ pub mod format;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod pretty;
|
pub mod pretty;
|
||||||
pub mod tipo;
|
pub mod tipo;
|
||||||
pub mod token;
|
|
||||||
pub mod uplc;
|
pub mod uplc;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
|
|
|
@ -3,8 +3,7 @@ use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self, DataType, Function, Span, TypeAlias, Use},
|
ast::{self, DataType, Function, Span, TypeAlias, Use},
|
||||||
expr, lexer,
|
expr, parser,
|
||||||
parser::module_parser,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -469,7 +469,7 @@ pub struct RecordAccessor {
|
||||||
pub tipo: Arc<Type>,
|
pub tipo: Arc<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum PatternConstructor {
|
pub enum PatternConstructor {
|
||||||
Record {
|
Record {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
@ -9,9 +9,7 @@ use uplc::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{BinOp, DataType, Function, Pattern, TypedArg, TypedPattern},
|
||||||
BinOp, DataType, Function, ModuleConstant, Pattern, TypeAlias, TypedArg, TypedPattern, Use,
|
|
||||||
},
|
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
tipo::{self, ModuleValueConstructor, Type, ValueConstructorVariant},
|
tipo::{self, ModuleValueConstructor, Type, ValueConstructorVariant},
|
||||||
};
|
};
|
||||||
|
@ -91,19 +89,19 @@ pub struct CodeGenerator<'a> {
|
||||||
uplc_data_constr_lookup: IndexMap<(String, String), ScopeLevels>,
|
uplc_data_constr_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
uplc_data_usage_holder_lookup: IndexMap<(String, String), ScopeLevels>,
|
||||||
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
||||||
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<(String, String), &'a DataType<Arc<tipo::Type>>>,
|
data_types: &'a HashMap<(String, String), &'a DataType<Arc<tipo::Type>>>,
|
||||||
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>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CodeGenerator<'a> {
|
impl<'a> CodeGenerator<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
functions: &'a HashMap<(String, String), &'a Function<Arc<tipo::Type>, TypedExpr>>,
|
||||||
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<(String, String), &'a DataType<Arc<tipo::Type>>>,
|
data_types: &'a HashMap<(String, String), &'a DataType<Arc<tipo::Type>>>,
|
||||||
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>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
CodeGenerator {
|
CodeGenerator {
|
||||||
uplc_function_holder: Vec::new(),
|
uplc_function_holder: Vec::new(),
|
||||||
|
@ -112,10 +110,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
uplc_data_constr_lookup: IndexMap::new(),
|
uplc_data_constr_lookup: IndexMap::new(),
|
||||||
uplc_data_usage_holder_lookup: IndexMap::new(),
|
uplc_data_usage_holder_lookup: IndexMap::new(),
|
||||||
functions,
|
functions,
|
||||||
type_aliases,
|
// type_aliases,
|
||||||
data_types,
|
data_types,
|
||||||
imports,
|
// imports,
|
||||||
constants,
|
// constants,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use aiken_lang::{error::ParseError, parser::ast::Span, tipo};
|
use aiken_lang::{ast::Span, parser::error::ParseError, tipo};
|
||||||
use miette::{Diagnostic, EyreContext, LabeledSpan, MietteHandlerOpts, RgbColors, SourceCode};
|
use miette::{Diagnostic, EyreContext, LabeledSpan, MietteHandlerOpts, RgbColors, SourceCode};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -347,10 +347,10 @@ impl Project {
|
||||||
if VALIDATOR_NAMES.contains(&name.as_str()) {
|
if VALIDATOR_NAMES.contains(&name.as_str()) {
|
||||||
let mut generator = CodeGenerator::new(
|
let mut generator = CodeGenerator::new(
|
||||||
&functions,
|
&functions,
|
||||||
&type_aliases,
|
// &type_aliases,
|
||||||
&data_types,
|
&data_types,
|
||||||
&imports,
|
// &imports,
|
||||||
&constants,
|
// &constants,
|
||||||
);
|
);
|
||||||
|
|
||||||
let program = generator.generate(body, arguments);
|
let program = generator.generate(body, arguments);
|
||||||
|
|
Loading…
Reference in New Issue