Skip to content

Commit

Permalink
Clean up lazy static and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed Oct 23, 2024
1 parent 4ea7db4 commit 0745455
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion takolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions takolib/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion takolib/src/ast/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pub struct Call {
pub args: SmallVec<NodeId, 2>,
}


#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct Op {
pub op: Symbol,
Expand Down
4 changes: 2 additions & 2 deletions takolib/src/ast/string_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions takolib/src/codegen/backend/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<Context>> = Arc::new(Mutex::new(Context::create()));
}
static CONTEXT: LazyLock<Arc<Mutex<Context>>> = LazyLock::new(|| {
Arc::new(Mutex::new(Context::create()));
});

#[derive(Debug)]
pub struct Llvm<'ctx> {
Expand Down
38 changes: 25 additions & 13 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -133,7 +136,6 @@ pub mod tokens {

#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Symbol {

MultiCommentOpen,
MultiCommentClose,
Comment,
Expand Down Expand Up @@ -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:?}")
Expand All @@ -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<Option<NodeId>, TError> {
fn handle_subtree<'a>(
curr: &mut TreeCursor<'a>,
ts_node: TreeNode<'a>,
file: &Path,
input: &str,
ast: &mut Ast,
) -> Result<Option<NodeId>, TError> {
// TODO: Check that this is large enough but not too large
let mut children: SmallVec::<NodeId, 5> = smallvec![];
let mut children: SmallVec<NodeId, 5> = smallvec![];
let mut children_walker = ts_node.walk();
for ts_child in ts_node.children(&mut children_walker) {
if !ts_child.is_named() {
Expand All @@ -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);
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 0745455

Please sign in to comment.