Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
352d0594b2 | ||
|
|
48ca58725a | ||
|
|
708b956750 | ||
|
|
df9e31e26d | ||
|
|
c716b6352c | ||
|
|
6f675b4253 | ||
|
|
5079b10819 | ||
|
|
d834ff595d | ||
|
|
70ec348f4d | ||
|
|
93ba0e97da | ||
|
|
9c0aa3d182 | ||
|
|
e1b851911d | ||
|
|
72f7b8430d | ||
|
|
0100abfa53 | ||
|
|
01b7e816ee | ||
|
|
ac94882e5a | ||
|
|
9220ee3b29 | ||
|
|
b15f13880a | ||
|
|
d538168692 | ||
|
|
b68e4245d4 | ||
|
|
c5354ff424 | ||
|
|
be68f93038 |
Generated
+5
-5
@@ -476,7 +476,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mist-analyzer"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"cargo_metadata",
|
||||
"dashmap 6.1.0",
|
||||
@@ -495,7 +495,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mist-api"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"cargo_metadata",
|
||||
"mist-codegen",
|
||||
@@ -507,7 +507,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mist-codegen"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"bytecount",
|
||||
"mist-parser",
|
||||
@@ -515,7 +515,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mist-lang"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"mist-analyzer",
|
||||
"mist-api",
|
||||
@@ -524,7 +524,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mist-parser"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_derive",
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mist-lang"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "The Mist programming language compiler"
|
||||
license = "Apache-2.0"
|
||||
@@ -33,10 +33,10 @@ exclude = [
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
mist-parser = { path = "crates/parser", version = "0.4.0-alpha.0" }
|
||||
mist-analyzer = { path = "crates/analyzer", version = "0.4.0-alpha.0" }
|
||||
mist-codegen = { path = "crates/codegen", version = "0.4.0-alpha.0" }
|
||||
mist-api = { path = "crates/mist-api", version = "0.4.0-alpha.0" }
|
||||
mist-parser = { path = "crates/parser", version = "0.4.0" }
|
||||
mist-analyzer = { path = "crates/analyzer", version = "0.4.0" }
|
||||
mist-codegen = { path = "crates/codegen", version = "0.4.0" }
|
||||
mist-api = { path = "crates/mist-api", version = "0.4.0" }
|
||||
|
||||
[[bin]]
|
||||
name = "mist"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mist-analyzer"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "The Mist programming language Analyzer LSP"
|
||||
license = "Apache-2.0"
|
||||
|
||||
+209
-20
@@ -21,7 +21,8 @@ use tower_lsp::{Client, LanguageServer, LspService, Server};
|
||||
|
||||
use crate::rust_analyzer::RustAnalyzer;
|
||||
use crate::transpiler::{
|
||||
TranspileError, TranspiledFile, format_mist, transpile_mist, transpile_mist_no_sem,
|
||||
TranspileError, TranspiledFile, format_mist, resolve_rust_path, transpile_mist,
|
||||
transpile_mist_no_sem,
|
||||
};
|
||||
|
||||
static MARKER_COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
@@ -93,7 +94,7 @@ fn clean_lsp_url(path: &std::path::Path) -> Option<Url> {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -188,6 +189,10 @@ fn find_marker_position(content: &str, marker: &str) -> Option<Position> {
|
||||
Some(Position { line, character })
|
||||
}
|
||||
|
||||
fn is_mist_file(path: &Path) -> bool {
|
||||
path.extension().and_then(|e| e.to_str()) == Some("mist")
|
||||
}
|
||||
|
||||
fn mist_to_rust_path(mist_path: &Path) -> PathBuf {
|
||||
let mut path = mist_path.to_path_buf();
|
||||
path.set_extension("rs");
|
||||
@@ -391,11 +396,14 @@ impl Backend {
|
||||
// Fallback: the source has a syntax error that prevents transpilation.
|
||||
// Use the last known working Rust content + mapping to inject the
|
||||
// marker at the nearest valid Rust position.
|
||||
let mist_target = MistMap(line as usize + 1, character as usize);
|
||||
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") {
|
||||
rust_path.set_file_name("mod.rs");
|
||||
}
|
||||
let mist_target = MistMap(line as usize, character as usize);
|
||||
let source_for_path = self
|
||||
.documents
|
||||
.lock()
|
||||
.await
|
||||
.get(mist_path)
|
||||
.map(|r| r.to_string());
|
||||
let rust_path = resolve_rust_path(mist_path, source_for_path.as_deref());
|
||||
|
||||
let (last_mapping, last_content, original_version) = {
|
||||
let map_guard = self.mapping.lock().await;
|
||||
@@ -417,7 +425,7 @@ impl Backend {
|
||||
.map(|(rust, _)| *rust);
|
||||
|
||||
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 modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
||||
let pos = find_marker_position(&modified, &marker)?;
|
||||
@@ -604,6 +612,55 @@ impl Backend {
|
||||
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 {
|
||||
let source_for_path = docs.get(path).map(|r| r.to_string());
|
||||
docs.remove(path);
|
||||
if path.extension().and_then(|e| e.to_str()) == Some("mist") {
|
||||
let rust_path = resolve_rust_path(path, source_for_path.as_deref());
|
||||
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;
|
||||
|
||||
// Collect sources first to avoid holding locks during transpile
|
||||
@@ -619,7 +676,11 @@ impl Backend {
|
||||
let package_mist = read_mist_package(crate_root);
|
||||
let mod_decls = compute_mod_decls(&docs, &src_root, &package_mist);
|
||||
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) {
|
||||
result.push((path.clone(), source.to_string(), decl));
|
||||
}
|
||||
@@ -1032,6 +1093,18 @@ impl LanguageServer for Backend {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Non-.mist files pass through directly to rust-analyzer.
|
||||
if !is_mist_file(&mist_path) {
|
||||
let _ = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.did_open(uri, ¶ms.text_document.text)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let source = params.text_document.text;
|
||||
|
||||
self.documents
|
||||
@@ -1054,6 +1127,18 @@ impl LanguageServer for Backend {
|
||||
}
|
||||
};
|
||||
|
||||
if !is_mist_file(&mist_path) {
|
||||
if let Some(change) = params.content_changes.into_iter().last() {
|
||||
let _ = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.did_change(uri, &change.text, params.text_document.version)
|
||||
.await;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(change) = params.content_changes.into_iter().last() {
|
||||
let source = change.text;
|
||||
|
||||
@@ -1086,6 +1171,11 @@ impl LanguageServer for Backend {
|
||||
.expect("Failed to read file")
|
||||
};
|
||||
|
||||
if !is_mist_file(&mist_path) {
|
||||
let _ = self.rust_analyzer.lock().await.did_save(uri, &text).await;
|
||||
return;
|
||||
}
|
||||
|
||||
self.documents
|
||||
.lock()
|
||||
.await
|
||||
@@ -1118,9 +1208,18 @@ impl LanguageServer for Backend {
|
||||
}
|
||||
};
|
||||
|
||||
if !is_mist_file(&mist_path) {
|
||||
let _ = self.rust_analyzer.lock().await.did_close(uri).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let source_for_path = {
|
||||
let docs = self.documents.lock().await;
|
||||
docs.get(&mist_path).map(|r| r.to_string())
|
||||
};
|
||||
self.documents.lock().await.remove(&mist_path);
|
||||
|
||||
let rust_path = mist_to_rust_path(&mist_path);
|
||||
let rust_path = resolve_rust_path(&mist_path, source_for_path.as_deref());
|
||||
|
||||
if let Some(rust_uri) = clean_lsp_url(&rust_path) {
|
||||
let _ = self.rust_analyzer.lock().await.did_close(rust_uri).await;
|
||||
@@ -1138,6 +1237,25 @@ impl LanguageServer for Backend {
|
||||
Ok(p) => p,
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
// Non-.mist files pass through directly to rust-analyzer.
|
||||
if !is_mist_file(&mist_path) {
|
||||
let result = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.request::<lsp_types::request::Completion>(params)
|
||||
.await;
|
||||
|
||||
return match result {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
eprintln!("completion error (passthrough): {e}");
|
||||
Ok(None)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let source = match self.documents.lock().await.get(&mist_path) {
|
||||
Some(r) => r.to_string(),
|
||||
None => return Ok(None),
|
||||
@@ -1161,6 +1279,11 @@ impl LanguageServer for Backend {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let trigger_char: Option<String> = params
|
||||
.context
|
||||
.as_ref()
|
||||
.and_then(|c| c.trigger_character.clone());
|
||||
|
||||
let comp_params = CompletionParams {
|
||||
text_document_position: TextDocumentPositionParams {
|
||||
text_document: TextDocumentIdentifier { uri: rust_uri },
|
||||
@@ -1188,13 +1311,13 @@ impl LanguageServer for Backend {
|
||||
|
||||
match completion_result {
|
||||
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::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)))
|
||||
}
|
||||
@@ -1210,7 +1333,7 @@ impl LanguageServer for Backend {
|
||||
&self,
|
||||
params: GotoDefinitionParams,
|
||||
) -> tower_lsp::jsonrpc::Result<Option<GotoDefinitionResponse>> {
|
||||
let mist_uri = params.text_document_position_params.text_document.uri;
|
||||
let mist_uri = ¶ms.text_document_position_params.text_document.uri;
|
||||
let mist_pos = params.text_document_position_params.position;
|
||||
eprintln!(
|
||||
"[goto_definition] entered at mist ({}, {})",
|
||||
@@ -1221,6 +1344,25 @@ impl LanguageServer for Backend {
|
||||
Ok(p) => p,
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
// Non-.mist files pass through directly to rust-analyzer.
|
||||
if !is_mist_file(&mist_path) {
|
||||
let result = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.request::<lsp_types::request::GotoDefinition>(params)
|
||||
.await;
|
||||
|
||||
return match result {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
eprintln!("goto_definition error (passthrough): {e}");
|
||||
Ok(None)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let source = match self.documents.lock().await.get(&mist_path) {
|
||||
Some(r) => r.to_string(),
|
||||
None => return Ok(None),
|
||||
@@ -1390,13 +1532,32 @@ impl LanguageServer for Backend {
|
||||
}
|
||||
|
||||
async fn hover(&self, params: HoverParams) -> tower_lsp::jsonrpc::Result<Option<Hover>> {
|
||||
let mist_uri = params.text_document_position_params.text_document.uri;
|
||||
let mist_uri = ¶ms.text_document_position_params.text_document.uri;
|
||||
let mist_pos = params.text_document_position_params.position;
|
||||
|
||||
let mist_path = match mist_uri.to_file_path() {
|
||||
Ok(p) => p,
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
// Non-.mist files pass through directly to rust-analyzer.
|
||||
if !is_mist_file(&mist_path) {
|
||||
let result = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.request::<lsp_types::request::HoverRequest>(params)
|
||||
.await;
|
||||
|
||||
return match result {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
eprintln!("hover error (passthrough): {e}");
|
||||
Ok(None)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let source = match self.documents.lock().await.get(&mist_path) {
|
||||
Some(r) => r.to_string(),
|
||||
None => return Ok(None),
|
||||
@@ -1460,6 +1621,24 @@ impl LanguageServer for Backend {
|
||||
.to_file_path()
|
||||
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())?;
|
||||
|
||||
// Non-.mist files pass through directly to rust-analyzer.
|
||||
if !is_mist_file(&mist_path) {
|
||||
let result = self
|
||||
.rust_analyzer
|
||||
.lock()
|
||||
.await
|
||||
.request::<lsp_types::request::Formatting>(params)
|
||||
.await;
|
||||
|
||||
return match result {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
eprintln!("formatting error (passthrough): {e}");
|
||||
Ok(None)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let docs = self.documents.lock().await;
|
||||
|
||||
let old_text = docs
|
||||
@@ -1489,10 +1668,13 @@ impl LanguageServer for Backend {
|
||||
}
|
||||
}
|
||||
|
||||
fn mist_ify_completions(source: &str, pos: &Position, items: &mut Vec<CompletionItem>) {
|
||||
let existing: HashSet<String> = items.iter().map(|item| item.label.clone()).collect();
|
||||
|
||||
items.extend(keyword_completion_items().filter(|item| !existing.contains(&item.label)));
|
||||
fn mist_ify_completions(
|
||||
source: &str,
|
||||
pos: &Position,
|
||||
items: &mut Vec<CompletionItem>,
|
||||
trigger_char: Option<&str>,
|
||||
) {
|
||||
let is_scoping_trigger = matches!(trigger_char, Some("." | ":"));
|
||||
|
||||
for item in items.iter_mut() {
|
||||
item.text_edit = None;
|
||||
@@ -1504,6 +1686,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);
|
||||
|
||||
// =========================
|
||||
@@ -1663,7 +1853,6 @@ fn mist_ify_completions(source: &str, pos: &Position, items: &mut Vec<Completion
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if matches!(curr_scope, Scope::Class | Scope::Struct) {
|
||||
items.push(CompletionItem {
|
||||
label: "field".into(),
|
||||
@@ -1869,7 +2058,7 @@ async fn handle_ra_notifications(
|
||||
character: if mist_end_pos.line == mist_start_pos.line {
|
||||
mist_end_pos.character.max(mist_start_pos.character + 1)
|
||||
} else {
|
||||
mist_end_pos.character.max(1)
|
||||
mist_end_pos.character.max(0)
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use mist_codegen::RustCodegen;
|
||||
use mist_parser::rev_mapper::Mapping;
|
||||
use mist_parser::{MistFmtConfig, parse};
|
||||
use mist_parser::{MistFmtConfig, parse, parse_module};
|
||||
|
||||
pub struct TranspiledFile {
|
||||
pub mist_path: PathBuf,
|
||||
@@ -17,18 +17,43 @@ pub enum TranspileError<'a> {
|
||||
Semantic(Vec<mist_parser::semantics::SemanticError>),
|
||||
}
|
||||
|
||||
/// Resolve the output `.rs` path for a `.mist` source file.
|
||||
///
|
||||
/// Always checks for a `pub module x;` declaration via `parse_module` and
|
||||
/// uses the declared module name as the filename when present. Falls back
|
||||
/// to the literal file stem when parsing fails or the file has no module
|
||||
/// declaration.
|
||||
pub fn resolve_rust_path(mist_path: &Path, source: Option<&str>) -> PathBuf {
|
||||
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
||||
// Package files (package.mist) must output as <dir>/mod.rs so the Rust
|
||||
// module hierarchy resolves correctly.
|
||||
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||
rust_path.set_file_name("mod.rs");
|
||||
} else if let Some(src) = source {
|
||||
// Prioritize the module declaration from the source over the file stem.
|
||||
// Every caller re-parses so we always pick up the current declaration.
|
||||
if let Ok(Some((_, ref name))) = parse_module(src) {
|
||||
if rust_path.file_name().map(|v| v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
||||
if let Some(ext) = rust_path.extension().map(|e| e.to_owned()) {
|
||||
let mut new_name = std::ffi::OsString::from(&name.0);
|
||||
new_name.push(".");
|
||||
new_name.push(ext);
|
||||
rust_path.set_file_name(new_name);
|
||||
} else {
|
||||
rust_path.set_file_name(&name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rust_path
|
||||
}
|
||||
|
||||
pub fn transpile_mist<'a>(
|
||||
mist_path: &Path,
|
||||
source: &'a str,
|
||||
extra_mod_decl: &str,
|
||||
) -> Result<TranspiledFile, TranspileError<'a>> {
|
||||
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
||||
// Package files (package.mist) must output as <dir>/mod.rs so the Rust module
|
||||
// hierarchy resolves correctly (pub mod <child>; declarations look for sibling
|
||||
// .rs files, and the parent module declaration looks for <dir>/mod.rs).
|
||||
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||
rust_path.set_file_name("mod.rs");
|
||||
}
|
||||
let rust_path = resolve_rust_path(mist_path, Some(source));
|
||||
|
||||
let parsed = parse(source).map_err(TranspileError::Parse)?;
|
||||
|
||||
@@ -58,13 +83,7 @@ pub fn transpile_mist_no_sem(
|
||||
source: &str,
|
||||
extra_mod_decl: &str,
|
||||
) -> Result<TranspiledFile, String> {
|
||||
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
||||
// Package files (package.mist) must output as <dir>/mod.rs so the Rust module
|
||||
// hierarchy resolves correctly (pub mod <child>; declarations look for sibling
|
||||
// .rs files, and the parent module declaration looks for <dir>/mod.rs).
|
||||
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||
rust_path.set_file_name("mod.rs");
|
||||
}
|
||||
let rust_path = resolve_rust_path(mist_path, Some(source));
|
||||
|
||||
let parsed = parse(source).map_err(|e| format!("parse error: {e:?}"))?;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mist-codegen"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "The Mist programming language Rust code generator"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -45,7 +45,7 @@ impl ClassProcessedData {
|
||||
.collect::<Vec<Spanned<FunctionDecl>>>();
|
||||
|
||||
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 {
|
||||
if matches!(method.item.visibility, Visibility::Public) {
|
||||
@@ -113,7 +113,7 @@ impl ClassProcessedData {
|
||||
cg.add(&get_type_from_path(inherits).get_rust());
|
||||
cg.addln(",");
|
||||
} 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 {
|
||||
@@ -174,11 +174,11 @@ impl ClassProcessedData {
|
||||
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;
|
||||
|
||||
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(
|
||||
@@ -193,7 +193,7 @@ impl ClassProcessedData {
|
||||
.get_rust();
|
||||
for (method_ident, is_virtual) in &overriden_method_idents.item {
|
||||
cg.add_indentedln(&format!(
|
||||
"table[{}::__FN_{}] = {}::{} as *const std::ffi::c_void;",
|
||||
"table[{}::__FN_{}] = {}::{} as *const core::ffi::c_void;",
|
||||
base_class_path,
|
||||
method_ident.0.to_uppercase(),
|
||||
self.self_path.get_rust(),
|
||||
@@ -204,7 +204,7 @@ impl ClassProcessedData {
|
||||
|
||||
for method_name in &self.v_table {
|
||||
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.get_rust()
|
||||
));
|
||||
@@ -216,7 +216,7 @@ impl ClassProcessedData {
|
||||
cg.indent += 1;
|
||||
for method_name in &self.v_table {
|
||||
cg.add_indentedln(&format!(
|
||||
"Self::__m_{} as *const std::ffi::c_void,",
|
||||
"Self::__m_{} as *const core::ffi::c_void,",
|
||||
method_name.get_rust()
|
||||
));
|
||||
}
|
||||
@@ -293,7 +293,7 @@ impl ClassProcessedData {
|
||||
|
||||
// Deref tests for override targets
|
||||
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 {
|
||||
if let Some(path) = &override_tier.0 {
|
||||
@@ -346,7 +346,7 @@ impl ClassProcessedData {
|
||||
cg.addln(") -> Self {");
|
||||
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;");
|
||||
|
||||
for field in &self.fields {
|
||||
@@ -433,7 +433,7 @@ impl ClassProcessedData {
|
||||
let generics_expr_str = Generics::from(self.generics.clone()).get_rust();
|
||||
|
||||
cg.add(&format!(
|
||||
"impl{} std::ops::Deref for {}{}",
|
||||
"impl{} core::ops::Deref for {}{}",
|
||||
generics_str,
|
||||
self.name.get_rust(),
|
||||
generics_expr_str
|
||||
@@ -452,7 +452,7 @@ impl ClassProcessedData {
|
||||
cg.addln("}");
|
||||
|
||||
cg.add(&format!(
|
||||
"impl{} std::ops::DerefMut for {}{}",
|
||||
"impl{} core::ops::DerefMut for {}{}",
|
||||
generics_str,
|
||||
self.name.get_rust(),
|
||||
generics_expr_str
|
||||
@@ -580,7 +580,7 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
||||
mutable: mutable_self,
|
||||
ty: Box::new(TypeExpr::Path(
|
||||
Path(vec![
|
||||
Identifier(String::from("std")),
|
||||
Identifier(String::from("core")),
|
||||
Identifier(String::from("ffi")),
|
||||
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.addln(" = std::mem::transmute(func_ptr);");
|
||||
cg.addln(" = core::mem::transmute(func_ptr);");
|
||||
|
||||
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 *mut core::ffi::c_void");
|
||||
} 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 {
|
||||
|
||||
@@ -46,7 +46,7 @@ impl RustCodegen {
|
||||
indent: 0,
|
||||
crates: HashMap::new(),
|
||||
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) {
|
||||
cg.mapping
|
||||
.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()
|
||||
}
|
||||
}
|
||||
Self::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||
Self::Tuple(types) => format!(
|
||||
"({})",
|
||||
types
|
||||
|
||||
@@ -24,7 +24,21 @@ impl GetRust for GenericsDecl {
|
||||
impl GetRust for GenericDecl {
|
||||
fn get_rust(&self) -> String {
|
||||
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) => {
|
||||
name.get_rust()
|
||||
+ &(if requirements.len() != 0 {
|
||||
@@ -32,7 +46,7 @@ impl GetRust for GenericDecl {
|
||||
": {}",
|
||||
requirements
|
||||
.into_iter()
|
||||
.map(TypeExpr::get_rust)
|
||||
.map(GetRust::get_rust)
|
||||
.collect::<Vec<_>>()
|
||||
.join("+")
|
||||
)
|
||||
@@ -252,6 +266,33 @@ impl GenRust for TopLevelKind {
|
||||
cg.indent -= 1;
|
||||
cg.addln("}\n");
|
||||
}
|
||||
Self::StructDeclTupleUnit {
|
||||
visibility,
|
||||
name,
|
||||
generics,
|
||||
unit,
|
||||
} => {
|
||||
cg.addln(&format!(
|
||||
"{}struct {}{}",
|
||||
visibility.get_rust(),
|
||||
name.get_rust(),
|
||||
generics.get_rust()
|
||||
));
|
||||
cg.indent += 1;
|
||||
|
||||
if let Some(unit) = unit {
|
||||
cg.add(" (");
|
||||
for unit in unit {
|
||||
cg.add_indented("");
|
||||
unit.gen_rust(ctx, cg);
|
||||
cg.add(", ");
|
||||
}
|
||||
cg.add(")");
|
||||
}
|
||||
|
||||
cg.indent -= 1;
|
||||
cg.addln(";\n");
|
||||
}
|
||||
Self::EnumDecl {
|
||||
visibility,
|
||||
name,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mist-api"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "The Mist programming language module system"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -19,19 +19,19 @@ use mist_parser::rev_mapper;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MistDiagnosticMessage
|
||||
{
|
||||
pub String message,
|
||||
pub PathBuf file_path,
|
||||
pub String file_name,
|
||||
pub usize line,
|
||||
pub usize column,
|
||||
pub String message;
|
||||
pub PathBuf file_path;
|
||||
pub String file_name;
|
||||
pub usize line;
|
||||
pub usize column;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MistDiagnostic
|
||||
{
|
||||
Error(MistDiagnosticMessage),
|
||||
Warning(MistDiagnosticMessage),
|
||||
Rust(CompilerMessage),
|
||||
Error(MistDiagnosticMessage);
|
||||
Warning(MistDiagnosticMessage);
|
||||
Rust(CompilerMessage);
|
||||
}
|
||||
|
||||
pub bool build(Vec<String> mut args, PathBuf root)
|
||||
@@ -58,7 +58,9 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
||||
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 (_, 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);
|
||||
match map.find(&rust_lookup) {
|
||||
Some((_, rev_mapper::MistMap(line, column))) => {
|
||||
let mist_msg = MistDiagnosticMessage {
|
||||
message: format!("{}: {}",
|
||||
msg.message.message,
|
||||
@@ -83,6 +85,12 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Message::BuildFinished(finish)) => {
|
||||
@@ -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(() => {
|
||||
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.saturating_sub(1)).map((v) => v.trim().to_string())
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ use serde::Deserialize;
|
||||
#[serde(default)]
|
||||
pub struct MistConfig
|
||||
{
|
||||
pub PathBuf package,
|
||||
pub Vec<PathBuf> packages,
|
||||
pub Vec<PathBuf> include,
|
||||
pub mist_parser::MistFmtConfig fmt,
|
||||
pub PathBuf package;
|
||||
pub Vec<PathBuf> packages;
|
||||
pub Vec<PathBuf> include;
|
||||
pub mist_parser::MistFmtConfig fmt;
|
||||
}
|
||||
|
||||
impl MistConfig
|
||||
@@ -77,6 +77,7 @@ pub void transpile(Path& root)
|
||||
let elapsed = start.elapsed();
|
||||
println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", elapsed);
|
||||
for incl in &config.include {
|
||||
let incl = if incl.is_relative() { root.join(incl) } else { incl.clone() };
|
||||
if ends_with_star(&incl) {
|
||||
let sub_crates = incl.parent().expect("Failed to get parent");
|
||||
let entries = match fs::read_dir(sub_crates) {
|
||||
@@ -95,7 +96,7 @@ pub void transpile(Path& root)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
transpile(incl);
|
||||
transpile(&incl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,8 +210,8 @@ std::io::Result<bool> is_source_newer(Path& source, Path& output)
|
||||
|
||||
pub enum TranspileError<'a>
|
||||
{
|
||||
Parse(error::ParseError<'a>),
|
||||
Semantic(Vec<mist_parser::semantics::SemanticError>),
|
||||
Parse(error::ParseError<'a>);
|
||||
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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mist-parser"
|
||||
version = "0.4.0-alpha.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "The Mist programming language parser"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -41,7 +41,6 @@ pub enum TypeExpr {
|
||||
Path(Path, Option<Generics>),
|
||||
StaticFn(Vec<TypeExpr>, Option<Box<TypeExpr>>),
|
||||
Tuple(Vec<TypeExpr>),
|
||||
Lifetime(Identifier),
|
||||
Void,
|
||||
Fn {
|
||||
kind: FnKind,
|
||||
@@ -61,7 +60,7 @@ pub struct Spanned<T> {
|
||||
impl From<GenericDecl> for Generic {
|
||||
fn from(value: GenericDecl) -> Self {
|
||||
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)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,12 @@ pub enum TopLevelKind {
|
||||
generics: GenericsDecl,
|
||||
fields: Vec<Spanned<FieldDecl>>,
|
||||
},
|
||||
StructDeclTupleUnit {
|
||||
visibility: Visibility,
|
||||
name: Identifier,
|
||||
generics: GenericsDecl,
|
||||
unit: Option<Vec<Spanned<TypeExpr>>>,
|
||||
},
|
||||
FunctionDecl(FunctionDecl),
|
||||
ClassDecl {
|
||||
visibility: Visibility,
|
||||
@@ -82,8 +88,8 @@ pub struct GenericsDecl(pub Vec<GenericDecl>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum GenericDecl {
|
||||
Lifetime(Identifier),
|
||||
Type(Identifier, Vec<TypeExpr>),
|
||||
Lifetime(Identifier, Vec<Generic>),
|
||||
Type(Identifier, Vec<Generic>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -90,7 +90,7 @@ mutable = { "mut" }
|
||||
// ======================================================
|
||||
// GENERICS
|
||||
// ======================================================
|
||||
generic_decl = { lifetime | (identifier ~ (":" ~ generic ~ ("+" ~ generic)*)?) }
|
||||
generic_decl = { (lifetime | identifier) ~ (":" ~ generic ~ ("+" ~ generic)*)? }
|
||||
generics_decl = { "<" ~ (generic_decl ~ ("," ~ generic_decl)*)? ~ ">" }
|
||||
|
||||
generic = { lifetime | type_expr }
|
||||
@@ -125,9 +125,9 @@ fn_kind_mut = { "FnMut" }
|
||||
fn_kind = _{
|
||||
fn_kind_fn
|
||||
| fn_kind_unsafe
|
||||
| fn_kind_closure
|
||||
| fn_kind_once
|
||||
| fn_kind_mut
|
||||
| fn_kind_closure
|
||||
}
|
||||
|
||||
fn_type = {
|
||||
@@ -287,6 +287,10 @@ struct_decl = {
|
||||
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ "{" ~ field_list ~ "}"
|
||||
}
|
||||
|
||||
tuple_struct_decl = {
|
||||
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ tuple_type? ~ ";"
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// ENUMS
|
||||
// ======================================================
|
||||
@@ -399,7 +403,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
|
||||
|
||||
top_level = {
|
||||
mod_attribute
|
||||
| (attributes ~ (include_global | include_local | include_use_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
|
||||
| (attributes ~ (include_global | include_local | include_use_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | tuple_struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -75,7 +75,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExpr {
|
||||
|
||||
Ok(ty)
|
||||
}
|
||||
Rule::lifetime => Ok(TypeExpr::Lifetime(inner.next().unwrap().try_into()?)),
|
||||
|
||||
Rule::void_type => Ok(TypeExpr::Void),
|
||||
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) {
|
||||
Ok(GenericDecl::Lifetime(
|
||||
pair.into_inner().next().unwrap().try_into()?,
|
||||
collect_recovered(inner)?,
|
||||
))
|
||||
} else {
|
||||
Ok(GenericDecl::Type(
|
||||
|
||||
@@ -57,6 +57,21 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
fields: collect_recovered(inner.next().unwrap().into_inner())?,
|
||||
}),
|
||||
|
||||
Rule::tuple_struct_decl => Ok(TopLevelKind::StructDeclTupleUnit {
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
name: inner.next().unwrap().try_into()?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
unit: consume_rule(&mut inner, Rule::tuple_type)
|
||||
.map(|v| collect_recovered(v.into_inner()))
|
||||
.transpose()?,
|
||||
}),
|
||||
|
||||
Rule::class_decl => Ok(TopLevelKind::ClassDecl {
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
@@ -147,7 +162,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
)),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ use std::{collections::HashSet, path::PathBuf};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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);
|
||||
|
||||
#[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);
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ pub class Animal
|
||||
"Unknown".to_string()
|
||||
}
|
||||
|
||||
pub virtual void speak_mut(&mut self){}
|
||||
|
||||
pub void test_speak<'a>(&'a self)
|
||||
{
|
||||
assert_eq!(self.speak(), "Woof!");
|
||||
|
||||
@@ -100,6 +100,9 @@ pub void test_struct_destructure_rename()
|
||||
assert_eq!(b, 15);
|
||||
}
|
||||
|
||||
struct TuplePoint(i32, i32);
|
||||
struct Unit;
|
||||
|
||||
pub void run_tests()
|
||||
{
|
||||
test_struct_create_access();
|
||||
|
||||
+18
-1
@@ -16,10 +16,11 @@ void main()
|
||||
process::exit(1);
|
||||
}
|
||||
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");
|
||||
modify_args(&mut args, &mut root);
|
||||
transpiler::transpile(&root);
|
||||
|
||||
println!("");
|
||||
if builder::build(args, root) {
|
||||
println!("\x1b[32m\nBuild successful\x1b[0m");
|
||||
@@ -27,6 +28,22 @@ void main()
|
||||
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" => {
|
||||
let mut root = env::current_dir().expect("Unable to find project root");
|
||||
modify_args(&mut args, &mut root);
|
||||
|
||||
Reference in New Issue
Block a user