Updated api bootstrap
This commit is contained in:
@@ -11,11 +11,11 @@ use mist_parser::rev_mapper;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MistDiagnosticMessage {
|
pub struct MistDiagnosticMessage {
|
||||||
pub message String,
|
pub String message,
|
||||||
pub file_path PathBuf,
|
pub PathBuf file_path,
|
||||||
pub file_name String ,
|
pub String file_name,
|
||||||
pub line usize,
|
pub usize line,
|
||||||
pub column usize,
|
pub usize column,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -25,7 +25,7 @@ pub enum MistDiagnostic {
|
|||||||
Rust(CompilerMessage),
|
Rust(CompilerMessage),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bool build(mut args Vec<String>, root PathBuf) {
|
pub bool build(Vec<String> mut args, PathBuf root) {
|
||||||
args.remove(0);
|
args.remove(0);
|
||||||
args.insert(1, "--message-format=json".to_string());
|
args.insert(1, "--message-format=json".to_string());
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ pub fn bool build(mut args Vec<String>, root PathBuf) {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void print_diagnostics(diagnostics *Vec<MistDiagnostic>) {
|
pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics) {
|
||||||
let mut files = HashMap::new();
|
let mut files = HashMap::new();
|
||||||
|
|
||||||
for diag in diagnostics {
|
for diag in diagnostics {
|
||||||
@@ -159,9 +159,9 @@ pub fn void print_diagnostics(diagnostics *Vec<MistDiagnostic>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Option<String> get_line(
|
pub Option<String> get_line(
|
||||||
files *mut HashMap<PathBuf, Vec<String>>,
|
HashMap<PathBuf, Vec<String>> mut& files,
|
||||||
msg *MistDiagnosticMessage,
|
MistDiagnosticMessage& msg,
|
||||||
) {
|
) {
|
||||||
let src_path = msg.file_path.clone();
|
let src_path = msg.file_path.clone();
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ use crate::transpiler::MistConfig;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub class Module {
|
pub class Module {
|
||||||
pub name String;
|
pub String name;
|
||||||
pub path PathBuf;
|
pub PathBuf path;
|
||||||
pub children Vec<Module>;
|
pub Vec<Module> children;
|
||||||
|
|
||||||
pub constructor(mist_path PathBuf, config *MistConfig) {
|
pub constructor(PathBuf mist_path, MistConfig& config) {
|
||||||
self.children = Vec::new();
|
self.children = Vec::new();
|
||||||
self.name = mist_path.file_stem()
|
self.name = mist_path.file_stem()
|
||||||
.and_then(fn(s) -> s.to_str())
|
.and_then(fn(s) -> s.to_str())
|
||||||
@@ -37,7 +37,7 @@ pub class Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void scan_directory(*mut self, search_dir *Path, config *MistConfig) {
|
void scan_directory(&mut self, Path& search_dir, MistConfig& config) {
|
||||||
let entries = match fs::read_dir(search_dir) {
|
let entries = match fs::read_dir(search_dir) {
|
||||||
Ok(entries) => entries;
|
Ok(entries) => entries;
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -65,11 +65,11 @@ pub class Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bool is_package(*self) {
|
pub bool is_package(&self) {
|
||||||
self.path.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() == Some("package.mist")
|
self.path.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() == Some("package.mist")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn PathBuf output_dir(*self, parent_dir *PathBuf) {
|
pub PathBuf output_dir(&self, PathBuf& parent_dir) {
|
||||||
if self.path.is_dir() || self.is_package() {
|
if self.path.is_dir() || self.is_package() {
|
||||||
parent_dir.join(&self.name)
|
parent_dir.join(&self.name)
|
||||||
} else {
|
} else {
|
||||||
@@ -77,7 +77,13 @@ pub class Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn PathBuf output_path(*self, parent_dir *PathBuf, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) {
|
pub PathBuf output_path(&self,
|
||||||
|
PathBuf& parent_dir,
|
||||||
|
Option<(
|
||||||
|
mist_parser::ast::Visibility,
|
||||||
|
mist_parser::ast::Identifier
|
||||||
|
)>& curr_mod_decl
|
||||||
|
) {
|
||||||
let name = if let Some((_, name)) = curr_mod_decl {
|
let name = if let Some((_, name)) = curr_mod_decl {
|
||||||
&name.0
|
&name.0
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ use serde::Deserialize;
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct MistConfig {
|
pub struct MistConfig {
|
||||||
pub package PathBuf,
|
pub PathBuf package,
|
||||||
pub packages Vec<PathBuf>,
|
pub Vec<PathBuf> packages,
|
||||||
pub main_mods String
|
pub String main_mods
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MistConfig {
|
impl MistConfig {
|
||||||
pub fn bool should_ignore(*self, path *Path) {
|
pub bool should_ignore(&self, Path& path) {
|
||||||
if path == self.package {
|
if path == self.package {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ impl MistConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for MistConfig {
|
impl Default for MistConfig {
|
||||||
fn Self default() {
|
Self default() {
|
||||||
Self {
|
Self {
|
||||||
package: PathBuf::from("main.mist"),
|
package: PathBuf::from("main.mist"),
|
||||||
packages: Vec::new(),
|
packages: Vec::new(),
|
||||||
@@ -46,7 +46,7 @@ impl Default for MistConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn PathBuf transpile() {
|
pub PathBuf transpile() {
|
||||||
let start = time::Instant::now();
|
let start = time::Instant::now();
|
||||||
|
|
||||||
let root = env::current_dir().expect("Unable to find project root");
|
let root = env::current_dir().expect("Unable to find project root");
|
||||||
@@ -58,7 +58,7 @@ pub fn PathBuf transpile() {
|
|||||||
let toml_content = fs::read_to_string(&toml_path)
|
let toml_content = fs::read_to_string(&toml_path)
|
||||||
.unwrap_or_else(fn(_) -> panic!("Could not read file at {:?}", toml_path));
|
.unwrap_or_else(fn(_) -> panic!("Could not read file at {:?}", toml_path));
|
||||||
|
|
||||||
let mut config MistConfig = toml::from_str(&toml_content)
|
MistConfig mut config = toml::from_str(&toml_content)
|
||||||
.unwrap_or_else(fn(_) -> panic!("Failed to parse Mist.toml from {:?}", toml_path));
|
.unwrap_or_else(fn(_) -> panic!("Failed to parse Mist.toml from {:?}", toml_path));
|
||||||
|
|
||||||
for pkg in &mut config.packages {
|
for pkg in &mut config.packages {
|
||||||
@@ -85,7 +85,7 @@ pub fn PathBuf transpile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl modules::Module {
|
impl modules::Module {
|
||||||
fn (bool, String) transpile(*self, parent_dir *PathBuf, config *mut MistConfig) {
|
(bool, String) transpile(&self, PathBuf& parent_dir, MistConfig mut& config) {
|
||||||
if !self.path.is_dir() && self.path.extension().and_then(fn(v) -> v.to_str()) != Some("mist") {
|
if !self.path.is_dir() && self.path.extension().and_then(fn(v) -> v.to_str()) != Some("mist") {
|
||||||
let file_name = self.path.file_name()
|
let file_name = self.path.file_name()
|
||||||
.and_then(fn(s) -> s.to_str())
|
.and_then(fn(s) -> s.to_str())
|
||||||
@@ -124,7 +124,7 @@ impl modules::Module {
|
|||||||
self.write_transpile(output, parent_dir, child_changed)
|
self.write_transpile(output, parent_dir, child_changed)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (bool, String) write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) {
|
(bool, String) write_transpile(&self, String output, PathBuf& parent_dir, bool child_changed) {
|
||||||
if self.path.is_dir() {
|
if self.path.is_dir() {
|
||||||
let output_file = self.output_path(parent_dir, &None);
|
let output_file = self.output_path(parent_dir, &None);
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ impl modules::Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn std::io::Result<bool> is_source_newer(source *Path, output *Path) {
|
std::io::Result<bool> is_source_newer(Path& source, Path& output) {
|
||||||
if !output.exists() {
|
if !output.exists() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
@@ -190,8 +190,14 @@ pub enum TranspileError<'a> {
|
|||||||
Semantic(Vec<mist_parser::semantics::SemanticError>)
|
Semantic(Vec<mist_parser::semantics::SemanticError>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>>
|
pub Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>>
|
||||||
transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) {
|
transpile_code<'a>(
|
||||||
|
PathBuf& path,
|
||||||
|
str 'a& source,
|
||||||
|
PathBuf mut output_file,
|
||||||
|
str& mod_decl,
|
||||||
|
Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>& curr_mod_decl
|
||||||
|
) {
|
||||||
|
|
||||||
if let Some((_, name)) = &curr_mod_decl {
|
if let Some((_, name)) = &curr_mod_decl {
|
||||||
if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
||||||
@@ -225,7 +231,14 @@ pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>>
|
|||||||
Ok((output_file, gc, output))
|
Ok((output_file, gc, output))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) {
|
pub void transpile_file(
|
||||||
|
PathBuf& path,
|
||||||
|
str& source,
|
||||||
|
PathBuf output_file,
|
||||||
|
str& mod_decl,
|
||||||
|
Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>& curr_mod_decl
|
||||||
|
) {
|
||||||
|
|
||||||
let (output_file, gc, output) = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) {
|
let (output_file, gc, output) = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) {
|
||||||
Ok(output) => output;
|
Ok(output) => output;
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -261,7 +274,7 @@ pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
pub void decode_err<'a>(TranspileError<'a>& err, PathBuf& path) {
|
||||||
let curr_dir = std::env::current_dir().unwrap();
|
let curr_dir = std::env::current_dir().unwrap();
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
|
|||||||
Reference in New Issue
Block a user