Skip to content

Commit

Permalink
Do not duplicate main code
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Feb 23, 2023
1 parent 5b06235 commit d291560
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions eopsin/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ def wrap_validator_double_function(x: plt.AST):
"""Wraps the validator function to enable a double function as minting script"""
return plt.Lambda(
["a0", "a1"],
plt.Ite(
# if the second argument has constructor 0 = script context
plt.DelayedChooseData(
plt.Var("a1"),
plt.EqualsInteger(plt.Constructor(plt.Var("a1")), plt.Integer(0)),
plt.Bool(False),
plt.Bool(False),
plt.Bool(False),
plt.Bool(False),
plt.Let(
[("p", x)],
plt.Ite(
# if the second argument has constructor 0 = script context
plt.DelayedChooseData(
plt.Var("a1"),
plt.EqualsInteger(plt.Constructor(plt.Var("a1")), plt.Integer(0)),
plt.Bool(False),
plt.Bool(False),
plt.Bool(False),
plt.Bool(False),
),
# call the validator with a0, a1, and plug in Unit for data
plt.Apply(plt.Var("p"), plt.Unit(), plt.Var("a0"), plt.Var("a1")),
# else call the validator with a0, a1 and return (now partially bound)
plt.Apply(plt.Var("p"), plt.Var("a0"), plt.Var("a1")),
),
# call the validator with a0, a1, and plug in Unit for data
plt.Apply(x, plt.Unit(), plt.Var("a0"), plt.Var("a1")),
# else call the validator with a0, a1 and return (now partially bound)
plt.Apply(x, plt.Var("a0"), plt.Var("a1")),
),
)

Expand Down

0 comments on commit d291560

Please sign in to comment.