Skip to content

Commit

Permalink
move prelude to util
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed May 29, 2024
1 parent 103effc commit 0891e2f
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 49 deletions.
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
2 changes: 1 addition & 1 deletion runtime/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use core::{
#[cfg(feature = "std")]
use std::sync::{Mutex, Once};

use crate::prelude::*;
use hvm64_util::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
2 changes: 1 addition & 1 deletion transform/src/eta_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

use core::ops::RangeFrom;

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

use ordered_float::OrderedFloat;
Expand Down
2 changes: 1 addition & 1 deletion transform/src/inline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ops::BitOr;

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

Expand Down
2 changes: 1 addition & 1 deletion transform/src/pre_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! 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
2 changes: 1 addition & 1 deletion transform/src/prune.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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};

0 comments on commit 0891e2f

Please sign in to comment.