Skip to content

Commit

Permalink
More progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 27, 2024
1 parent 9f59957 commit 84a4a49
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 46 deletions.
1 change: 0 additions & 1 deletion crates/rue-compiler/src/compiler/expr/field_access_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
32 changes: 16 additions & 16 deletions examples/cat.rue
Original file line number Diff line number Diff line change
Expand Up @@ -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<Condition>,
tail_solution: List<Any>,
) -> List<Condition>;

// Information about the TAIL reveal.
// This is revealed with `RunTailCondition`.
struct TailInfo {
tail_puzzle: Tail,
tail_solution: Any[],
tail_solution: List<Any>,
}

// A custom condition `(51 () -113 tail_puzzle tail_solution)`.
Expand All @@ -49,7 +49,7 @@ struct RunTailCondition {
puzzle_hash: Nil,
amount: Int,
tail_puzzle: Tail,
tail_solution: Any[],
tail_solution: List<Any>,
}

// Information about the current coin.
Expand Down Expand Up @@ -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<Condition>,
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<Condition> {
// For simplicity, we'll pack these values into a struct.
let cat_info = CatInfo {
mod_hash: mod_hash,
Expand Down Expand Up @@ -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> = [
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<Any>),
},
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<Any>)),
},
...morph.conditions,
];
Expand Down Expand Up @@ -191,20 +191,20 @@ fun main(

struct Morph {
// The morphed conditions.
conditions: Condition[],
conditions: List<Condition>,

// 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<Condition>,
cat_info: CatInfo,
tail_info: TailInfo?,
tail_info: TailInfo | Nil,
) -> Morph {
// If there are no conditions, return an empty morph.
if conditions is Nil {
Expand Down
14 changes: 7 additions & 7 deletions examples/multisig.rue
Original file line number Diff line number Diff line change
@@ -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<PublicKey>,
required: Int,
indices: Int[],
conditions: Condition[],
) -> Condition[] {
indices: List<Int>,
conditions: List<Condition>,
) -> List<Condition> {
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<PublicKey>,
required: Int,
indices: Int[],
indices: List<Int>,
pos: Int,
message: Bytes,
) -> Condition[] {
) -> List<Condition> {
if required == 0 {
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/p2_conditions.rue
Original file line number Diff line number Diff line change
@@ -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<Condition>) -> List<Condition> {
let agg_sig = Condition::AggSigMe {
public_key: public_key,
message: tree_hash(conditions),
Expand Down
6 changes: 3 additions & 3 deletions examples/p2_delegated_or_hidden.rue
Original file line number Diff line number Diff line change
Expand Up @@ -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<Condition>,
delegated_solution: Any
) -> Condition[] {
) -> List<Condition> {
let conditions = delegated_puzzle(...delegated_solution);
let delegated_puzzle_hash = tree_hash(delegated_puzzle);

Expand Down
2 changes: 1 addition & 1 deletion examples/p2_fusion.rue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun main(
my_inner_puzzle_hash: Bytes32,
my_amount: Int,
p2_puzzle_hash: Bytes32,
) -> Condition[] {
) -> List<Condition> {
// 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,
Expand Down
12 changes: 6 additions & 6 deletions examples/royalty_split.rue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Payout {
share: Int,
}

fun main(payouts: Payout[], total_shares: Int, my_amount: Int) -> Condition[] {
fun main(payouts: List<Payout>, total_shares: Int, my_amount: Int) -> List<Condition> {
let announcement = Condition::CreateCoinAnnouncement { message: '$' };
let assert_amount = Condition::AssertMyAmount { amount: my_amount };

Expand All @@ -14,13 +14,13 @@ fun main(payouts: Payout[], total_shares: Int, my_amount: Int) -> Condition[] {
}

fun calculate_amount_and_split(
payouts: Payout[],
payouts: List<Payout>,
total_amount: Int,
total_shares: Int,
shares_sum: Int,
remaining_amount: Int,
) -> Condition[] {
if payouts is (Payout, Payout[]) {
) -> List<Condition> {
if payouts is (Payout, List<Payout>) {
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);
}
Expand All @@ -29,13 +29,13 @@ fun calculate_amount_and_split(
}

fun split_amount_and_create_coins(
payouts: (Payout, Payout[]),
payouts: (Payout, List<Payout>),
this_amount: Int,
total_amount: Int,
total_shares: Int,
shares_sum: Int,
remaining_amount: Int,
) -> Condition[] {
) -> List<Condition> {
let payout = payouts.first;
let create_coin = Condition::CreateCoin {
puzzle_hash: payout.puzzle_hash,
Expand Down
10 changes: 5 additions & 5 deletions examples/singleton.rue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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<Condition>,
lineage_proof: LineageProof,
my_amount: Int,
inner_solution: Any,
) -> Condition[] {
) -> List<Condition> {
// Ensure that the amount is odd.
assert my_amount & 1 == 1;

Expand Down Expand Up @@ -55,9 +55,9 @@ fun main(

fun morph_conditions(
singleton: Singleton,
conditions: Condition[],
conditions: List<Condition>,
found_singleton_output: Bool,
) -> Condition[] {
) -> List<Condition> {
if conditions is Nil {
// We must have a singleton output.
assert found_singleton_output;
Expand Down
2 changes: 1 addition & 1 deletion tests/function/external_function.rue
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fun main(conditions: fun(...solution: Any) -> Condition[]) -> Condition[] {
fun main(conditions: fun(...solution: Any) -> List<Condition>) -> List<Condition> {
conditions(...nil)
}
4 changes: 2 additions & 2 deletions tests/function/function_call.rue
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ fun two_optional(_a: Int, _b?: Int) -> Bool {
true
}

fun one_spread_list(..._a: Int[]) -> Bool {
fun one_spread_list(..._a: List<Int>) -> Bool {
true
}

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<Int>) -> Bool {
true
}

Expand Down
6 changes: 3 additions & 3 deletions tests/function/function_rest_param.rue
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int> {
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>) -> Int {
if nums is (Int, List<Int>) {
nums.first + sum(...nums.rest)
} else {
0
Expand Down

0 comments on commit 84a4a49

Please sign in to comment.