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,195 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from owl_basic.singleton import Singleton
|
|
4
|
+
from owl_basic.owltyping.type_system import IntegerOwlType, AddressOwlType, StringOwlType
|
|
5
|
+
|
|
6
|
+
# Symbol table
|
|
7
|
+
|
|
8
|
+
def hasSymbolTable(node):
|
|
9
|
+
return hasattr(node, "symbolTable")
|
|
10
|
+
|
|
11
|
+
def hasSymbolTableLookup(node):
|
|
12
|
+
return hasSymbolTable(node) and hasattr(node.symbolTable, "lookup")
|
|
13
|
+
|
|
14
|
+
class AddSymbolException(Exception):
|
|
15
|
+
def __init__(self, value):
|
|
16
|
+
self.value = value
|
|
17
|
+
def __str__(self):
|
|
18
|
+
return repr(self.value)
|
|
19
|
+
|
|
20
|
+
class SymbolInfo(object):
|
|
21
|
+
"""
|
|
22
|
+
Stores information regarding a symbol
|
|
23
|
+
"""
|
|
24
|
+
(modifier_static, modifier_system, modifier_global, modifier_arg, modifier_ref_arg, modifier_local, modifier_private) = list(range(7))
|
|
25
|
+
|
|
26
|
+
def __init__(self, name, type, modifier=None, table=None, rank=None):
|
|
27
|
+
self.name = name
|
|
28
|
+
self.table = table
|
|
29
|
+
self.type = type
|
|
30
|
+
self.modifier = modifier
|
|
31
|
+
self.rank = rank
|
|
32
|
+
self.realization = None # Can be used by code generator to attach specific data
|
|
33
|
+
|
|
34
|
+
def __repr__(self):
|
|
35
|
+
return "SymbolInfo(name=%s, modifier=%s, table=%s, rank=%s, realization=%s)" % (repr(self.name), repr(self.modifier), repr(self.table),
|
|
36
|
+
repr(self.rank), repr(self.realization))
|
|
37
|
+
|
|
38
|
+
class SymbolTable(object):
|
|
39
|
+
|
|
40
|
+
protections = list(range(3))
|
|
41
|
+
(readonly, writethrough, writable) = protections
|
|
42
|
+
|
|
43
|
+
symbol_tables = set()
|
|
44
|
+
|
|
45
|
+
def __init__(self, name, protection=writable, parent=None):
|
|
46
|
+
self.__name = name
|
|
47
|
+
assert protection in SymbolTable.protections
|
|
48
|
+
self.__protection = protection
|
|
49
|
+
assert parent is None or isinstance(parent, SymbolTable)
|
|
50
|
+
self.__parent = parent
|
|
51
|
+
self._symbols = {} # TODO: Wrap this in a property
|
|
52
|
+
logging.debug("Creating symbol table %s", self.__name)
|
|
53
|
+
SymbolTable.symbol_tables.add(self)
|
|
54
|
+
|
|
55
|
+
def __getName(self):
|
|
56
|
+
return self.__name
|
|
57
|
+
|
|
58
|
+
name = property(__getName)
|
|
59
|
+
|
|
60
|
+
def __getSymbols(self):
|
|
61
|
+
return self._symbols
|
|
62
|
+
|
|
63
|
+
symbols = property(__getSymbols)
|
|
64
|
+
|
|
65
|
+
def __getParent(self):
|
|
66
|
+
return self.__parent
|
|
67
|
+
|
|
68
|
+
parent = property(__getParent)
|
|
69
|
+
|
|
70
|
+
def isWritable(self):
|
|
71
|
+
return self.__protection == SymbolTable.writable
|
|
72
|
+
|
|
73
|
+
def isWritethrough(self):
|
|
74
|
+
return self.__protection == SymbolTable.writethrough
|
|
75
|
+
|
|
76
|
+
def isReadonly(self):
|
|
77
|
+
return self.__protection == SymbolTable.readonly
|
|
78
|
+
|
|
79
|
+
def tryAdd(self, symbol_info):
|
|
80
|
+
"""
|
|
81
|
+
Add a SymbolInfo object to the table if its not already present.
|
|
82
|
+
Returns True if the symbol was added, otherwise False.
|
|
83
|
+
"""
|
|
84
|
+
if self.lookup(symbol_info.name) is None:
|
|
85
|
+
self.add(symbol_info)
|
|
86
|
+
return True
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
def add(self, symbol_info):
|
|
90
|
+
"""
|
|
91
|
+
Add a SymbolInfo object to the table
|
|
92
|
+
"""
|
|
93
|
+
if self.isWritable():
|
|
94
|
+
symbol_info.table = self
|
|
95
|
+
self._symbols[symbol_info.name] = symbol_info
|
|
96
|
+
elif self.isWritethrough():
|
|
97
|
+
if self.__parent is not None:
|
|
98
|
+
self.__parent.add(symbol_info)
|
|
99
|
+
else:
|
|
100
|
+
raise AddSymbolException("Cannot add symbol '%s' because write-through symbol table '%s' has no parent" % (symbol_info.name, self.name))
|
|
101
|
+
elif self.isReadonly():
|
|
102
|
+
raise AddSymbolException("Cannot add symbol '%s' to read-only symbol table '%s'" % (symbol_info.name, self.name))
|
|
103
|
+
|
|
104
|
+
def lookup(self, name):
|
|
105
|
+
"""
|
|
106
|
+
Returns a SymbolInfo object or None
|
|
107
|
+
"""
|
|
108
|
+
if name in self._symbols:
|
|
109
|
+
return self._symbols[name]
|
|
110
|
+
if self.__parent is not None:
|
|
111
|
+
return self.__parent.lookup(name)
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
class StaticSymbolTable(SymbolTable, Singleton):
|
|
115
|
+
"""
|
|
116
|
+
A symbol table used for representing the built-in static
|
|
117
|
+
integer variables A% to Z%
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
def __init__(self):
|
|
121
|
+
super(StaticSymbolTable, self).__init__("static symbol table", protection=SymbolTable.readonly, parent=None)
|
|
122
|
+
# Add IntegerTypes for A% to Z% into the symbol table
|
|
123
|
+
names = [chr(x) + '%' for x in range(65, 91)]
|
|
124
|
+
symbol_infos = [(name, SymbolInfo(name, IntegerOwlType(), SymbolInfo.modifier_static)) for name in names]
|
|
125
|
+
self._symbols.update(symbol_infos)
|
|
126
|
+
|
|
127
|
+
class SystemSymbolTable(SymbolTable, Singleton):
|
|
128
|
+
"""
|
|
129
|
+
A symbol table for build-in system variables.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
def __init__(self):
|
|
133
|
+
super(SystemSymbolTable, self).__init__("system symbol table", protection=SymbolTable.readonly, parent=StaticSymbolTable.getInstance())
|
|
134
|
+
# Add the built-in symbols
|
|
135
|
+
self._symbols['@%'] = SymbolInfo('@%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
136
|
+
self._symbols['@hwnd%'] = SymbolInfo('@hwnd%', AddressOwlType(), SymbolInfo.modifier_system)
|
|
137
|
+
self._symbols['@memhdc%'] = SymbolInfo('@memhdc%', AddressOwlType(), SymbolInfo.modifier_system)
|
|
138
|
+
self._symbols['@prthdc%'] = SymbolInfo('@prthdc%', AddressOwlType(), SymbolInfo.modifier_system)
|
|
139
|
+
self._symbols['@hcsr%'] = SymbolInfo('@hcsr%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
140
|
+
self._symbols['@hpal%'] = SymbolInfo('@hpal%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
141
|
+
self._symbols['@msg%'] = SymbolInfo('@msg%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
142
|
+
self._symbols['@wparam%'] = SymbolInfo('@wparam%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
143
|
+
self._symbols['@lparam%'] = SymbolInfo('@lparam%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
144
|
+
self._symbols['@midi%'] = SymbolInfo('@midi%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
145
|
+
self._symbols['@ispal%'] = SymbolInfo('@ispal%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
146
|
+
self._symbols['@hfile%'] = SymbolInfo('@hfile%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
147
|
+
self._symbols['@vdu%'] = SymbolInfo('@vdu%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
148
|
+
self._symbols['@cmd$'] = SymbolInfo('@cmd$', StringOwlType(), SymbolInfo.modifier_system)
|
|
149
|
+
self._symbols['@dir$'] = SymbolInfo('@dir$', StringOwlType(), SymbolInfo.modifier_system)
|
|
150
|
+
self._symbols['@hmdi%'] = SymbolInfo('@hmdi%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
151
|
+
self._symbols['@flags%'] = SymbolInfo('@flags%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
152
|
+
self._symbols['@lib$'] = SymbolInfo('@lib$', StringOwlType(), SymbolInfo.modifier_system)
|
|
153
|
+
self._symbols['@ox%'] = SymbolInfo('@ox%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
154
|
+
self._symbols['@oy%'] = SymbolInfo('@oy%', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
155
|
+
self._symbols['@tmp$'] = SymbolInfo('@tmp$', StringOwlType(), SymbolInfo.modifier_system)
|
|
156
|
+
self._symbols['@usr$'] = SymbolInfo('@usr$', StringOwlType(), SymbolInfo.modifier_system)
|
|
157
|
+
self._symbols['@vdu{}'] = SymbolInfo('@vdu{}', IntegerOwlType(), SymbolInfo.modifier_system)
|
|
158
|
+
|
|
159
|
+
class ScopedSymbolTable(SymbolTable):
|
|
160
|
+
"""
|
|
161
|
+
A symbol table containing additional scope information.
|
|
162
|
+
"""
|
|
163
|
+
def __init__(self, procedure, protection, parent):
|
|
164
|
+
super(ScopedSymbolTable, self).__init__(procedure, protection, parent)
|
|
165
|
+
self.procedure = procedure
|
|
166
|
+
|
|
167
|
+
class FormalParameterSymbolTable(ScopedSymbolTable):
|
|
168
|
+
"""
|
|
169
|
+
A write-through symbol table for storing formal parameters of
|
|
170
|
+
procedures and functions
|
|
171
|
+
"""
|
|
172
|
+
def __init__(self, symbol_infos, procedure, parent):
|
|
173
|
+
super(FormalParameterSymbolTable, self).__init__("formal parameters for PROC/FN %s" % procedure, SymbolTable.writethrough, parent)
|
|
174
|
+
print("symbol_infos = %s" % symbol_infos)
|
|
175
|
+
for symbol_info in symbol_infos:
|
|
176
|
+
self._symbols[symbol_info.name] = symbol_info
|
|
177
|
+
|
|
178
|
+
class LocalSymbolTable(ScopedSymbolTable):
|
|
179
|
+
"""
|
|
180
|
+
A write-through symbol table for storing local variables. Generated by a LOCAL statement
|
|
181
|
+
"""
|
|
182
|
+
def __init__(self, symbol_infos, procedure, parent):
|
|
183
|
+
super(LocalSymbolTable, self).__init__("LOCAL symbols for %s" % procedure, SymbolTable.writethrough, parent)
|
|
184
|
+
for symbol_info in symbol_infos:
|
|
185
|
+
self._symbols[symbol_info.name] = symbol_info
|
|
186
|
+
|
|
187
|
+
class PrivateSymbolTable(ScopedSymbolTable):
|
|
188
|
+
"""
|
|
189
|
+
A write-through symbol table for storing private variables. Generated by a PRIVATE statement
|
|
190
|
+
"""
|
|
191
|
+
def __init__(self, symbol_infos, procedure, parent):
|
|
192
|
+
super(PrivateSymbolTable, self).__init__("PRIVATE symbols for %s" % procedure, SymbolTable.writethrough, parent)
|
|
193
|
+
for symbol, type in symbol_types:
|
|
194
|
+
self._symbols.update(symbol_types)
|
|
195
|
+
|
|
File without changes
|