owl-basic 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- owl_basic/__init__.py +3 -0
- owl_basic/algorithms.py +29 -0
- owl_basic/ast_utils.py +204 -0
- owl_basic/basic_visitor.py +55 -0
- owl_basic/cfg_vertex.py +65 -0
- owl_basic/codegen/__init__.py +0 -0
- owl_basic/codegen/clr/__init__.py +0 -0
- owl_basic/codegen/clr/cil_visitor.py +1296 -0
- owl_basic/codegen/clr/cts.py +56 -0
- owl_basic/codegen/clr/emitters.py +94 -0
- owl_basic/codegen/clr/generate.py +539 -0
- owl_basic/correlation_visitor.py +119 -0
- owl_basic/data_visitor.py +62 -0
- owl_basic/decoder.py +339 -0
- owl_basic/errors.py +22 -0
- owl_basic/flow/__init__.py +17 -0
- owl_basic/flow/basic_block.py +34 -0
- owl_basic/flow/basic_block_identifier.py +66 -0
- owl_basic/flow/basic_block_orderer.py +29 -0
- owl_basic/flow/connectors.py +19 -0
- owl_basic/flow/convert_sub_visitor.py +28 -0
- owl_basic/flow/entry_point_locator.py +55 -0
- owl_basic/flow/entry_point_visitor.py +48 -0
- owl_basic/flow/flow_analysis.py +56 -0
- owl_basic/flow/flow_graph_creator.py +14 -0
- owl_basic/flow/flowgraph_visitor.py +178 -0
- owl_basic/flow/longjump_converter.py +20 -0
- owl_basic/flow/longjump_visitor.py +53 -0
- owl_basic/flow/subroutine_converter.py +38 -0
- owl_basic/flow/traversal.py +110 -0
- owl_basic/gml_visitor.py +151 -0
- owl_basic/line_mapper.py +43 -0
- owl_basic/line_number_visitor.py +65 -0
- owl_basic/main.py +381 -0
- owl_basic/node.py +21 -0
- owl_basic/options.py +22 -0
- owl_basic/owltyping/__init__.py +1 -0
- owl_basic/owltyping/function_type_inferer.py +50 -0
- owl_basic/owltyping/hindley_milner.py +524 -0
- owl_basic/owltyping/set_function_type_visitor.py +25 -0
- owl_basic/owltyping/type_system.py +220 -0
- owl_basic/owltyping/typecheck.py +60 -0
- owl_basic/owltyping/typecheck_visitor.py +471 -0
- owl_basic/parent_visitor.py +37 -0
- owl_basic/process.py +36 -0
- owl_basic/separation_visitor.py +98 -0
- owl_basic/sigil.py +30 -0
- owl_basic/simplify_visitor.py +204 -0
- owl_basic/singleton.py +127 -0
- owl_basic/source_debugging.py +124 -0
- owl_basic/symbol_table_visitor.py +220 -0
- owl_basic/symbol_tables.py +195 -0
- owl_basic/syntax/__init__.py +0 -0
- owl_basic/syntax/ast.py +1081 -0
- owl_basic/syntax/ast_meta.py +228 -0
- owl_basic/syntax/grammar.py +1972 -0
- owl_basic/syntax/lexer.py +943 -0
- owl_basic/syntax/parser.py +77 -0
- owl_basic/utility.py +26 -0
- owl_basic/visitor.py +43 -0
- owl_basic/xml_blocks.py +137 -0
- owl_basic/xml_visitor.py +101 -0
- owl_basic-0.6.0.dist-info/METADATA +37 -0
- owl_basic-0.6.0.dist-info/RECORD +69 -0
- owl_basic-0.6.0.dist-info/WHEEL +5 -0
- owl_basic-0.6.0.dist-info/entry_points.txt +2 -0
- owl_basic-0.6.0.dist-info/licenses/LICENSE +21 -0
- owl_basic-0.6.0.dist-info/licenses/THIRD-PARTY-NOTICES.md +57 -0
- owl_basic-0.6.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Created on 28 Mar 2010
|
|
3
|
+
|
|
4
|
+
@author: rjs
|
|
5
|
+
'''
|
|
6
|
+
|
|
7
|
+
from owl_basic.visitor import Visitable
|
|
8
|
+
|
|
9
|
+
class OwlTypeSingleton(type):
|
|
10
|
+
def __init__(cls, name, bases, dict):
|
|
11
|
+
super(OwlTypeSingleton, cls).__init__(name, bases, dict)
|
|
12
|
+
cls.instance = None
|
|
13
|
+
|
|
14
|
+
def __call__(cls, *args, **kw):
|
|
15
|
+
if cls.instance is None:
|
|
16
|
+
cls.instance = super(OwlTypeSingleton, cls).__call__(*args, **kw)
|
|
17
|
+
|
|
18
|
+
return cls.instance
|
|
19
|
+
|
|
20
|
+
class OwlType(Visitable, metaclass=OwlTypeSingleton):
|
|
21
|
+
"OwlType"
|
|
22
|
+
|
|
23
|
+
def isArray(self):
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
def arrayRank(self):
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
def makeArrayType(self, rank=1):
|
|
30
|
+
'''
|
|
31
|
+
Returns a OwlType object that represents an array
|
|
32
|
+
of the current type.
|
|
33
|
+
'''
|
|
34
|
+
return ArrayOwlType(self, rank)
|
|
35
|
+
|
|
36
|
+
def elementType(self):
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
def isA(self, other):
|
|
40
|
+
#assert not isinstance(other, type)
|
|
41
|
+
return isinstance(self, type(other))
|
|
42
|
+
|
|
43
|
+
def isConvertibleTo(self, other):
|
|
44
|
+
'''
|
|
45
|
+
Determines whether an instance of the current OwlType
|
|
46
|
+
can be converted to an instance of the specified OwlType.
|
|
47
|
+
'''
|
|
48
|
+
assert not isinstance(other, type)
|
|
49
|
+
return other.isAssignableFrom(self)
|
|
50
|
+
|
|
51
|
+
def isAssignableFrom(self, other):
|
|
52
|
+
'''
|
|
53
|
+
Determines whether an instance of the current OwlType
|
|
54
|
+
can be assigned from an instance of the specified OwlType.
|
|
55
|
+
'''
|
|
56
|
+
assert not isinstance(other, type)
|
|
57
|
+
return type(other) == type(self)
|
|
58
|
+
|
|
59
|
+
def bitsIntegerPrecision(self):
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
def isDefined(self):
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
def __str__(self):
|
|
66
|
+
return self.__doc__
|
|
67
|
+
|
|
68
|
+
def __repr__(self):
|
|
69
|
+
return self.__doc__
|
|
70
|
+
|
|
71
|
+
class PendingOwlType(OwlType, metaclass=OwlTypeSingleton):
|
|
72
|
+
"Pending"
|
|
73
|
+
|
|
74
|
+
def isAssignableFrom(self, other):
|
|
75
|
+
# TODO: Is this correct?
|
|
76
|
+
assert not isinstance(other, type)
|
|
77
|
+
return True
|
|
78
|
+
|
|
79
|
+
class VoidOwlType(OwlType, metaclass=OwlTypeSingleton):
|
|
80
|
+
"Void"
|
|
81
|
+
|
|
82
|
+
def isDefined(self):
|
|
83
|
+
return True
|
|
84
|
+
|
|
85
|
+
class ScalarOwlType(OwlType, metaclass=OwlTypeSingleton):
|
|
86
|
+
"Scalar"
|
|
87
|
+
|
|
88
|
+
class ObjectOwlType(ScalarOwlType, metaclass=OwlTypeSingleton):
|
|
89
|
+
"Object"
|
|
90
|
+
# OWL BASIC only - object reference
|
|
91
|
+
|
|
92
|
+
def isConvertibleTo(self, other):
|
|
93
|
+
assert not isinstance(other, type)
|
|
94
|
+
return True
|
|
95
|
+
|
|
96
|
+
def isAssignableFrom(self, other):
|
|
97
|
+
assert not isinstance(other, type)
|
|
98
|
+
return True
|
|
99
|
+
|
|
100
|
+
def isDefined(self):
|
|
101
|
+
return True
|
|
102
|
+
|
|
103
|
+
class NumericOwlType(ScalarOwlType, metaclass=OwlTypeSingleton):
|
|
104
|
+
"Numeric"
|
|
105
|
+
|
|
106
|
+
def isConvertibleTo(self, other):
|
|
107
|
+
assert not isinstance(other, type)
|
|
108
|
+
return other.isAssignableFrom(self)
|
|
109
|
+
|
|
110
|
+
def isAssignableFrom(self, other):
|
|
111
|
+
assert not isinstance(other, type)
|
|
112
|
+
return isinstance(other, NumericOwlType)
|
|
113
|
+
|
|
114
|
+
class IntegerOwlType(NumericOwlType, metaclass=OwlTypeSingleton):
|
|
115
|
+
"Integer"
|
|
116
|
+
|
|
117
|
+
def bitsIntegerPrecision(self):
|
|
118
|
+
return 32
|
|
119
|
+
|
|
120
|
+
def isDefined(self):
|
|
121
|
+
return True
|
|
122
|
+
|
|
123
|
+
class AddressOwlType(NumericOwlType, metaclass=OwlTypeSingleton):
|
|
124
|
+
"Address"
|
|
125
|
+
|
|
126
|
+
def bitsIntegerPrecision(self):
|
|
127
|
+
return 32 # What about this 32/64?
|
|
128
|
+
|
|
129
|
+
def isDefined(self):
|
|
130
|
+
return True
|
|
131
|
+
|
|
132
|
+
class ChannelOwlType(IntegerOwlType):
|
|
133
|
+
"Channel"
|
|
134
|
+
|
|
135
|
+
class FloatOwlType(NumericOwlType, metaclass=OwlTypeSingleton):
|
|
136
|
+
"Float"
|
|
137
|
+
def bitsIntegerPrecision(self):
|
|
138
|
+
"Representing a double precision float with 52 (+ 1 implied) bits in the mantissa."
|
|
139
|
+
return 53
|
|
140
|
+
|
|
141
|
+
def isDefined(self):
|
|
142
|
+
return True
|
|
143
|
+
|
|
144
|
+
class StringOwlType(ObjectOwlType, metaclass=OwlTypeSingleton):
|
|
145
|
+
"String"
|
|
146
|
+
# TODO: Assigning StringOwlType to ObjectOwlType should be possible
|
|
147
|
+
|
|
148
|
+
class ByteOwlType(NumericOwlType, metaclass=OwlTypeSingleton):
|
|
149
|
+
"Byte"
|
|
150
|
+
|
|
151
|
+
def bitsIntegerPrecision(self):
|
|
152
|
+
return 8
|
|
153
|
+
|
|
154
|
+
def isDefined(self):
|
|
155
|
+
return True
|
|
156
|
+
|
|
157
|
+
class ArrayOwlType(ObjectOwlType):
|
|
158
|
+
|
|
159
|
+
def __init__(self, element_type=None, rank=None):
|
|
160
|
+
self.element_type = element_type # None = Unknown or unspecified
|
|
161
|
+
self.rank = rank # None = Unknown or unspecified
|
|
162
|
+
|
|
163
|
+
def isArray(self):
|
|
164
|
+
return True
|
|
165
|
+
|
|
166
|
+
def elementType(self):
|
|
167
|
+
return self.element_type
|
|
168
|
+
|
|
169
|
+
def arrayRank(self):
|
|
170
|
+
return self.rank
|
|
171
|
+
|
|
172
|
+
def __eq__(self, rhs):
|
|
173
|
+
if (hasattr(rhs, "elementType") and hasattr(rhs, "arrayRank")):
|
|
174
|
+
return ((self.elementType() == rhs.elementType())
|
|
175
|
+
and (self.arrayRank() == rhs.arrayRank()))
|
|
176
|
+
else:
|
|
177
|
+
return False
|
|
178
|
+
|
|
179
|
+
def __ne__(self, rhs):
|
|
180
|
+
return not (self == rhs)
|
|
181
|
+
|
|
182
|
+
def isDefined(self):
|
|
183
|
+
return self.element_type is not None and self.rank is not None
|
|
184
|
+
|
|
185
|
+
def __repr__(self):
|
|
186
|
+
rank_desc = ""
|
|
187
|
+
if rank is not None:
|
|
188
|
+
rank_desc = ";" + str(self.arrayRank())
|
|
189
|
+
return "Array[" + str(self.elementType()) + rank_desc + "]"
|
|
190
|
+
|
|
191
|
+
class ByteArrayOwlType(ArrayOwlType):
|
|
192
|
+
"Array[Byte]"
|
|
193
|
+
|
|
194
|
+
def __init__(self, rank=None):
|
|
195
|
+
super(ByteArrayOwlType, self).__init__(ByteOwlType(), rank)
|
|
196
|
+
|
|
197
|
+
class IntegerArrayOwlType(ArrayOwlType):
|
|
198
|
+
"Array[Integer]"
|
|
199
|
+
|
|
200
|
+
def __init__(self, rank=None):
|
|
201
|
+
super(IntegerArrayOwlType, self).__init__(IntegerOwlType(), rank)
|
|
202
|
+
|
|
203
|
+
class FloatArrayOwlType(ArrayOwlType):
|
|
204
|
+
"Array[Integer]"
|
|
205
|
+
|
|
206
|
+
def __init__(self, rank=None):
|
|
207
|
+
super(FloatArrayOwlType, self).__init__(FloatOwlType(), rank)
|
|
208
|
+
|
|
209
|
+
class StringArrayOwlType(ArrayOwlType):
|
|
210
|
+
"Array[String]"
|
|
211
|
+
|
|
212
|
+
def __init__(self, rank=None):
|
|
213
|
+
super(StringArrayOwlType, self).__init__(StringOwlType(), rank)
|
|
214
|
+
|
|
215
|
+
class ObjectArrayOwlType(ArrayOwlType):
|
|
216
|
+
"Array[Object]"
|
|
217
|
+
|
|
218
|
+
def __init__(self, rank=None):
|
|
219
|
+
super(ObjectArrayOwlType, self).__init__(ObjectOwlType(), rank)
|
|
220
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Created on 5 Jan 2010
|
|
3
|
+
|
|
4
|
+
@author: rjs
|
|
5
|
+
'''
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
from owl_basic.syntax.ast import DefineFunction
|
|
10
|
+
|
|
11
|
+
from .typecheck_visitor import TypecheckVisitor
|
|
12
|
+
from .function_type_inferer import inferTypeOfFunction
|
|
13
|
+
from .set_function_type_visitor import SetFunctionTypeVisitor
|
|
14
|
+
from owl_basic.owltyping.type_system import PendingOwlType
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def typecheck(parse_tree, entry_points, options):
|
|
18
|
+
'''
|
|
19
|
+
:param parse_tree: The parse_tree to be type checked
|
|
20
|
+
:param entry_points: A dictionary of entry point names to AstStatements
|
|
21
|
+
:param options: Command line options.
|
|
22
|
+
'''
|
|
23
|
+
logging.debug("Type checking... ")
|
|
24
|
+
|
|
25
|
+
# TODO: Need to iteratively resolve types here.
|
|
26
|
+
# while (pending_types_remaining):
|
|
27
|
+
parse_tree.accept(TypecheckVisitor(entry_points))
|
|
28
|
+
pending = True
|
|
29
|
+
while pending:
|
|
30
|
+
pending = inferUserFunctionTypes(parse_tree, entry_points, options)
|
|
31
|
+
|
|
32
|
+
def inferUserFunctionTypes(parse_tree, entry_points, options):
|
|
33
|
+
"""
|
|
34
|
+
Iteratively examine the return types of user defined function calls
|
|
35
|
+
and assign the actual type.
|
|
36
|
+
:returns: True if any function types are still pending, otherwise False.
|
|
37
|
+
"""
|
|
38
|
+
logging.debug("Infer user function types")
|
|
39
|
+
pending = False
|
|
40
|
+
for entry_point in entry_points.values():
|
|
41
|
+
if isinstance(entry_point, DefineFunction):
|
|
42
|
+
function_type = inferTypeOfFunction(entry_point)
|
|
43
|
+
if function_type != PendingOwlType():
|
|
44
|
+
setFunctionType(parse_tree, entry_point.name, function_type)
|
|
45
|
+
else:
|
|
46
|
+
pending = True
|
|
47
|
+
return pending
|
|
48
|
+
|
|
49
|
+
def setFunctionType(parse_tree, function_name, function_type):
|
|
50
|
+
'''
|
|
51
|
+
Given a function name such as 'FNx' set the actual type of all
|
|
52
|
+
calls to that function.
|
|
53
|
+
:param function_name: The name of a function including the FN prefix
|
|
54
|
+
:param type: The type to which the actualType of call should be set
|
|
55
|
+
'''
|
|
56
|
+
assert function_name.startswith('FN')
|
|
57
|
+
# TODO: Visit each function call and the the type of those that match
|
|
58
|
+
print("Setting type of %s to %s" % (function_name, function_type))
|
|
59
|
+
sftv = SetFunctionTypeVisitor(function_name, function_type)
|
|
60
|
+
parse_tree.accept(sftv)
|