diff --git a/Cargo.lock b/Cargo.lock index ba88825b0..f160e82d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.5.0" @@ -91,20 +100,19 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d5f1946157a96594eb2d2c10eb7ad9a2b27518cb3000209dec700c35df9197d" +checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78116e32a042dd73c2901f0dc30790d20ff3447f3e3472fad359e8c3d282bcd6" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" dependencies = [ "anstream", "anstyle", @@ -114,9 +122,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9fd1a5729c4548118d7d70ff234a44868d00489a4b6597b0b020918a0e91a1a" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", @@ -174,6 +182,19 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -182,9 +203,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -251,6 +272,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + [[package]] name = "home" version = "0.5.5" @@ -260,6 +287,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "2.0.0" @@ -270,6 +303,17 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "libc" version = "0.2.147" @@ -283,6 +327,7 @@ dependencies = [ "anyhow", "clap", "dirs", + "env_logger", "lig_core", "rustyline", ] @@ -302,6 +347,7 @@ version = "0.0.0" dependencies = [ "anyhow", "fallible-iterator", + "log", "sqlite3-parser", ] @@ -319,9 +365,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "5486aed0026218e61b8a01d5fbd5a0a134649abb71a0e53b7bc088529dced86e" [[package]] name = "nibble_vec" @@ -334,14 +380,13 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" dependencies = [ "bitflags 1.3.2", "cfg-if", "libc", - "static_assertions", ] [[package]] @@ -459,10 +504,39 @@ dependencies = [ ] [[package]] -name = "rustix" -version = "0.38.9" +name = "regex" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + +[[package]] +name = "rustix" +version = "0.38.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" dependencies = [ "bitflags 2.4.0", "errno", @@ -531,12 +605,6 @@ dependencies = [ "uncased", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "str-buf" version = "1.0.6" @@ -560,6 +628,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.47" @@ -695,6 +772,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index cde2bdf1d..42cbc77b6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,5 +18,6 @@ path = "main.rs" anyhow = "1.0.75" clap = { version = "4.4.0", features = ["derive"] } dirs = "5.0.1" +env_logger = "0.10.0" lig_core = { path = "../core" } rustyline = "12.0.0" diff --git a/cli/main.rs b/cli/main.rs index 1735eb69a..cce7f6c84 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -16,6 +16,7 @@ struct Opts { } fn main() -> anyhow::Result<()> { + env_logger::init(); let opts = Opts::parse(); let io = IO::new(); let db = Database::open(Arc::new(io), opts.database.to_str().unwrap())?; diff --git a/core/Cargo.toml b/core/Cargo.toml index babb1eb2b..43d25989e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,4 +16,5 @@ path = "lib.rs" [dependencies] anyhow = "1.0.75" fallible-iterator = "0.3.0" +log = "0.4.20" sqlite3-parser = "0.11.0" diff --git a/core/lib.rs b/core/lib.rs index 139d87d38..e5bd5f8a5 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -59,7 +59,7 @@ impl Connection { for i in 0..program.column_count() { row.push(program.column(i).unwrap().to_string()); } - println!("Row = {:?}", row); + log::trace!("Row = {:?}", row); } vdbe::StepResult::IO => todo!(), vdbe::StepResult::Done => break, diff --git a/core/vdbe.rs b/core/vdbe.rs index d27c35ba4..cf6a4a6c8 100644 --- a/core/vdbe.rs +++ b/core/vdbe.rs @@ -136,7 +136,7 @@ impl Program { pub fn step(&mut self) -> Result { loop { let insn = &self.insns[self.pc]; - print_insn(self.pc, insn); + trace_insn(self.pc, insn); match insn { Insn::Init(init) => { self.pc = init.target_pc; @@ -288,7 +288,17 @@ fn translate_select(pager: Arc, schema: &Schema, select: Select) -> Resul } } +fn trace_insn(addr: usize, insn: &Insn) { + let s = insn_to_str(addr, insn); + log::trace!("{}", s); +} + fn print_insn(addr: usize, insn: &Insn) { + let s = insn_to_str(addr, insn); + println!("{}", s); +} + +fn insn_to_str(addr: usize, insn: &Insn) -> String { let (opcode, p1, p2, p3, p4, p5, comment) = match insn { Insn::Init(init) => ( "Init", @@ -343,8 +353,8 @@ fn print_insn(addr: usize, insn: &Insn) { Insn::Transaction => ("Transaction", 0, 0, 0, "", 0, "".to_string()), Insn::Goto(goto) => ("Goto", 0, goto.target_pc, 0, "", 0, "".to_string()), }; - println!( + format!( "{:<4} {:<13} {:<4} {:<4} {:<4} {:<13} {:<2} {}", addr, opcode, p1, p2, p3, p4, p5, comment - ); + ) }