Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Jan 31, 2024
1 parent a56c7f4 commit 9e328e8
Show file tree
Hide file tree
Showing 16 changed files with 3,930 additions and 510 deletions.
1,120 changes: 808 additions & 312 deletions docs/index.js

Large diffs are not rendered by default.

211 changes: 185 additions & 26 deletions docs/opshin/compiler.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ <h1 class="title">Module <code>opshin.compiler</code></h1>
from .rewrite.rewrite_augassign import RewriteAugAssign
from .rewrite.rewrite_cast_condition import RewriteConditions
from .rewrite.rewrite_comparison_chaining import RewriteComparisonChaining
from .rewrite.rewrite_empty_dicts import RewriteEmptyDicts
from .rewrite.rewrite_empty_lists import RewriteEmptyLists
from .rewrite.rewrite_forbidden_overwrites import RewriteForbiddenOverwrites
from .rewrite.rewrite_forbidden_return import RewriteForbiddenReturn
from .rewrite.rewrite_import import RewriteImport
Expand Down Expand Up @@ -113,11 +115,6 @@ <h1 class="title">Module <code>opshin.compiler</code></h1>
Or: plt.Or,
}

UnaryOpMap = {
Not: {BoolInstanceType: plt.Not},
USub: {IntegerInstanceType: lambda x: plt.SubtractInteger(plt.Integer(0), x)},
}


def rec_constant_map_data(c):
if isinstance(c, bool):
Expand Down Expand Up @@ -276,13 +273,11 @@ <h1 class="title">Module <code>opshin.compiler</code></h1>
return ops

def visit_UnaryOp(self, node: TypedUnaryOp) -&gt; plt.AST:
opmap = UnaryOpMap.get(type(node.op))
assert opmap is not None, f&#34;Operator {type(node.op)} is not supported&#34;
op = opmap.get(node.operand.typ)
assert (
op is not None
), f&#34;Operator {type(node.op)} is not supported for type {node.operand.typ}&#34;
return op(self.visit(node.operand))
op = node.operand.typ.unop(node.op)
return plt.Apply(
op,
self.visit(node.operand),
)

def visit_Compare(self, node: TypedCompare) -&gt; plt.AST:
assert len(node.ops) == 1, &#34;Only single comparisons are supported&#34;
Expand Down Expand Up @@ -1046,6 +1041,57 @@ <h1 class="title">Module <code>opshin.compiler</code></h1>
empty_list_con,
)

def visit_DictComp(self, node: TypedDictComp) -&gt; plt.AST:
assert len(node.generators) == 1, &#34;Currently only one generator supported&#34;
gen = node.generators[0]
assert isinstance(gen.iter.typ, InstanceType), &#34;Only lists are valid generators&#34;
assert isinstance(gen.iter.typ.typ, ListType), &#34;Only lists are valid generators&#34;
assert isinstance(
gen.target, Name
), &#34;Can only assign value to singleton element&#34;
lst = self.visit(gen.iter)
ifs = None
for ifexpr in gen.ifs:
if ifs is None:
ifs = self.visit(ifexpr)
else:
ifs = plt.And(ifs, self.visit(ifexpr))
map_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
plt.MkPairData(
transform_output_map(node.key.typ)(
self.visit(node.key),
),
transform_output_map(node.value.typ)(
self.visit(node.value),
),
),
),
)
empty_list_con = plt.EmptyDataPairList()
if ifs is not None:
filter_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
ifs,
),
)
return plt.MapFilterList(
lst,
filter_fun,
map_fun,
empty_list_con,
)
else:
return plt.MapList(
lst,
map_fun,
empty_list_con,
)

def visit_FormattedValue(self, node: TypedFormattedValue) -&gt; plt.AST:
return plt.Apply(
node.value.typ.stringify(),
Expand Down Expand Up @@ -1095,6 +1141,8 @@ <h1 class="title">Module <code>opshin.compiler</code></h1>
# The type inference needs to be run after complex python operations were rewritten
AggressiveTypeInferencer(allow_isinstance_anything),
# Rewrites that circumvent the type inference or use its results
RewriteEmptyLists(),
RewriteEmptyDicts(),
RewriteImportUPLCBuiltins(),
RewriteInjectBuiltinsConstr(),
RewriteRemoveTypeStuff(),
Expand Down Expand Up @@ -1166,6 +1214,8 @@ <h2 class="section-title" id="header-functions">Functions</h2>
# The type inference needs to be run after complex python operations were rewritten
AggressiveTypeInferencer(allow_isinstance_anything),
# Rewrites that circumvent the type inference or use its results
RewriteEmptyLists(),
RewriteEmptyDicts(),
RewriteImportUPLCBuiltins(),
RewriteInjectBuiltinsConstr(),
RewriteRemoveTypeStuff(),
Expand Down Expand Up @@ -1443,13 +1493,11 @@ <h3>Methods</h3>
return ops

def visit_UnaryOp(self, node: TypedUnaryOp) -&gt; plt.AST:
opmap = UnaryOpMap.get(type(node.op))
assert opmap is not None, f&#34;Operator {type(node.op)} is not supported&#34;
op = opmap.get(node.operand.typ)
assert (
op is not None
), f&#34;Operator {type(node.op)} is not supported for type {node.operand.typ}&#34;
return op(self.visit(node.operand))
op = node.operand.typ.unop(node.op)
return plt.Apply(
op,
self.visit(node.operand),
)

def visit_Compare(self, node: TypedCompare) -&gt; plt.AST:
assert len(node.ops) == 1, &#34;Only single comparisons are supported&#34;
Expand Down Expand Up @@ -2213,6 +2261,57 @@ <h3>Methods</h3>
empty_list_con,
)

