Skip to content

Commit

Permalink
chore: rename parent to child
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmgr committed Nov 14, 2024
1 parent b525148 commit ed72769
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 257 deletions.
44 changes: 22 additions & 22 deletions nada_dsl/ast_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ASTOperation(ABC):
source_ref: SourceRef
ty: NadaTypeRepr

def inner_operations(self) -> List[int]:
"""Returns the list of identifiers of all the parent operations of this operation."""
def child_operations(self) -> List[int]:
"""Returns the list of identifiers of all the child operations of this operation."""
return []

def to_mir(self):
Expand All @@ -68,7 +68,7 @@ class BinaryASTOperation(ASTOperation):
left: int
right: int

def inner_operations(self) -> List[int]:
def child_operations(self) -> List[int]:
return [self.left, self.right]

def to_mir(self):
Expand All @@ -88,17 +88,17 @@ class UnaryASTOperation(ASTOperation):
"""Superclass of all the unary operations in AST representation"""

name: str
parent: int
this: int

def inner_operations(self):
return [self.parent]
def child_operations(self):
return [self.this]

def to_mir(self):

return {
self.name: {
"id": self.id,
"this": self.parent,
"this": self.this,
"type": self.ty,
"source_ref_index": self.source_ref.to_index(),
}
Expand All @@ -113,7 +113,7 @@ class IfElseASTOperation(ASTOperation):
arg_0: int
arg_1: int

def inner_operations(self):
def child_operations(self):
return [self.this, self.arg_0, self.arg_1]

def to_mir(self):
Expand All @@ -133,7 +133,7 @@ def to_mir(self):
class RandomASTOperation(ASTOperation):
"""AST Representation of a Random operation."""

def inner_operations(self):
def child_operations(self):
return []

def to_mir(self):
Expand Down Expand Up @@ -215,19 +215,19 @@ def to_mir(self):
class ReduceASTOperation(ASTOperation):
"""AST Representation of a Reduce operation."""

parent: int
child: int
fn: int
initial: int

def inner_operations(self):
return [self.parent, self.initial]
def child_operations(self):
return [self.child, self.initial]

def to_mir(self):
return {
"Reduce": {
"id": self.id,
"fn": self.fn,
"parent": self.parent,
"child": self.child,
"initial": self.initial,
"type": self.ty,
"source_ref_index": self.source_ref.to_index(),
Expand All @@ -239,18 +239,18 @@ def to_mir(self):
class MapASTOperation(ASTOperation):
"""AST representation of a Map operation."""

parent: int
child: int
fn: int

def inner_operations(self):
return [self.parent]
def child_operations(self):
return [self.child]

def to_mir(self):
return {
"Map": {
"id": self.id,
"fn": self.fn,
"parent": self.parent,
"child": self.child,
"type": self.ty,
"source_ref_index": self.source_ref.to_index(),
}
Expand All @@ -264,7 +264,7 @@ class NewASTOperation(ASTOperation):
name: str
elements: List[int]

def inner_operations(self):
def child_operations(self):
return self.elements

def to_mir(self):
Expand All @@ -285,7 +285,7 @@ class NadaFunctionCallASTOperation(ASTOperation):
args: List[int]
fn: int

def inner_operations(self):
def child_operations(self):
return self.args

def to_mir(self):
Expand Down Expand Up @@ -326,7 +326,7 @@ class NadaFunctionASTOperation(ASTOperation):

name: str
args: List[int]
parent: int
child: int

# pylint: disable=arguments-differ
def to_mir(self, operations):
Expand All @@ -346,7 +346,7 @@ def to_mir(self, operations):
for arg in arg_operations
],
"function": self.name,
"return_operation_id": self.parent,
"return_operation_id": self.child,
"operations": operations,
"return_type": self.ty,
"source_ref_index": self.source_ref.to_index(),
Expand All @@ -363,7 +363,7 @@ class CastASTOperation(ASTOperation):

target: int

def inner_operations(self):
def child_operations(self):
return [self.target]

def to_mir(self):
Expand Down
6 changes: 3 additions & 3 deletions nada_dsl/compiler_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def nada_dsl_to_nada_mir(outputs: List[Output]) -> Dict[str, Any]:
timer.start(
f"nada_dsl.compiler_frontend.nada_dsl_to_nada_mir.{output.name}.process_operation"
)
out_operation_id = output.parent.parent.id
out_operation_id = output.child.child.id
extra_fns = traverse_and_process_operations(
out_operation_id, operations, FUNCTIONS
)
Expand Down Expand Up @@ -184,7 +184,7 @@ def to_mir_function_list(functions: Dict[int, NadaFunctionASTOperation]) -> List
function_operations = {}

extra_functions = traverse_and_process_operations(
function.parent,
function.child,
function_operations,
functions,
)
Expand Down Expand Up @@ -255,7 +255,7 @@ def traverse_and_process_operations(
extra_functions[wrapped_operation.extra_function.id] = (
wrapped_operation.extra_function
)
stack.extend(operation.inner_operations())
stack.extend(operation.child_operations())
return extra_functions


Expand Down
16 changes: 8 additions & 8 deletions nada_dsl/nada_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class NadaType:
This is the parent class of all nada types.
In Nada, all the types wrap Operations. For instance, an addition between two integers
is represented like this SecretInteger(parent=Addition(...)).
is represented like this SecretInteger(child=Addition(...)).
In MIR, the representation is based around operations. A MIR operation points to other
operations and has a return type.
Expand All @@ -130,23 +130,23 @@ class NadaType:
MIR-friendly format, as subclasses of ASTOperation.
Whenever the Python interpreter constructs an instance of NadaType, it will also store
in memory the corresponding parent operation. In order to do so, the ASTOperation will
in memory the corresponding child operation. In order to do so, the ASTOperation will
need the type in MIR format. Which is why all instances of `NadaType` provide an implementation
of `to_mir()`.
"""

parent: OperationType
child: OperationType

def __init__(self, parent: OperationType):
def __init__(self, child: OperationType):
"""NadaType default constructor
Args:
parent (OperationType): The parent operation of this Data type
child (OperationType): The child operation of this Data type
"""
self.parent = parent
if self.parent is not None:
self.parent.store_in_ast(self.to_mir())
self.child = child
if self.child is not None:
self.child.store_in_ast(self.to_mir())

def to_mir(self):
"""Default implementation for the Conversion of a type into MIR representation."""
Expand Down
Loading

0 comments on commit ed72769

Please sign in to comment.