#![deny(nonstandard_style, warnings, unused)]
#![deny(
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces,
unused_qualifications
)]
#![cfg_attr(feature = "cargo-clippy", deny(clippy::all, clippy::pedantic))]
#[macro_use]
extern crate enum_primitive_derive;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lalrpop_util;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate specs_derive;
#[macro_use]
extern crate specs_visitor_derive;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
use std::fmt;
mod ast;
mod codegen;
mod interpreter;
mod ir;
mod parser;
mod value;
#[cfg(test)]
mod test_util;
pub mod diagnostic;
pub mod error;
pub mod graph;
pub mod module;
pub use crate::error::Error;
pub use crate::error::Result;
pub struct Tin {
ir: ir::Ir,
codemap: codespan::CodeMap,
parser: <ast::Module<parser::Context> as parser::Parse>::Parser,
}
impl Tin {
pub fn new() -> Tin {
use crate::parser::Parse;
let ir = ir::Ir::new();
let codemap = codespan::CodeMap::new();
let parser = ast::Module::new_parser();
Tin {
ir,
codemap,
parser,
}
}
pub fn load<F>(&mut self, file_name: F, source: &str) -> Result<()>
where
F: Into<codespan::FileName>,
{
let span = self
.codemap
.add_filemap(file_name.into(), source.to_owned())
.span();
let module = parser::Parser::parse(&mut self.parser, span, source)?;
self.ir.load(&module)?;
Ok(())
}
pub fn graph(&self) -> graph::Graph {
graph::Graph::new(&self.ir)
}
pub fn compile(&mut self) -> Result<module::Module> {
self.ir.check_types()?;
let module = codegen::Codegen::new(&self.ir, &self.codemap).compile();
Ok(module)
}
pub fn codemap(&self) -> &codespan::CodeMap {
&self.codemap
}
}
impl Default for Tin {
fn default() -> Self {
Tin::new()
}
}
impl fmt::Debug for Tin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Tin").finish()
}
}