feat: typecheck If expressions
This commit is contained in:
@@ -8,7 +8,11 @@ use clap::{Parser, Subcommand};
|
||||
#[clap(propagate_version = true)]
|
||||
pub enum Args {
|
||||
/// Build an aiken project
|
||||
Build,
|
||||
Build {
|
||||
/// Path to project
|
||||
#[clap(short, long)]
|
||||
directory: Option<PathBuf>,
|
||||
},
|
||||
/// Typecheck a project project
|
||||
Check {
|
||||
/// Path to project
|
||||
|
||||
@@ -55,7 +55,14 @@ impl Error {
|
||||
}
|
||||
|
||||
pub fn report(&self) {
|
||||
eprintln!("Error: {:?}", self)
|
||||
match self {
|
||||
Error::List(errors) => {
|
||||
for error in errors {
|
||||
eprintln!("Error: {:?}", error)
|
||||
}
|
||||
}
|
||||
rest => eprintln!("Error: {:?}", rest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use uplc::{
|
||||
},
|
||||
};
|
||||
|
||||
use aiken::{config::Config, error, project::Project};
|
||||
use aiken::{config::Config, project::Project};
|
||||
|
||||
mod args;
|
||||
|
||||
@@ -28,14 +28,35 @@ fn main() -> miette::Result<()> {
|
||||
let args = Args::default();
|
||||
|
||||
match args {
|
||||
Args::Build => {
|
||||
// 1. load and parse modules
|
||||
// * lib - contains modules, types, and functions
|
||||
// * contracts - contains validators
|
||||
// * scripts - contains native scripts dsl
|
||||
// 2. type check everything
|
||||
// 3. generate uplc and policy/address if relevant
|
||||
todo!()
|
||||
Args::Build { directory } => {
|
||||
let project_path = if let Some(d) = directory {
|
||||
d
|
||||
} else {
|
||||
env::current_dir().into_diagnostic()?
|
||||
};
|
||||
|
||||
let config = Config::load(project_path.clone()).into_diagnostic()?;
|
||||
|
||||
let mut project = Project::new(config, project_path);
|
||||
|
||||
let build_result = project.build();
|
||||
|
||||
let warning_count = project.warnings.len();
|
||||
|
||||
for warning in project.warnings {
|
||||
warning.report()
|
||||
}
|
||||
|
||||
if let Err(err) = build_result {
|
||||
err.report();
|
||||
|
||||
miette::bail!(
|
||||
"failed: {} error(s), {warning_count} warning(s)",
|
||||
err.total(),
|
||||
);
|
||||
};
|
||||
|
||||
println!("finished with {warning_count} warning(s)")
|
||||
}
|
||||
|
||||
Args::Check { directory } => {
|
||||
@@ -49,24 +70,24 @@ fn main() -> miette::Result<()> {
|
||||
|
||||
let mut project = Project::new(config, project_path);
|
||||
|
||||
let build_result = project.build();
|
||||
let build_result = project.check();
|
||||
|
||||
let warning_count = project.warnings.len();
|
||||
|
||||
for warning in project.warnings {
|
||||
warning.report()
|
||||
}
|
||||
|
||||
if let Err(err) = build_result {
|
||||
match &err {
|
||||
error::Error::List(errors) => {
|
||||
for error in errors {
|
||||
eprintln!("Error: {:?}", error)
|
||||
}
|
||||
}
|
||||
rest => eprintln!("Error: {:?}", rest),
|
||||
}
|
||||
err.report();
|
||||
|
||||
// miette::bail!("failed: {} errors", err.total());
|
||||
miette::bail!(
|
||||
"failed: {} error(s), {warning_count} warning(s)",
|
||||
err.total(),
|
||||
);
|
||||
};
|
||||
|
||||
println!("finished with {warning_count} warning(s)")
|
||||
}
|
||||
|
||||
Args::Dev => {
|
||||
|
||||
@@ -50,15 +50,21 @@ impl Project {
|
||||
}
|
||||
|
||||
pub fn build(&mut self) -> Result<(), Error> {
|
||||
self.compile(true)
|
||||
}
|
||||
|
||||
pub fn check(&mut self) -> Result<(), Error> {
|
||||
self.compile(false)
|
||||
}
|
||||
|
||||
pub fn compile(&mut self, _uplc_gen: bool) -> Result<(), Error> {
|
||||
self.read_source_files()?;
|
||||
|
||||
let parsed_modules = self.parse_sources()?;
|
||||
|
||||
let processing_sequence = parsed_modules.sequence()?;
|
||||
|
||||
let checked_modules = self.type_check(parsed_modules, processing_sequence)?;
|
||||
|
||||
println!("{:?}", checked_modules);
|
||||
let _checked_modules = self.type_check(parsed_modules, processing_sequence)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -143,7 +149,8 @@ impl Project {
|
||||
path,
|
||||
code,
|
||||
kind,
|
||||
package,
|
||||
// TODO: come back and figure out where to use this
|
||||
package: _package,
|
||||
ast,
|
||||
}) = parsed_modules.remove(&name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user