Skip to content

Commit 6b63b3d

Browse files
committed
v250216.1
1 parent 2064f0f commit 6b63b3d

8 files changed

+50
-30
lines changed
-32.5 KB
Binary file not shown.
32.6 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__ = "250210.1"
12+
__version__ = "250216.1"

easycoder/ec_compiler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(self, program):
1313
self.tokens = self.script.tokens
1414
self.symbols = self.program.symbols
1515
self.code = self.program.code
16-
self.warnings = []
1716
self.program.compiler = self
1817
self.addCommand = self.program.add
1918
self.compileConstant = self.value.compileConstant
@@ -107,11 +106,10 @@ def showWarnings(self):
107106
def getSymbolRecord(self):
108107
token = self.getToken()
109108
symbol = self.symbols[token]
110-
if symbol != None:
111-
symbolRecord = self.code[symbol]
112-
symbolRecord['used'] = True
113-
return symbolRecord
114-
return None
109+
if symbol == None: return None
110+
symbolRecord = self.code[symbol]
111+
symbolRecord['used'] = True
112+
return symbolRecord
115113

116114
def compileLabel(self, command):
117115
return self.compileSymbol(command, self.getToken(), False)
@@ -144,6 +142,7 @@ def compileSymbol(self, command, name, valueHolder):
144142

145143
# Compile the current token
146144
def compileToken(self):
145+
self.warnings = []
147146
token = self.getToken()
148147
# print(f'Compile {token}')
149148
if not token:

easycoder/ec_condition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def __init__(self, compiler):
99
self.tokenIs = compiler.tokenIs
1010
self.rewindTo = compiler.rewindTo
1111
self.program = compiler.program
12+
self.negate = False
1213

1314
def compileCondition(self):
1415
mark = self.getIndex()

easycoder/ec_core.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -696,22 +696,28 @@ def k_load(self, command):
696696
self.program.importPlugin(f'{source}:{clazz}')
697697
return True
698698
elif self.isSymbol():
699-
command['target'] = self.getToken()
700-
if self.nextIs('from'):
701-
command['file'] = self.nextValue()
702-
self.add(command)
703-
return True
699+
symbolRecord = self.getSymbolRecord()
700+
if symbolRecord['valueHolder']:
701+
command['target'] = symbolRecord['name']
702+
if self.nextIs('from'):
703+
command['file'] = self.nextValue()
704+
self.add(command)
705+
return True
706+
else:
707+
FatalError(self.program.compiler, f'I don\'t understand \'{self.getToken()}\'')
704708
return False
705709

706710
def r_load(self, command):
707711
target = self.getVariable(command['target'])
708-
file = self.getRuntimeValue(command['file'])
712+
filename = self.getRuntimeValue(command['file'])
713+
try:
714+
with open(filename) as f: content = f.read()
715+
except:
716+
RuntimeError(self.program, f'File \'{filename}\' not found')
709717
try:
710-
with open(file, 'r') as f:
711-
content = f.read()
718+
if filename.endswith('.json'): content = json.loads(content)
712719
except:
713-
content=None
714-
if content != None and file.endswith('.json'): content = json.loads(content)
720+
RuntimeError(self.program, 'Bad or null JSON string')
715721
value = {}
716722
value['type'] = 'text'
717723
value['content'] = content
@@ -1219,10 +1225,9 @@ def k_save(self, command):
12191225

12201226
def r_save(self, command):
12211227
content = self.getRuntimeValue(command['content'])
1222-
file = self.getRuntimeValue(command['file'])
1223-
if file.endswith('.json'): content = json.dumps(content)
1224-
with open(file, 'w') as f:
1225-
f.write(content)
1228+
filename = self.getRuntimeValue(command['file'])
1229+
if filename.endswith('.json'): content = json.dumps(content)
1230+
with open(filename, 'w') as f: f.write(content)
12261231
return self.nextPC()
12271232

12281233
# Send a message to a module
@@ -1691,6 +1696,7 @@ def compileValue(self):
16911696
value['name'] = token
16921697
symbolRecord = self.getSymbolRecord()
16931698
keyword = symbolRecord['keyword']
1699+
16941700
if keyword == 'module':
16951701
value['type'] = 'module'
16961702
return value
@@ -2375,6 +2381,7 @@ def v_weekday(self, v):
23752381
# Compile a condition
23762382
def compileCondition(self):
23772383
condition = Condition()
2384+
23782385
if self.getToken() == 'not':
23792386
condition.type = 'not'
23802387
condition.value = self.nextValue()
@@ -2406,6 +2413,18 @@ def compileCondition(self):
24062413
return condition
24072414
return None
24082415

2416+
if token == 'does':
2417+
self.nextToken()
2418+
if self.nextIs('not'):
2419+
if self.nextIs('have'):
2420+
if self.nextToken() == 'property':
2421+
prop = self.nextValue()
2422+
condition.type = 'hasProperty'
2423+
condition.property = prop
2424+
condition.negate = not condition.negate
2425+
return condition
2426+
return None
2427+
24092428
if token in ['starts', 'ends']:
24102429
self.nextToken()
24112430
if self.nextToken() == 'with':
@@ -2498,7 +2517,7 @@ def c_hasProperty(self, condition):
24982517
hasProp = True
24992518
except:
25002519
hasProp = False
2501-
return hasProp
2520+
return not hasProp if condition.negate else hasProp
25022521

25032522
def c_includes(self, condition):
25042523
value1 = self.getRuntimeValue(condition.value1)
@@ -2543,4 +2562,3 @@ def c_starts(self, condition):
25432562
def c_string(self, condition):
25442563
comparison = type(self.getRuntimeValue(condition.value1)) is str
25452564
return not comparison if condition.negate else comparison
2546-
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

easycoder/ec_program.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,19 @@ def doValue(self, value):
149149
elif valType == 'symbol':
150150
name = value['name']
151151
symbolRecord = self.getSymbolRecord(name)
152-
if symbolRecord['value'] == [None]:
153-
RuntimeWarning(self, f'Variable "{name}" has no value')
154-
return None
155-
handler = self.domainIndex[symbolRecord['domain']].valueHandler('symbol')
156-
result = handler(symbolRecord)
152+
if symbolRecord['valueHolder']:
153+
handler = self.domainIndex[symbolRecord['domain']].valueHandler('symbol')
154+
result = handler(symbolRecord)
155+
else:
156+
# Call the given domain to handle a value
157+
domain = self.domainIndex[value['domain']]
158+
handler = domain.valueHandler(value['type'])
159+
if handler: result = handler(value)
157160
else:
158161
# Call the given domain to handle a value
159162
domain = self.domainIndex[value['domain']]
160163
handler = domain.valueHandler(value['type'])
161-
if handler:
162-
result = handler(value)
164+
if handler: result = handler(value)
163165

164166
return result
165167

0 commit comments

Comments
 (0)