Working map shift gen
This commit is contained in:
@@ -8,6 +8,7 @@ use std::time;
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use mist_parser::error;
|
use mist_parser::error;
|
||||||
|
use mist_parser::rev_mapper;
|
||||||
use crate::modules;
|
use crate::modules;
|
||||||
use mist_codegen::GetRust;
|
use mist_codegen::GetRust;
|
||||||
|
|
||||||
@@ -238,6 +239,8 @@ fn transpile_file(path *PathBuf, source *str, mut output_file PathBuf, mod_decl
|
|||||||
|
|
||||||
let res = fs::write(&output_file, format!("{mod_decl}{output}"));
|
let res = fs::write(&output_file, format!("{mod_decl}{output}"));
|
||||||
|
|
||||||
|
rev_mapper::shift_rust_mappings(&mut gc.mapping, mod_decl.lines().count() as isize, 0);
|
||||||
|
|
||||||
let output_file_map = output_file.with_extension("map.json");
|
let output_file_map = output_file.with_extension("map.json");
|
||||||
|
|
||||||
let res_map = fs::write(&output_file_map, serde_json::to_string(&gc.mapping).unwrap());
|
let res_map = fs::write(&output_file_map, serde_json::to_string(&gc.mapping).unwrap());
|
||||||
|
|||||||
@@ -22,3 +22,35 @@ pub fn find_mapping(
|
|||||||
.filter(|(rust, _)| rust <= target)
|
.filter(|(rust, _)| rust <= target)
|
||||||
.max_by_key(|(rust, _)| *rust)
|
.max_by_key(|(rust, _)| *rust)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RustMap {
|
||||||
|
pub fn shifted(self, lines: isize, cols: isize) -> Self {
|
||||||
|
Self(
|
||||||
|
self.0.saturating_add_signed(lines),
|
||||||
|
self.1.saturating_add_signed(cols),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MistMap {
|
||||||
|
pub fn shifted(self, lines: isize, cols: isize) -> Self {
|
||||||
|
Self(
|
||||||
|
self.0.saturating_add_signed(lines),
|
||||||
|
self.1.saturating_add_signed(cols),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shift_rust_mappings(mappings: &mut HashSet<(RustMap, MistMap)>, lines: isize, cols: isize) {
|
||||||
|
*mappings = mappings
|
||||||
|
.iter()
|
||||||
|
.map(|(rust, mist)| (rust.shifted(lines, cols), *mist))
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shift_mist_mappings(mappings: &mut HashSet<(RustMap, MistMap)>, lines: isize, cols: isize) {
|
||||||
|
*mappings = mappings
|
||||||
|
.iter()
|
||||||
|
.map(|(rust, mist)| (*rust, mist.shifted(lines, cols)))
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user