Skip to content

Commit

Permalink
Merge pull request #233 from koto-lang/switch-to-crate-import-granula…
Browse files Browse the repository at this point in the history
…rity

Switch to using the `crate` import granularity style
  • Loading branch information
irh authored Aug 8, 2023
2 parents 5ab894f + 2fdae01 commit 9a0baa9
Show file tree
Hide file tree
Showing 75 changed files with 362 additions and 437 deletions.
14 changes: 6 additions & 8 deletions core/bytecode/src/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use {
crate::InstructionReader,
koto_memory::Ptr,
koto_parser::{ConstantPool, Span},
std::{
fmt::{self, Write},
path::PathBuf,
},
use crate::InstructionReader;
use koto_memory::Ptr;
use koto_parser::{ConstantPool, Span};
use std::{
fmt::{self, Write},
path::PathBuf,
};

/// Debug information for a Koto program
Expand Down
16 changes: 7 additions & 9 deletions core/bytecode/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use {
crate::{DebugInfo, FunctionFlags, Op, TypeId},
koto_parser::{
AssignTarget, Ast, AstBinaryOp, AstFor, AstIf, AstIndex, AstNode, AstTry, AstUnaryOp,
ConstantIndex, Function, ImportItemNode, LookupNode, MapKey, MatchArm, MetaKeyId, Node,
Scope, Span, StringNode, SwitchArm,
},
smallvec::SmallVec,
std::{collections::HashSet, error, fmt},
use crate::{DebugInfo, FunctionFlags, Op, TypeId};
use koto_parser::{
AssignTarget, Ast, AstBinaryOp, AstFor, AstIf, AstIndex, AstNode, AstTry, AstUnaryOp,
ConstantIndex, Function, ImportItemNode, LookupNode, MapKey, MatchArm, MetaKeyId, Node, Scope,
Span, StringNode, SwitchArm,
};
use smallvec::SmallVec;
use std::{collections::HashSet, error, fmt};

/// The error type used to report errors during compilation
#[derive(Clone, Debug)]
Expand Down
10 changes: 4 additions & 6 deletions core/bytecode/src/instruction_reader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use {
crate::{Chunk, Op},
koto_memory::Ptr,
koto_parser::{ConstantIndex, MetaKeyId},
std::fmt,
};
use crate::{Chunk, Op};
use koto_memory::Ptr;
use koto_parser::{ConstantIndex, MetaKeyId};
use std::fmt;

#[derive(Debug)]
#[repr(u8)]
Expand Down
2 changes: 1 addition & 1 deletion core/bytecode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod instruction_reader;
mod loader;
mod op;

pub use {
pub use crate::{
chunk::{Chunk, DebugInfo},
compiler::{Compiler, CompilerError, CompilerSettings},
instruction_reader::{FunctionFlags, Instruction, InstructionReader, TypeId},
Expand Down
14 changes: 6 additions & 8 deletions core/bytecode/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use {
crate::{Chunk, Compiler, CompilerError, CompilerSettings},
dunce::canonicalize,
koto_memory::Ptr,
koto_parser::{format_error_with_excerpt, Parser, ParserError},
rustc_hash::FxHasher,
std::{collections::HashMap, error, fmt, hash::BuildHasherDefault, path::PathBuf},
};
use crate::{Chunk, Compiler, CompilerError, CompilerSettings};
use dunce::canonicalize;
use koto_memory::Ptr;
use koto_parser::{format_error_with_excerpt, Parser, ParserError};
use rustc_hash::FxHasher;
use std::{collections::HashMap, error, fmt, hash::BuildHasherDefault, path::PathBuf};

/// Errors that can be returned from [Loader] operations
#[derive(Clone, Debug)]
Expand Down
6 changes: 2 additions & 4 deletions core/bytecode/tests/compile_failures.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod bytecode {
use {
koto_bytecode::{Compiler, CompilerSettings},
koto_parser::Parser,
};
use koto_bytecode::{Compiler, CompilerSettings};
use koto_parser::Parser;

fn check_compilation_fails(source: &str) {
match Parser::parse(source) {
Expand Down
3 changes: 2 additions & 1 deletion core/cli/src/help.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {indexmap::IndexMap, std::iter::Peekable};
use indexmap::IndexMap;
use std::iter::Peekable;

const HELP_RESULT_STR: &str = "# ➝ ";
const HELP_INDENT: usize = 2;
Expand Down
10 changes: 4 additions & 6 deletions core/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod help;
mod repl;

use {
crossterm::tty::IsTty,
koto::{bytecode::Chunk, Koto, KotoSettings},
repl::{Repl, ReplSettings},
std::{fs, io},
};
use crossterm::tty::IsTty;
use koto::{bytecode::Chunk, Koto, KotoSettings};
use repl::{Repl, ReplSettings};
use std::{fs, io};

#[cfg(all(jemalloc, not(debug_assertions), not(target_env = "msvc")))]
#[global_allocator]
Expand Down
32 changes: 15 additions & 17 deletions core/cli/src/repl.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use {
crate::help::Help,
crossterm::{
cursor,
event::{read, Event, KeyCode, KeyEvent, KeyModifiers},
execute, queue, style,
terminal::{self, ClearType},
tty::IsTty,
Result,
},
koto::{bytecode::Chunk, Koto, KotoSettings},
std::{
cmp::Ordering,
fmt,
io::{self, Stdout, Write},
},
unicode_width::UnicodeWidthChar,
use crate::help::Help;
use crossterm::{
cursor,
event::{read, Event, KeyCode, KeyEvent, KeyModifiers},
execute, queue, style,
terminal::{self, ClearType},
tty::IsTty,
Result,
};
use koto::{bytecode::Chunk, Koto, KotoSettings};
use std::{
cmp::Ordering,
fmt,
io::{self, Stdout, Write},
};
use unicode_width::UnicodeWidthChar;

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
8 changes: 3 additions & 5 deletions core/koto/benches/koto_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
criterion::{criterion_group, criterion_main, Criterion},
koto::Koto,
std::{fs::read_to_string, path::PathBuf},
};
use criterion::{criterion_group, criterion_main, Criterion};
use koto::Koto;
use std::{fs::read_to_string, path::PathBuf};

#[cfg(not(target_env = "msvc"))]
#[global_allocator]
Expand Down
12 changes: 5 additions & 7 deletions core/koto/src/koto.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
crate::prelude::*,
dunce::canonicalize,
koto_bytecode::CompilerSettings,
koto_runtime::ModuleImportedCallback,
std::{error::Error, fmt, path::PathBuf, rc::Rc},
};
use crate::prelude::*;
use dunce::canonicalize;
use koto_bytecode::CompilerSettings;
use koto_runtime::ModuleImportedCallback;
use std::{error::Error, fmt, path::PathBuf, rc::Rc};

/// The error type returned by [Koto] operations
#[allow(missing_docs)]
Expand Down
8 changes: 4 additions & 4 deletions core/koto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
mod koto;
pub mod prelude;

pub use {
crate::koto::{Koto, KotoError, KotoSettings},
koto_bytecode as bytecode, koto_parser as parser, koto_runtime as runtime,
};
pub use crate::koto::{Koto, KotoError, KotoSettings};
pub use koto_bytecode as bytecode;
pub use koto_parser as parser;
pub use koto_runtime as runtime;
8 changes: 3 additions & 5 deletions core/koto/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! A collection of useful items to make it easier to work with `koto`

pub use {
crate::{Koto, KotoError, KotoSettings},
koto_bytecode::{Chunk, Loader, LoaderError},
koto_runtime::prelude::*,
};
pub use crate::{Koto, KotoError, KotoSettings};
pub use koto_bytecode::{Chunk, Loader, LoaderError};
pub use koto_runtime::prelude::*;
12 changes: 5 additions & 7 deletions core/koto/tests/docs_examples.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
koto::prelude::*,
std::{
ops::Deref,
path::{Path, PathBuf},
rc::Rc,
},
use koto::prelude::*;
use std::{
ops::Deref,
path::{Path, PathBuf},
rc::Rc,
};

struct ExampleTestRunner {
Expand Down
14 changes: 6 additions & 8 deletions core/koto/tests/koto_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use {
koto::prelude::*,
std::{
cell::RefCell,
fs::read_to_string,
path::{Path, PathBuf},
rc::Rc,
},
use koto::prelude::*;
use std::{
cell::RefCell,
fs::read_to_string,
path::{Path, PathBuf},
rc::Rc,
};

fn run_script(script: &str, script_path: Option<PathBuf>, expected_module_paths: &[PathBuf]) {
Expand Down
3 changes: 2 additions & 1 deletion core/koto/tests/repl_mode_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//! The exports map gets populated with any top-level assigned IDs, and is then made available to
//! each subsequent chunk.

use {koto::prelude::*, std::rc::Rc};
use koto::prelude::*;
use std::rc::Rc;

fn run_repl_mode_test(inputs_and_expected_outputs: &[(&str, &str)]) {
let output = PtrMut::from(String::new());
Expand Down
10 changes: 4 additions & 6 deletions core/lexer/src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use {
crate::{Position, Span},
std::{iter::Peekable, str::Chars},
unicode_width::UnicodeWidthChar,
unicode_xid::UnicodeXID,
};
use crate::{Position, Span};
use std::{iter::Peekable, str::Chars};
use unicode_width::UnicodeWidthChar;
use unicode_xid::UnicodeXID;

/// The tokens that can emerge from the lexer
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion core/lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mod lexer;
mod span;

pub use {
pub use crate::{
lexer::{is_id_continue, is_id_start, KotoLexer as Lexer, Token},
span::{Position, Span},
};
2 changes: 1 addition & 1 deletion core/memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

mod rc;

pub use rc::*;
pub use crate::rc::*;
3 changes: 2 additions & 1 deletion core/memory/src/rc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
mod ptr;
mod ptr_mut;

pub use {ptr::*, ptr_mut::*};
pub use ptr::*;
pub use ptr_mut::*;
6 changes: 2 additions & 4 deletions core/parser/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use {
crate::{error::*, ConstantPool, Node},
koto_lexer::Span,
};
use crate::{error::*, ConstantPool, Node};
use koto_lexer::Span;

/// The index type used by nodes in the [Ast]
pub type AstIndex = u32;
Expand Down
16 changes: 7 additions & 9 deletions core/parser/src/constant_pool.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use {
crate::{ConstantIndex, ConstantIndexTryFromOutOfRange},
koto_memory::Ptr,
std::{
collections::{hash_map::DefaultHasher, HashMap},
fmt,
hash::{Hash, Hasher},
ops::Range,
},
use crate::{ConstantIndex, ConstantIndexTryFromOutOfRange};
use koto_memory::Ptr;
use std::{
collections::{hash_map::DefaultHasher, HashMap},
fmt,
hash::{Hash, Hasher},
ops::Range,
};

// An entry in the list of constants contained in a [ConstantPool]
Expand Down
12 changes: 5 additions & 7 deletions core/parser/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
koto_lexer::{Position, Span},
std::{
error,
fmt::{self, Write},
path::PathBuf,
},
use koto_lexer::{Position, Span};
use std::{
error,
fmt::{self, Write},
path::PathBuf,
};

/// An error that represents a problem with the Parser's internal logic, rather than a user error
Expand Down
4 changes: 2 additions & 2 deletions core/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ mod error;
mod node;
mod parser;

pub use {
pub use crate::{
ast::*,
constant_index::{ConstantIndex, ConstantIndexTryFromOutOfRange},
constant_pool::{Constant, ConstantPool},
error::{format_error_with_excerpt, ParserError},
koto_lexer::{Position, Span},
node::*,
parser::Parser,
};
pub use koto_lexer::{Position, Span};
6 changes: 2 additions & 4 deletions core/parser/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use {
crate::{ast::AstIndex, ConstantIndex},
std::fmt,
};
use crate::{ast::AstIndex, ConstantIndex};
use std::fmt;

/// A parsed node that can be included in the [AST](crate::Ast).
///
Expand Down
20 changes: 9 additions & 11 deletions core/parser/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#![cfg_attr(feature = "panic_on_parser_error", allow(unreachable_code))]

use {
crate::{
constant_pool::ConstantPoolBuilder,
error::{
ErrorType as ParserErrorType, ExpectedIndentation, InternalError, ParserError,
SyntaxError,
},
*,
use crate::{
constant_pool::ConstantPoolBuilder,
error::{
ErrorType as ParserErrorType, ExpectedIndentation, InternalError, ParserError, SyntaxError,
},
koto_lexer::{Lexer, Span, Token},
std::{collections::HashSet, str::FromStr},
*,
};
use koto_lexer::{Lexer, Span, Token};
use std::{collections::HashSet, str::FromStr};

// Contains info about the current frame, representing either the module's top level or a function
#[derive(Debug, Default)]
Expand Down Expand Up @@ -2793,7 +2790,8 @@ impl<'source> Parser<'source> {
&mut self,
context: &ExpressionContext,
) -> Result<Option<(AstString, Span, ExpressionContext)>, ParserError> {
use {SyntaxError::*, Token::*};
use SyntaxError::*;
use Token::*;

match self.peek_token_with_context(context) {
Some(PeekInfo {
Expand Down
Loading

0 comments on commit 9a0baa9

Please sign in to comment.