Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

First Results #50

Open
wants to merge 52 commits into
base: entrega-final
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f7a974d
Grammar and AST
BlackBeard98 Feb 25, 2020
f28508d
lexer working
juandamdc Feb 25, 2020
d539365
lexer ok
juandamdc Feb 25, 2020
a6ad7f2
Merge branch 'BlackBeard98' into lexer
juandamdc Feb 25, 2020
84100a4
tokens file added
juandamdc Feb 25, 2020
40f24be
parser almost working
juandamdc Feb 25, 2020
3a36e2a
fixed problem with token NOT, all test ok
juandamdc Feb 26, 2020
f796978
add github information
juandamdc Feb 26, 2020
8481efe
Merge branch 'lexer' into entrega-parser
juandamdc Feb 26, 2020
471be1c
update requirements.txt
juandamdc Feb 26, 2020
114dfaf
before split context
BlackBeard98 Oct 26, 2020
fae617e
to test
BlackBeard98 Oct 29, 2020
8f58bab
adapting errors to real ones
BlackBeard98 Oct 30, 2020
eb31572
almost semantics
BlackBeard98 Oct 30, 2020
cd62744
Merge branch 'karl' into BlackBeard98
BlackBeard98 Oct 30, 2020
a77e7ba
final run code gen
BlackBeard98 Nov 22, 2020
4ec6f43
cool2cil v1
juandamdc Nov 23, 2020
f2766c2
add visitor for AttrDeclarationNode, LetInNode, ComplementNode, NotNo…
juandamdc Nov 24, 2020
473f5ab
begging cil to mips
juandamdc Nov 25, 2020
53e73a2
all defaults methods done
juandamdc Nov 27, 2020
3539d57
goto, minus and comparer from cil to mips
juandamdc Nov 27, 2020
6b1295d
changing layout
juandamdc Nov 27, 2020
2be6193
falta un caso
juandamdc Nov 29, 2020
c890dfd
Merge branch 'code_gen' into BlackBeard98
BlackBeard98 Nov 29, 2020
a39814a
fix ~ bug all test cases of cod gen passed ps:FUCK hairy Scary
BlackBeard98 Nov 29, 2020
19fc3f9
ready to make test
BlackBeard98 Nov 29, 2020
60ac2c0
Merge remote-tracking branch 'entrega-final/entrega-final' into Black…
BlackBeard98 Nov 29, 2020
8c4781c
case semantics fixed
BlackBeard98 Nov 29, 2020
539fd91
update req
BlackBeard98 Nov 29, 2020
dc27401
/r
BlackBeard98 Nov 29, 2020
bae9ff1
bash
BlackBeard98 Nov 30, 2020
07b0a29
fix format
BlackBeard98 Nov 30, 2020
88094f0
again
BlackBeard98 Nov 30, 2020
6bb5ebb
fix case top_sort
BlackBeard98 Nov 30, 2020
6008f2e
new in basic types
BlackBeard98 Nov 30, 2020
fd677e6
salto de linea
BlackBeard98 Nov 30, 2020
2a3b1a8
col pos
BlackBeard98 Nov 30, 2020
eef8c73
fix semantics
BlackBeard98 Nov 30, 2020
8a121dc
change ~
BlackBeard98 Nov 30, 2020
313b815
graph done
BlackBeard98 Nov 30, 2020
af5ba09
abort in their way
BlackBeard98 Nov 30, 2020
4de36f6
req back
BlackBeard98 Nov 30, 2020
2a4fe60
doc added
juandamdc Dec 1, 2020
28ec436
change in_string
BlackBeard98 Dec 1, 2020
e2f3393
Merge branch 'BlackBeard98' of https://github.com/juandamdc/cool-comp…
BlackBeard98 Dec 1, 2020
532d605
Revert "change in_string"
BlackBeard98 Dec 1, 2020
cdf58ca
change in_string 2.0
BlackBeard98 Dec 2, 2020
ea59c6e
typo
BlackBeard98 Dec 2, 2020
f2ddf13
typo2
BlackBeard98 Dec 2, 2020
86ef663
typo3
BlackBeard98 Dec 2, 2020
e724268
last time typo
BlackBeard98 Dec 2, 2020
5a7d449
update Reporte.pdf
juandamdc Dec 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

