-
Notifications
You must be signed in to change notification settings - Fork 0
/
gonetype.py
57 lines (45 loc) · 1.34 KB
/
gonetype.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class GoneType(object):
'''
Class that represents a type in the Gone language. Types
are declared as singleton instances of this type.
'''
def __init__(self, name):
self.name = name
self.bin_ops = set()
self.un_ops = set()
self.default = 0
class IntType(GoneType):
def __init__(self):
self.name = "int"
self.bin_ops = {"+", "-", "*", "/", "<", ">", "<=", ">=", "==", "!="}
self.un_ops = {"+", "-"}
self.default = 0
class FloatType(GoneType):
def __init__(self):
self.name = "float"
self.bin_ops = {"+", "-", "*", "/", "<", ">", "<=", ">=", "==", "!="}
self.un_ops = {"+", "-"}
self.default = 0.0
class StringType(GoneType):
def __init__(self):
self.name = "string"
self.bin_ops = {"+", "==", "!="}
self.un_ops = {}
self.default = ""
class BoolType(GoneType):
def __init__(self):
self.name = "bool"
self.bin_ops = {"!=", "==", "||", "&&"}
self.un_ops = {"!"}
self.default = "false"
class ErrorType(GoneType):
def __init__(self):
self.name = "<error>"
self.bin_ops = {}
self.un_ops = {}
self.default = None
int_type = IntType()
float_type = FloatType()
string_type = StringType()
bool_type = BoolType()
error_type = ErrorType()