From 84a4a49622359ea6112b7f38799d89b2003a24e6 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Fri, 26 Jul 2024 23:34:09 -0400 Subject: [PATCH] More progress --- .../src/compiler/expr/field_access_expr.rs | 1 - examples/cat.rue | 32 +++++++++---------- examples/multisig.rue | 14 ++++---- examples/p2_conditions.rue | 2 +- examples/p2_delegated_or_hidden.rue | 6 ++-- examples/p2_fusion.rue | 2 +- examples/royalty_split.rue | 12 +++---- examples/singleton.rue | 10 +++--- tests/function/external_function.rue | 2 +- tests/function/function_call.rue | 4 +-- tests/function/function_rest_param.rue | 6 ++-- 11 files changed, 45 insertions(+), 46 deletions(-) diff --git a/crates/rue-compiler/src/compiler/expr/field_access_expr.rs b/crates/rue-compiler/src/compiler/expr/field_access_expr.rs index a3cc50a..84cea4c 100644 --- a/crates/rue-compiler/src/compiler/expr/field_access_expr.rs +++ b/crates/rue-compiler/src/compiler/expr/field_access_expr.rs @@ -83,7 +83,6 @@ impl Compiler<'_> { if index == fields.len() - 1 && variant.rest == Rest::Optional { // TODO: type_id = self.ty.alloc(Type::Optional(type_id)); - todo!() } let fields_hir_id = self.db.alloc_hir(Hir::Op(Op::Rest, old_value.hir_id)); diff --git a/examples/cat.rue b/examples/cat.rue index b414691..2598bea 100644 --- a/examples/cat.rue +++ b/examples/cat.rue @@ -29,17 +29,17 @@ struct Truths { type Tail = fun( truths: Truths, parent_is_cat: Bool, - lineage_proof: LineageProof?, + lineage_proof: LineageProof | Nil, extra_delta: Int, - conditions: Condition[], - tail_solution: Any[], -) -> Condition[]; + conditions: List, + tail_solution: List, +) -> List; // Information about the TAIL reveal. // This is revealed with `RunTailCondition`. struct TailInfo { tail_puzzle: Tail, - tail_solution: Any[], + tail_solution: List, } // A custom condition `(51 () -113 tail_puzzle tail_solution)`. @@ -49,7 +49,7 @@ struct RunTailCondition { puzzle_hash: Nil, amount: Int, tail_puzzle: Tail, - tail_solution: Any[], + tail_solution: List, } // Information about the current coin. @@ -90,15 +90,15 @@ inline fun cat_puzzle_hash(cat_info: CatInfo, inner_puzzle_hash: Bytes32) -> Byt fun main( mod_hash: Bytes32, asset_id: Bytes32, - inner_puzzle: fun(...solution: Any) -> Condition[], + inner_puzzle: fun(...solution: Any) -> List, inner_solution: Any, - lineage_proof: LineageProof?, + lineage_proof: LineageProof | Nil, prev_coin_id: Bytes32, my_coin: Coin, next_coin_proof: CoinProof, prev_subtotal: Int, extra_delta: Int, -) -> Condition[] { +) -> List { // For simplicity, we'll pack these values into a struct. let cat_info = CatInfo { mod_hash: mod_hash, @@ -144,12 +144,12 @@ fun main( // Prepend the ring conditions to the morphed conditions. // This ensures that the previous and next CATs are linked. // When they form a ring like this, you can be sure the supply isn't changed. - let conditions: Condition[] = [ + let conditions: List = [ Condition::CreateCoinAnnouncement { - message: RING_MORPH_BYTE + tree_hash([prev_coin_id, prev_subtotal] as Any[]), + message: RING_MORPH_BYTE + tree_hash([prev_coin_id, prev_subtotal] as List), }, Condition::AssertCoinAnnouncement { - announcement_id: sha256(next_coin_id + RING_MORPH_BYTE + tree_hash([my_coin_id, subtotal] as Any[])), + announcement_id: sha256(next_coin_id + RING_MORPH_BYTE + tree_hash([my_coin_id, subtotal] as List)), }, ...morph.conditions, ]; @@ -191,20 +191,20 @@ fun main( struct Morph { // The morphed conditions. - conditions: Condition[], + conditions: List, // The total amount of coins created. sum: Int, // Information about the TAIL, revealed in the conditions. - tail_info: TailInfo?, + tail_info: TailInfo | Nil, } // Morph all of the conditions and extract the TAIL info. fun morph_conditions( - conditions: Condition[], + conditions: List, cat_info: CatInfo, - tail_info: TailInfo?, + tail_info: TailInfo | Nil, ) -> Morph { // If there are no conditions, return an empty morph. if conditions is Nil { diff --git a/examples/multisig.rue b/examples/multisig.rue index 9bba1dc..4205d82 100644 --- a/examples/multisig.rue +++ b/examples/multisig.rue @@ -1,23 +1,23 @@ // This puzzle has not been audited or tested, and is for example purposes only. fun main( - public_keys: PublicKey[], + public_keys: List, required: Int, - indices: Int[], - conditions: Condition[], -) -> Condition[] { + indices: List, + conditions: List, +) -> List { let message = tree_hash(conditions); let agg_sigs = check_signatures(public_keys, required, indices, 0, message); concat(agg_sigs, conditions) } fun check_signatures( - public_keys: PublicKey[], + public_keys: List, required: Int, - indices: Int[], + indices: List, pos: Int, message: Bytes, -) -> Condition[] { +) -> List { if required == 0 { return nil; } diff --git a/examples/p2_conditions.rue b/examples/p2_conditions.rue index f017e95..1f5dd95 100644 --- a/examples/p2_conditions.rue +++ b/examples/p2_conditions.rue @@ -1,6 +1,6 @@ // This puzzle has not been audited or tested, and is for example purposes only. -fun main(public_key: PublicKey, conditions: Condition[]) -> Condition[] { +fun main(public_key: PublicKey, conditions: List) -> List { let agg_sig = Condition::AggSigMe { public_key: public_key, message: tree_hash(conditions), diff --git a/examples/p2_delegated_or_hidden.rue b/examples/p2_delegated_or_hidden.rue index a4f66e4..188add2 100644 --- a/examples/p2_delegated_or_hidden.rue +++ b/examples/p2_delegated_or_hidden.rue @@ -2,10 +2,10 @@ fun main( synthetic_pk: PublicKey, - original_pk: PublicKey?, - delegated_puzzle: fun(...solution: Any) -> Condition[], + original_pk: PublicKey | Nil, + delegated_puzzle: fun(...solution: Any) -> List, delegated_solution: Any -) -> Condition[] { +) -> List { let conditions = delegated_puzzle(...delegated_solution); let delegated_puzzle_hash = tree_hash(delegated_puzzle); diff --git a/examples/p2_fusion.rue b/examples/p2_fusion.rue index dbf19d0..b01324e 100644 --- a/examples/p2_fusion.rue +++ b/examples/p2_fusion.rue @@ -20,7 +20,7 @@ fun main( my_inner_puzzle_hash: Bytes32, my_amount: Int, p2_puzzle_hash: Bytes32, -) -> Condition[] { +) -> List { // The NFT singleton has the same mod hash and launcher puzzle hash as the fusion singleton. let nft_singleton = SingletonInfo { mod_hash: fusion_singleton.mod_hash, diff --git a/examples/royalty_split.rue b/examples/royalty_split.rue index 6078916..a6922f8 100644 --- a/examples/royalty_split.rue +++ b/examples/royalty_split.rue @@ -5,7 +5,7 @@ struct Payout { share: Int, } -fun main(payouts: Payout[], total_shares: Int, my_amount: Int) -> Condition[] { +fun main(payouts: List, total_shares: Int, my_amount: Int) -> List { let announcement = Condition::CreateCoinAnnouncement { message: '$' }; let assert_amount = Condition::AssertMyAmount { amount: my_amount }; @@ -14,13 +14,13 @@ fun main(payouts: Payout[], total_shares: Int, my_amount: Int) -> Condition[] { } fun calculate_amount_and_split( - payouts: Payout[], + payouts: List, total_amount: Int, total_shares: Int, shares_sum: Int, remaining_amount: Int, -) -> Condition[] { - if payouts is (Payout, Payout[]) { +) -> List { + if payouts is (Payout, List) { let amount = get_amount(payouts.first, total_amount, total_shares); return split_amount_and_create_coins(payouts, amount, total_amount, total_shares, shares_sum, remaining_amount); } @@ -29,13 +29,13 @@ fun calculate_amount_and_split( } fun split_amount_and_create_coins( - payouts: (Payout, Payout[]), + payouts: (Payout, List), this_amount: Int, total_amount: Int, total_shares: Int, shares_sum: Int, remaining_amount: Int, -) -> Condition[] { +) -> List { let payout = payouts.first; let create_coin = Condition::CreateCoin { puzzle_hash: payout.puzzle_hash, diff --git a/examples/singleton.rue b/examples/singleton.rue index 8112a28..7cff2b7 100644 --- a/examples/singleton.rue +++ b/examples/singleton.rue @@ -8,7 +8,7 @@ struct Singleton { struct LineageProof { parent_parent_coin_info: Bytes32, - parent_inner_puzzle_hash: Bytes32?, + parent_inner_puzzle_hash: Bytes32 | Nil, parent_amount: Int, } @@ -18,11 +18,11 @@ fun singleton_puzzle_hash(singleton: Singleton, inner_puzzle_hash: Bytes32) -> B fun main( singleton: Singleton, - inner_puzzle: fun(...solution: Any) -> Condition[], + inner_puzzle: fun(...solution: Any) -> List, lineage_proof: LineageProof, my_amount: Int, inner_solution: Any, -) -> Condition[] { +) -> List { // Ensure that the amount is odd. assert my_amount & 1 == 1; @@ -55,9 +55,9 @@ fun main( fun morph_conditions( singleton: Singleton, - conditions: Condition[], + conditions: List, found_singleton_output: Bool, -) -> Condition[] { +) -> List { if conditions is Nil { // We must have a singleton output. assert found_singleton_output; diff --git a/tests/function/external_function.rue b/tests/function/external_function.rue index 97e6602..665c977 100644 --- a/tests/function/external_function.rue +++ b/tests/function/external_function.rue @@ -1,3 +1,3 @@ -fun main(conditions: fun(...solution: Any) -> Condition[]) -> Condition[] { +fun main(conditions: fun(...solution: Any) -> List) -> List { conditions(...nil) } diff --git a/tests/function/function_call.rue b/tests/function/function_call.rue index 0655ef1..4996b81 100644 --- a/tests/function/function_call.rue +++ b/tests/function/function_call.rue @@ -68,7 +68,7 @@ fun two_optional(_a: Int, _b?: Int) -> Bool { true } -fun one_spread_list(..._a: Int[]) -> Bool { +fun one_spread_list(..._a: List) -> Bool { true } @@ -76,7 +76,7 @@ fun one_spread_raw(..._a: Int) -> Bool { true } -fun two_spread_list(_a: Int, ..._b: Int[]) -> Bool { +fun two_spread_list(_a: Int, ..._b: List) -> Bool { true } diff --git a/tests/function/function_rest_param.rue b/tests/function/function_rest_param.rue index 667d63c..caadd06 100644 --- a/tests/function/function_rest_param.rue +++ b/tests/function/function_rest_param.rue @@ -2,15 +2,15 @@ fun main() -> Int { sum(...range_inclusive(1, 10)) } -fun range_inclusive(start: Int, end: Int) -> Int[] { +fun range_inclusive(start: Int, end: Int) -> List { if start > end { return nil; } [start, ...range_inclusive(start + 1, end)] } -fun sum(...nums: Int[]) -> Int { - if nums is (Int, Int[]) { +fun sum(...nums: List) -> Int { + if nums is (Int, List) { nums.first + sum(...nums.rest) } else { 0