feat: transpile hello world view function
This commit is contained in:
parent
8354d51ecb
commit
2f335b02ae
6 changed files with 385 additions and 81 deletions
51
src/elm.rs
51
src/elm.rs
|
|
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||
use std::fs::{self, canonicalize, metadata};
|
||||
use std::io::{self, BufRead, Error, ErrorKind, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command};
|
||||
use std::process::Command;
|
||||
use tracing::info_span;
|
||||
|
||||
pub fn make(file: &Path, debug: bool, verbosity: u64) -> Result<(), Problem> {
|
||||
|
|
@ -39,7 +39,9 @@ pub fn make(file: &Path, debug: bool, verbosity: u64) -> Result<(), Problem> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_interfaces(elm_cache_dir: &Path) -> Result<HashMap<String, elmi::Interface>, Problem> {
|
||||
pub fn load_interfaces(
|
||||
elm_cache_dir: &Path,
|
||||
) -> Result<HashMap<elmi::ModuleNameCanonical, elmi::Interface>, Problem> {
|
||||
let mut interfaces = HashMap::new();
|
||||
|
||||
let entries = fs::read_dir(&elm_cache_dir)
|
||||
|
|
@ -51,6 +53,27 @@ pub fn load_interfaces(elm_cache_dir: &Path) -> Result<HashMap<String, elmi::Int
|
|||
})?;
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
match path.file_name() {
|
||||
Some(file_name) if file_name == "i.dat" => {
|
||||
let data = std::fs::read(&path)
|
||||
.map_err(|io_err| CompilerError::ReadInputFailed(io_err, path.clone()))?;
|
||||
|
||||
let (_remaining, i) = <elmi::Interfaces as elmi::DataBinary>::get(&data)
|
||||
.map_err(|_err| {
|
||||
CompilerError::FailedElmiParse("todo elmi parsing".to_owned())
|
||||
})?;
|
||||
|
||||
for (module_name, dep_interface) in i.into_iter() {
|
||||
match dep_interface {
|
||||
elmi::DependencyInterface::Public(interface) => {
|
||||
interfaces.insert(module_name, interface);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
match path.extension() {
|
||||
Some(ext) if ext == "elmi" => {
|
||||
// step 4 load all the modules
|
||||
|
|
@ -70,12 +93,16 @@ pub fn load_interfaces(elm_cache_dir: &Path) -> Result<HashMap<String, elmi::Int
|
|||
if let Some(stem) = path.file_stem() {
|
||||
// in theory the module name of the interface can be determined by
|
||||
// the filename in elm 0.19.0 and 0.19.1
|
||||
let module_name: String = stem
|
||||
let module: String = stem
|
||||
.to_string_lossy()
|
||||
.split('-')
|
||||
.collect::<Vec<&str>>()
|
||||
.join(".");
|
||||
interfaces.insert(module_name, i);
|
||||
let cannonical_module = elmi::ModuleNameCanonical {
|
||||
package: elmi::PackageName::new("author", "project"),
|
||||
module: elmi::Name(module),
|
||||
};
|
||||
interfaces.insert(cannonical_module, i);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
@ -103,13 +130,14 @@ pub fn load_objects(elm_cache_dir: &Path) -> Result<HashMap<elmi::Global, elmi::
|
|||
let data = std::fs::read(&path)
|
||||
.map_err(|io_err| CompilerError::ReadInputFailed(io_err, path.clone()))?;
|
||||
|
||||
let (_remaining, opt_global_graph) = elmi::OptGlobalGraph::get(&data).map_err(|_err| {
|
||||
CompilerError::FailedElmiParse("todo elmi parsing".to_owned())
|
||||
})?;
|
||||
let (_remaining, opt_global_graph) =
|
||||
elmi::OptGlobalGraph::get(&data).map_err(|_err| {
|
||||
CompilerError::FailedElmiParse("todo elmi parsing".to_owned())
|
||||
})?;
|
||||
|
||||
objects.extend(opt_global_graph.nodes.into_iter());
|
||||
}
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
match path.extension() {
|
||||
Some(ext) if ext == "elmo" => {
|
||||
|
|
@ -123,9 +151,10 @@ pub fn load_objects(elm_cache_dir: &Path) -> Result<HashMap<elmi::Global, elmi::
|
|||
.map_err(|io_err| CompilerError::ReadInputFailed(io_err, path.clone()))?;
|
||||
drop(load_guard);
|
||||
|
||||
let (_remaining, opt_local_graph) = elmi::OptLocalGraph::get(&data).map_err(|_err| {
|
||||
CompilerError::FailedElmiParse("todo elmi parsing".to_owned())
|
||||
})?;
|
||||
let (_remaining, opt_local_graph) =
|
||||
elmi::OptLocalGraph::get(&data).map_err(|_err| {
|
||||
CompilerError::FailedElmiParse("todo elmi parsing".to_owned())
|
||||
})?;
|
||||
|
||||
objects.extend(opt_local_graph.nodes.into_iter());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue