valhallac

Compiler for set-theoretic programming language.
git clone git://git.knutsen.co/valhallac
Log | Files | Refs | README | LICENSE

commit bc379f20e5b205f9416fe524276caf6718890adf
parent 4439a2022ed785a16bc1a08a973b59bad2b12760
Author: Demonstrandum <moi@knutsen.co>
Date:   Thu, 11 Jun 2020 20:33:54 +0100

Compile less without debug features.

Diffstat:
MCargo.toml | 8++++----
Mgraph.png | 0
Ascripts/graph.sh | 12++++++++++++
Msrc/bin.rs | 28+++++++++++++++++-----------
Msrc/compiler/block.rs | 3+++
Msrc/compiler/element.rs | 2++
Msrc/compiler/marshal.rs | 11+++++++++--
Msrc/syntax/analysis/type_resolver.rs | 3+++
Msrc/syntax/mod.rs | 2++
Msrc/syntax/token.rs | 16++++++++++++----
10 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -18,9 +18,8 @@ edition = "2018" build = "build.rs" - [features] -debug = [] # No deps. +debug = ["snailquote"] [lib] name = "valhallac" @@ -33,13 +32,14 @@ path = "src/bin.rs" [dependencies] lazy_static = "1.3.0" regex = "1" -toml = "0.5.6" unindent = "0.1.3" -snailquote = "0.2.0" unicode-width = "0.1.5" enum-primitive-derive = "^0.1" num-traits = "^0.1" colored = "1.8" +# Debug dependencies: +snailquote = { version = "0.2.0", optional = true } + [build-dependencies] toml = "0.5.6" diff --git a/graph.png b/graph.png Binary files differ. diff --git a/scripts/graph.sh b/scripts/graph.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +cargo deps --all-deps --include-orphans --subgraph \ + lazy_static regex unindent snailquote unicode-width \ + enum-primitive-derive num-traits colored toml \ + --subgraph-name "Direct Dependencies" \ + --manifest-path "$PWD/Cargo.toml" \ + | dot -Tpng \ + -Nfontname='Iosevka Term' -Gfontname='Iosevka Term' \ + -Gsize='3,2\!' -Gratio=auto -Gdpi=1000 \ + -o"$PWD/graph.png" + diff --git a/src/bin.rs b/src/bin.rs @@ -102,7 +102,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> { return Ok(()); } + #[allow(unused_variables)] let verbose : bool = flags.contains_key(&Flags::Verbose); + + #[allow(unused_variables)] #[cfg(feature="debug")] let verbose = true; @@ -158,19 +161,22 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> { }); } - let elapsed = begin.elapsed(); - let seconds = elapsed.as_secs_f64(); - not_debug!(verbose, { - print!("{}{} ", *INFO, "Took".bold().blue()); - println!("{}", if seconds < 0.1f64 { - format!("{}ms.", begin.elapsed().as_millis()) - } else { - format!("{:0.5}s", seconds) - }.white()); + #[allow(unused_variables)] { + let elapsed = begin.elapsed(); + let seconds = elapsed.as_secs_f64(); - println!(); - }); + not_debug!(verbose, { + print!("{}{} ", *INFO, "Took".bold().blue()); + println!("{}", if seconds < 0.1f64 { + format!("{}ms.", begin.elapsed().as_millis()) + } else { + format!("{:0.5}s", seconds) + }.white()); + + println!(); + }); + } Ok(()) } diff --git a/src/compiler/block.rs b/src/compiler/block.rs @@ -1,4 +1,6 @@ +#[cfg(feature="debug")] use std::fmt; + use std::collections::{HashMap, VecDeque}; use super::super::err; @@ -374,6 +376,7 @@ impl<'a> LocalBlock<'a> { } } +#[cfg(feature="debug")] impl<'a> fmt::Display for LocalBlock<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for c in &self.constants { diff --git a/src/compiler/element.rs b/src/compiler/element.rs @@ -2,6 +2,7 @@ use std::fmt; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; +#[cfg(feature="debug")] use snailquote::escape; use super::block; @@ -64,6 +65,7 @@ impl<'a> Element<'a> { } +#[cfg(feature="debug")] impl<'a> fmt::Display for Element<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self { diff --git a/src/compiler/marshal.rs b/src/compiler/marshal.rs @@ -105,8 +105,15 @@ fn marshal_element(element : &Element) -> Vec<u8> { num_marshal_append!(s_bytes_len, bytes); bytes.extend(s_bytes); } - _ => panic!("I do not know how to marshal type of `{}'.", - element) + + #[allow(unreachable_code)] + _ => { + #[cfg(feature="debug")] { + panic!("I do not know how to marshal type of `{}'.", + element); + } + panic!("Type cannot be marshalled! This is a (big) bug!") + } }; bytes } diff --git a/src/syntax/analysis/type_resolver.rs b/src/syntax/analysis/type_resolver.rs @@ -1,3 +1,6 @@ +#![allow(unused_variables)] +#![allow(dead_code)] + use super::ast; use ast::{Nodes, StaticTypes}; diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs @@ -46,6 +46,8 @@ pub fn parse_file(filename : &str) -> ast::Root { println!("Stream:\n{}\n", stream.to_string()); let mut tree = parser::parse(stream, filename); + + #[allow(unused_variables)] let transformations = transformations![ TYPE_RESOLUTION, CONSTANT_FOLDING diff --git a/src/syntax/token.rs b/src/syntax/token.rs @@ -1,12 +1,16 @@ -use std::{fmt, collections::VecDeque}; +use std::fmt; use super::location; -use snailquote::escape; -use unicode_width::UnicodeWidthStr; - +#[cfg(feature="debug")] +use { + snailquote::escape, + unicode_width::UnicodeWidthStr, + std::collections::VecDeque +}; /// # TODO: Use this. /// Way of representing a level of indentation. +#[allow(dead_code)] enum Indent { Tab, Spaces(u32), @@ -105,6 +109,7 @@ impl Token { } /// String representation of the token. +#[cfg(feature="debug")] impl fmt::Display for Token { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut escaped = escape(&self.string.to_string()).into_owned(); @@ -123,10 +128,13 @@ impl fmt::Display for Token { /// Allows for a custom string representation for the /// token-stream as a whole. +#[cfg(feature="debug")] pub trait ShowStream { /// String representation of token-stream. fn to_string(&self) -> String; } + +#[cfg(feature="debug")] impl ShowStream for VecDeque<Token> { fn to_string(&self) -> String { let lines : Vec<String> = self.iter().map(Token::to_string).collect();