def visit_DictComp(self, node: TypedDictComp) -&gt; plt.AST:
assert len(node.generators) == 1, &#34;Currently only one generator supported&#34;
gen = node.generators[0]
assert isinstance(gen.iter.typ, InstanceType), &#34;Only lists are valid generators&#34;
assert isinstance(gen.iter.typ.typ, ListType), &#34;Only lists are valid generators&#34;
assert isinstance(
gen.target, Name
), &#34;Can only assign value to singleton element&#34;
lst = self.visit(gen.iter)
ifs = None
for ifexpr in gen.ifs:
if ifs is None:
ifs = self.visit(ifexpr)
else:
ifs = plt.And(ifs, self.visit(ifexpr))
map_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
plt.MkPairData(
transform_output_map(node.key.typ)(
self.visit(node.key),
),
transform_output_map(node.value.typ)(
self.visit(node.value),
),
),
),
)
empty_list_con = plt.EmptyDataPairList()
if ifs is not None:
filter_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
ifs,
),
)
return plt.MapFilterList(
lst,
filter_fun,
map_fun,
empty_list_con,
)
else:
return plt.MapList(
lst,
map_fun,
empty_list_con,
)

def visit_FormattedValue(self, node: TypedFormattedValue) -&gt; plt.AST:
return plt.Apply(
node.value.typ.stringify(),
Expand Down Expand Up @@ -2549,6 +2648,67 @@ <h3>Methods</h3>
return l</code></pre>
</details>
</dd>
<dt id="opshin.compiler.PlutoCompiler.visit_DictComp"><code class="name flex">
<span>def <span class="ident">visit_DictComp</span></span>(<span>self, node: <a title="opshin.typed_ast.TypedDictComp" href="typed_ast.html#opshin.typed_ast.TypedDictComp">TypedDictComp</a>) ‑> pluthon.pluthon_ast.AST</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_DictComp(self, node: TypedDictComp) -&gt; plt.AST:
assert len(node.generators) == 1, &#34;Currently only one generator supported&#34;
gen = node.generators[0]
assert isinstance(gen.iter.typ, InstanceType), &#34;Only lists are valid generators&#34;
assert isinstance(gen.iter.typ.typ, ListType), &#34;Only lists are valid generators&#34;
assert isinstance(
gen.target, Name
), &#34;Can only assign value to singleton element&#34;
lst = self.visit(gen.iter)
ifs = None
for ifexpr in gen.ifs:
if ifs is None:
ifs = self.visit(ifexpr)
else:
ifs = plt.And(ifs, self.visit(ifexpr))
map_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
plt.MkPairData(
transform_output_map(node.key.typ)(
self.visit(node.key),
),
transform_output_map(node.value.typ)(
self.visit(node.value),
),
),
),
)
empty_list_con = plt.EmptyDataPairList()
if ifs is not None:
filter_fun = OLambda(
[&#34;x&#34;],
plt.Let(
[(gen.target.id, plt.Delay(OVar(&#34;x&#34;)))],
ifs,
),
)
return plt.MapFilterList(
lst,
filter_fun,
map_fun,
empty_list_con,
)
else:
return plt.MapList(
lst,
map_fun,
empty_list_con,
)</code></pre>
</details>
</dd>
<dt id="opshin.compiler.PlutoCompiler.visit_Expr"><code class="name flex">
<span>def <span class="ident">visit_Expr</span></span>(<span>self, node: <a title="opshin.typed_ast.TypedExpr" href="typed_ast.html#opshin.typed_ast.TypedExpr">TypedExpr</a>) ‑> Callable[[pluthon.pluthon_ast.AST], pluthon.pluthon_ast.AST]</span>
</code></dt>
Expand Down Expand Up @@ -3312,13 +3472,11 @@ <h3>Methods</h3>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_UnaryOp(self, node: TypedUnaryOp) -&gt; plt.AST:
opmap = UnaryOpMap.get(type(node.op))
assert opmap is not None, f&#34;Operator {type(node.op)} is not supported&#34;
op = opmap.get(node.operand.typ)
assert (
op is not None
), f&#34;Operator {type(node.op)} is not supported for type {node.operand.typ}&#34;
return op(self.visit(node.operand))</code></pre>
op = node.operand.typ.unop(node.op)
return plt.Apply(
op,
self.visit(node.operand),
)</code></pre>
</details>
</dd>
<dt id="opshin.compiler.PlutoCompiler.visit_While"><code class="name flex">
Expand Down Expand Up @@ -3491,6 +3649,7 @@ <h4><code><a title="opshin.compiler.PlutoCompiler" href="#opshin.compiler.PlutoC
<li><code><a title="opshin.compiler.PlutoCompiler.visit_Compare" href="#opshin.compiler.PlutoCompiler.visit_Compare">visit_Compare</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_Constant" href="#opshin.compiler.PlutoCompiler.visit_Constant">visit_Constant</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_Dict" href="#opshin.compiler.PlutoCompiler.visit_Dict">visit_Dict</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_DictComp" href="#opshin.compiler.PlutoCompiler.visit_DictComp">visit_DictComp</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_Expr" href="#opshin.compiler.PlutoCompiler.visit_Expr">visit_Expr</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_For" href="#opshin.compiler.PlutoCompiler.visit_For">visit_For</a></code></li>
<li><code><a title="opshin.compiler.PlutoCompiler.visit_FormattedValue" href="#opshin.compiler.PlutoCompiler.visit_FormattedValue">visit_FormattedValue</a></code></li>
Expand Down
Loading

0 comments on commit 9e328e8

Please sign in to comment.