Skip to content

Commit

Permalink
Final draft of example
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 8, 2024
1 parent 9814ff9 commit 8998743
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 38 deletions.
13 changes: 3 additions & 10 deletions crates/rue-compiler/src/dependency_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions crates/rue-compiler/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl Environment {
self.parent
}

pub fn parent_mut(&mut self) -> &mut Option<EnvironmentId> {
&mut self.parent
}

pub fn build(&self) -> IndexSet<SymbolId> {
let mut symbol_ids = IndexSet::new();
symbol_ids.extend(self.definitions.iter().copied());
Expand Down
14 changes: 0 additions & 14 deletions crates/rue-compiler/src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 5 additions & 8 deletions examples/cat.rue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8998743

Please sign in to comment.