Skip to content

Commit 6dd255b

Browse files
committed
v250123.1
1 parent db7b7ae commit 6dd255b

14 files changed

+663
-168
lines changed
-31.2 KB
Binary file not shown.
32.3 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__ = "250117.2"
12+
__version__ = "250123.1"

easycoder/ec_core.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from psutil import Process
33
from datetime import datetime, timezone
44
from random import randrange
5-
from .ec_classes import FatalError, RuntimeWarning, RuntimeError, AssertionError, Condition
5+
from .ec_classes import FatalError, RuntimeWarning, RuntimeError, AssertionError, Condition, Object
66
from .ec_handler import Handler
77
from .ec_timestamp import getTimestamp
88

@@ -729,6 +729,12 @@ def r_lock(self, command):
729729
target['locked'] = True
730730
return self.nextPC()
731731

732+
# Log a message
733+
def k_log(self, command):
734+
command['log'] = True
735+
command['keyword'] = 'print'
736+
return self.k_print(command)
737+
732738
# Declare a module variable
733739
def k_module(self, command):
734740
return self.compileVariable(command)
@@ -996,10 +1002,9 @@ def r_print(self, command):
9961002
program = command['program']
9971003
code = program.code[program.pc]
9981004
lino = code['lino'] + 1
999-
if value == None:
1000-
print(f'{lino}-> <empty>')
1001-
else:
1002-
print(f'{lino}-> {value}')
1005+
if value == None: value = '<empty>'
1006+
if 'log' in command: print(f'{datetime.now().time()}: {lino}-> {value}')
1007+
else: print(value)
10031008
return self.nextPC()
10041009

10051010
# Push a value onto a stack
@@ -1147,6 +1152,7 @@ def r_return(self, command):
11471152
return self.stack.pop()
11481153

11491154
# Compile and run a script
1155+
# run {path} [as {module}] [with {variable} [and {variable}...]]
11501156
def k_run(self, command):
11511157
try:
11521158
command['path'] = self.nextValue()
@@ -1157,20 +1163,24 @@ def k_run(self, command):
11571163
if self.nextIsSymbol():
11581164
record = self.getSymbolRecord()
11591165
if record['keyword'] == 'module':
1160-
command['module'] = record['name']
1161-
exports = []
1162-
if self.nextIs('with'):
1163-
while True:
1164-
name = self.nextToken()
1165-
record = self.getSymbolRecord()
1166-
exports.append(name)
1167-
if self.peek() != 'and':
1168-
break
1169-
self.nextToken()
1170-
command['exports'] = json.dumps(exports)
1171-
self.add(command)
1172-
return True
1173-
return False
1166+
name = record['name']
1167+
command['module'] = name
1168+
else: RuntimeError(self.program, f'Symbol \'name\' is not a module')
1169+
else: RuntimeError(self.program, 'Module name expected after \'as\'')
1170+
else: RuntimeError(self.program, '\'as {module name}\' expected')
1171+
exports = []
1172+
if self.peek() == 'with':
1173+
self.nextToken()
1174+
while True:
1175+
name = self.nextToken()
1176+
record = self.getSymbolRecord()
1177+
exports.append(name)
1178+
if self.peek() != 'and':
1179+
break
1180+
self.nextToken()
1181+
command['exports'] = json.dumps(exports)
1182+
self.add(command)
1183+
return True
11741184

11751185
def r_run(self, command):
11761186
module = self.getVariable(command['module'])
@@ -1734,10 +1744,7 @@ def compileValue(self):
17341744
if symbolRecord['valueHolder']:
17351745
value['target'] = symbolRecord['name']
17361746
return value
1737-
else:
1738-
value['value'] = self.getValue()
1739-
return value
1740-
self.warning(f'Core.compileValue: Token \'{self.getToken()}\' does not hold a value')
1747+
FatalError(self.program.compiler, 'Variable does not hold a value')
17411748
return None
17421749

17431750
if token == 'arg':
@@ -2503,7 +2510,7 @@ def c_none(self, condition):
25032510
return not comparison if condition.negate else comparison
25042511

25052512
def c_not(self, condition):
2506-
return not self.getRuntimeValue(condition.value1)
2513+
return not self.getRuntimeValue(condition.value)
25072514

25082515
def c_object(self, condition):
25092516
comparison = type(self.getRuntimeValue(condition.value1)) is dict

0 commit comments

Comments
 (0)