Updated api bootstrap

This commit is contained in:
2026-06-05 23:11:48 +02:00
parent 1a281cd344
commit 6e26b283fa
4 changed files with 41 additions and 41 deletions
+15 -15
View File
@@ -11,11 +11,11 @@ use mist_parser::rev_mapper;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MistDiagnosticMessage { pub struct MistDiagnosticMessage {
pub String message, pub message String,
pub PathBuf file_path, pub file_path PathBuf,
pub String file_name, pub file_name String ,
pub usize line, pub line usize,
pub usize column, pub column usize,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -25,7 +25,7 @@ pub enum MistDiagnostic {
Rust[CompilerMessage], Rust[CompilerMessage],
} }
pub bool build(Vec<String> mut args, PathBuf root) { pub fn build(mut args Vec<String>, root PathBuf) bool {
args.remove(0); args.remove(0);
args.insert(1, "--message-format=json".to_string()); args.insert(1, "--message-format=json".to_string());
@@ -68,7 +68,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
break; break;
} }
let map = mapping.entry(rust_path.clone()).or_insert_with(|| { let map = mapping.entry(rust_path.clone()).or_insert_with(fn() {
rev_mapper::get_mapping( rev_mapper::get_mapping(
&fs::read_to_string(rust_path) &fs::read_to_string(rust_path)
.expect("Failed to read file for mapping") .expect("Failed to read file for mapping")
@@ -117,7 +117,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
let mut stdout = std::io::stdout(); let mut stdout = std::io::stdout();
std::io::copy(&mut raw_reader, &mut stdout) std::io::copy(&mut raw_reader, &mut stdout)
.map_err(|let v| v.to_string()) .map_err(fn(v) -> v.to_string())
.expect("(Mist) Failed to copy IO"); .expect("(Mist) Failed to copy IO");
command.wait().unwrap(); command.wait().unwrap();
@@ -133,7 +133,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
false false
} }
pub void print_diagnostics(Vec<MistDiagnostic>* diagnostics) { pub fn print_diagnostics(diagnostics *Vec<MistDiagnostic>) {
let mut files = HashMap::new(); let mut files = HashMap::new();
for (diag : diagnostics) { for (diag : diagnostics) {
@@ -169,13 +169,13 @@ pub void print_diagnostics(Vec<MistDiagnostic>* diagnostics) {
} }
} }
pub Option<String> get_line( pub fn get_line(
HashMap<PathBuf, Vec<String>> mut* files, files *mut HashMap<PathBuf, Vec<String>>,
MistDiagnosticMessage* msg, msg *MistDiagnosticMessage,
) { ) Option<String> {
let src_path = msg.file_path.clone(); let src_path = msg.file_path.clone();
let lines = files.entry(src_path.clone()).or_insert_with(|| { let lines = files.entry(src_path.clone()).or_insert_with(fn() {
fs::read_to_string(src_path) fs::read_to_string(src_path)
.expect("Unable to read mist file") .expect("Unable to read mist file")
.lines() .lines()
@@ -184,5 +184,5 @@ pub Option<String> get_line(
.collect() .collect()
}); });
lines.get(msg.line - 1).map(|let v| v.trim().to_string()) lines.get(msg.line - 1).map(fn(v) -> v.trim().to_string())
} }
+1 -1
View File
@@ -2,4 +2,4 @@ pub mod builder;
pub mod transpiler; pub mod transpiler;
pub mod modules; pub mod modules;
void main() {} fn main() {}
+13 -13
View File
@@ -5,22 +5,22 @@ use std::process;
#[derive(Debug)] #[derive(Debug)]
pub class Module { pub class Module {
pub String name; pub name String;
pub PathBuf path; pub path PathBuf;
pub Vec<Self> children; pub children Vec<Self>;
pub constructor(PathBuf mist_path) { pub constructor(mist_path PathBuf) {
self.children = Vec::new(); self.children = Vec::new();
self.name = mist_path.file_stem() self.name = mist_path.file_stem()
.and_then(|let s| s.to_str()) .and_then(fn(s) -> s.to_str())
.expect("Failed to get module name") .expect("Failed to get module name")
.to_string(); .to_string();
self.path = mist_path; self.path = mist_path;
if (self.path.is_dir()) { if (self.path.is_dir()) {
PathBuf dir = self.path.clone(); let dir = self.path.clone();
PathBuf pkg_gate = self.path.join("package.mist"); let pkg_gate = self.path.join("package.mist");
if (pkg_gate.exists()) { if (pkg_gate.exists()) {
self.path = pkg_gate; self.path = pkg_gate;
} }
@@ -29,7 +29,7 @@ pub class Module {
} }
} }
void scan_directory(self mut*, Path* search_dir) { fn scan_directory(*mut self, search_dir *Path) {
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] => {
@@ -47,7 +47,7 @@ pub class Module {
} }
}; };
PathBuf child_path = entry.path(); let child_path = entry.path();
if (child_path == self.path) { if (child_path == self.path) {
continue; continue;
@@ -57,7 +57,7 @@ pub class Module {
} }
} }
pub PathBuf output_dir(self*, PathBuf* parent_dir) { pub fn output_dir(*self, parent_dir *PathBuf) PathBuf {
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) { if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
parent_dir.join(&self.name) parent_dir.join(&self.name)
} else { } else {
@@ -65,7 +65,7 @@ pub class Module {
} }
} }
pub PathBuf output_path(self*, PathBuf* parent_dir) { pub fn output_path(*self, parent_dir *PathBuf) PathBuf {
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) { if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
parent_dir.join(&self.name).join("mod.rs") parent_dir.join(&self.name).join("mod.rs")
} else { } else {
@@ -74,10 +74,10 @@ pub class Module {
} }
} }
pub Module master_package(PathBuf mist_path) { pub fn master_package(mist_path PathBuf) Module {
let mut root_mod = Module::new(mist_path.clone()); let mut root_mod = Module::new(mist_path.clone());
Path* parent_dir = mist_path.parent() let parent_dir = mist_path.parent()
.expect("Failed to get parent directory of root file"); .expect("Failed to get parent directory of root file");
root_mod.scan_directory(parent_dir); root_mod.scan_directory(parent_dir);
+12 -12
View File
@@ -7,13 +7,13 @@ use std::env;
use mist_parser::error; use mist_parser::error;
use crate::modules; use crate::modules;
pub PathBuf transpile() { pub fn transpile() PathBuf {
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");
PathBuf src = root.join("src"); let src = root.join("src");
PathBuf out = root.join(".mist/src"); let out = root.join(".mist/src");
let master = modules::master_package(src.join("main.mist")); let master = modules::master_package(src.join("main.mist"));
@@ -30,10 +30,10 @@ pub PathBuf transpile() {
} }
impl modules::Module { impl modules::Module {
String transpile(self*, PathBuf* parent_dir) { fn transpile(*self, parent_dir *PathBuf) String {
if (!self.path.is_dir() && self.path.extension().and_then(|let 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(|let s| s.to_str()) .and_then(fn(s) -> s.to_str())
.expect("Failed to get file name"); .expect("Failed to get file name");
fs::copy(&self.path, parent_dir.join(&file_name)).expect("Failed to copy SideFile"); fs::copy(&self.path, parent_dir.join(&file_name)).expect("Failed to copy SideFile");
@@ -41,12 +41,12 @@ impl modules::Module {
return String::new(); return String::new();
} }
PathBuf dir = self.output_dir(&parent_dir); let dir = self.output_dir(&parent_dir);
PathBuf output_file = self.output_path(&parent_dir); let output_file = self.output_path(&parent_dir);
let _ = fs::create_dir_all(&dir); let _ = fs::create_dir_all(&dir);
String mut output = String::new(); let mut output = String::new();
for (child : &self.children) { for (child : &self.children) {
output.push_str(&child.transpile(&dir)); output.push_str(&child.transpile(&dir));
@@ -76,8 +76,8 @@ impl modules::Module {
} }
} }
void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) { fn transpile_file(path *PathBuf, output_file *PathBuf, mod_decl *str) {
String source = match (fs::read_to_string(path)) { let source = match (fs::read_to_string(path)) {
Ok[s] => s; Ok[s] => s;
Err[e] => { Err[e] => {
eprintln!("error: failed to read file {}\n {}", path.display(), e); eprintln!("error: failed to read file {}\n {}", path.display(), e);
@@ -88,7 +88,7 @@ void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) {
let mut gc = mist_codegen::RustCodegen::new(); let mut gc = mist_codegen::RustCodegen::new();
String output = gc.generate(match (mist_parser::parse(&source)) { let output = gc.generate(match (mist_parser::parse(&source)) {
Ok[ast] => ast; Ok[ast] => ast;
Err[e] => { Err[e] => {
match (e) { match (e) {