Skip to content

Commit 573f2eb

Browse files
committed
250425.1
1 parent 026ca9a commit 573f2eb

10 files changed

+472
-268
lines changed

config.ecs

Lines changed: 250 additions & 78 deletions
Large diffs are not rendered by default.
-37.8 KB
Binary file not shown.
38.2 KB
Binary file not shown.
Binary file not shown.

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
from .ec_timestamp import *
1010
from .ec_value import *
1111

12-
__version__ = "250424.3"
12+
__version__ = "250425.1"

easycoder/ec_compiler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def isSymbol(self):
8787
def nextIsSymbol(self):
8888
self.next()
8989
return self.isSymbol()
90+
91+
def skip(self, token):
92+
if self.peek() == token: self.nextToken()
9093

9194
def rewindTo(self, index):
9295
self.index = index
@@ -114,10 +117,10 @@ def getSymbolRecord(self):
114117
def compileLabel(self, command):
115118
return self.compileSymbol(command, self.getToken(), False)
116119

117-
def compileVariable(self, command, hasValue = False):
118-
return self.compileSymbol(command, self.nextToken(), hasValue)
120+
def compileVariable(self, command, hasValue = False, extra=None):
121+
return self.compileSymbol(command, self.nextToken(), hasValue, extra)
119122

120-
def compileSymbol(self, command, name, hasValue):
123+
def compileSymbol(self, command, name, hasValue, extra=None):
121124
try:
122125
v = self.symbols[name]
123126
except:
@@ -137,6 +140,7 @@ def compileSymbol(self, command, name, hasValue):
137140
command['debug'] = False
138141
command['import'] = None
139142
command['locked'] = False
143+
command['extra'] = extra
140144
self.addCommand(command)
141145
return True
142146

@@ -164,7 +168,7 @@ def compileToken(self):
164168
self.rewindTo(mark)
165169
else:
166170
self.rewindTo(mark)
167-
FatalError(self, f'No handler found for "{token}"')
171+
FatalError(self, f'Unable to compile "{token}" (in this context)')
168172

169173
# Compile a single command
170174
def compileOne(self):

easycoder/ec_core.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, compiler):
1414

1515
def getName(self):
1616
return 'core'
17+
18+
def noSymbolWarning(self):
19+
self.warning(f'Symbol "{self.getToken()}" not found')
1720

1821
#############################################################################
1922
# Keyword handlers
@@ -1379,6 +1382,33 @@ def r_set(self, command):
13791382
self.putSymbolValue(targetVariable, val)
13801383
return self.nextPC()
13811384

1385+
# Shuffle a list
1386+
def k_shuffle(self, command):
1387+
if self.nextIsSymbol():
1388+
symbolRecord = self.getSymbolRecord()
1389+
if symbolRecord['hasValue']:
1390+
command['target'] = self.getToken()
1391+
self.add(command)
1392+
return True
1393+
self.warning(f'Core.negate: Variable "{symbolRecord["name"]}" does not hold a value')
1394+
return False
1395+
1396+
def r_shuffle(self, command):
1397+
symbolRecord = self.getVariable(command['target'])
1398+
if not symbolRecord['hasValue']:
1399+
RuntimeError(self.program, f'{symbolRecord["name"]} does not hold a value')
1400+
return None
1401+
value = self.getSymbolValue(symbolRecord)
1402+
if value == None:
1403+
RuntimeError(self.program, f'{symbolRecord["name"]} has not been initialised')
1404+
content = value['content']
1405+
if isinstance(content, list):
1406+
random.shuffle(content)
1407+
value['content'] = content
1408+
self.putSymbolValue(symbolRecord, value)
1409+
return self.nextPC()
1410+
RuntimeError(self.program, f'{symbolRecord["name"]} is not a list')
1411+
13821412
# Split a string into a variable with several elements
13831413
# split {variable} on {value}
13841414
def k_split(self, command):
@@ -1400,6 +1430,7 @@ def k_split(self, command):
14001430
command['on'] = self.nextValue()
14011431
self.add(command)
14021432
return True
1433+
else: self.noSymbolWarning()
14031434
return False
14041435

14051436
def r_split(self, command):
@@ -1419,33 +1450,6 @@ def r_split(self, command):
14191450

14201451
return self.nextPC()
14211452

1422-
# Shuffle a list
1423-
def k_shuffle(self, command):
1424-
if self.nextIsSymbol():
1425-
symbolRecord = self.getSymbolRecord()
1426-
if symbolRecord['hasValue']:
1427-
command['target'] = self.getToken()
1428-
self.add(command)
1429-
return True
1430-
self.warning(f'Core.negate: Variable "{symbolRecord["name"]}" does not hold a value')
1431-
return False
1432-
1433-
def r_shuffle(self, command):
1434-
symbolRecord = self.getVariable(command['target'])
1435-
if not symbolRecord['hasValue']:
1436-
RuntimeError(self.program, f'{symbolRecord["name"]} does not hold a value')
1437-
return None
1438-
value = self.getSymbolValue(symbolRecord)
1439-
if value == None:
1440-
RuntimeError(self.program, f'{symbolRecord["name"]} has not been initialised')
1441-
content = value['content']
1442-
if isinstance(content, list):
1443-
random.shuffle(content)
1444-
value['content'] = content
1445-
self.putSymbolValue(symbolRecord, value)
1446-
return self.nextPC()
1447-
RuntimeError(self.program, f'{symbolRecord["name"]} is not a list')
1448-
14491453
# Declare a stack variable
14501454
def k_stack(self, command):
14511455
return self.compileVariable(command)

easycoder/ec_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def __init__(self, compiler):
77
self.program = compiler.program
88
self.getToken = compiler.getToken
99
self.nextToken = compiler.nextToken
10+
self.skip = compiler.skip
1011
self.peek = compiler.peek
1112
self.getValue = compiler.getValue
1213
self.nextValue = compiler.nextValue

0 commit comments

Comments
 (0)