Skip to content

Commit

Permalink
type HeavyLang inlets and outlets (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer authored Dec 7, 2024
1 parent ec41869 commit b13ab0f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 27 deletions.
4 changes: 3 additions & 1 deletion hvcc/core/hv2ir/HIrInlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .HeavyIrObject import HeavyIrObject
from .HeavyGraph import HeavyGraph

from hvcc.types.Lang import LangLetType


class HIrInlet(HeavyIrObject):
""" A specific implementation of the inlet object.
Expand All @@ -34,7 +36,7 @@ def __init__(
) -> None:
super().__init__("__inlet", args=args, graph=graph, annotations=annotations)

def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[str]:
def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[LangLetType]:
if self.graph is not None:
connections = self.graph.inlet_connections[self.args["index"]]
connection_type_set = {c.type for c in connections}
Expand Down
4 changes: 3 additions & 1 deletion hvcc/core/hv2ir/HLangAdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .HeavyLangObject import HeavyLangObject
from .HeavyGraph import HeavyGraph

from hvcc.types.Lang import LangLetType


class HLangAdc(HeavyLangObject):
""" adc
Expand All @@ -38,7 +40,7 @@ def __init__(
num_outlets=len(args[self._HEAVY_LANG_DICT[obj_type].args[0].name]),
annotations=annotations)

def _resolved_outlet_type(self, outlet_index: int = 0) -> str:
def _resolved_outlet_type(self, outlet_index: int = 0) -> LangLetType:
return "~f>"

def reduce(self) -> tuple:
Expand Down
3 changes: 2 additions & 1 deletion hvcc/core/hv2ir/HeavyGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .HeavyLangObject import HeavyLangObject

from hvcc.types.compiler import CompilerNotif
from hvcc.types.Lang import LangLetType


class HeavyGraph(HeavyIrObject):
Expand Down Expand Up @@ -482,7 +483,7 @@ def _remove_unused_inlet_connections(self) -> None:
for o in [o for o in self.objs.values() if (o.type == "__graph")]:
o._remove_unused_inlet_connections()

def _resolved_outlet_type(self, outlet_index: int = 0) -> str:
def _resolved_outlet_type(self, outlet_index: int = 0) -> LangLetType:
# a graph's outlet type depends on the connections incident on the
# corresponding outlet object
connection_type_set = {c.type for c in self.outlet_objs[outlet_index].inlet_connections[0]}
Expand Down
6 changes: 4 additions & 2 deletions hvcc/core/hv2ir/HeavyIrObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

from typing import Dict, List, Optional, TYPE_CHECKING

from hvcc.core.hv2ir.types import HeavyIRType, IRNode
from .Connection import Connection
from .HeavyException import HeavyException
from .HeavyLangObject import HeavyLangObject
from .BufferPool import BufferPool

from hvcc.types.IR import HeavyIRType, IRNode
from hvcc.types.Lang import LangLetType

if TYPE_CHECKING:
from .HeavyGraph import HeavyGraph

Expand Down Expand Up @@ -184,7 +186,7 @@ def assign_signal_buffers(self, buffer_pool: Optional[BufferPool]) -> None:
if len(self.outlet_connections[i]) == 0:
exclude_set.add(b)

def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[str]:
def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[LangLetType]:
""" Returns the connection type at the given outlet.
This information is always well-defined for IR objects.
"""
Expand Down
8 changes: 4 additions & 4 deletions hvcc/core/hv2ir/HeavyLangObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from struct import unpack, pack
from typing import Optional, Union, List, Dict, Any, TYPE_CHECKING

from hvcc.core.hv2ir.types import HeavyLangType, LangNode, Inlet, Outlet
from .Connection import Connection
from .HeavyException import HeavyException

from hvcc.types.compiler import CompilerMsg, CompilerNotif
from hvcc.types.Lang import HeavyLangType, LangNode, LangLet, LangLetType

if TYPE_CHECKING:
from .HeavyGraph import HeavyGraph
Expand Down Expand Up @@ -115,10 +115,10 @@ def _obj_desc(self) -> LangNode:
"""
return self._HEAVY_LANG_DICT[self.type]

def inlet_connection_type(self, index: int) -> Inlet:
def inlet_connection_type(self, index: int) -> LangLet:
return self._obj_desc.inlets[index]

def outlet_connection_type(self, index: int) -> Outlet:
def outlet_connection_type(self, index: int) -> LangLet:
return self._obj_desc.outlets[index]

def name_for_arg(self, index: int = 0) -> str:
Expand Down Expand Up @@ -318,7 +318,7 @@ def is_root(self) -> bool:
"""
return all(len(c) == 0 for c in self.inlet_connections)

def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[str]:
def _resolved_outlet_type(self, outlet_index: int = 0) -> Optional[LangLetType]:
""" Returns the connection type expected at the given outlet.
The result may be influenced by the state of the input connections.
"""
Expand Down
2 changes: 0 additions & 2 deletions hvcc/core/hv2ir/types/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion hvcc/generators/ir2c/ir2c_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections import defaultdict
from typing import Dict

from hvcc.core.hv2ir.types import HeavyIRType
from hvcc.types.IR import HeavyIRType


class ir2c_perf:
Expand Down
4 changes: 3 additions & 1 deletion hvcc/interpreters/pd2hv/HeavyObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import importlib_resources
from typing import Optional, List, Dict, Any, Union, cast

from hvcc.core.hv2ir.types import HeavyIRType, HeavyLangType, IRNode, LangNode, IRArg, LangArg
from .Connection import Connection
from .NotificationEnum import NotificationEnum
from .PdObject import PdObject

from hvcc.types.IR import HeavyIRType, IRNode, IRArg
from hvcc.types.Lang import HeavyLangType, LangNode, LangArg


class HeavyObject(PdObject):

Expand Down
9 changes: 4 additions & 5 deletions hvcc/core/hv2ir/types/IR.py → hvcc/types/IR.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pydantic import BaseModel, RootModel
from typing import Dict, List, Optional, Union, Literal
from typing import Dict, List, Optional, Union


IRConnectionType = Literal["-->", "~i>", "~f>", "signal"]
from hvcc.types.Lang import LangLetType


class IRArg(BaseModel):
Expand All @@ -26,9 +25,9 @@ class Perf(BaseModel):


class IRNode(BaseModel):
inlets: List[IRConnectionType]
inlets: List[LangLetType]
ir: IR
outlets: List[IRConnectionType]
outlets: List[LangLetType]
args: List[IRArg] = []
perf: Optional[Perf] = Perf()
# perf: Perf
Expand Down
13 changes: 4 additions & 9 deletions hvcc/core/hv2ir/types/Lang.py → hvcc/types/Lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


LangConnectionType = Literal["-->", "-~>", "~f>"]
LangLetType = Literal["-->", "-~>", "~i>", "~f>", "signal"]


class LangArg(BaseModel):
Expand All @@ -13,22 +14,16 @@ class LangArg(BaseModel):
required: bool


class Inlet(BaseModel):
name: str
connectionType: LangConnectionType
description: str


class Outlet(BaseModel):
class LangLet(BaseModel):
name: str
connectionType: LangConnectionType
description: str


class LangNode(BaseModel):
description: str
inlets: List[Inlet]
outlets: List[Outlet]
inlets: List[LangLet]
outlets: List[LangLet]
args: List[LangArg]
alias: List[str]
tags: List[str]
Expand Down

0 comments on commit b13ab0f

Please sign in to comment.