Compare commits
13
Commits
v0.4.0-alpha.0
...
v0.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93ba0e97da | ||
|
|
9c0aa3d182 | ||
|
|
e1b851911d | ||
|
|
72f7b8430d | ||
|
|
0100abfa53 | ||
|
|
01b7e816ee | ||
|
|
ac94882e5a | ||
|
|
9220ee3b29 | ||
|
|
b15f13880a | ||
|
|
d538168692 | ||
|
|
b68e4245d4 | ||
|
|
c5354ff424 | ||
|
|
be68f93038 |
Generated
+5
-5
@@ -476,7 +476,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist-analyzer"
|
name = "mist-analyzer"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
"dashmap 6.1.0",
|
"dashmap 6.1.0",
|
||||||
@@ -495,7 +495,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist-api"
|
name = "mist-api"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
"mist-codegen",
|
"mist-codegen",
|
||||||
@@ -507,7 +507,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist-codegen"
|
name = "mist-codegen"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytecount",
|
"bytecount",
|
||||||
"mist-parser",
|
"mist-parser",
|
||||||
@@ -515,7 +515,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist-lang"
|
name = "mist-lang"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"mist-analyzer",
|
"mist-analyzer",
|
||||||
"mist-api",
|
"mist-api",
|
||||||
@@ -524,7 +524,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist-parser"
|
name = "mist-parser"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pest",
|
"pest",
|
||||||
"pest_derive",
|
"pest_derive",
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist-lang"
|
name = "mist-lang"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "The Mist programming language compiler"
|
description = "The Mist programming language compiler"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
@@ -33,10 +33,10 @@ exclude = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
mist-parser = { path = "crates/parser", version = "0.4.0-alpha.0" }
|
mist-parser = { path = "crates/parser", version = "0.4.0" }
|
||||||
mist-analyzer = { path = "crates/analyzer", version = "0.4.0-alpha.0" }
|
mist-analyzer = { path = "crates/analyzer", version = "0.4.0" }
|
||||||
mist-codegen = { path = "crates/codegen", version = "0.4.0-alpha.0" }
|
mist-codegen = { path = "crates/codegen", version = "0.4.0" }
|
||||||
mist-api = { path = "crates/mist-api", version = "0.4.0-alpha.0" }
|
mist-api = { path = "crates/mist-api", version = "0.4.0" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "mist"
|
name = "mist"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist-analyzer"
|
name = "mist-analyzer"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "The Mist programming language Analyzer LSP"
|
description = "The Mist programming language Analyzer LSP"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
+80
-12
@@ -93,12 +93,12 @@ fn clean_lsp_url(path: &std::path::Path) -> Option<Url> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn lsp_pos_to_rust_map(pos: &Position) -> RustMap {
|
fn lsp_pos_to_rust_map(pos: &Position) -> RustMap {
|
||||||
RustMap(pos.line as usize + 1, pos.character as usize)
|
RustMap(pos.line as usize, pos.character as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mist_map_to_lsp_pos(map: &MistMap) -> Position {
|
fn mist_map_to_lsp_pos(map: &MistMap) -> Position {
|
||||||
Position {
|
Position {
|
||||||
line: map.0.saturating_sub(1) as u32,
|
line: map.0 as u32,
|
||||||
character: map.1 as u32,
|
character: map.1 as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ impl Backend {
|
|||||||
// Fallback: the source has a syntax error that prevents transpilation.
|
// Fallback: the source has a syntax error that prevents transpilation.
|
||||||
// Use the last known working Rust content + mapping to inject the
|
// Use the last known working Rust content + mapping to inject the
|
||||||
// marker at the nearest valid Rust position.
|
// marker at the nearest valid Rust position.
|
||||||
let mist_target = MistMap(line as usize + 1, character as usize);
|
let mist_target = MistMap(line as usize, character as usize);
|
||||||
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
||||||
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||||
rust_path.set_file_name("mod.rs");
|
rust_path.set_file_name("mod.rs");
|
||||||
@@ -417,7 +417,7 @@ impl Backend {
|
|||||||
.map(|(rust, _)| *rust);
|
.map(|(rust, _)| *rust);
|
||||||
|
|
||||||
let (modified_rust, rust_pos) = if let Some(next_rust) = rust_next {
|
let (modified_rust, rust_pos) = if let Some(next_rust) = rust_next {
|
||||||
let lsp_line = (next_rust.0 - 1) as u32;
|
let lsp_line = next_rust.0 as u32;
|
||||||
let lsp_col = next_rust.1 as u32;
|
let lsp_col = next_rust.1 as u32;
|
||||||
let modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
let modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
||||||
let pos = find_marker_position(&modified, &marker)?;
|
let pos = find_marker_position(&modified, &marker)?;
|
||||||
@@ -604,6 +604,59 @@ impl Backend {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Prune documents whose source files no longer exist on disk.
|
||||||
|
// Without this, deleted .mist files linger in the in-memory map
|
||||||
|
// and compute_mod_decls keeps generating stale pub mod declarations.
|
||||||
|
// Also clean up stale synthetic package.mist entries and generated
|
||||||
|
// mod.rs output files for directories with no remaining source children.
|
||||||
|
{
|
||||||
|
let mut docs = self.documents.lock().await;
|
||||||
|
let stale: Vec<PathBuf> = docs
|
||||||
|
.keys()
|
||||||
|
.filter(|p| !p.exists())
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
for path in &stale {
|
||||||
|
docs.remove(path);
|
||||||
|
if path.extension().and_then(|e| e.to_str()) == Some("mist") {
|
||||||
|
let rust_path = mist_to_rust_path(path);
|
||||||
|
let _ = std::fs::remove_file(&rust_path);
|
||||||
|
let map_path = rust_path.with_extension("map.json");
|
||||||
|
let _ = std::fs::remove_file(&map_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also remove synthetic package.mist entries whose directories
|
||||||
|
// no longer contain any real .mist source files.
|
||||||
|
let synthetic: Vec<PathBuf> = docs
|
||||||
|
.keys()
|
||||||
|
.filter(|p| {
|
||||||
|
p.file_name().and_then(|n| n.to_str()) == Some("package.mist")
|
||||||
|
&& !p.exists()
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
for path in &synthetic {
|
||||||
|
docs.remove(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
drop(docs);
|
||||||
|
|
||||||
|
// Clean up auxiliary state for deleted files
|
||||||
|
let mut versions = self.doc_versions.lock().await;
|
||||||
|
let mut contents = self.last_rust_contents.lock().await;
|
||||||
|
let mut diags = self.previous_diagnostics.lock().await;
|
||||||
|
let all_stale: Vec<PathBuf> = stale.into_iter().chain(synthetic).collect();
|
||||||
|
let stale_set: std::collections::HashSet<_> = all_stale.iter().collect();
|
||||||
|
versions.retain(|k, _| !stale_set.contains(k));
|
||||||
|
contents.retain(|k, _| !stale_set.contains(k));
|
||||||
|
for path in &all_stale {
|
||||||
|
if let Some(uri) = clean_lsp_url(path) {
|
||||||
|
diags.remove(&uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.ensure_implicit_packages().await;
|
self.ensure_implicit_packages().await;
|
||||||
|
|
||||||
// Collect sources first to avoid holding locks during transpile
|
// Collect sources first to avoid holding locks during transpile
|
||||||
@@ -619,7 +672,11 @@ impl Backend {
|
|||||||
let package_mist = read_mist_package(crate_root);
|
let package_mist = read_mist_package(crate_root);
|
||||||
let mod_decls = compute_mod_decls(&docs, &src_root, &package_mist);
|
let mod_decls = compute_mod_decls(&docs, &src_root, &package_mist);
|
||||||
for (path, decl) in mod_decls {
|
for (path, decl) in mod_decls {
|
||||||
if !decl.is_empty() {
|
// Include files that have mod declarations OR that are
|
||||||
|
// already known package/directory entries in the doc map.
|
||||||
|
// The latter case covers parents whose children were
|
||||||
|
// deleted — they need a regenerated (empty) mod.rs.
|
||||||
|
if !decl.is_empty() || docs.contains_key(&path) {
|
||||||
if let Some(source) = docs.get(&path) {
|
if let Some(source) = docs.get(&path) {
|
||||||
result.push((path.clone(), source.to_string(), decl));
|
result.push((path.clone(), source.to_string(), decl));
|
||||||
}
|
}
|
||||||
@@ -1161,6 +1218,11 @@ impl LanguageServer for Backend {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let trigger_char: Option<String> = params
|
||||||
|
.context
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|c| c.trigger_character.clone());
|
||||||
|
|
||||||
let comp_params = CompletionParams {
|
let comp_params = CompletionParams {
|
||||||
text_document_position: TextDocumentPositionParams {
|
text_document_position: TextDocumentPositionParams {
|
||||||
text_document: TextDocumentIdentifier { uri: rust_uri },
|
text_document: TextDocumentIdentifier { uri: rust_uri },
|
||||||
@@ -1188,13 +1250,13 @@ impl LanguageServer for Backend {
|
|||||||
|
|
||||||
match completion_result {
|
match completion_result {
|
||||||
Ok(Some(CompletionResponse::Array(mut items))) => {
|
Ok(Some(CompletionResponse::Array(mut items))) => {
|
||||||
mist_ify_completions(&source, &mist_pos, &mut items);
|
mist_ify_completions(&source, &mist_pos, &mut items, trigger_char.as_deref());
|
||||||
|
|
||||||
Ok(Some(CompletionResponse::Array(items)))
|
Ok(Some(CompletionResponse::Array(items)))
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(CompletionResponse::List(mut list))) => {
|
Ok(Some(CompletionResponse::List(mut list))) => {
|
||||||
mist_ify_completions(&source, &mist_pos, &mut list.items);
|
mist_ify_completions(&source, &mist_pos, &mut list.items, trigger_char.as_deref());
|
||||||
|
|
||||||
Ok(Some(CompletionResponse::List(list)))
|
Ok(Some(CompletionResponse::List(list)))
|
||||||
}
|
}
|
||||||
@@ -1489,10 +1551,8 @@ impl LanguageServer for Backend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mist_ify_completions(source: &str, pos: &Position, items: &mut Vec<CompletionItem>) {
|
fn mist_ify_completions(source: &str, pos: &Position, items: &mut Vec<CompletionItem>, trigger_char: Option<&str>) {
|
||||||
let existing: HashSet<String> = items.iter().map(|item| item.label.clone()).collect();
|
let is_scoping_trigger = matches!(trigger_char, Some("." | ":"));
|
||||||
|
|
||||||
items.extend(keyword_completion_items().filter(|item| !existing.contains(&item.label)));
|
|
||||||
|
|
||||||
for item in items.iter_mut() {
|
for item in items.iter_mut() {
|
||||||
item.text_edit = None;
|
item.text_edit = None;
|
||||||
@@ -1504,6 +1564,14 @@ fn mist_ify_completions(source: &str, pos: &Position, items: &mut Vec<Completion
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_scoping_trigger {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let existing: HashSet<String> = items.iter().map(|item| item.label.clone()).collect();
|
||||||
|
|
||||||
|
items.extend(keyword_completion_items().filter(|item| !existing.contains(&item.label)));
|
||||||
|
|
||||||
let curr_scope = current_scope(&source, pos.line, pos.character);
|
let curr_scope = current_scope(&source, pos.line, pos.character);
|
||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
@@ -1869,7 +1937,7 @@ async fn handle_ra_notifications(
|
|||||||
character: if mist_end_pos.line == mist_start_pos.line {
|
character: if mist_end_pos.line == mist_start_pos.line {
|
||||||
mist_end_pos.character.max(mist_start_pos.character + 1)
|
mist_end_pos.character.max(mist_start_pos.character + 1)
|
||||||
} else {
|
} else {
|
||||||
mist_end_pos.character.max(1)
|
mist_end_pos.character.max(0)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist-codegen"
|
name = "mist-codegen"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "The Mist programming language Rust code generator"
|
description = "The Mist programming language Rust code generator"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ impl ClassProcessedData {
|
|||||||
.collect::<Vec<Spanned<FunctionDecl>>>();
|
.collect::<Vec<Spanned<FunctionDecl>>>();
|
||||||
|
|
||||||
let mut v_table = Vec::new();
|
let mut v_table = Vec::new();
|
||||||
let mut override_v_table = std::collections::HashMap::new();
|
let mut override_v_table = HashMap::new();
|
||||||
|
|
||||||
for method in &methods {
|
for method in &methods {
|
||||||
if matches!(method.item.visibility, Visibility::Public) {
|
if matches!(method.item.visibility, Visibility::Public) {
|
||||||
@@ -113,7 +113,7 @@ impl ClassProcessedData {
|
|||||||
cg.add(&get_type_from_path(inherits).get_rust());
|
cg.add(&get_type_from_path(inherits).get_rust());
|
||||||
cg.addln(",");
|
cg.addln(",");
|
||||||
} else {
|
} else {
|
||||||
cg.add_indentedln("pub _vptr: &'static [*const std::ffi::c_void],");
|
cg.add_indentedln("pub _vptr: &'static [*const core::ffi::c_void],");
|
||||||
}
|
}
|
||||||
|
|
||||||
for field in &self.fields {
|
for field in &self.fields {
|
||||||
@@ -174,11 +174,11 @@ impl ClassProcessedData {
|
|||||||
self.v_table.len()
|
self.v_table.len()
|
||||||
));
|
));
|
||||||
|
|
||||||
cg.add_indentedln("pub const __V_TABLE: &'static [*const std::ffi::c_void] = &{");
|
cg.add_indentedln("pub const __V_TABLE: &'static [*const core::ffi::c_void] = &{");
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
if has_parent {
|
if has_parent {
|
||||||
cg.add_indentedln("let mut table = [std::ptr::null(); Self::__V_COUNT];");
|
cg.add_indentedln("let mut table = [core::ptr::null(); Self::__V_COUNT];");
|
||||||
|
|
||||||
cg.add_indentedln(&format!("let parent_table = {}::__V_TABLE;", parent_path));
|
cg.add_indentedln(&format!("let parent_table = {}::__V_TABLE;", parent_path));
|
||||||
cg.add_indentedln(
|
cg.add_indentedln(
|
||||||
@@ -193,7 +193,7 @@ impl ClassProcessedData {
|
|||||||
.get_rust();
|
.get_rust();
|
||||||
for (method_ident, is_virtual) in &overriden_method_idents.item {
|
for (method_ident, is_virtual) in &overriden_method_idents.item {
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"table[{}::__FN_{}] = {}::{} as *const std::ffi::c_void;",
|
"table[{}::__FN_{}] = {}::{} as *const core::ffi::c_void;",
|
||||||
base_class_path,
|
base_class_path,
|
||||||
method_ident.0.to_uppercase(),
|
method_ident.0.to_uppercase(),
|
||||||
self.self_path.get_rust(),
|
self.self_path.get_rust(),
|
||||||
@@ -204,7 +204,7 @@ impl ClassProcessedData {
|
|||||||
|
|
||||||
for method_name in &self.v_table {
|
for method_name in &self.v_table {
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"table[Self::__FN_{}] = Self::__m_{} as *const std::ffi::c_void;",
|
"table[Self::__FN_{}] = Self::__m_{} as *const core::ffi::c_void;",
|
||||||
method_name.0.to_uppercase(),
|
method_name.0.to_uppercase(),
|
||||||
method_name.get_rust()
|
method_name.get_rust()
|
||||||
));
|
));
|
||||||
@@ -216,7 +216,7 @@ impl ClassProcessedData {
|
|||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
for method_name in &self.v_table {
|
for method_name in &self.v_table {
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"Self::__m_{} as *const std::ffi::c_void,",
|
"Self::__m_{} as *const core::ffi::c_void,",
|
||||||
method_name.get_rust()
|
method_name.get_rust()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ impl ClassProcessedData {
|
|||||||
|
|
||||||
// Deref tests for override targets
|
// Deref tests for override targets
|
||||||
if self.inherits.is_some() && !self.override_v_table.is_empty() {
|
if self.inherits.is_some() && !self.override_v_table.is_empty() {
|
||||||
cg.add_indentedln("let this: &Self = &unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
cg.add_indentedln("let this: &Self = &unsafe { core::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||||
|
|
||||||
for (override_tier, v) in &self.override_v_table {
|
for (override_tier, v) in &self.override_v_table {
|
||||||
if let Some(path) = &override_tier.0 {
|
if let Some(path) = &override_tier.0 {
|
||||||
@@ -346,7 +346,7 @@ impl ClassProcessedData {
|
|||||||
cg.addln(") -> Self {");
|
cg.addln(") -> Self {");
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
cg.add_indentedln("let mut this: Self = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
cg.add_indentedln("let mut this: Self = unsafe { core::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||||
cg.add_indentedln("this._vptr = &Self::__V_TABLE;");
|
cg.add_indentedln("this._vptr = &Self::__V_TABLE;");
|
||||||
|
|
||||||
for field in &self.fields {
|
for field in &self.fields {
|
||||||
@@ -433,7 +433,7 @@ impl ClassProcessedData {
|
|||||||
let generics_expr_str = Generics::from(self.generics.clone()).get_rust();
|
let generics_expr_str = Generics::from(self.generics.clone()).get_rust();
|
||||||
|
|
||||||
cg.add(&format!(
|
cg.add(&format!(
|
||||||
"impl{} std::ops::Deref for {}{}",
|
"impl{} core::ops::Deref for {}{}",
|
||||||
generics_str,
|
generics_str,
|
||||||
self.name.get_rust(),
|
self.name.get_rust(),
|
||||||
generics_expr_str
|
generics_expr_str
|
||||||
@@ -452,7 +452,7 @@ impl ClassProcessedData {
|
|||||||
cg.addln("}");
|
cg.addln("}");
|
||||||
|
|
||||||
cg.add(&format!(
|
cg.add(&format!(
|
||||||
"impl{} std::ops::DerefMut for {}{}",
|
"impl{} core::ops::DerefMut for {}{}",
|
||||||
generics_str,
|
generics_str,
|
||||||
self.name.get_rust(),
|
self.name.get_rust(),
|
||||||
generics_expr_str
|
generics_expr_str
|
||||||
@@ -580,7 +580,7 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
|||||||
mutable: mutable_self,
|
mutable: mutable_self,
|
||||||
ty: Box::new(TypeExpr::Path(
|
ty: Box::new(TypeExpr::Path(
|
||||||
Path(vec![
|
Path(vec![
|
||||||
Identifier(String::from("std")),
|
Identifier(String::from("core")),
|
||||||
Identifier(String::from("ffi")),
|
Identifier(String::from("ffi")),
|
||||||
Identifier(String::from("c_void")),
|
Identifier(String::from("c_void")),
|
||||||
]),
|
]),
|
||||||
@@ -590,12 +590,12 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
|||||||
);
|
);
|
||||||
|
|
||||||
cg.add(&TypeExpr::StaticFn(param_types, method.return_type.clone().map(Box::new)).get_rust());
|
cg.add(&TypeExpr::StaticFn(param_types, method.return_type.clone().map(Box::new)).get_rust());
|
||||||
cg.addln(" = std::mem::transmute(func_ptr);");
|
cg.addln(" = core::mem::transmute(func_ptr);");
|
||||||
|
|
||||||
if mutable_self {
|
if mutable_self {
|
||||||
cg.add_indented("func(self as *mut Self as *const std::ffi::c_void");
|
cg.add_indented("func(self as *mut Self as *const core::ffi::c_void");
|
||||||
} else {
|
} else {
|
||||||
cg.add_indented("func(self as *const Self as *const std::ffi::c_void");
|
cg.add_indented("func(self as *const Self as *const core::ffi::c_void");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (_, param) in ¶ms {
|
for (_, param) in ¶ms {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl RustCodegen {
|
|||||||
indent: 0,
|
indent: 0,
|
||||||
crates: HashMap::new(),
|
crates: HashMap::new(),
|
||||||
mapping: Mapping::new(mist_path),
|
mapping: Mapping::new(mist_path),
|
||||||
position: RustMap(1, 0),
|
position: RustMap(0, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ impl<T> GenSpanTranslation for Spanned<T> {
|
|||||||
fn gen_span(&self, cg: &mut RustCodegen) {
|
fn gen_span(&self, cg: &mut RustCodegen) {
|
||||||
cg.mapping
|
cg.mapping
|
||||||
.map
|
.map
|
||||||
.insert((cg.position, MistMap(self.line, self.column)));
|
.insert((cg.position, MistMap(self.line, self.column - 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +239,6 @@ impl GetRust for TypeExpr {
|
|||||||
path.get_rust()
|
path.get_rust()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Lifetime(name) => format!("'{}", name.get_rust()),
|
|
||||||
Self::Tuple(types) => format!(
|
Self::Tuple(types) => format!(
|
||||||
"({})",
|
"({})",
|
||||||
types
|
types
|
||||||
|
|||||||
@@ -24,7 +24,21 @@ impl GetRust for GenericsDecl {
|
|||||||
impl GetRust for GenericDecl {
|
impl GetRust for GenericDecl {
|
||||||
fn get_rust(&self) -> String {
|
fn get_rust(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
GenericDecl::Lifetime(name) => format!("'{}", name.get_rust()),
|
GenericDecl::Lifetime(name, requirements) => {
|
||||||
|
format!("'{}", name.get_rust())
|
||||||
|
+ &(if requirements.len() != 0 {
|
||||||
|
format!(
|
||||||
|
": {}",
|
||||||
|
requirements
|
||||||
|
.into_iter()
|
||||||
|
.map(GetRust::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("+")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
})
|
||||||
|
}
|
||||||
GenericDecl::Type(name, requirements) => {
|
GenericDecl::Type(name, requirements) => {
|
||||||
name.get_rust()
|
name.get_rust()
|
||||||
+ &(if requirements.len() != 0 {
|
+ &(if requirements.len() != 0 {
|
||||||
@@ -32,7 +46,7 @@ impl GetRust for GenericDecl {
|
|||||||
": {}",
|
": {}",
|
||||||
requirements
|
requirements
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(TypeExpr::get_rust)
|
.map(GetRust::get_rust)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("+")
|
.join("+")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist-api"
|
name = "mist-api"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "The Mist programming language module system"
|
description = "The Mist programming language module system"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -19,19 +19,19 @@ use mist_parser::rev_mapper;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MistDiagnosticMessage
|
pub struct MistDiagnosticMessage
|
||||||
{
|
{
|
||||||
pub String message,
|
pub String message;
|
||||||
pub PathBuf file_path,
|
pub PathBuf file_path;
|
||||||
pub String file_name,
|
pub String file_name;
|
||||||
pub usize line,
|
pub usize line;
|
||||||
pub usize column,
|
pub usize column;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum MistDiagnostic
|
pub enum MistDiagnostic
|
||||||
{
|
{
|
||||||
Error(MistDiagnosticMessage),
|
Error(MistDiagnosticMessage);
|
||||||
Warning(MistDiagnosticMessage),
|
Warning(MistDiagnosticMessage);
|
||||||
Rust(CompilerMessage),
|
Rust(CompilerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub bool build(Vec<String> mut args, PathBuf root)
|
pub bool build(Vec<String> mut args, PathBuf root)
|
||||||
@@ -58,28 +58,36 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
|||||||
serde_json::from_str<rev_mapper::Mapping>(&map_str).expect("Failed to parse map file")
|
serde_json::from_str<rev_mapper::Mapping>(&map_str).expect("Failed to parse map file")
|
||||||
});
|
});
|
||||||
let mist_file = map.mist_path.strip_prefix(&root);
|
let mist_file = map.mist_path.strip_prefix(&root);
|
||||||
let (_, rev_mapper::MistMap(line, column)) = map.find(&rev_mapper::RustMap(span.line_end, span.column_start)).unwrap_or_default();
|
let rust_lookup = rev_mapper::RustMap(span.line_end - 1, span.column_start - 1);
|
||||||
let mist_msg = MistDiagnosticMessage {
|
match map.find(&rust_lookup) {
|
||||||
message: format!("{}: {}",
|
Some((_, rev_mapper::MistMap(line, column))) => {
|
||||||
msg.message.message,
|
let mist_msg = MistDiagnosticMessage {
|
||||||
span.label.clone().unwrap_or_default()),
|
message: format!("{}: {}",
|
||||||
file_name: if let Ok(mist_file) = mist_file {
|
msg.message.message,
|
||||||
mist_file.to_string_lossy().to_string()
|
span.label.clone().unwrap_or_default()),
|
||||||
} else {
|
file_name: if let Ok(mist_file) = mist_file {
|
||||||
map.mist_path.to_string_lossy().to_string()
|
mist_file.to_string_lossy().to_string()
|
||||||
},
|
} else {
|
||||||
file_path: map.mist_path.clone(),
|
map.mist_path.to_string_lossy().to_string()
|
||||||
line: line,
|
},
|
||||||
column: column,
|
file_path: map.mist_path.clone(),
|
||||||
};
|
line: line,
|
||||||
match msg.message.level {
|
column: column,
|
||||||
cargo_metadata::diagnostic::DiagnosticLevel::Error => {
|
};
|
||||||
diagnostics.push(MistDiagnostic::Error(mist_msg))
|
match msg.message.level {
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Error => {
|
||||||
|
diagnostics.push(MistDiagnostic::Error(mist_msg))
|
||||||
|
}
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
|
||||||
|
diagnostics.push(MistDiagnostic::Warning(mist_msg))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
|
None => {
|
||||||
diagnostics.push(MistDiagnostic::Warning(mist_msg))
|
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||||
}
|
break;
|
||||||
_ => {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,8 +118,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
|||||||
let line = get_line(&mut files, &msg);
|
let line = get_line(&mut files, &msg);
|
||||||
println!("\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
println!("\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line,
|
msg.line + 1,
|
||||||
msg.column,
|
msg.column + 1,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),)
|
line.unwrap_or_default(),)
|
||||||
}
|
}
|
||||||
@@ -119,8 +127,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
|||||||
let line = get_line(&mut files, &msg);
|
let line = get_line(&mut files, &msg);
|
||||||
println!("\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
println!("\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line,
|
msg.line + 1,
|
||||||
msg.column,
|
msg.column + 1,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),)
|
line.unwrap_or_default(),)
|
||||||
}
|
}
|
||||||
@@ -135,5 +143,5 @@ pub Option<String> get_line(HashMap<PathBuf, Vec<String>> mut& files, MistDiagno
|
|||||||
let lines = files.entry(src_path.clone()).or_insert_with(() => {
|
let lines = files.entry(src_path.clone()).or_insert_with(() => {
|
||||||
fs::read_to_string(src_path).expect("Unable to read mist file").lines().into_iter().map(String::from).collect()
|
fs::read_to_string(src_path).expect("Unable to read mist file").lines().into_iter().map(String::from).collect()
|
||||||
});
|
});
|
||||||
lines.get(msg.line - 1).map((v) => v.trim().to_string())
|
lines.get(msg.line).map((v) => v.trim().to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ use serde::Deserialize;
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct MistConfig
|
pub struct MistConfig
|
||||||
{
|
{
|
||||||
pub PathBuf package,
|
pub PathBuf package;
|
||||||
pub Vec<PathBuf> packages,
|
pub Vec<PathBuf> packages;
|
||||||
pub Vec<PathBuf> include,
|
pub Vec<PathBuf> include;
|
||||||
pub mist_parser::MistFmtConfig fmt,
|
pub mist_parser::MistFmtConfig fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MistConfig
|
impl MistConfig
|
||||||
@@ -77,6 +77,7 @@ pub void transpile(Path& root)
|
|||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", elapsed);
|
println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", elapsed);
|
||||||
for incl in &config.include {
|
for incl in &config.include {
|
||||||
|
let incl = if incl.is_relative() { root.join(incl) } else { incl.clone() };
|
||||||
if ends_with_star(&incl) {
|
if ends_with_star(&incl) {
|
||||||
let sub_crates = incl.parent().expect("Failed to get parent");
|
let sub_crates = incl.parent().expect("Failed to get parent");
|
||||||
let entries = match fs::read_dir(sub_crates) {
|
let entries = match fs::read_dir(sub_crates) {
|
||||||
@@ -95,7 +96,7 @@ pub void transpile(Path& root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
transpile(incl);
|
transpile(&incl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,8 +210,8 @@ std::io::Result<bool> is_source_newer(Path& source, Path& output)
|
|||||||
|
|
||||||
pub enum TranspileError<'a>
|
pub enum TranspileError<'a>
|
||||||
{
|
{
|
||||||
Parse(error::ParseError<'a>),
|
Parse(error::ParseError<'a>);
|
||||||
Semantic(Vec<mist_parser::semantics::SemanticError>),
|
Semantic(Vec<mist_parser::semantics::SemanticError>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> 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)
|
pub Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> 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)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist-parser"
|
name = "mist-parser"
|
||||||
version = "0.4.0-alpha.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "The Mist programming language parser"
|
description = "The Mist programming language parser"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ pub enum TypeExpr {
|
|||||||
Path(Path, Option<Generics>),
|
Path(Path, Option<Generics>),
|
||||||
StaticFn(Vec<TypeExpr>, Option<Box<TypeExpr>>),
|
StaticFn(Vec<TypeExpr>, Option<Box<TypeExpr>>),
|
||||||
Tuple(Vec<TypeExpr>),
|
Tuple(Vec<TypeExpr>),
|
||||||
Lifetime(Identifier),
|
|
||||||
Void,
|
Void,
|
||||||
Fn {
|
Fn {
|
||||||
kind: FnKind,
|
kind: FnKind,
|
||||||
@@ -61,7 +60,7 @@ pub struct Spanned<T> {
|
|||||||
impl From<GenericDecl> for Generic {
|
impl From<GenericDecl> for Generic {
|
||||||
fn from(value: GenericDecl) -> Self {
|
fn from(value: GenericDecl) -> Self {
|
||||||
match value {
|
match value {
|
||||||
GenericDecl::Lifetime(life) => Generic::Lifetime(life),
|
GenericDecl::Lifetime(life, _) => Generic::Lifetime(life),
|
||||||
GenericDecl::Type(ty, _) => Generic::Type(TypeExpr::Path(Path(vec![ty]), None)),
|
GenericDecl::Type(ty, _) => Generic::Type(TypeExpr::Path(Path(vec![ty]), None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ pub struct GenericsDecl(pub Vec<GenericDecl>);
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum GenericDecl {
|
pub enum GenericDecl {
|
||||||
Lifetime(Identifier),
|
Lifetime(Identifier, Vec<Generic>),
|
||||||
Type(Identifier, Vec<TypeExpr>),
|
Type(Identifier, Vec<Generic>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ mutable = { "mut" }
|
|||||||
// ======================================================
|
// ======================================================
|
||||||
// GENERICS
|
// GENERICS
|
||||||
// ======================================================
|
// ======================================================
|
||||||
generic_decl = { lifetime | (identifier ~ (":" ~ generic ~ ("+" ~ generic)*)?) }
|
generic_decl = { (lifetime | identifier) ~ (":" ~ generic ~ ("+" ~ generic)*)? }
|
||||||
generics_decl = { "<" ~ (generic_decl ~ ("," ~ generic_decl)*)? ~ ">" }
|
generics_decl = { "<" ~ (generic_decl ~ ("," ~ generic_decl)*)? ~ ">" }
|
||||||
|
|
||||||
generic = { lifetime | type_expr }
|
generic = { lifetime | type_expr }
|
||||||
@@ -125,9 +125,9 @@ fn_kind_mut = { "FnMut" }
|
|||||||
fn_kind = _{
|
fn_kind = _{
|
||||||
fn_kind_fn
|
fn_kind_fn
|
||||||
| fn_kind_unsafe
|
| fn_kind_unsafe
|
||||||
| fn_kind_closure
|
|
||||||
| fn_kind_once
|
| fn_kind_once
|
||||||
| fn_kind_mut
|
| fn_kind_mut
|
||||||
|
| fn_kind_closure
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_type = {
|
fn_type = {
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExpr {
|
|||||||
|
|
||||||
Ok(ty)
|
Ok(ty)
|
||||||
}
|
}
|
||||||
Rule::lifetime => Ok(TypeExpr::Lifetime(inner.next().unwrap().try_into()?)),
|
|
||||||
|
|
||||||
Rule::void_type => Ok(TypeExpr::Void),
|
Rule::void_type => Ok(TypeExpr::Void),
|
||||||
Rule::tuple_type => Ok(TypeExpr::Tuple(collect_recovered(inner)?)),
|
Rule::tuple_type => Ok(TypeExpr::Tuple(collect_recovered(inner)?)),
|
||||||
@@ -132,6 +131,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for GenericDecl {
|
|||||||
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
||||||
Ok(GenericDecl::Lifetime(
|
Ok(GenericDecl::Lifetime(
|
||||||
pair.into_inner().next().unwrap().try_into()?,
|
pair.into_inner().next().unwrap().try_into()?,
|
||||||
|
collect_recovered(inner)?,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(GenericDecl::Type(
|
Ok(GenericDecl::Type(
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ use std::{collections::HashSet, path::PathBuf};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||||
)]
|
)]
|
||||||
pub struct MistMap(pub usize, pub usize);
|
pub struct MistMap(pub usize, pub usize);
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||||
)]
|
)]
|
||||||
pub struct RustMap(pub usize, pub usize);
|
pub struct RustMap(pub usize, pub usize);
|
||||||
|
|
||||||
|
|||||||
+18
-1
@@ -16,10 +16,11 @@ void main()
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
"run" | "build" | "check" | "test" | "publish" | "bench" | "doc" | "fix" | "clippy" | "r" | "b" | "c" => {
|
"run" | "build" | "check" | "test" | "bench" | "doc" | "fix" | "clippy" | "r" | "b" | "c" => {
|
||||||
let mut root = env::current_dir().expect("Unable to find project root");
|
let mut root = env::current_dir().expect("Unable to find project root");
|
||||||
modify_args(&mut args, &mut root);
|
modify_args(&mut args, &mut root);
|
||||||
transpiler::transpile(&root);
|
transpiler::transpile(&root);
|
||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
if builder::build(args, root) {
|
if builder::build(args, root) {
|
||||||
println!("\x1b[32m\nBuild successful\x1b[0m");
|
println!("\x1b[32m\nBuild successful\x1b[0m");
|
||||||
@@ -27,6 +28,22 @@ void main()
|
|||||||
println!("\x1b[31m\nBuild failed\x1b[0m");
|
println!("\x1b[31m\nBuild failed\x1b[0m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"publish" => {
|
||||||
|
let mut root = env::current_dir().expect("Unable to find project root");
|
||||||
|
modify_args(&mut args, &mut root);
|
||||||
|
transpiler::transpile(&root);
|
||||||
|
|
||||||
|
let status = std::process::Command::new("cargo")
|
||||||
|
.args(args)
|
||||||
|
.status()
|
||||||
|
.expect("Failed to run cargo");
|
||||||
|
|
||||||
|
if status.success() {
|
||||||
|
println!("\x1b[32m\nPublished successfully\x1b[0m");
|
||||||
|
} else {
|
||||||
|
println!("\x1b[31m\nFailed to publish\x1b[0m");
|
||||||
|
}
|
||||||
|
}
|
||||||
"transpile" | "t" => {
|
"transpile" | "t" => {
|
||||||
let mut root = env::current_dir().expect("Unable to find project root");
|
let mut root = env::current_dir().expect("Unable to find project root");
|
||||||
modify_args(&mut args, &mut root);
|
modify_args(&mut args, &mut root);
|
||||||
|
|||||||
Reference in New Issue
Block a user