Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move prelude to util #138

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
//! [interaction calculus]: https://en.wikipedia.org/wiki/Interaction_nets#Interaction_calculus
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

#[cfg(feature = "parser")]
mod parser;

use alloc::collections::BTreeMap;

use crate::prelude::*;
use hvm64_util::{create_var, deref_to, maybe_grow, multi_iterator, ops::TypedOp as Op, var_to_num};
use hvm64_util::{create_var, deref_to, maybe_grow, multi_iterator, ops::TypedOp as Op, prelude::*, var_to_num};

use ordered_float::OrderedFloat;

Expand Down
2 changes: 1 addition & 1 deletion ast/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::*;
use hvm64_util::prelude::*;

use alloc::collections::BTreeMap;
use core::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion host/src/encode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::*;
use hvm64_util::prelude::*;

use crate::Host;
use hvm64_ast::{Lab, Net as AstNet, Tree};
Expand Down
4 changes: 1 addition & 3 deletions host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
//! the runtime.
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

use crate::prelude::*;
use hvm64_ast::{Book, Tree};
use hvm64_runtime::{Addr, Def, DynDef, InterpretedDef, LabSet, Port, Tag, Wire};
use hvm64_util::prelude::*;

mod calc_labels;
mod encode;
Expand Down
2 changes: 1 addition & 1 deletion host/src/readback.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::*;
use hvm64_util::prelude::*;

use super::{Addr, Host, Port, Tag, Wire};

Expand Down
21 changes: 0 additions & 21 deletions prelude.rs

This file was deleted.

2 changes: 1 addition & 1 deletion runtime/src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{sync::Barrier, thread};

use ::alloc::sync::Arc;
use alloc::sync::Arc;
use atomic::AtomicUsize;

use super::*;
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#![cfg_attr(feature = "trace", feature(const_type_name))]
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

use crate::prelude::*;
use hvm64_util::prelude::*;

pub use hvm64_util::ops;

Expand Down
3 changes: 2 additions & 1 deletion runtime/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#![allow(non_snake_case)]
#![cfg_attr(not(feature = "trace"), allow(unused))]

use hvm64_util::prelude::*;

use core::{
cell::UnsafeCell,
fmt::{self, Debug, Formatter, Write},
Expand All @@ -73,7 +75,6 @@ use core::{
#[cfg(feature = "std")]
use std::sync::{Mutex, Once};

use crate::prelude::*;
use hvm64_util::ops::TypedOp as Op;

use crate::{Addr, Port, Trg, Wire};
Expand Down
2 changes: 1 addition & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use alloc::collections::{BTreeMap, BTreeSet};
use core::{fmt::Write, hash::Hasher};
use std::hash::DefaultHasher;

use crate::prelude::*;
use hvm64_host::Host;
use hvm64_runtime::{Def, Instruction, InterpretedDef, LabSet, Port, Tag};
use hvm64_util::prelude::*;

struct DefInfo<'a> {
rust_name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/compile/include_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ hvm64-runtime = { path = "../runtime", default-features = false }
fs::write(".hvm/gen/src/lib.rs", lib)?;

include_files! {
prelude
crate util {
lib
bi_enum
Expand All @@ -87,6 +86,7 @@ hvm64-runtime = { path = "../runtime", default-features = false }
word
}
parse_abbrev_number
prelude
pretty_num
}
crate runtime {
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include!("../prelude.rs");

mod compile;

mod args;
mod full;

use crate::prelude::*;
use hvm64_util::prelude::*;

use core::time::Duration;
use std::{
Expand Down
3 changes: 2 additions & 1 deletion transform/src/eta_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
//!
//! The pass also reduces subnets such as `(* *) -> *`

use hvm64_util::prelude::*;

use core::ops::RangeFrom;

use crate::prelude::*;
use hvm64_ast::{Net, Tree};

use ordered_float::OrderedFloat;
Expand Down
3 changes: 2 additions & 1 deletion transform/src/inline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hvm64_util::prelude::*;

use core::ops::BitOr;

use crate::prelude::*;
use hvm64_ast::{Book, Net, Tree};
use hvm64_util::maybe_grow;

Expand Down
3 changes: 2 additions & 1 deletion transform/src/pre_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
//! At the end, each mutated [`ast::Net`] is placed into the [`Book`],
//! overriding the previous one.

use crate::prelude::*;
use hvm64_util::prelude::*;

use hvm64_ast::{Book, Tree};
use hvm64_host::Host;
use hvm64_runtime::{AsDef, Def, Heap, InterpretedDef, LabSet, Port, Rewrites};
Expand Down
3 changes: 2 additions & 1 deletion transform/src/prune.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use hvm64_util::prelude::*;

use hvm64_ast::{Book, Tree};
use hvm64_util::maybe_grow;

Expand Down
4 changes: 1 addition & 3 deletions transform/src/transform.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

use crate::prelude::*;
use hvm64_util::prelude::*;

use hvm64_ast::Book;

Expand Down
1 change: 1 addition & 0 deletions util/src/bi_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ macro_rules! bi_enum {

#[test]
fn test_bi_enum() {
use crate::prelude::*;
use alloc::string::ToString;
use core::str::FromStr;

Expand Down
2 changes: 1 addition & 1 deletion util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");
pub mod prelude;

pub mod ops;

Expand Down
18 changes: 18 additions & 0 deletions util/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub extern crate alloc;

pub use alloc::{
borrow::ToOwned,
boxed::Box,
format,
string::{String, ToString},
vec,
vec::Vec,
};

pub use core::{fmt, hint, iter, mem, ptr};

#[cfg(feature = "std")]
pub use std::collections::{hash_map::Entry, HashMap as Map, HashSet as Set};

#[cfg(not(feature = "std"))]
pub use alloc::collections::{btree_map::Entry, BTreeMap as Map, BTreeSet as Set};
Loading