**Nombre** | **Grupo** | **Github**
--|--|--
Nombre1 Apellido1 Apellido2 | C4xx | [@github_user](https://github.com/<user>)
Nombre2 Apellido1 Apellido2 | C4xx | [@github_user](https://github.com/<user>)
Nombre3 Apellido1 Apellido2 | C4xx | [@github_user](https://github.com/<user>)
Juan David Menendez del Cueto | C412 | [@juandamdc](https://github.com/juandamdc)
Karl Lewis Sosa Justiz | C412 | [@BlackBeard98](https://github.com/BlackBeard98)

## Readme

Expand Down
Binary file added doc/Reporte.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
pytest-ordering
ply
169 changes: 169 additions & 0 deletions src/AstNodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# AST Classes
class Node:
pass

class ProgramNode(Node):
def __init__(self, declarations):
self.declarations = declarations
self.line = declarations[0].line
self.column = declarations[0].column

class DeclarationNode(Node):
pass

class ClassDeclarationNode(DeclarationNode):
def __init__(self, idx, features, parent=None):
self.id = idx
self.parent = parent
self.features = features
self.line = 0
self.column = 0

class AttrDeclarationNode(DeclarationNode):
def __init__(self, idx, typex, expression=None):
self.id = idx
self.type = typex
self.expression = expression
self.line = 0
self.column = 0

class FuncDeclarationNode(DeclarationNode):
def __init__(self, idx, params, return_type, body):
self.id = idx
self.params = params
self.type = return_type
self.body = body
self.line = 0
self.column = 0

class ExpressionNode(Node):
pass

class IfThenElseNode(ExpressionNode):
def __init__(self, condition, if_body, else_body):
self.condition = condition
self.if_body = if_body
self.else_body = else_body
self.line = condition.line
self.column = condition.column

class WhileLoopNode(ExpressionNode):
def __init__(self, condition, body):
self.condition = condition
self.body = body
self.line = condition.line
self.column = condition.column


class BlockNode(ExpressionNode):
def __init__(self, expressions):
self.expressions = expressions
self.line = expressions[-1].line
self.column = expressions[-1].column

class LetInNode(ExpressionNode):
def __init__(self, let_body, in_body):
self.let_body = let_body
self.in_body = in_body
self.line = in_body.line
self.column = in_body.column

class CaseOfNode(ExpressionNode):
def __init__(self, expression, branches):
self.expression = expression
self.branches = branches
self.line = expression.line
self.column = expression.column

class AssignNode(ExpressionNode):
def __init__(self, idx, expression):
self.id = idx
self.expression = expression
self.line = 0
self.column = 0

class UnaryNode(ExpressionNode):
def __init__(self, expression):
self.expression = expression
self.line = expression.line
self.column = expression.column

class NotNode(UnaryNode):
pass

class BinaryNode(ExpressionNode):
def __init__(self, left, right):
self.left = left
self.right = right
self.line = left.line
self.column = left.column

class LessEqualNode(BinaryNode):
pass

class LessNode(BinaryNode):
pass

class EqualNode(BinaryNode):
pass

class ArithmeticNode(BinaryNode):
pass

class PlusNode(ArithmeticNode):
pass

class MinusNode(ArithmeticNode):
pass

class StarNode(ArithmeticNode):
pass

class DivNode(ArithmeticNode):
pass

class IsVoidNode(UnaryNode):
pass

class ComplementNode(UnaryNode):
pass

class FunctionCallNode(ExpressionNode):
def __init__(self, obj, line, idx, args, typex=None):
self.obj = obj
self.id = idx
self.args = args
self.typex = typex
self.line = line
self.column = 0

class MemberCallNode(ExpressionNode):
def __init__(self, idx, args):
self.id = idx
self.args = args
self.line = 0
self.column = 0

class NewNode(ExpressionNode):
def __init__(self, typex):
self.type = typex
self.line = 0
self.column = 0

class AtomicNode(ExpressionNode):
def __init__(self, token):
self.token = token
self.line = 0
self.column = 0

class IntegerNode(AtomicNode):
pass

class IdNode(AtomicNode):
pass

class StringNode(AtomicNode):
pass

class BoolNode(AtomicNode):
pass
156 changes: 156 additions & 0 deletions src/BaseToCILVisitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import cil
from semantic import VariableInfo, Scope
import queue

class BaseCOOLToCILVisitor:
def __init__(self, context):
self.dottypes = []
self.dotdata = [ cil.DataNode('_empty', '')]
self.dotcode = []
self.current_type = None
self.current_method = None
self.current_function = None
self.context = context
self.basic_types()

@property
def params(self):
return self.current_function.params

@property
def localvars(self):
return self.current_function.localvars

@property
def instructions(self):
return self.current_function.instructions

@property
def labels(self):
return self.current_function.labels

def basic_types(self):
for basicType in ['Int', 'String', 'Bool']:
cil_type = self.register_type(basicType)
cil_type.attributes.append(self.to_attribute_name('value', basicType))

for method , typeMethod in self.context.get_type(basicType).all_methods():
cil_type.methods.append((method.name, self.to_function_name(method.name, typeMethod.name)))

for basicType in ['Object', 'IO']:
cil_type = self.register_type(basicType)
for method , typeMethod in self.context.get_type(basicType).all_methods():
cil_type.methods.append((method.name, self.to_function_name(method.name, typeMethod.name)))


def register_param(self, vinfo):
vinfo.cilName = vinfo.name # f'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}'
param_node = cil.ParamNode(vinfo.cilName)
self.params.append(param_node)
return vinfo.cilName

def register_local(self, vinfo):
vinfo.cilName = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}'
local_node = cil.LocalNode(vinfo.cilName)
self.localvars.append(local_node)
return vinfo.cilName

def register_label(self):
name = f'label_{self.current_function.name[9:]}_{len(self.labels)}'
self.labels.append(name)
return name

def define_internal_local(self):
vinfo = VariableInfo('internal', None)
return self.register_local(vinfo)

def register_instruction(self, instruction):
self.instructions.append(instruction)
return instruction

def to_function_name(self, method_name, type_name):
return f'function_{method_name}_at_{type_name}'

def to_attribute_name(self, attr_name, attr_type):
return f'attribute_{attr_name}'

def register_function(self, function_name):
function_node = cil.FunctionNode(function_name, [], [], [], [])
self.dotcode.append(function_node)
return function_node

def register_type(self, name):
type_node = cil.TypeNode(name)
self.dottypes.append(type_node)
return type_node

def register_data(self, value):
for dataNode in self.dotdata:
if dataNode.value == value:
return dataNode

vname = f'data_{len(self.dotdata)}'
data_node = cil.DataNode(vname, value)
self.dotdata.append(data_node)
return data_node


def get_attr(self, function_name, attribute):
for dottype in self.dottypes:
if dottype.name == function_name:
break


# for attrib in dottype.attributes:
# if self.to_attribute_name(attribute, None) == attrib:
# break

return dottype.attributes.index(self.to_attribute_name(attribute,None))

def get_method(self, type_name, method_name):
for typeContext in self.context.types:
if typeContext == type_name:
break

methods = list(self.context.types[typeContext].all_methods())

for m in methods:
if m[0].name == method_name:
break

return methods.index(m)

def sort_types(self, types):
q = queue.deque()
lst = []
for tp1 in types:
if not any ([x for x in types if x!= tp1 and tp1.conforms_to(x) ]):
q.append(tp1)

while len(q) != 0:
tp = q.popleft()
if tp in types:
lst.append(tp)
for s in tp.sons:
q.append(s)
lst = list(reversed(lst))
return lst

def get_preordenTypes(self, typex):
ret_lis = []

for son in typex.sons:
ret_lis.extend(self.get_preordenTypes(son))

ret_lis.append(typex)
return ret_lis


def box(self, typeName, value):
obj_internal = self.define_internal_local()
self.register_instruction(cil.AllocateNode(typeName, obj_internal))
self.register_instruction(cil.SetAttribNode(obj_internal, 0, value))
self.register_instruction(cil.LoadNode(obj_internal, f'{typeName}_name'))
self.register_instruction(cil.LoadIntNode(obj_internal, f'{typeName}_size', 4))
self.register_instruction(cil.LoadNode(obj_internal, f'__virtual_table__{typeName}', 8))
return obj_internal
Loading