2
2
from psutil import Process
3
3
from datetime import datetime , timezone
4
4
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
6
6
from .ec_handler import Handler
7
7
from .ec_timestamp import getTimestamp
8
8
@@ -729,6 +729,12 @@ def r_lock(self, command):
729
729
target ['locked' ] = True
730
730
return self .nextPC ()
731
731
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
+
732
738
# Declare a module variable
733
739
def k_module (self , command ):
734
740
return self .compileVariable (command )
@@ -996,10 +1002,9 @@ def r_print(self, command):
996
1002
program = command ['program' ]
997
1003
code = program .code [program .pc ]
998
1004
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 )
1003
1008
return self .nextPC ()
1004
1009
1005
1010
# Push a value onto a stack
@@ -1147,6 +1152,7 @@ def r_return(self, command):
1147
1152
return self .stack .pop ()
1148
1153
1149
1154
# Compile and run a script
1155
+ # run {path} [as {module}] [with {variable} [and {variable}...]]
1150
1156
def k_run (self , command ):
1151
1157
try :
1152
1158
command ['path' ] = self .nextValue ()
@@ -1157,20 +1163,24 @@ def k_run(self, command):
1157
1163
if self .nextIsSymbol ():
1158
1164
record = self .getSymbolRecord ()
1159
1165
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
1174
1184
1175
1185
def r_run (self , command ):
1176
1186
module = self .getVariable (command ['module' ])
@@ -1734,10 +1744,7 @@ def compileValue(self):
1734
1744
if symbolRecord ['valueHolder' ]:
1735
1745
value ['target' ] = symbolRecord ['name' ]
1736
1746
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' )
1741
1748
return None
1742
1749
1743
1750
if token == 'arg' :
@@ -2503,7 +2510,7 @@ def c_none(self, condition):
2503
2510
return not comparison if condition .negate else comparison
2504
2511
2505
2512
def c_not (self , condition ):
2506
- return not self .getRuntimeValue (condition .value1 )
2513
+ return not self .getRuntimeValue (condition .value )
2507
2514
2508
2515
def c_object (self , condition ):
2509
2516
comparison = type (self .getRuntimeValue (condition .value1 )) is dict
0 commit comments