Skip to content

Commit

Permalink
Rebuild docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Feb 4, 2024
1 parent d4e9f7f commit 1e9059c
Show file tree
Hide file tree
Showing 14 changed files with 2,619 additions and 1,623 deletions.
2,882 changes: 1,471 additions & 1,411 deletions docs/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/opshin/builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="opshin.builder.PlutusContract"><code class="flex name class">
<span>class <span class="ident">PlutusContract</span></span>
<span>(</span><span>contract: pycardano.plutus.PlutusV2Script, datum_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, redeemer_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, parameter_types: List[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = &lt;factory&gt;, purpose: Iterable[<a title="opshin.builder.Purpose" href="#opshin.builder.Purpose">Purpose</a>] = (&lt;Purpose.any: &#x27;any&#x27;&gt;,), version: Optional[str] = '1.0.0', title: str = 'validator', description: Optional[str] = 'opshin 0.19.0 Smart Contract', license: Optional[str] = None)</span>
<span>(</span><span>contract: pycardano.plutus.PlutusV2Script, datum_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, redeemer_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, parameter_types: List[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = &lt;factory&gt;, purpose: Iterable[<a title="opshin.builder.Purpose" href="#opshin.builder.Purpose">Purpose</a>] = (&lt;Purpose.any: &#x27;any&#x27;&gt;,), version: Optional[str] = '1.0.0', title: str = 'validator', description: Optional[str] = 'opshin 0.19.1 Smart Contract', license: Optional[str] = None)</span>
</code></dt>
<dd>
<div class="desc"><p>PlutusContract(contract: pycardano.plutus.PlutusV2Script, datum_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, redeemer_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, parameter_types: List[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = <factory>, purpose: Iterable[opshin.builder.Purpose] = (<Purpose.any: 'any'>,), version: Optional[str] = '1.0.0', title: str = 'validator', description: Optional[str] = 'opshin 0.19.0 Smart Contract', license: Optional[str] = None)</p></div>
<div class="desc"><p>PlutusContract(contract: pycardano.plutus.PlutusV2Script, datum_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, redeemer_type: Optional[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = None, parameter_types: List[Tuple[str, Type[Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData]]]] = <factory>, purpose: Iterable[opshin.builder.Purpose] = (<Purpose.any: 'any'>,), version: Optional[str] = '1.0.0', title: str = 'validator', description: Optional[str] = 'opshin 0.19.1 Smart Contract', license: Optional[str] = None)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
Expand Down
169 changes: 40 additions & 129 deletions docs/opshin/compiler.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/opshin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h3 id="supporters">Supporters</h3>

import warnings

__version__ = &#34;0.19.0&#34;
__version__ = &#34;0.19.1&#34;
__author__ = &#34;nielstron&#34;
__author_email__ = &#34;[email protected]&#34;
__copyright__ = &#34;Copyright (C) 2023 nielstron&#34;
Expand Down
42 changes: 27 additions & 15 deletions docs/opshin/optimize/optimize_remove_deadvars.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1 class="title">Module <code>opshin.optimize.optimize_remove_deadvars</code></

from ..util import CompilingNodeVisitor, CompilingNodeTransformer
from ..type_inference import INITIAL_SCOPE
from ..typed_ast import TypedAnnAssign
from ..typed_ast import TypedAnnAssign, TypedFunctionDef, TypedClassDef, TypedName

&#34;&#34;&#34;
Removes assignments to variables that are never read
Expand All @@ -89,18 +89,22 @@ <h1 class="title">Module <code>opshin.optimize.optimize_remove_deadvars</code></
def __init__(self):
self.loaded = defaultdict(int)

def visit_Name(self, node: Name) -&gt; None:
def visit_Name(self, node: TypedName) -&gt; None:
if isinstance(node.ctx, Load):
self.loaded[node.id] += 1

def visit_ClassDef(self, node: ClassDef):
def visit_ClassDef(self, node: TypedClassDef):
# ignore the content (i.e. attribute names) of class definitions
pass

def visit_FunctionDef(self, node: FunctionDef):
def visit_FunctionDef(self, node: TypedFunctionDef):
# ignore the type hints of function arguments
for s in node.body:
self.visit(s)
for v in node.typ.typ.bound_vars.keys():
self.loaded[v] += 1
if node.typ.typ.bind_self is not None:
self.loaded[node.typ.typ.bind_self] += 1


class SafeOperationVisitor(CompilingNodeVisitor):
Expand Down Expand Up @@ -305,18 +309,22 @@ <h2 class="section-title" id="header-classes">Classes</h2>
def __init__(self):
self.loaded = defaultdict(int)

def visit_Name(self, node: Name) -&gt; None:
def visit_Name(self, node: TypedName) -&gt; None:
if isinstance(node.ctx, Load):
self.loaded[node.id] += 1

def visit_ClassDef(self, node: ClassDef):
def visit_ClassDef(self, node: TypedClassDef):
# ignore the content (i.e. attribute names) of class definitions
pass

def visit_FunctionDef(self, node: FunctionDef):
def visit_FunctionDef(self, node: TypedFunctionDef):
# ignore the type hints of function arguments
for s in node.body:
self.visit(s)</code></pre>
self.visit(s)
for v in node.typ.typ.bound_vars.keys():
self.loaded[v] += 1
if node.typ.typ.bind_self is not None:
self.loaded[node.typ.typ.bind_self] += 1</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand Down Expand Up @@ -344,44 +352,48 @@ <h3>Methods</h3>
<div class="desc inherited"><p>Visit a node.</p></div>
</dd>
<dt id="opshin.optimize.optimize_remove_deadvars.NameLoadCollector.visit_ClassDef"><code class="name flex">
<span>def <span class="ident">visit_ClassDef</span></span>(<span>self, node: ast.ClassDef)</span>
<span>def <span class="ident">visit_ClassDef</span></span>(<span>self, node: <a title="opshin.typed_ast.TypedClassDef" href="../typed_ast.html#opshin.typed_ast.TypedClassDef">TypedClassDef</a>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_ClassDef(self, node: ClassDef):
<pre><code class="python">def visit_ClassDef(self, node: TypedClassDef):
# ignore the content (i.e. attribute names) of class definitions
pass</code></pre>
</details>
</dd>
<dt id="opshin.optimize.optimize_remove_deadvars.NameLoadCollector.visit_FunctionDef"><code class="name flex">
<span>def <span class="ident">visit_FunctionDef</span></span>(<span>self, node: ast.FunctionDef)</span>
<span>def <span class="ident">visit_FunctionDef</span></span>(<span>self, node: <a title="opshin.typed_ast.TypedFunctionDef" href="../typed_ast.html#opshin.typed_ast.TypedFunctionDef">TypedFunctionDef</a>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_FunctionDef(self, node: FunctionDef):
<pre><code class="python">def visit_FunctionDef(self, node: TypedFunctionDef):
# ignore the type hints of function arguments
for s in node.body:
self.visit(s)</code></pre>
self.visit(s)
for v in node.typ.typ.bound_vars.keys():
self.loaded[v] += 1
if node.typ.typ.bind_self is not None:
self.loaded[node.typ.typ.bind_self] += 1</code></pre>
</details>
</dd>
<dt id="opshin.optimize.optimize_remove_deadvars.NameLoadCollector.visit_Name"><code class="name flex">
<span>def <span class="ident">visit_Name</span></span>(<span>self, node: ast.Name) ‑> None</span>
<span>def <span class="ident">visit_Name</span></span>(<span>self, node: <a title="opshin.typed_ast.TypedName" href="../typed_ast.html#opshin.typed_ast.TypedName">TypedName</a>) ‑> None</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_Name(self, node: Name) -&gt; None:
<pre><code class="python">def visit_Name(self, node: TypedName) -&gt; None:
if isinstance(node.ctx, Load):
self.loaded[node.id] += 1</code></pre>
</details>
Expand Down
61 changes: 45 additions & 16 deletions docs/opshin/rewrite/rewrite_remove_type_stuff.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,42 @@ <h1 class="title">Module <code>opshin.rewrite.rewrite_remove_type_stuff</code></
</summary>
<pre><code class="python">from typing import Optional

from ..typed_ast import TypedAssign, ClassType
from ..typed_ast import (
TypedAssign,
ClassType,
InstanceType,
PolymorphicFunctionType,
TypeInferenceError,
)
from ..util import CompilingNodeTransformer

&#34;&#34;&#34;
Remove class reassignments without constructors
Remove class reassignments without constructors and polymorphic function reassignments

Both of these are only present during the type inference and are discarded or generated in-place during compilation.
&#34;&#34;&#34;


class RewriteRemoveTypeStuff(CompilingNodeTransformer):
step = &#34;Removing class re-assignments&#34;
step = &#34;Removing class and polymorphic function re-assignments&#34;

def visit_Assign(self, node: TypedAssign) -&gt; Optional[TypedAssign]:
assert (
len(node.targets) == 1
), &#34;Assignments to more than one variable not supported yet&#34;
try:
if isinstance(node.value.typ, ClassType):
node.value.typ.constr()
except NotImplementedError:
# The type does not have a constructor and the constructor can hence not be passed on
return None
try:
typ = node.value.typ.constr_type()
except TypeInferenceError:
# no constr_type is also fine
return None
else:
typ = node.value.typ
if isinstance(typ, InstanceType) and isinstance(
typ.typ, PolymorphicFunctionType
):
return None
except AttributeError:
# untyped attributes are fine too
pass
Expand Down Expand Up @@ -142,18 +157,25 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">class RewriteRemoveTypeStuff(CompilingNodeTransformer):
step = &#34;Removing class re-assignments&#34;
step = &#34;Removing class and polymorphic function re-assignments&#34;

def visit_Assign(self, node: TypedAssign) -&gt; Optional[TypedAssign]:
assert (
len(node.targets) == 1
), &#34;Assignments to more than one variable not supported yet&#34;
try:
if isinstance(node.value.typ, ClassType):
node.value.typ.constr()
except NotImplementedError:
# The type does not have a constructor and the constructor can hence not be passed on
return None
try:
typ = node.value.typ.constr_type()
except TypeInferenceError:
# no constr_type is also fine
return None
else:
typ = node.value.typ
if isinstance(typ, InstanceType) and isinstance(
typ.typ, PolymorphicFunctionType
):
return None
except AttributeError:
# untyped attributes are fine too
pass
Expand Down Expand Up @@ -200,10 +222,17 @@ <h3>Methods</h3>
), &#34;Assignments to more than one variable not supported yet&#34;
try:
if isinstance(node.value.typ, ClassType):
node.value.typ.constr()
except NotImplementedError:
# The type does not have a constructor and the constructor can hence not be passed on
return None
try:
typ = node.value.typ.constr_type()
except TypeInferenceError:
# no constr_type is also fine
return None
else:
typ = node.value.typ
if isinstance(typ, InstanceType) and isinstance(
typ.typ, PolymorphicFunctionType
):
return None
except AttributeError:
# untyped attributes are fine too
pass
Expand Down
34 changes: 34 additions & 0 deletions docs/opshin/std/math.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ <h1 class="title">Module <code>opshin.std.math</code></h1>
return acc


def bytes_big_from_unsigned_int(b: int) -&gt; bytes:
&#34;&#34;&#34;Converts an integer into the corresponding bytestring, big/network byteorder, unsigned&#34;&#34;&#34;
assert b &gt;= 0
if b == 0:
return b&#34;\x00&#34;
acc = b&#34;&#34;
while b &gt; 0:
acc = bytes([b % 256]) + acc
b //= 256
return acc


def ceil(a: int, b: int):
&#34;&#34;&#34;Returns a divided by b rounded towards positive infinity&#34;&#34;&#34;
return (a + b - 1) // b if b &gt; 0 else (a + b + 1) // b
Expand All @@ -107,6 +119,27 @@ <h1 class="title">Module <code>opshin.std.math</code></h1>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="opshin.std.math.bytes_big_from_unsigned_int"><code class="name flex">
<span>def <span class="ident">bytes_big_from_unsigned_int</span></span>(<span>b: int) ‑> bytes</span>
</code></dt>
<dd>
<div class="desc"><p>Converts an integer into the corresponding bytestring, big/network byteorder, unsigned</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def bytes_big_from_unsigned_int(b: int) -&gt; bytes:
&#34;&#34;&#34;Converts an integer into the corresponding bytestring, big/network byteorder, unsigned&#34;&#34;&#34;
assert b &gt;= 0
if b == 0:
return b&#34;\x00&#34;
acc = b&#34;&#34;
while b &gt; 0:
acc = bytes([b % 256]) + acc
b //= 256
return acc</code></pre>
</details>
</dd>
<dt id="opshin.std.math.ceil"><code class="name flex">
<span>def <span class="ident">ceil</span></span>(<span>a: int, b: int)</span>
</code></dt>
Expand Down Expand Up @@ -251,6 +284,7 @@ <h1>Index</h1>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="opshin.std.math.bytes_big_from_unsigned_int" href="#opshin.std.math.bytes_big_from_unsigned_int">bytes_big_from_unsigned_int</a></code></li>
<li><code><a title="opshin.std.math.ceil" href="#opshin.std.math.ceil">ceil</a></code></li>
<li><code><a title="opshin.std.math.floor" href="#opshin.std.math.floor">floor</a></code></li>
<li><code><a title="opshin.std.math.gcd" href="#opshin.std.math.gcd">gcd</a></code></li>
Expand Down
5 changes: 5 additions & 0 deletions docs/opshin/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="opshin.tests.test_types" href="test_types.html">opshin.tests.test_types</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="opshin.tests.utils" href="utils.html">opshin.tests.utils</a></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -194,6 +198,7 @@ <h1>Index</h1>
<li><code><a title="opshin.tests.test_ops" href="test_ops.html">opshin.tests.test_ops</a></code></li>
<li><code><a title="opshin.tests.test_std" href="test_std/index.html">opshin.tests.test_std</a></code></li>
<li><code><a title="opshin.tests.test_stdlib" href="test_stdlib.html">opshin.tests.test_stdlib</a></code></li>
<li><code><a title="opshin.tests.test_types" href="test_types.html">opshin.tests.test_types</a></code></li>
<li><code><a title="opshin.tests.utils" href="utils.html">opshin.tests.utils</a></code></li>
</ul>
</li>
Expand Down
Loading

0 comments on commit 1e9059c

Please sign in to comment.