Skip to content

Commit

Permalink
Minor Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-pino committed Feb 26, 2021
1 parent d1c603f commit 31322b6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/devdeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def run_pipeline(program):
print("Error Importing Files")
count = 4

filenames = [r'/home/rodro/Aarka/Complementos de Compilacion/cool-compiler-2022/src/zTests/Misc/06FooBarRaz.cl']
filenames = [r'/home/rodro/Aarka/Complementos de Compilacion/cool-compiler-2022/src/zTests/Misc/07MultipleClass.cl']
filenames = [r'/home/rodro/Aarka/Complementos de Compilacion/cool-compiler-2022/src/zTests/Misc/10BiG.cl']

for filename in filenames:
if count == 0:
Expand Down
5 changes: 2 additions & 3 deletions src/semantics/autotype_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class AutotypeCollector:
def __init__(self, context:Context):
self.context = context
self.current_type = None
self.inference_graph = dict()
self.errors = []

@visitor.on('node')
Expand Down Expand Up @@ -87,10 +86,10 @@ def visit(self, node, scope):

@visitor.when(CaseNode)
def visit(self, node, scope:Scope):
self.visit(node.expr, scope)
self.visit(node.case_expr, scope)

type_list = []
for var in node.casevars:
for var in node.options:
child = scope.create_child()
self.visit(var, child)
type_list.append(var.inferenced_type)
Expand Down
2 changes: 1 addition & 1 deletion src/semantics/type_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def dfs_type_graph(self, root, graph, visited:set, new_order, index):
visited.add(node)
if node not in {"Int", "String", "IO", "Bool", "Object"}:
new_order.append(self.node_dict[node])
self.context.get_type(node).index = index
self.context.get_type(node, unpacked=True).index = index
self.dfs_type_graph(node, graph, visited, new_order, index + 1)

def check_circular_heritage(self, root, graph, path, visited):
Expand Down
49 changes: 0 additions & 49 deletions src/semantics/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
def conform_to_condition(type_set, parent) -> set:
set_result = set()
for typex in type_set:
Expand All @@ -10,62 +9,14 @@ def order_set_by_index(type_set):
return sorted(list(type_set), key = lambda x: x.index)

def set_intersection(parent, type_set) -> set:
=======
from semantics.tools import Type, ErrorType, AutoType

def conforms(type1:Type, type2:Type):
if isinstance(type1, ErrorType) or isinstance(type2, ErrorType):
return ErrorType()
if not isinstance(type1, AutoType) and isinstance(type2, AutoType):
type2.set_upper_limmit([type1])
return type1
if not isinstance(type1, AutoType):
type1 = AutoType("TEMP01", [type1], {type1})
if not isinstance(type2, AutoType):
type2 = AutoType("TEMP02", [type2], {type2})

print("type 1 set:", ", ".join(typex.name for typex in type1.type_set))
print("type 2 set:", ", ".join(typex.name for typex in type2.type_set))

condition_set_list, conform_set_list = conforming(type1, type2)
type1.set_new_conditions(condition_set_list, conform_set_list)

print("Conditions obtained", [[typex.name for typex in type_set] for type_set in condition_set_list])
print("Conforms obtained", [[typex.name for typex in type_set] for type_set in conform_set_list])
print("Updated set:", ", ".join(typex.name for typex in type1.type_set),"\n")
return type1

def conforming(auto1:AutoType, auto2:AutoType):
ord_types2 = sorted(list(auto2.type_set), lambda x: x.index)

condition_set_list = []
conform_set_list = []
for type2 in ord_types2:
conforms = conform_intersection(auto1.type_set, type2)
for i in range(len(condition_set_list)):
prev_conform = conform_set_list[i]
if len(prev_conform) == len(conforms) and len(conforms.intersection(prev_conform)) == len(conforms):
condition_set_list[i].add(type2)
break
else:
condition_set_list.append(set([type2]))
conform_set_list.append(conforms)
return condition_set_list, conform_set_list

def conform_intersection(type_set, parent) -> set:
>>>>>>> Added Type Builder and Type Collector
set_result = set()
for typex in type_set:
if typex.conforms_to(parent):
set_result.add(typex)
<<<<<<< HEAD
return set_result

def from_dict_to_set(types:dict):
type_set = set()
for typex in types:
type_set.add(types[typex])
return type_set
=======
return set_result
>>>>>>> Added Type Builder and Type Collector

0 comments on commit 31322b6

Please sign in to comment.