From 8998743dfb8eff4ebfdf56a16fdc2680c468b2c6 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 7 Jul 2024 23:40:06 -0400 Subject: [PATCH] Final draft of example --- crates/rue-compiler/src/dependency_graph.rs | 13 +++---------- crates/rue-compiler/src/environment.rs | 4 ++++ crates/rue-compiler/src/optimizer.rs | 14 -------------- examples/cat.rue | 13 +++++-------- tests.toml | 11 +++++------ 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/crates/rue-compiler/src/dependency_graph.rs b/crates/rue-compiler/src/dependency_graph.rs index 8f4b115..5727086 100644 --- a/crates/rue-compiler/src/dependency_graph.rs +++ b/crates/rue-compiler/src/dependency_graph.rs @@ -214,16 +214,9 @@ impl<'a> GraphBuilder<'a> { .or_default() .insert(parent_scope_id); - let parent_environment_id = self.graph.environments[&parent_scope_id]; - - let child_environment_id = self - .db - .alloc_env(Environment::binding(parent_environment_id)); - - self.graph - .environments - .insert(child_scope_id, child_environment_id); - + let parent_env_id = self.graph.environments[&parent_scope_id]; + let child_env_id = self.db.alloc_env(Environment::binding(parent_env_id)); + self.graph.environments.insert(child_scope_id, child_env_id); self.walk_hir(child_scope_id, hir_id); } diff --git a/crates/rue-compiler/src/environment.rs b/crates/rue-compiler/src/environment.rs index 70d2239..505a779 100644 --- a/crates/rue-compiler/src/environment.rs +++ b/crates/rue-compiler/src/environment.rs @@ -66,6 +66,10 @@ impl Environment { self.parent } + pub fn parent_mut(&mut self) -> &mut Option { + &mut self.parent + } + pub fn build(&self) -> IndexSet { let mut symbol_ids = IndexSet::new(); symbol_ids.extend(self.definitions.iter().copied()); diff --git a/crates/rue-compiler/src/optimizer.rs b/crates/rue-compiler/src/optimizer.rs index e9c9e5f..fa7707b 100644 --- a/crates/rue-compiler/src/optimizer.rs +++ b/crates/rue-compiler/src/optimizer.rs @@ -116,21 +116,7 @@ impl<'a> Optimizer<'a> { let mut environment = Vec::new(); let mut rest; - println!("Referencing {}", self.db.dbg_symbol(symbol_id)); - loop { - for symbol_id in self.db.env(env_id).definitions() { - println!(" Defining {}", self.db.dbg_symbol(symbol_id)); - } - - for symbol_id in self.db.env(env_id).captures() { - println!(" Capturing {}", self.db.dbg_symbol(symbol_id)); - } - - for symbol_id in self.db.env(env_id).parameters() { - println!(" Parameter {}", self.db.dbg_symbol(symbol_id)); - } - environment.extend(self.db.env(env_id).build()); rest = self.db.env(env_id).rest(); diff --git a/examples/cat.rue b/examples/cat.rue index eb9129b..b414691 100644 --- a/examples/cat.rue +++ b/examples/cat.rue @@ -131,14 +131,11 @@ fun main( }; // Check whether the parent is a CAT or not. - let parent_is_cat = lineage_proof is LineageProof && { - let parent_coin_id = calculate_coin_id( - lineage_proof.parent_parent_coin_info, - cat_puzzle_hash(cat_info, lineage_proof.parent_inner_puzzle_hash), - lineage_proof.parent_amount, - ); - my_coin.parent_coin_info == parent_coin_id - }; + let parent_is_cat = lineage_proof is LineageProof && my_coin.parent_coin_info == calculate_coin_id( + lineage_proof.parent_parent_coin_info, + cat_puzzle_hash(cat_info, lineage_proof.parent_inner_puzzle_hash), + lineage_proof.parent_amount, + ); // Calculate the new subtotal. let remainder = my_coin.amount - morph.sum; diff --git a/tests.toml b/tests.toml index b7f4732..7a5887f 100644 --- a/tests.toml +++ b/tests.toml @@ -563,12 +563,11 @@ output = "()" hash = "e3153c4596c3b27d1f1cea81cf4c475e2d8f617330a82684bd97f6fae2bacf50" [cat] -bytes = 2117 -cost = 0 -input = "()" -output = "()" -hash = "5a8eefb2374bd0974bb9464f5c421a70d13e2cc2adb54ef610ebd6d3f53968be" -error = "()" +bytes = 2107 +cost = 359978 +input = "(0x00f43ce9fcc63d5019e209c103e6b0aaf56bbe7fc7fafae5af7f5ee6887a8719 0xd622c62a7292ffee5cf2537a90360ca0b7337b76d7014ec042930c0a87592213 (q (g1_negate () -113 (a (q 2 (i 47 (q 8) (q 2 (i (= 45 2) () (q 8)) 1)) 1) (c (q . 0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861) 1)) ()) (g1_negate 0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001 1 (0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001))) () () 0x615236766bed52d7abaa41d270407f3ec852981852334b213bd8515924459a5d (0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861 0x1ecb863db5d2ae6c71e9a8b0741acb3e034e8164b8ca0e564d5fad8b9dc875d5 1) (0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861 0x130deb20b44082a68293974f8cab9c51e21f9a9f3005000168eb77e49e0fc378 1) () ())" +output = "((70 0x615236766bed52d7abaa41d270407f3ec852981852334b213bd8515924459a5d) (60 0xcb7f53b5de05b4afe58ab663b952aa785fd9ad911564709bd8eacbf4c58ba1e589) (61 0x389f1ea7b9fab7a9294104eb3a181d662f2dbe9c43fbe52802ba9b7eef357e77) (g1_negate 0xc9644528436f44cd9b33282684b4964f55d5551cb3a970ab9cf8f536e0d72ad1 1 (0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001)))" +hash = "00f43ce9fcc63d5019e209c103e6b0aaf56bbe7fc7fafae5af7f5ee6887a8719" [external_function] bytes = 7