Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from OpShin/bump/0.12.4
Browse files Browse the repository at this point in the history
Merge 0.12.4
  • Loading branch information
nielstron authored Apr 15, 2023
2 parents f96603f + 9844606 commit 6b7a327
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 382 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ script:
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/assert_sum.py
- >
for i in $(find examples -type f -name "*.py" -not \( -name "broken*" -o -name "extract*" \)); do
coverage run -a --source=hebi -m hebi compile "$i"
for i in $(find examples -type f -name "*.py" -not \( -name "broken*" -o -name "extract*" -o -name "__*" \)); do
echo "$i"
coverage run -a --source=hebi -m hebi compile "$i" > /dev/null
done
# smart contracts with special parameters
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/parameterized.py '{"int": 42}'
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/dual_use.py --force-three-params
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/wrapped_token.py '{"bytes": "ae810731b5d21c0d182d89c60a1eff7095dffd1c0dce8707a8611099"}' '{"bytes": "4d494c4b"}' '{"int": 1000000}' --force-three-params
after_success:
- coverage report
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ python3 -m hebi compile_pluto examples/smart_contracts/assert_sum.py

You can sponsor the development of hebi through GitHub or [Teiki](https://alpha.teiki.network/projects/opshin) or just by sending ADA. Drop me a message on social media and let me know what it is for.

- **[Teiki](https://alpha.teiki.network/projects/opshin)** Stake your ada to support OpShin at [Teiki](https://alpha.teiki.network/projects/opshin)
- **[Kreate](https://beta.kreate.community/projects/opshin)** Stake your ada to support OpShin at [Kreate](https://beta.kreate.community/projects/opshin)
- **GitHub** Sponsor the developers of this project through the button "Sponsor" next to them
- **ADA** Donation in ADA can be submitted to `$opshin` or `addr1qyz3vgd5xxevjy2rvqevz9n7n7dney8n6hqggp23479fm6vwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjns74lhmr`.

Expand Down
106 changes: 60 additions & 46 deletions docs/hebi/compiler.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
from .rewrite.rewrite_zero_ary import RewriteZeroAry
from .optimize.optimize_remove_pass import OptimizeRemovePass
from .optimize.optimize_remove_deadvars import OptimizeRemoveDeadvars
from .optimize.optimize_varlen import OptimizeVarlen
from .type_inference import *
from .util import CompilingNodeTransformer, PowImpl
from .typed_ast import transform_ext_params_map, transform_output_map, RawPlutoExpr
Expand Down Expand Up @@ -258,10 +257,7 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
# TODO can use more sophisiticated procedure here i.e. functions marked by comment
main_fun: typing.Optional[InstanceType] = None
for s in node.body:
if (
isinstance(s, FunctionDef)
and s.orig_name == self.validator_function_name
):
if isinstance(s, FunctionDef) and s.name == self.validator_function_name:
main_fun = s
assert (
main_fun is not None
Expand All @@ -273,9 +269,9 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>

# check if this is a contract written to double function
enable_double_func_mint_spend = False
if len(main_fun_typ.typ.argtyps) &gt;= 3 and self.force_three_params:
if len(main_fun_typ.argtyps) &gt;= 3 and self.force_three_params:
# check if is possible
second_last_arg = main_fun_typ.typ.argtyps[-2]
second_last_arg = main_fun_typ.argtyps[-2]
assert isinstance(
second_last_arg, InstanceType
), &#34;Can not pass Class into validator&#34;
Expand All @@ -300,36 +296,40 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
body = node.body + [
TypedReturn(
value=Name(
id=self.validator_function_name, typ=main_fun_typ, ctx=Load()
id=self.validator_function_name,
typ=InstanceType(main_fun_typ),
ctx=Load(),
),
typ=main_fun_typ.typ.rettyp,
typ=InstanceType(main_fun_typ),
)
]

validator = plt.Lambda(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.typ.argtyps)],
transform_output_map(main_fun_typ.typ.rettyp)(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.argtyps)],
transform_output_map(main_fun_typ.rettyp)(
plt.Let(
[
(
&#34;val&#34;,
self.visit_sequence(body)(plt.Unit()),
self.visit_sequence(body)(
plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
),
),
],
plt.Apply(
plt.Var(&#34;val&#34;),
plt.Var(&#34;val&#34;),
*[
transform_ext_params_map(a)(plt.Var(f&#34;p{i}&#34;))
for i, a in enumerate(main_fun_typ.typ.argtyps)
for i, a in enumerate(main_fun_typ.argtyps)
],
),
),
),
)
if enable_double_func_mint_spend:
validator = wrap_validator_double_function(
validator, pass_through=len(main_fun_typ.typ.argtyps) - 3
validator, pass_through=len(main_fun_typ.argtyps) - 3
)
elif self.force_three_params:
# Error if the double function is enforced but not possible
Expand Down Expand Up @@ -431,7 +431,11 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
) -&gt; typing.Callable[[plt.AST], plt.AST]:
body = node.body.copy()
# defaults to returning None if there is no return statement
compiled_body = self.visit_sequence(body)(plt.Unit())
if node.typ.typ.rettyp.typ == AnyType():
ret_val = plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
else:
ret_val = plt.Unit()
compiled_body = self.visit_sequence(body)(ret_val)
return lambda x: plt.Let(
[
(
Expand All @@ -455,7 +459,7 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
def visit_Return(self, node: TypedReturn) -&gt; typing.Callable[[plt.AST], plt.AST]:
# Throw away the term we were passed, this is going to be the last!
compiled_return = self.visit(node.value)
if isinstance(node.typ.typ.rettyp.typ, AnyType):
if isinstance(node.typ.typ, AnyType):
# if the function returns generic data, wrap the function return value
compiled_return = transform_output_map(node.value.typ)(compiled_return)
return lambda _: compiled_return
Expand Down Expand Up @@ -992,10 +996,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
# TODO can use more sophisiticated procedure here i.e. functions marked by comment
main_fun: typing.Optional[InstanceType] = None
for s in node.body:
if (
isinstance(s, FunctionDef)
and s.orig_name == self.validator_function_name
):
if isinstance(s, FunctionDef) and s.name == self.validator_function_name:
main_fun = s
assert (
main_fun is not None
Expand All @@ -1007,9 +1008,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>

# check if this is a contract written to double function
enable_double_func_mint_spend = False
if len(main_fun_typ.typ.argtyps) &gt;= 3 and self.force_three_params:
if len(main_fun_typ.argtyps) &gt;= 3 and self.force_three_params:
# check if is possible
second_last_arg = main_fun_typ.typ.argtyps[-2]
second_last_arg = main_fun_typ.argtyps[-2]
assert isinstance(
second_last_arg, InstanceType
), &#34;Can not pass Class into validator&#34;
Expand All @@ -1034,36 +1035,40 @@ <h2 class="section-title" id="header-classes">Classes</h2>
body = node.body + [
TypedReturn(
value=Name(
id=self.validator_function_name, typ=main_fun_typ, ctx=Load()
id=self.validator_function_name,
typ=InstanceType(main_fun_typ),
ctx=Load(),
),
typ=main_fun_typ.typ.rettyp,
typ=InstanceType(main_fun_typ),
)
]

validator = plt.Lambda(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.typ.argtyps)],
transform_output_map(main_fun_typ.typ.rettyp)(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.argtyps)],
transform_output_map(main_fun_typ.rettyp)(
plt.Let(
[
(
&#34;val&#34;,
self.visit_sequence(body)(plt.Unit()),
self.visit_sequence(body)(
plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
),
),
],
plt.Apply(
plt.Var(&#34;val&#34;),
plt.Var(&#34;val&#34;),
*[
transform_ext_params_map(a)(plt.Var(f&#34;p{i}&#34;))
for i, a in enumerate(main_fun_typ.typ.argtyps)
for i, a in enumerate(main_fun_typ.argtyps)
],
),
),
),
)
if enable_double_func_mint_spend:
validator = wrap_validator_double_function(
validator, pass_through=len(main_fun_typ.typ.argtyps) - 3
validator, pass_through=len(main_fun_typ.argtyps) - 3
)
elif self.force_three_params:
# Error if the double function is enforced but not possible
Expand Down Expand Up @@ -1165,7 +1170,11 @@ <h2 class="section-title" id="header-classes">Classes</h2>
) -&gt; typing.Callable[[plt.AST], plt.AST]:
body = node.body.copy()
# defaults to returning None if there is no return statement
compiled_body = self.visit_sequence(body)(plt.Unit())
if node.typ.typ.rettyp.typ == AnyType():
ret_val = plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
else:
ret_val = plt.Unit()
compiled_body = self.visit_sequence(body)(ret_val)
return lambda x: plt.Let(
[
(
Expand All @@ -1189,7 +1198,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
def visit_Return(self, node: TypedReturn) -&gt; typing.Callable[[plt.AST], plt.AST]:
# Throw away the term we were passed, this is going to be the last!
compiled_return = self.visit(node.value)
if isinstance(node.typ.typ.rettyp.typ, AnyType):
if isinstance(node.typ.typ, AnyType):
# if the function returns generic data, wrap the function return value
compiled_return = transform_output_map(node.value.typ)(compiled_return)
return lambda _: compiled_return
Expand Down Expand Up @@ -1812,7 +1821,11 @@ <h3>Methods</h3>
) -&gt; typing.Callable[[plt.AST], plt.AST]:
body = node.body.copy()
# defaults to returning None if there is no return statement
compiled_body = self.visit_sequence(body)(plt.Unit())
if node.typ.typ.rettyp.typ == AnyType():
ret_val = plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
else:
ret_val = plt.Unit()
compiled_body = self.visit_sequence(body)(ret_val)
return lambda x: plt.Let(
[
(
Expand Down Expand Up @@ -1941,10 +1954,7 @@ <h3>Methods</h3>
# TODO can use more sophisiticated procedure here i.e. functions marked by comment
main_fun: typing.Optional[InstanceType] = None
for s in node.body:
if (
isinstance(s, FunctionDef)
and s.orig_name == self.validator_function_name
):
if isinstance(s, FunctionDef) and s.name == self.validator_function_name:
main_fun = s
assert (
main_fun is not None
Expand All @@ -1956,9 +1966,9 @@ <h3>Methods</h3>

# check if this is a contract written to double function
enable_double_func_mint_spend = False
if len(main_fun_typ.typ.argtyps) &gt;= 3 and self.force_three_params:
if len(main_fun_typ.argtyps) &gt;= 3 and self.force_three_params:
# check if is possible
second_last_arg = main_fun_typ.typ.argtyps[-2]
second_last_arg = main_fun_typ.argtyps[-2]
assert isinstance(
second_last_arg, InstanceType
), &#34;Can not pass Class into validator&#34;
Expand All @@ -1983,36 +1993,40 @@ <h3>Methods</h3>
body = node.body + [
TypedReturn(
value=Name(
id=self.validator_function_name, typ=main_fun_typ, ctx=Load()
id=self.validator_function_name,
typ=InstanceType(main_fun_typ),
ctx=Load(),
),
typ=main_fun_typ.typ.rettyp,
typ=InstanceType(main_fun_typ),
)
]

validator = plt.Lambda(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.typ.argtyps)],
transform_output_map(main_fun_typ.typ.rettyp)(
[f&#34;p{i}&#34; for i, _ in enumerate(main_fun_typ.argtyps)],
transform_output_map(main_fun_typ.rettyp)(
plt.Let(
[
(
&#34;val&#34;,
self.visit_sequence(body)(plt.Unit()),
self.visit_sequence(body)(
plt.ConstrData(plt.Integer(0), plt.EmptyDataList())
),
),
],
plt.Apply(
plt.Var(&#34;val&#34;),
plt.Var(&#34;val&#34;),
*[
transform_ext_params_map(a)(plt.Var(f&#34;p{i}&#34;))
for i, a in enumerate(main_fun_typ.typ.argtyps)
for i, a in enumerate(main_fun_typ.argtyps)
],
),
),
),
)
if enable_double_func_mint_spend:
validator = wrap_validator_double_function(
validator, pass_through=len(main_fun_typ.typ.argtyps) - 3
validator, pass_through=len(main_fun_typ.argtyps) - 3
)
elif self.force_three_params:
# Error if the double function is enforced but not possible
Expand Down Expand Up @@ -2093,7 +2107,7 @@ <h3>Methods</h3>
<pre><code class="python">def visit_Return(self, node: TypedReturn) -&gt; typing.Callable[[plt.AST], plt.AST]:
# Throw away the term we were passed, this is going to be the last!
compiled_return = self.visit(node.value)
if isinstance(node.typ.typ.rettyp.typ, AnyType):
if isinstance(node.typ.typ, AnyType):
# if the function returns generic data, wrap the function return value
compiled_return = transform_output_map(node.value.typ)(compiled_return)
return lambda _: compiled_return</code></pre>
Expand Down
18 changes: 9 additions & 9 deletions docs/hebi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ <h3 id="debugging-artefacts">Debugging artefacts</h3>
<h3 id="sponsoring">Sponsoring</h3>
<p>You can sponsor the development of hebi through GitHub or <a href="https://alpha.teiki.network/projects/opshin">Teiki</a> or just by sending ADA. Drop me a message on social media and let me know what it is for.</p>
<ul>
<li><strong><a href="https://alpha.teiki.network/projects/opshin">Teiki</a></strong> Stake your ada to support OpShin at <a href="https://alpha.teiki.network/projects/opshin">Teiki</a></li>
<li><strong><a href="https://beta.kreate.community/projects/opshin">Kreate</a></strong> Stake your ada to support OpShin at <a href="https://beta.kreate.community/projects/opshin">Kreate</a></li>
<li><strong>GitHub</strong> Sponsor the developers of this project through the button "Sponsor" next to them</li>
<li><strong>ADA</strong> Donation in ADA can be submitted to <code>$opshin</code> or <code>addr1qyz3vgd5xxevjy2rvqevz9n7n7dney8n6hqggp23479fm6vwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjns74lhmr</code>.</li>
</ul>
Expand Down Expand Up @@ -241,18 +241,18 @@ <h3 id="supporters">Supporters</h3>

import warnings

try:
from .compiler import *
from .builder import *
except ImportError as e:
warnings.warn(ImportWarning(e))

__version__ = &#34;0.1.1.0.12.3&#34;
__version__ = &#34;0.1.1.0.12.4&#34;
__author__ = &#34;nielstron&#34;
__author_email__ = &#34;[email protected]&#34;
__copyright__ = &#34;Copyright (C) 2023 nielstron&#34;
__license__ = &#34;MIT&#34;
__url__ = &#34;https://github.com/imperatorlang/hebi&#34;</code></pre>
__url__ = &#34;https://github.com/imperatorlang/hebi&#34;

try:
from .compiler import *
from .builder import *
except ImportError as e:
warnings.warn(ImportWarning(e))</code></pre>
</details>
</section>
<section>
Expand Down
2 changes: 2 additions & 0 deletions docs/hebi/std/fractions.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ <h1 class="title">Module <code>hebi.std.fractions</code></h1>
from dataclasses import dataclass
from pycardano import PlutusData

from hebi.std.math import *


@dataclass(unsafe_hash=True)
class Fraction(PlutusData):
Expand Down
Loading

0 comments on commit 6b7a327

Please sign in to comment.