nac3-spec/toy-impl/type_def.py

75 lines
1.3 KiB
Python

class Type:
pass
class BotType:
pass
class PrimitiveType(Type):
name: str
def __init__(self, name: str):
self.name = name
def __str__(self):
return self.name
class TypeVariable(Type):
name: str
constraints: list[Type]
def __init__(self, name: str, constraints: list[Type]):
self.name = name
self.constraints = constraints
def __str__(self):
return self.name
class ClassType(Type):
name: str
parents: list['ClassType']
methods: dict[str, tuple[list[Type], Type, set[str]]]
fields: dict[str, Type]
def __init__(self, name: str):
self.name = name
self.parents = []
self.methods = {}
self.fields = {}
def __str__(self):
return self.name
class VirtualClassType(Type):
base: ClassType
def __init__(self, base: ClassType):
self.base = base
def __str__(self):
return f"virtual[{self.base}]"
class ListType(Type):
elements: Type
def __init__(self, elements: Type):
self.elements = elements
def __str__(self):
return f"list[{self.elements}]"
class TupleType(Type):
elements: list[Type]
def __init__(self, elements: Type):
self.elements = elements
def __str__(self):
return f"tuple[{', '.join([str(v) for v in self.elements])}]"