mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 11:56:54 +03:00
Small cleanups
This commit is contained in:
parent
ea083f5a17
commit
12a1a0b0cd
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -82,16 +82,6 @@ version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "ariadne"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72fe02fc62033df9ba41cba57ee19acf5e742511a140c7dbc3a873e19a19a1bd"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.69"
|
||||
@ -305,7 +295,6 @@ name = "hvm-lang"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ariadne",
|
||||
"bimap",
|
||||
"byte-unit",
|
||||
"chumsky",
|
||||
|
@ -16,14 +16,12 @@ cli = ["dep:clap", "dep:byte-unit"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.72"
|
||||
ariadne = "0.3.0"
|
||||
bimap = "0.6.3"
|
||||
byte-unit = { version = "4.0.19", optional = true }
|
||||
chumsky = "= 1.0.0-alpha.4"
|
||||
clap = { version = "4.4.1", features = ["derive"], optional = true }
|
||||
derive_more = "0.99.17"
|
||||
hvm-core = { git = "https://github.com/HigherOrderCO/hvm-core.git" }
|
||||
#hvmc = { path = "../hvm-core/" }
|
||||
itertools = "0.11.0"
|
||||
logos = "0.13.0"
|
||||
miette = { version = "5.10.0", features = ["fancy"] }
|
||||
|
@ -36,10 +36,7 @@ pub fn run_compiled(book: &Book, main: DefId, mem_size: usize) -> (Net, RunStats
|
||||
root.boot(main.to_internal());
|
||||
|
||||
let start_time = Instant::now();
|
||||
|
||||
// Computes its normal form
|
||||
root.normal(&runtime_book);
|
||||
|
||||
let elapsed = start_time.elapsed().as_secs_f64();
|
||||
let rewrites = Rewrites { anni: root.anni, comm: root.comm, eras: root.eras, dref: root.dref, oper: root.oper };
|
||||
let net = net_from_runtime(&root);
|
||||
|
10
src/main.rs
10
src/main.rs
@ -1,8 +1,9 @@
|
||||
#![feature(slice_group_by)]
|
||||
|
||||
use clap::{Parser, ValueEnum};
|
||||
use hvm_lang::{check_book, compile_book, load_file_to_book, run_book, RunInfo};
|
||||
use hvmc::ast::{show_book, show_net};
|
||||
use hvmc::{
|
||||
ast::{show_book, show_net},
|
||||
run::Ptr,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
@ -53,7 +54,8 @@ fn main() -> anyhow::Result<()> {
|
||||
println!("{}", show_book(&compiled));
|
||||
}
|
||||
Mode::Run => {
|
||||
let (res_term, def_names, info) = run_book(book, args.mem / std::mem::size_of::<u64>())?;
|
||||
let mem_size = args.mem / std::mem::size_of::<(Ptr, Ptr)>();
|
||||
let (res_term, def_names, info) = run_book(book, mem_size)?;
|
||||
let RunInfo { stats, valid_readback, net: lnet } = info;
|
||||
let rps = stats.rewrites.total_rewrites() as f64 / stats.run_time / 1_000_000.0;
|
||||
if args.verbose {
|
||||
|
@ -1,9 +1,8 @@
|
||||
use super::{parser::parse_definition_book, DefinitionBook};
|
||||
use ariadne::{Color, Label, Report, ReportKind, Source};
|
||||
use chumsky::prelude::Rich;
|
||||
use itertools::Itertools;
|
||||
use miette::{diagnostic, miette, Diagnostic, NamedSource, SourceSpan};
|
||||
use std::{fmt::Display, ops::Range, path::Path};
|
||||
use std::{fmt::Display, path::Path};
|
||||
|
||||
/// Reads a file and parses to a definition book.
|
||||
pub fn load_file_to_book(path: &Path) -> anyhow::Result<DefinitionBook> {
|
||||
@ -17,29 +16,10 @@ pub fn load_file_to_book(path: &Path) -> anyhow::Result<DefinitionBook> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_err_for_console<T: Display>(err: Rich<T>, path: &Path, code: &str) -> String {
|
||||
let path = path.to_string_lossy();
|
||||
let report = err_to_report(err, &path);
|
||||
let mut out: Vec<u8> = vec![];
|
||||
report.write((path.as_ref(), Source::from(code)), &mut out).unwrap();
|
||||
String::from_utf8(out).unwrap()
|
||||
}
|
||||
|
||||
pub fn display_err_for_text<T: Display>(err: Rich<T>) -> String {
|
||||
err.to_string()
|
||||
}
|
||||
|
||||
pub fn err_to_report<'a, T: Display>(err: Rich<T>, path: &'a str) -> Report<'a, (&'a str, Range<usize>)> {
|
||||
Report::build(ReportKind::Error, path, err.span().start)
|
||||
.with_message(err.to_string())
|
||||
.with_label(
|
||||
Label::new((path, err.span().into_range()))
|
||||
.with_message(err.reason().to_string())
|
||||
.with_color(Color::Red),
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
|
||||
/// Displays a formatted [SyntaxError] from the given `err` based on the current report handler.
|
||||
pub fn display_miette_err<T: Display>(err: Rich<T>, path: &Path, code: &str) -> String {
|
||||
let source = code.to_string();
|
||||
|
Loading…
Reference in New Issue
Block a user