Skip to content

Commit

Permalink
exp/ivy/compiler: annotate clauses with the names of contracts they call
Browse files Browse the repository at this point in the history
Closes #1278
  • Loading branch information
bobg authored and iampogo committed Jun 5, 2017
1 parent 9d9b47f commit e11c978
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions exp/ivy/compiler/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type Clause struct {

// Values is the list of values unlocked or relocked in this clause.
Values []ValueInfo `json:"values"`

// Contracts is the list of contracts called by this clause.
Contracts []string `json:"contracts,omitempty"`
}

// HashCall describes a call to a hash function.
Expand Down
2 changes: 2 additions & 0 deletions exp/ivy/compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ func compileExpr(b *builder, stk stack, contract *Contract, clause *Clause, env
if bi == nil {
if v, ok := e.fn.(varRef); ok {
if entry := env.lookup(string(v)); entry != nil && entry.t == contractType {
clause.Contracts = append(clause.Contracts, entry.c.Name)

partialName := fmt.Sprintf("%s(...)", v)
stk = b.addData(stk, nil)

Expand Down
4 changes: 2 additions & 2 deletions exp/ivy/compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func TestCompile(t *testing.T) {
{
"PriceChanger",
ivytest.PriceChanger,
`[{"name":"PriceChanger","params":[{"name":"askAmount","declared_type":"Amount"},{"name":"askAsset","declared_type":"Asset"},{"name":"sellerKey","declared_type":"PublicKey"},{"name":"sellerProg","declared_type":"Program"}],"clauses":[{"name":"changePrice","params":[{"name":"newAmount","declared_type":"Amount"},{"name":"newAsset","declared_type":"Asset"},{"name":"sig","declared_type":"Signature"}],"values":[{"name":"offered","program":"PriceChanger(newAmount, newAsset, sellerKey, sellerProg)"}]},{"name":"redeem","reqs":[{"name":"payment","asset":"askAsset","amount":"askAmount"}],"values":[{"name":"payment","program":"sellerProg","asset":"askAsset","amount":"askAmount"},{"name":"offered"}]}],"value":"offered","body_bytecode":"557a6433000000557a5479ae7cac690000c3c251005a7a89597a89597a89597a89567a890274787e008901c07ec1633d0000000000537a547a51577ac1","body_opcodes":"5 ROLL JUMPIF:$redeem $changePrice 5 ROLL 4 PICK TXSIGHASH SWAP CHECKSIG VERIFY 0 0 AMOUNT ASSET 1 0 10 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 6 ROLL CATPUSHDATA 0x7478 CAT 0 CATPUSHDATA 192 CAT CHECKOUTPUT JUMP:$_end $redeem 0 0 3 ROLL 4 ROLL 1 7 ROLL CHECKOUTPUT $_end","recursive":true}]`,
`[{"name":"PriceChanger","params":[{"name":"askAmount","declared_type":"Amount"},{"name":"askAsset","declared_type":"Asset"},{"name":"sellerKey","declared_type":"PublicKey"},{"name":"sellerProg","declared_type":"Program"}],"clauses":[{"name":"changePrice","params":[{"name":"newAmount","declared_type":"Amount"},{"name":"newAsset","declared_type":"Asset"},{"name":"sig","declared_type":"Signature"}],"values":[{"name":"offered","program":"PriceChanger(newAmount, newAsset, sellerKey, sellerProg)"}],"contracts":["PriceChanger"]},{"name":"redeem","reqs":[{"name":"payment","asset":"askAsset","amount":"askAmount"}],"values":[{"name":"payment","program":"sellerProg","asset":"askAsset","amount":"askAmount"},{"name":"offered"}]}],"value":"offered","body_bytecode":"557a6433000000557a5479ae7cac690000c3c251005a7a89597a89597a89597a89567a890274787e008901c07ec1633d0000000000537a547a51577ac1","body_opcodes":"5 ROLL JUMPIF:$redeem $changePrice 5 ROLL 4 PICK TXSIGHASH SWAP CHECKSIG VERIFY 0 0 AMOUNT ASSET 1 0 10 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 9 ROLL CATPUSHDATA 6 ROLL CATPUSHDATA 0x7478 CAT 0 CATPUSHDATA 192 CAT CHECKOUTPUT JUMP:$_end $redeem 0 0 3 ROLL 4 ROLL 1 7 ROLL CHECKOUTPUT $_end","recursive":true}]`,
},
{
"OneTwo",
ivytest.OneTwo,
`[{"name":"Two","params":[{"name":"b","declared_type":"Program"},{"name":"c","declared_type":"Program"},{"name":"expirationTime","declared_type":"Time"}],"clauses":[{"name":"redeem","maxtimes":["expirationTime"],"values":[{"name":"value","program":"b"}]},{"name":"default","mintimes":["expirationTime"],"values":[{"name":"value","program":"c"}]}],"value":"value","body_bytecode":"537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac1","body_opcodes":"3 ROLL JUMPIF:$default $redeem ROT MAXTIME GREATERTHAN VERIFY 0 0 AMOUNT ASSET 1 5 ROLL CHECKOUTPUT JUMP:$_end $default ROT MINTIME LESSTHAN VERIFY 0 0 AMOUNT ASSET 1 6 ROLL CHECKOUTPUT $_end","recursive":false},{"name":"One","params":[{"name":"a","declared_type":"Program"},{"name":"b","declared_type":"Program"},{"name":"c","declared_type":"Program"},{"name":"switchTime","declared_type":"Time"},{"name":"expirationTime","declared_type":"Time"}],"clauses":[{"name":"redeem","maxtimes":["switchTime"],"values":[{"name":"value","program":"a"}]},{"name":"switch","mintimes":["switchTime"],"values":[{"name":"value","program":"Two(b, c, expirationTime)"}]}],"value":"value","body_bytecode":"557a6419000000537ac6a0690000c3c251557ac1635c000000537ac59f690000c3c25100597a89587a89577a8901747e24537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac189008901c07ec1","body_opcodes":"5 ROLL JUMPIF:$switch $redeem 3 ROLL MAXTIME GREATERTHAN VERIFY 0 0 AMOUNT ASSET 1 5 ROLL CHECKOUTPUT JUMP:$_end $switch 3 ROLL MINTIME LESSTHAN VERIFY 0 0 AMOUNT ASSET 1 0 9 ROLL CATPUSHDATA 8 ROLL CATPUSHDATA 7 ROLL CATPUSHDATA 116 CAT 0x537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac1 CATPUSHDATA 0 CATPUSHDATA 192 CAT CHECKOUTPUT $_end","recursive":false}]`,
`[{"name":"Two","params":[{"name":"b","declared_type":"Program"},{"name":"c","declared_type":"Program"},{"name":"expirationTime","declared_type":"Time"}],"clauses":[{"name":"redeem","maxtimes":["expirationTime"],"values":[{"name":"value","program":"b"}]},{"name":"default","mintimes":["expirationTime"],"values":[{"name":"value","program":"c"}]}],"value":"value","body_bytecode":"537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac1","body_opcodes":"3 ROLL JUMPIF:$default $redeem ROT MAXTIME GREATERTHAN VERIFY 0 0 AMOUNT ASSET 1 5 ROLL CHECKOUTPUT JUMP:$_end $default ROT MINTIME LESSTHAN VERIFY 0 0 AMOUNT ASSET 1 6 ROLL CHECKOUTPUT $_end","recursive":false},{"name":"One","params":[{"name":"a","declared_type":"Program"},{"name":"b","declared_type":"Program"},{"name":"c","declared_type":"Program"},{"name":"switchTime","declared_type":"Time"},{"name":"expirationTime","declared_type":"Time"}],"clauses":[{"name":"redeem","maxtimes":["switchTime"],"values":[{"name":"value","program":"a"}]},{"name":"switch","mintimes":["switchTime"],"values":[{"name":"value","program":"Two(b, c, expirationTime)"}],"contracts":["Two"]}],"value":"value","body_bytecode":"557a6419000000537ac6a0690000c3c251557ac1635c000000537ac59f690000c3c25100597a89587a89577a8901747e24537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac189008901c07ec1","body_opcodes":"5 ROLL JUMPIF:$switch $redeem 3 ROLL MAXTIME GREATERTHAN VERIFY 0 0 AMOUNT ASSET 1 5 ROLL CHECKOUTPUT JUMP:$_end $switch 3 ROLL MINTIME LESSTHAN VERIFY 0 0 AMOUNT ASSET 1 0 9 ROLL CATPUSHDATA 8 ROLL CATPUSHDATA 7 ROLL CATPUSHDATA 116 CAT 0x537a64180000007bc6a0690000c3c251557ac163240000007bc59f690000c3c251567ac1 CATPUSHDATA 0 CATPUSHDATA 192 CAT CHECKOUTPUT $_end","recursive":false}]`,
},
}
for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion generated/rev/RevId.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

public final class RevId {
public final String Id = "main/rev3209";
public final String Id = "main/rev3210";
}
2 changes: 1 addition & 1 deletion generated/rev/revid.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package rev

const ID string = "main/rev3209"
const ID string = "main/rev3210"
2 changes: 1 addition & 1 deletion generated/rev/revid.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

export const rev_id = "main/rev3209"
export const rev_id = "main/rev3210"
2 changes: 1 addition & 1 deletion generated/rev/revid.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

module Chain::Rev
ID = "main/rev3209".freeze
ID = "main/rev3210".freeze
end

0 comments on commit e11c978

Please sign in to comment.