diff --git a/Cargo.lock b/Cargo.lock index 3cc3f803..75b32b3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2793,7 +2793,6 @@ dependencies = [ "futures", "fxhash", "inkwell", - "lazy_static", "llamada", "log", "melior", diff --git a/takolib/Cargo.toml b/takolib/Cargo.toml index 3b177370..e5e52b4e 100644 --- a/takolib/Cargo.toml +++ b/takolib/Cargo.toml @@ -45,7 +45,6 @@ fxhash = "0.2" static_assertions = "1.1" num-traits = "0.2" enum-kinds = "0.5" -lazy_static = "1.4.0" env_logger = { version = "0.11.3", optional = true } inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0"], optional = true } wasm-logger = { version = "0.2.0", optional = true } diff --git a/takolib/src/ast/mod.rs b/takolib/src/ast/mod.rs index 4f106b5c..654952fe 100644 --- a/takolib/src/ast/mod.rs +++ b/takolib/src/ast/mod.rs @@ -5,7 +5,6 @@ pub mod location; mod pretty_printer; pub mod string_interner; -use tree_sitter::Language; use crate::parser::semantics::Literal; use crate::parser::tokens::Symbol; use entity_component_slab::{make_component, make_world}; @@ -15,6 +14,7 @@ use short_typed_index::TypedIndex; use smallvec::{smallvec, SmallVec}; use std::path::PathBuf; use string_interner::{Identifier, StringInterner}; +use tree_sitter::Language; type TsNodeId = u16; @@ -100,7 +100,7 @@ impl Ast { #[must_use] pub fn new(filepath: PathBuf) -> Self { let tako_lang: &Language = &tree_sitter_tako::LANGUAGE.into(); - let int_literal_node_id = tako_lang.id_for_node_kind("int_literal", /*named*/true); + let int_literal_node_id = tako_lang.id_for_node_kind("int_literal", /*named*/ true); Self { filepath, int_literal_node_id, diff --git a/takolib/src/ast/nodes.rs b/takolib/src/ast/nodes.rs index dff77846..be53959b 100644 --- a/takolib/src/ast/nodes.rs +++ b/takolib/src/ast/nodes.rs @@ -61,7 +61,6 @@ pub struct Call { pub args: SmallVec, } - #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct Op { pub op: Symbol, diff --git a/takolib/src/ast/string_interner.rs b/takolib/src/ast/string_interner.rs index 465e8e42..92d2ef62 100644 --- a/takolib/src/ast/string_interner.rs +++ b/takolib/src/ast/string_interner.rs @@ -17,10 +17,10 @@ assert_eq_size!(Identifier, [u8; 8]); assert_eq_size!([Identifier; 2], [u8; 16]); // This means we can store two identifier references in the AST in the same // memory as a &str. -#[cfg(not(target_family="wasm"))] +#[cfg(not(target_family = "wasm"))] assert_eq_size!([Identifier; 2], &str); // And 3 in the space of a String. -#[cfg(not(target_family="wasm"))] +#[cfg(not(target_family = "wasm"))] assert_eq_size!([Identifier; 3], String); #[derive(Clone, Debug, Hash, PartialEq, Eq)] diff --git a/takolib/src/codegen/backend/llvm.rs b/takolib/src/codegen/backend/llvm.rs index 4fdb31e1..d84167eb 100644 --- a/takolib/src/codegen/backend/llvm.rs +++ b/takolib/src/codegen/backend/llvm.rs @@ -13,16 +13,16 @@ use inkwell::{ AddressSpace, OptimizationLevel, }; use std::collections::HashMap; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; use std::{ io::{stderr, stdout, Write}, path::Path, process::Command, }; -lazy_static::lazy_static! { - static ref CONTEXT: Arc> = Arc::new(Mutex::new(Context::create())); -} +static CONTEXT: LazyLock>> = LazyLock::new(|| { + Arc::new(Mutex::new(Context::create())); +}); #[derive(Debug)] pub struct Llvm<'ctx> { diff --git a/takolib/src/parser/mod.rs b/takolib/src/parser/mod.rs index 235276c9..2b0ff8ea 100644 --- a/takolib/src/parser/mod.rs +++ b/takolib/src/parser/mod.rs @@ -1,13 +1,16 @@ -use std::path::Path; use log::error; +use std::path::Path; -use smallvec::{SmallVec, smallvec}; -use tree_sitter::{Language, TreeCursor, Node as TreeNode}; -use tree_sitter::{Tree, Parser as TSParser}; +use smallvec::{smallvec, SmallVec}; +use tree_sitter::{Language, Node as TreeNode, TreeCursor}; +use tree_sitter::{Parser as TSParser, Tree}; use tokens::{Symbol, Token}; -use crate::{ast::{location::Location, Ast, NodeId}, error::TError}; +use crate::{ + ast::{location::Location, Ast, NodeId}, + error::TError, +}; pub mod semantics; @@ -20,7 +23,7 @@ pub enum TokenType { Comma, // A regular comma. Ident, // A named value. Atom, // A symbol starting with a '$', used differently to symbols which have values. - // Literals (i.e. tokens representing values): + // Literals (i.e. tokens representing values): NumberLit, ColorLit, // Short strings can be stored as symbols. @@ -133,7 +136,6 @@ pub mod tokens { #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum Symbol { - MultiCommentOpen, MultiCommentClose, Comment, @@ -274,8 +276,7 @@ pub mod tokens { } } #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] - pub enum Token { - } + pub enum Token {} impl std::fmt::Display for Token { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{self:?}") @@ -288,9 +289,15 @@ pub mod tokens { } } -fn handle_subtree<'a>(curr: &mut TreeCursor<'a>, ts_node: TreeNode<'a>, file: &Path, input: &str, ast: &mut Ast) -> Result, TError> { +fn handle_subtree<'a>( + curr: &mut TreeCursor<'a>, + ts_node: TreeNode<'a>, + file: &Path, + input: &str, + ast: &mut Ast, +) -> Result, TError> { // TODO: Check that this is large enough but not too large - let mut children: SmallVec:: = smallvec![]; + let mut children: SmallVec = smallvec![]; let mut children_walker = ts_node.walk(); for ts_child in ts_node.children(&mut children_walker) { if !ts_child.is_named() { @@ -300,7 +307,7 @@ fn handle_subtree<'a>(curr: &mut TreeCursor<'a>, ts_node: TreeNode<'a>, file: &P let child = handle_subtree(curr, ts_child, file, input, ast)?; // TODO: Check that this subtree is allowed. - + if let Some(child) = child { children.push(child); } @@ -320,7 +327,12 @@ fn handle_subtree<'a>(curr: &mut TreeCursor<'a>, ts_node: TreeNode<'a>, file: &P ts_node.is_error(), ts_node.is_named(), ); - println!("{:?} {:?} FROM {}", info, ts_node, ts_node.utf8_text(input.as_bytes()).unwrap()); + println!( + "{:?} {:?} FROM {}", + info, + ts_node, + ts_node.utf8_text(input.as_bytes()).unwrap() + ); // TODO: return the ID Ok(None) }