easycoder 251104.2__py2.py3-none-any.whl → 260108.1__py2.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.
Potentially problematic release.
This version of easycoder might be problematic. Click here for more details.
- easycoder/__init__.py +6 -3
- easycoder/debugger/__init__.py +5 -0
- easycoder/debugger/ec_dbg_value_display copy.py +195 -0
- easycoder/debugger/ec_dbg_value_display.py +24 -0
- easycoder/debugger/ec_dbg_watch_list copy.py +219 -0
- easycoder/debugger/ec_dbg_watchlist.py +293 -0
- easycoder/debugger/ec_debug.py +1025 -0
- easycoder/ec_border.py +15 -11
- easycoder/ec_classes.py +493 -11
- easycoder/ec_compiler.py +81 -44
- easycoder/ec_condition.py +1 -1
- easycoder/ec_core.py +1043 -1089
- easycoder/ec_gclasses.py +236 -0
- easycoder/ec_graphics.py +1683 -0
- easycoder/ec_handler.py +18 -13
- easycoder/ec_keyboard.py +50 -50
- easycoder/ec_mqtt.py +249 -0
- easycoder/ec_program.py +308 -156
- easycoder/ec_psutil.py +48 -0
- easycoder/ec_timestamp.py +2 -1
- easycoder/ec_value.py +65 -47
- easycoder/icons/exit.png +0 -0
- easycoder/icons/run.png +0 -0
- easycoder/icons/step.png +0 -0
- easycoder/icons/stop.png +0 -0
- easycoder/pre/README.md +3 -0
- easycoder/pre/__init__.py +17 -0
- easycoder/pre/debugger/__init__.py +5 -0
- easycoder/pre/debugger/ec_dbg_value_display copy.py +195 -0
- easycoder/pre/debugger/ec_dbg_value_display.py +24 -0
- easycoder/pre/debugger/ec_dbg_watch_list copy.py +219 -0
- easycoder/pre/debugger/ec_dbg_watchlist.py +293 -0
- easycoder/pre/debugger/ec_debug.py +1014 -0
- easycoder/pre/ec_border.py +67 -0
- easycoder/pre/ec_classes.py +470 -0
- easycoder/pre/ec_compiler.py +291 -0
- easycoder/pre/ec_condition.py +27 -0
- easycoder/pre/ec_core.py +2772 -0
- easycoder/pre/ec_gclasses.py +230 -0
- easycoder/{ec_pyside.py → pre/ec_graphics.py} +631 -496
- easycoder/pre/ec_handler.py +79 -0
- easycoder/pre/ec_keyboard.py +439 -0
- easycoder/pre/ec_program.py +557 -0
- easycoder/pre/ec_psutil.py +48 -0
- easycoder/pre/ec_timestamp.py +11 -0
- easycoder/pre/ec_value.py +124 -0
- easycoder/pre/icons/close.png +0 -0
- easycoder/pre/icons/exit.png +0 -0
- easycoder/pre/icons/run.png +0 -0
- easycoder/pre/icons/step.png +0 -0
- easycoder/pre/icons/stop.png +0 -0
- easycoder/pre/icons/tick.png +0 -0
- {easycoder-251104.2.dist-info → easycoder-260108.1.dist-info}/METADATA +11 -1
- easycoder-260108.1.dist-info/RECORD +59 -0
- easycoder/ec_debug.py +0 -464
- easycoder-251104.2.dist-info/RECORD +0 -20
- /easycoder/{close.png → icons/close.png} +0 -0
- /easycoder/{tick.png → icons/tick.png} +0 -0
- {easycoder-251104.2.dist-info → easycoder-260108.1.dist-info}/WHEEL +0 -0
- {easycoder-251104.2.dist-info → easycoder-260108.1.dist-info}/entry_points.txt +0 -0
- {easycoder-251104.2.dist-info → easycoder-260108.1.dist-info}/licenses/LICENSE +0 -0
easycoder/ec_program.py
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import time,
|
|
1
|
+
import time, sys, json
|
|
2
2
|
from copy import deepcopy
|
|
3
3
|
from collections import deque
|
|
4
|
-
from .ec_classes import
|
|
4
|
+
from .ec_classes import (
|
|
5
|
+
Script,
|
|
6
|
+
Token,
|
|
7
|
+
FatalError,
|
|
8
|
+
RuntimeError,
|
|
9
|
+
NoValueRuntimeError,
|
|
10
|
+
ECObject,
|
|
11
|
+
ECValue,
|
|
12
|
+
normalize_type
|
|
13
|
+
)
|
|
5
14
|
from .ec_compiler import Compiler
|
|
6
15
|
from .ec_core import Core
|
|
7
16
|
import importlib
|
|
@@ -16,20 +25,25 @@ def flush():
|
|
|
16
25
|
|
|
17
26
|
class Program:
|
|
18
27
|
|
|
19
|
-
def __init__(self,
|
|
28
|
+
def __init__(self, arg):
|
|
20
29
|
global queue
|
|
21
30
|
print(f'EasyCoder version {version("easycoder")}')
|
|
22
|
-
if len(
|
|
31
|
+
if len(arg) == 0:
|
|
23
32
|
print('No script supplied')
|
|
24
33
|
exit()
|
|
25
|
-
if
|
|
26
|
-
|
|
34
|
+
if arg in ['-v', '--version']: return
|
|
35
|
+
if arg[0:6] == 'debug ':
|
|
36
|
+
print('Debug mode requested')
|
|
37
|
+
self.scriptName = arg[6:]
|
|
38
|
+
self.debugging = True
|
|
39
|
+
else:
|
|
40
|
+
self.scriptName = arg
|
|
41
|
+
self.debugging = False
|
|
27
42
|
|
|
28
|
-
f = open(scriptName, 'r')
|
|
43
|
+
f = open(self.scriptName, 'r')
|
|
29
44
|
source = f.read()
|
|
30
45
|
f.close()
|
|
31
46
|
queue = deque()
|
|
32
|
-
self.argv = argv
|
|
33
47
|
self.domains = []
|
|
34
48
|
self.domainIndex = {}
|
|
35
49
|
self.name = '<anon>'
|
|
@@ -38,28 +52,35 @@ class Program:
|
|
|
38
52
|
self.symbols = {}
|
|
39
53
|
self.onError = 0
|
|
40
54
|
self.debugStep = False
|
|
55
|
+
self.debugSkip = False
|
|
41
56
|
self.stack = []
|
|
42
57
|
self.script = Script(source)
|
|
43
58
|
self.compiler = Compiler(self)
|
|
59
|
+
self.object = ECObject()
|
|
44
60
|
self.value = self.compiler.value
|
|
45
61
|
self.condition = self.compiler.condition
|
|
46
62
|
self.graphics = None
|
|
63
|
+
self.psutil = None
|
|
47
64
|
self.useClass(Core)
|
|
48
|
-
self.externalControl = False
|
|
49
65
|
self.ticker = 0
|
|
50
|
-
self.
|
|
51
|
-
self.debugging = False
|
|
66
|
+
self.graphicsRunning = False
|
|
52
67
|
self.debugger = None
|
|
53
|
-
self.running =
|
|
68
|
+
self.running = False
|
|
69
|
+
self.parent = None
|
|
70
|
+
self.message = None
|
|
71
|
+
self.onMessagePC = 0
|
|
72
|
+
self.breakpoint = False
|
|
54
73
|
|
|
55
74
|
# This is called at 10msec intervals by the GUI code
|
|
56
75
|
def flushCB(self):
|
|
57
76
|
self.ticker += 1
|
|
77
|
+
# if self.ticker % 1000 == 0: print(f'GUI Tick {self.ticker}')
|
|
58
78
|
flush()
|
|
59
79
|
|
|
60
80
|
def start(self, parent=None, module = None, exports=[]):
|
|
61
81
|
self.parent = parent
|
|
62
82
|
self.exports = exports
|
|
83
|
+
if self.debugging: self.useGraphics()
|
|
63
84
|
if module != None:
|
|
64
85
|
module['child'] = self
|
|
65
86
|
startCompile = time.time()
|
|
@@ -72,7 +93,7 @@ class Program:
|
|
|
72
93
|
f'{round((finishCompile - startCompile) * 1000)} ms')
|
|
73
94
|
for name in self.symbols.keys():
|
|
74
95
|
record = self.code[self.symbols[name]]
|
|
75
|
-
if name[-1] != ':' and not
|
|
96
|
+
if name[-1] != ':' and not 'used' in record:
|
|
76
97
|
print(f'Variable "{name}" not used')
|
|
77
98
|
else:
|
|
78
99
|
print(f'Run {self.name}')
|
|
@@ -81,13 +102,44 @@ class Program:
|
|
|
81
102
|
self.compiler.showWarnings()
|
|
82
103
|
|
|
83
104
|
# If this is the main script and there's no graphics, run a main loop
|
|
84
|
-
if parent == None
|
|
85
|
-
while
|
|
105
|
+
if parent == None:
|
|
106
|
+
while not self.graphicsRunning:
|
|
86
107
|
if self.running == True:
|
|
87
108
|
flush()
|
|
88
109
|
time.sleep(0.01)
|
|
89
110
|
else:
|
|
90
111
|
break
|
|
112
|
+
|
|
113
|
+
# Use the graphics module
|
|
114
|
+
def useGraphics(self):
|
|
115
|
+
if self.graphics == None:
|
|
116
|
+
print('Loading graphics module')
|
|
117
|
+
from .ec_graphics import Graphics
|
|
118
|
+
self.graphics = Graphics
|
|
119
|
+
self.useClass(Graphics)
|
|
120
|
+
return True
|
|
121
|
+
|
|
122
|
+
# Use the mqtt module
|
|
123
|
+
def useMQTT(self):
|
|
124
|
+
if self.psutil == None:
|
|
125
|
+
print('Loading mqtt module')
|
|
126
|
+
from .ec_mqtt import MQTT
|
|
127
|
+
self.psutil = MQTT
|
|
128
|
+
self.useClass(MQTT)
|
|
129
|
+
return True
|
|
130
|
+
|
|
131
|
+
# Use the psutil module
|
|
132
|
+
def usePSUtil(self):
|
|
133
|
+
if self.psutil == None:
|
|
134
|
+
print('Loading psutil module')
|
|
135
|
+
from .ec_psutil import PSUtil
|
|
136
|
+
self.psutil = PSUtil
|
|
137
|
+
self.useClass(PSUtil)
|
|
138
|
+
return True
|
|
139
|
+
|
|
140
|
+
# Indicate that graphics are running
|
|
141
|
+
def startGraphics(self):
|
|
142
|
+
self.graphicsRunning = True
|
|
91
143
|
|
|
92
144
|
# Import a plugin
|
|
93
145
|
def importPlugin(self, source):
|
|
@@ -112,122 +164,225 @@ class Program:
|
|
|
112
164
|
self.domains.append(handler)
|
|
113
165
|
self.domainIndex[handler.getName()] = handler
|
|
114
166
|
|
|
167
|
+
# This is the runtime callback for event handlers
|
|
168
|
+
def callback(self, item, record, goto):
|
|
169
|
+
object = self.getObject(record)
|
|
170
|
+
values = object.getValues() # type: ignore
|
|
171
|
+
for i, v in enumerate(values):
|
|
172
|
+
if isinstance(v, ECValue): v = v.getContent()
|
|
173
|
+
if v == item:
|
|
174
|
+
object.setIndex(i) # type: ignore
|
|
175
|
+
self.run(goto)
|
|
176
|
+
return
|
|
177
|
+
|
|
178
|
+
# Ensure the program is running
|
|
179
|
+
def ensureRunning(self):
|
|
180
|
+
if not self.running:
|
|
181
|
+
raise RuntimeError(self, 'Improper use of runtime function')
|
|
182
|
+
|
|
183
|
+
# Ensure the program is not running
|
|
184
|
+
def ensureNotRunning(self):
|
|
185
|
+
if self.running:
|
|
186
|
+
raise RuntimeError(self, 'Improper use of non-runtime function')
|
|
187
|
+
|
|
115
188
|
# Get the domain list
|
|
116
189
|
def getDomains(self):
|
|
117
190
|
return self.domains
|
|
118
|
-
|
|
119
|
-
def
|
|
191
|
+
|
|
192
|
+
def isSymbol(self, name):
|
|
193
|
+
return name in self.symbols
|
|
194
|
+
|
|
195
|
+
# Get the symbol record for a given name
|
|
196
|
+
def getVariable(self, name):
|
|
197
|
+
self.ensureRunning()
|
|
198
|
+
if isinstance(name, dict): name = name['name']
|
|
120
199
|
try:
|
|
121
200
|
target = self.code[self.symbols[name]]
|
|
122
|
-
if
|
|
201
|
+
if 'import' in target:
|
|
123
202
|
target = target['import']
|
|
124
203
|
return target
|
|
125
204
|
except:
|
|
126
205
|
RuntimeError(self, f'Unknown symbol \'{name}\'')
|
|
206
|
+
|
|
207
|
+
# Get the object represented by a symbol record
|
|
208
|
+
def getObject(self, record):
|
|
209
|
+
if isinstance(record, dict) and 'object' in record:
|
|
210
|
+
return record['object']
|
|
211
|
+
return record
|
|
212
|
+
|
|
213
|
+
# Check if an object is an instance of a given class
|
|
214
|
+
# This can either be variable record (a dict) or an instance of ECObject
|
|
215
|
+
def isObjectType(self, object, classes):
|
|
216
|
+
if isinstance(object, dict) and 'object' in object and isinstance(object['object'], ECObject):
|
|
217
|
+
object = object['object']
|
|
218
|
+
return isinstance(object, classes)
|
|
219
|
+
|
|
220
|
+
# Check if the object is an instance of one of a set of classes. Compile and runtime
|
|
221
|
+
def checkObjectType(self, object, classes):
|
|
222
|
+
if isinstance(object, dict): return
|
|
223
|
+
if not isinstance(object, classes):
|
|
224
|
+
if isinstance(classes, tuple):
|
|
225
|
+
class_names = ", ".join([c.__name__ for c in classes])
|
|
226
|
+
message = f"Variable {object.name} should be one of {class_names}"
|
|
227
|
+
else:
|
|
228
|
+
class_names = classes.__name__
|
|
229
|
+
message = f"Variable {object.name} should be {class_names}"
|
|
230
|
+
if self.running:
|
|
231
|
+
raise RuntimeError(self, message)
|
|
232
|
+
else:
|
|
233
|
+
raise FatalError(self.compiler, message)
|
|
234
|
+
|
|
235
|
+
# Get the inner (non-EC) object from a name, record or object
|
|
236
|
+
def getInnerObject(self, object):
|
|
237
|
+
if isinstance(object, dict): object = object['object']
|
|
238
|
+
elif isinstance(object, str):
|
|
239
|
+
record = self.getVariable(object) # type: ignore
|
|
240
|
+
object = self.getObject(record) # type: ignore
|
|
241
|
+
value = object.getValue() # type: ignore
|
|
242
|
+
if isinstance(value, ECValue) and value.getType() == 'object':
|
|
243
|
+
return value.getContent()
|
|
244
|
+
else: return value
|
|
127
245
|
|
|
128
|
-
def
|
|
129
|
-
if value == None:
|
|
130
|
-
RuntimeError(self, f'Undefined value (variable not initialized?)')
|
|
131
|
-
|
|
246
|
+
def constant(self, content, numeric):
|
|
132
247
|
result = {}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
248
|
+
result['type'] = int if numeric else str
|
|
249
|
+
result['content'] = content
|
|
250
|
+
return result
|
|
251
|
+
|
|
252
|
+
# Test if an item is a string or a number
|
|
253
|
+
def getItemType(self, value):
|
|
254
|
+
return int if isinstance(value, int) else str
|
|
255
|
+
|
|
256
|
+
# Get the value of an item that may be an ECValue or a raw value. Return as an ECValue
|
|
257
|
+
def getValueOf(self, item):
|
|
258
|
+
value = ECValue()
|
|
259
|
+
if isinstance(item, ECValue):
|
|
260
|
+
if item.getType() == 'object':
|
|
261
|
+
return item.getContent()
|
|
262
|
+
else: value = item
|
|
263
|
+
else:
|
|
264
|
+
varType = type(item).__name__
|
|
265
|
+
if varType == 'int': value.setValue(type=int, content=item)
|
|
266
|
+
elif varType == 'str': value.setValue(type=str, content=item)
|
|
267
|
+
elif varType == 'bool': value.setValue(type=bool, content=item)
|
|
268
|
+
elif varType == 'float': value.setValue(type=str, content=str(item))
|
|
269
|
+
elif varType == 'list': value.setValue(type=list, content=item)
|
|
270
|
+
elif varType == 'dict': value.setValue(type=dict, content=item)
|
|
271
|
+
else: value.setValue(type=None, content=None)
|
|
272
|
+
return value
|
|
273
|
+
|
|
274
|
+
# Runtime function to evaluate an ECObject or ECValue. Returns another ECValue
|
|
275
|
+
# This function may be called recursively by value handlers.
|
|
276
|
+
def evaluate(self, item):
|
|
277
|
+
self.ensureRunning()
|
|
278
|
+
if isinstance(item, ECObject):
|
|
279
|
+
value = item.getValue()
|
|
280
|
+
if value == None:
|
|
281
|
+
raise RuntimeError(self, f'Symbol {item.getName()} not initialized')
|
|
282
|
+
else: value = item
|
|
283
|
+
try:
|
|
284
|
+
valType = normalize_type(value.getType()) # type: ignore
|
|
285
|
+
except:
|
|
286
|
+
RuntimeError(self, 'Value does not hold a valid ECValue')
|
|
287
|
+
result = ECValue(type=valType)
|
|
288
|
+
|
|
289
|
+
if valType in ('str', 'int', 'bool', 'list', 'dict', None):
|
|
290
|
+
# Simple value - just return the content
|
|
291
|
+
result.setContent(value.getContent()) # type: ignore
|
|
292
|
+
|
|
293
|
+
elif valType == 'object':
|
|
294
|
+
# Object other than ECVariable
|
|
295
|
+
record = self.getVariable(value.getName())
|
|
296
|
+
object = self.getObject(record) # type: ignore
|
|
297
|
+
result = object.getContent() # type: ignore
|
|
298
|
+
|
|
299
|
+
elif valType == 'symbol': # type: ignore
|
|
300
|
+
# If it's a symbol, get its value
|
|
301
|
+
record = self.getVariable(value.getContent()) # type: ignore
|
|
302
|
+
if not 'object' in record: return None # type: ignore
|
|
303
|
+
variable = self.getObject(record) # type: ignore
|
|
304
|
+
result = variable.getValue() # type: ignore
|
|
305
|
+
if isinstance(result, ECValue): return self.evaluate(result)
|
|
306
|
+
if isinstance(result, ECObject): return result.getValue()
|
|
307
|
+
if isinstance(result, dict) or isinstance(result, list):
|
|
308
|
+
return result
|
|
309
|
+
# See if one of the domains can handle this value
|
|
310
|
+
value = result
|
|
311
|
+
result = None
|
|
312
|
+
for domain in self.domains:
|
|
313
|
+
result = domain.getUnknownValue(value)
|
|
314
|
+
if result != None: break
|
|
315
|
+
|
|
136
316
|
elif valType == 'cat':
|
|
317
|
+
# Handle concatenation
|
|
137
318
|
content = ''
|
|
138
|
-
for part in value[
|
|
139
|
-
val = self.
|
|
140
|
-
if val
|
|
141
|
-
val =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
content += val
|
|
147
|
-
result['type'] = 'text'
|
|
148
|
-
result['content'] = content
|
|
149
|
-
elif valType == 'symbol':
|
|
150
|
-
name = value['name']
|
|
151
|
-
symbolRecord = self.getSymbolRecord(name)
|
|
152
|
-
# if symbolRecord['hasValue']:
|
|
153
|
-
if symbolRecord:
|
|
154
|
-
handler = self.domainIndex[symbolRecord['domain']].valueHandler('symbol')
|
|
155
|
-
result = handler(symbolRecord)
|
|
156
|
-
# else:
|
|
157
|
-
# # Call the given domain to handle a value
|
|
158
|
-
# # domain = self.domainIndex[value['domain']]
|
|
159
|
-
# handler = domain.valueHandler(value['type'])
|
|
160
|
-
# if handler: result = handler(value)
|
|
319
|
+
for part in value.getContent(): # pyright: ignore[reportOptionalMemberAccess]
|
|
320
|
+
val = self.evaluate(part) # pyright: ignore[reportAttributeAccessIssue]
|
|
321
|
+
if val != None:
|
|
322
|
+
if isinstance(val, ECValue): val = str(val.getContent())
|
|
323
|
+
if val == None: val = ''
|
|
324
|
+
else: content += str(val)
|
|
325
|
+
result.setValue(type=str, content=content)
|
|
326
|
+
|
|
161
327
|
else:
|
|
162
328
|
# Call the given domain to handle a value
|
|
163
|
-
|
|
164
|
-
|
|
329
|
+
domainName = value.getDomain() # type: ignore
|
|
330
|
+
if domainName == None: domainName = 'core'
|
|
331
|
+
domain = self.domainIndex[domainName]
|
|
332
|
+
handler = domain.valueHandler(value.getType()) # type: ignore
|
|
165
333
|
if handler: result = handler(value)
|
|
166
334
|
|
|
167
335
|
return result
|
|
168
336
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
result['content'] = content
|
|
173
|
-
return result
|
|
174
|
-
|
|
175
|
-
def evaluate(self, value):
|
|
176
|
-
if value == None:
|
|
177
|
-
result = {}
|
|
178
|
-
result['type'] = 'text'
|
|
179
|
-
result['content'] = ''
|
|
180
|
-
return result
|
|
181
|
-
|
|
182
|
-
result = self.doValue(value)
|
|
183
|
-
if result:
|
|
184
|
-
return result
|
|
185
|
-
return None
|
|
186
|
-
|
|
187
|
-
def getValue(self, value):
|
|
188
|
-
result = self.evaluate(value)
|
|
189
|
-
if result:
|
|
190
|
-
return result.get('content') # type: ignore[union-attr]
|
|
191
|
-
return None
|
|
192
|
-
|
|
193
|
-
def getRuntimeValue(self, value):
|
|
337
|
+
# Get the runtime value of a value object (as a string or integer)
|
|
338
|
+
def textify(self, value):
|
|
339
|
+
self.ensureRunning()
|
|
194
340
|
if value is None:
|
|
195
341
|
return None
|
|
196
|
-
|
|
197
|
-
if
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
342
|
+
|
|
343
|
+
if isinstance(value, dict):
|
|
344
|
+
value = value['object']
|
|
345
|
+
if isinstance(value, ECObject):
|
|
346
|
+
value = value.getValue()
|
|
347
|
+
if isinstance(value, ECValue): # type: ignore
|
|
348
|
+
v = self.evaluate(value) # type: ignore
|
|
349
|
+
else:
|
|
350
|
+
v = value
|
|
351
|
+
if v is None: return None
|
|
352
|
+
if isinstance(v, ECValue):
|
|
353
|
+
if v.getType() == 'object':
|
|
354
|
+
return value.getContent() # type: ignore
|
|
355
|
+
return v.getContent()
|
|
356
|
+
if isinstance(v, (dict, list)):
|
|
357
|
+
return json.dumps(v)
|
|
358
|
+
return v
|
|
359
|
+
|
|
360
|
+
# Get the content of a symbol
|
|
361
|
+
def getSymbolContent(self, record):
|
|
362
|
+
if len(record['value']) == 0:
|
|
214
363
|
return None
|
|
215
|
-
try:
|
|
216
|
-
except:
|
|
217
|
-
|
|
364
|
+
try: return record['value'][record['index']]
|
|
365
|
+
except: raise RuntimeError(self, f'Cannot get content of symbol "{record["name"]}"')
|
|
366
|
+
|
|
367
|
+
# Get the value of a symbol as an ECValue
|
|
368
|
+
def getSymbolValue(self, record):
|
|
369
|
+
self.ensureRunning()
|
|
370
|
+
object = self.getObject(record)
|
|
371
|
+
self.checkObjectType(object, ECObject)
|
|
372
|
+
value = object.getValue() # type: ignore
|
|
373
|
+
if value is None:
|
|
374
|
+
raise NoValueRuntimeError(self, f'Symbol "{record["name"]}" has no value')
|
|
375
|
+
# copy = deepcopy(value)
|
|
376
|
+
copy = ECValue(domain=value.getDomain(),type=value.getType(),content=deepcopy(value.getContent()))
|
|
218
377
|
return copy
|
|
219
378
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
index = symbolRecord['index']
|
|
228
|
-
if index == None:
|
|
229
|
-
index = 0
|
|
230
|
-
symbolRecord['value'][index] = value
|
|
379
|
+
# Set the value of a symbol to either an ECValue or a raw value
|
|
380
|
+
def putSymbolValue(self, record, value):
|
|
381
|
+
variable = self.getObject(record)
|
|
382
|
+
if variable.isLocked(): # type: ignore
|
|
383
|
+
name = record['name']
|
|
384
|
+
raise RuntimeError(self, f'Symbol "{name}" is locked')
|
|
385
|
+
variable.setValue(self.getValueOf(value)) # type: ignore
|
|
231
386
|
|
|
232
387
|
def encode(self, value):
|
|
233
388
|
return value
|
|
@@ -304,23 +459,35 @@ class Program:
|
|
|
304
459
|
self.pc = pc
|
|
305
460
|
while self.running:
|
|
306
461
|
command = self.code[self.pc]
|
|
462
|
+
|
|
463
|
+
# Check if debugger wants to halt before executing this command
|
|
464
|
+
if self.debugger != None:
|
|
465
|
+
# pc==1 is the first real command (pc==0 is the debug loader)
|
|
466
|
+
is_first = (self.pc == 1)
|
|
467
|
+
if self.debugger.checkIfHalt(is_first):
|
|
468
|
+
# Debugger says halt - break out and wait for user
|
|
469
|
+
break
|
|
470
|
+
|
|
307
471
|
domainName = command['domain']
|
|
308
472
|
if domainName == None:
|
|
309
473
|
self.pc += 1
|
|
310
474
|
else:
|
|
311
475
|
keyword = command['keyword']
|
|
312
|
-
if self.debugStep and
|
|
476
|
+
if self.debugStep and not self.debugSkip and 'debug' in command:
|
|
313
477
|
lino = command['lino'] + 1
|
|
314
478
|
line = self.script.lines[command['lino']].strip()
|
|
315
479
|
print(f'{self.name}: Line {lino}: {domainName}:{keyword}: {line}')
|
|
316
|
-
if self.debugger != None:
|
|
317
|
-
self.debugger.step()
|
|
318
480
|
domain = self.domainIndex[domainName]
|
|
319
481
|
handler = domain.runHandler(keyword)
|
|
320
482
|
if handler:
|
|
321
483
|
command = self.code[self.pc]
|
|
322
484
|
command['program'] = self
|
|
323
|
-
|
|
485
|
+
try:
|
|
486
|
+
if self.breakpoint:
|
|
487
|
+
pass # Place a breakpoint here for a debugger to catch
|
|
488
|
+
self.pc = handler(command)
|
|
489
|
+
except Exception as e:
|
|
490
|
+
raise RuntimeError(self, f'Error during execution of {domainName}:{keyword}: {str(e)}')
|
|
324
491
|
# Deal with 'exit'
|
|
325
492
|
if self.pc == -1:
|
|
326
493
|
queue = deque()
|
|
@@ -334,63 +501,48 @@ class Program:
|
|
|
334
501
|
# Run the script at a given PC value
|
|
335
502
|
def run(self, pc):
|
|
336
503
|
global queue
|
|
337
|
-
item =
|
|
338
|
-
item.program = self
|
|
339
|
-
item.pc = pc
|
|
504
|
+
item = ECValue()
|
|
505
|
+
item.program = self # type: ignore
|
|
506
|
+
item.pc = pc # type: ignore
|
|
340
507
|
queue.append(item)
|
|
508
|
+
self.running = True
|
|
341
509
|
|
|
342
510
|
def kill(self):
|
|
343
511
|
self.running = False
|
|
344
512
|
if self.parent != None: self.parent.program.kill()
|
|
345
513
|
|
|
346
|
-
def setExternalControl(self):
|
|
347
|
-
self.externalControl = True
|
|
348
|
-
|
|
349
514
|
def nonNumericValueError(self):
|
|
350
515
|
FatalError(self.compiler, 'Non-numeric value')
|
|
351
516
|
|
|
352
|
-
def variableDoesNotHoldAValueError(self, name):
|
|
353
|
-
raise FatalError(self.compiler, f'Variable "{name}" does not hold a value')
|
|
354
|
-
|
|
355
|
-
def noneValueError(self, name):
|
|
356
|
-
raise FatalError(self.compiler, f'Value is None')
|
|
357
|
-
|
|
358
517
|
def compare(self, value1, value2):
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
518
|
+
if value1 == None or value2 == None:
|
|
519
|
+
RuntimeError(self, 'Cannot compare a value with None')
|
|
520
|
+
v1 = self.textify(value1)
|
|
521
|
+
v2 = self.textify(value2)
|
|
522
|
+
if v1 == None or v2 == None:
|
|
523
|
+
raise RuntimeError(self, 'Both items must have a value for comparison')
|
|
524
|
+
if type(v1) == str and type(v2) == str:
|
|
525
|
+
# String comparison
|
|
526
|
+
if v1 < v2: return -1
|
|
527
|
+
if v1 > v2: return 1
|
|
362
528
|
return 0
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
RuntimeError(None, f'Line {lino}: \'{v2}\' is not an integer')
|
|
377
|
-
else:
|
|
378
|
-
if v2 != None and val2['type'] == 'int':
|
|
379
|
-
v2 = str(v2)
|
|
380
|
-
if v1 == None:
|
|
381
|
-
v1 = ''
|
|
382
|
-
if v2 == None:
|
|
383
|
-
v2 = ''
|
|
384
|
-
if type(v1) == int:
|
|
385
|
-
if type(v2) != int:
|
|
386
|
-
v1 = f'{v1}'
|
|
387
|
-
if type(v2) == int:
|
|
388
|
-
if type(v1) != int:
|
|
389
|
-
v2 = f'{v2}'
|
|
390
|
-
if v1 > v2: # type: ignore[operator]
|
|
391
|
-
return 1
|
|
529
|
+
|
|
530
|
+
if type(v1) is str:
|
|
531
|
+
try:
|
|
532
|
+
v1 = int(v1)
|
|
533
|
+
except:
|
|
534
|
+
print(f'{v1} is not an integer')
|
|
535
|
+
return None
|
|
536
|
+
if type(v2) is str:
|
|
537
|
+
try:
|
|
538
|
+
v2 = int(v2)
|
|
539
|
+
except:
|
|
540
|
+
print(f'{v2} is not an integer')
|
|
541
|
+
return None
|
|
392
542
|
if v1 < v2: # type: ignore[operator]
|
|
393
543
|
return -1
|
|
544
|
+
if v1 > v2: # type: ignore[operator]
|
|
545
|
+
return 1
|
|
394
546
|
return 0
|
|
395
547
|
|
|
396
548
|
# Set up a message handler
|
|
@@ -405,7 +557,7 @@ class Program:
|
|
|
405
557
|
# This is the program launcher
|
|
406
558
|
def Main():
|
|
407
559
|
if (len(sys.argv) > 1):
|
|
408
|
-
Program(sys.argv[1]).start()
|
|
560
|
+
Program(' '.join(sys.argv[1:])).start()
|
|
409
561
|
else:
|
|
410
562
|
Program('-v')
|
|
411
563
|
|
easycoder/ec_psutil.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from easycoder import Handler, ECValue
|
|
2
|
+
import os
|
|
3
|
+
from psutil import Process
|
|
4
|
+
|
|
5
|
+
class PSUtil(Handler):
|
|
6
|
+
|
|
7
|
+
def __init__(self, compiler):
|
|
8
|
+
Handler.__init__(self, compiler)
|
|
9
|
+
|
|
10
|
+
def getName(self):
|
|
11
|
+
return 'psutil'
|
|
12
|
+
|
|
13
|
+
#############################################################################
|
|
14
|
+
# Keyword handlers
|
|
15
|
+
|
|
16
|
+
#############################################################################
|
|
17
|
+
# Compile a value in this domain
|
|
18
|
+
def compileValue(self):
|
|
19
|
+
value = ECValue(domain=self.getName())
|
|
20
|
+
if self.tokenIs('the'):
|
|
21
|
+
self.nextToken()
|
|
22
|
+
token = self.getToken()
|
|
23
|
+
if token in ['mem', 'memory']:
|
|
24
|
+
value.setType('memory')
|
|
25
|
+
return value
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
#############################################################################
|
|
29
|
+
# Modify a value or leave it unchanged.
|
|
30
|
+
def modifyValue(self, value):
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
#############################################################################
|
|
34
|
+
# Value handlers
|
|
35
|
+
|
|
36
|
+
def v_memory(self, v):
|
|
37
|
+
process: Process = Process(os.getpid())
|
|
38
|
+
megabytes: float = process.memory_info().rss / (1024 * 1024)
|
|
39
|
+
return ECValue(domain=self.getName(), type=float, content=megabytes)
|
|
40
|
+
|
|
41
|
+
#############################################################################
|
|
42
|
+
# Compile a condition
|
|
43
|
+
def compileCondition(self):
|
|
44
|
+
condition = {}
|
|
45
|
+
return condition
|
|
46
|
+
|
|
47
|
+
#############################################################################
|
|
48
|
+
# Condition handlers
|
easycoder/ec_timestamp.py
CHANGED
|
@@ -5,6 +5,7 @@ def getTimestamp(t):
|
|
|
5
5
|
tz = pytz.timezone('GB') # Localize this!
|
|
6
6
|
dt = datetime.fromtimestamp(t)
|
|
7
7
|
# print(f'{dt} + {tz.dst(dt).seconds}')
|
|
8
|
-
|
|
8
|
+
dst = tz.dst(dt)
|
|
9
|
+
return int(t) + (dst.seconds if dst else 0)
|
|
9
10
|
|
|
10
11
|
# Usage: print(getTimestamp(time.time()))
|