1
- import json , math , hashlib , threading , os , requests , time
1
+ import json , math , hashlib , threading , os , requests , time , numbers
2
2
from datetime import datetime , timezone
3
3
from random import randrange
4
4
from ec_classes import FatalError , RuntimeError
@@ -124,7 +124,7 @@ def r_clear(self, command):
124
124
val ['type' ] = 'boolean'
125
125
val ['content' ] = False
126
126
self .putSymbolValue (target , val )
127
- self .add (command )
127
+ # self.add(command)
128
128
return self .nextPC ()
129
129
130
130
def k_close (self , command ):
@@ -173,7 +173,7 @@ def r_decrement(self, command):
173
173
return self .incdec (command , '-' )
174
174
175
175
def k_dictionary (self , command ):
176
- return self .compileVariable (command , False )
176
+ return self .compileVariable (command , 'dictionary' , False )
177
177
178
178
def r_dictionary (self , command ):
179
179
return self .nextPC ()
@@ -245,10 +245,10 @@ def k_exit(self, command):
245
245
return True
246
246
247
247
def r_exit (self , command ):
248
- return 0
248
+ return - 1
249
249
250
250
def k_file (self , command ):
251
- return self .compileVariable (command , False )
251
+ return self .compileVariable (command , 'file' , False )
252
252
253
253
def r_file (self , command ):
254
254
return self .nextPC ()
@@ -561,6 +561,7 @@ def r_print(self, command):
561
561
if value != None :
562
562
print (f'-> { value } ' )
563
563
return self .nextPC ()
564
+ return False
564
565
565
566
def k_put (self , command ):
566
567
command ['value' ] = self .nextValue ()
@@ -621,17 +622,20 @@ def k_read(self, command):
621
622
else :
622
623
command ['line' ] = False
623
624
if self .nextIsSymbol ():
624
- symbolRecord = self .getSymbolRecord ()
625
- if symbolRecord ['valueHolder' ]:
626
- if self .peek () == 'from' :
627
- self .nextToken ()
628
- if self .nextIsSymbol ():
629
- fileRecord = self .getSymbolRecord ()
630
- if fileRecord ['keyword' ] == 'file' :
631
- command ['target' ] = symbolRecord ['name' ]
632
- command ['file' ] = fileRecord ['name' ]
633
- self .add (command )
634
- return True
625
+ symbolRecord = self .getSymbolRecord ()
626
+ if symbolRecord ['valueHolder' ]:
627
+ if self .peek () == 'from' :
628
+ self .nextToken ()
629
+ if self .nextIsSymbol ():
630
+ fileRecord = self .getSymbolRecord ()
631
+ if fileRecord ['keyword' ] == 'file' :
632
+ command ['target' ] = symbolRecord ['name' ]
633
+ command ['file' ] = fileRecord ['name' ]
634
+ self .add (command )
635
+ return True
636
+ FatalError (self .program .compiler , f'Symbol "{ symbolRecord ["name" ]} " is not a value holder' )
637
+ return False
638
+ FatalError (self .program .compiler , f'Symbol "{ self .getToken ()} " has not been declared' )
635
639
return False
636
640
637
641
def r_read (self , command ):
@@ -781,13 +785,58 @@ def r_set(self, command):
781
785
self .putSymbolValue (target , val )
782
786
return self .nextPC ()
783
787
788
+ def k_split (self , command ):
789
+ if self .nextIsSymbol ():
790
+ symbolRecord = self .getSymbolRecord ()
791
+ if symbolRecord ['valueHolder' ]:
792
+ command ['target' ] = symbolRecord ['name' ]
793
+ command ['on' ] = '\n '
794
+ if self .peek () == 'on' :
795
+ self .nextToken ()
796
+ command ['on' ] = self .getValue ()
797
+ self .add (command )
798
+ return True
799
+ return False
800
+
801
+ def r_split (self , command ):
802
+ target = self .getVariable (command ['target' ])
803
+ value = self .getSymbolValue (target )
804
+ content = value ['content' ].split (command ['on' ])
805
+ elements = len (content )
806
+ target ['elements' ] = elements
807
+ target ['value' ] = [None ] * elements
808
+
809
+ for index , item in enumerate (content ):
810
+ element = {}
811
+ element ['type' ] = 'text'
812
+ element ['numeric' ] = 'false'
813
+ element ['content' ] = item
814
+ target ['value' ][index ] = element
815
+
816
+ return self .nextPC ()
817
+
784
818
def k_stop (self , command ):
785
819
self .add (command )
786
820
return True
787
821
788
822
def r_stop (self , command ):
789
823
return 0
790
824
825
+ def k_system (self , command ):
826
+ value = self .nextValue ()
827
+ if value != None :
828
+ command ['value' ] = value
829
+ self .add (command )
830
+ return True
831
+ FatalError (self .program .compiler , 'I can\' t give this command' )
832
+ return False
833
+
834
+ def r_system (self , command ):
835
+ value = self .getRuntimeValue (command ['value' ])
836
+ if value != None :
837
+ os .system (value )
838
+ return self .nextPC ()
839
+
791
840
def k_take (self , command ):
792
841
# Get the (first) value
793
842
command ['value1' ] = self .nextValue ()
@@ -862,17 +911,19 @@ def r_toggle(self, command):
862
911
val ['type' ] = 'boolean'
863
912
val ['content' ] = not value ['content' ]
864
913
self .putSymbolValue (target , val )
865
- self .add (command )
866
914
return self .nextPC ()
867
915
868
916
def k_variable (self , command ):
869
- return self .compileVariable (command , True )
917
+ return self .compileVariable (command , 'variable' , True )
870
918
871
919
def r_variable (self , command ):
872
920
return self .nextPC ()
873
921
874
922
def k_wait (self , command ):
875
- command ['value' ] = self .nextValue ()
923
+ value = self .nextValue ()
924
+ if value is None :
925
+ return False
926
+ command ['value' ] = value
876
927
multipliers = {}
877
928
multipliers ['milli' ] = 1
878
929
multipliers ['millis' ] = 1
@@ -881,7 +932,7 @@ def k_wait(self, command):
881
932
multipliers ['second' ] = 1000
882
933
multipliers ['seconds' ] = 1000
883
934
multipliers ['minute' ] = 60000
884
- multipliers ['minutes7 ' ] = 60000
935
+ multipliers ['minutes ' ] = 60000
885
936
command ['multiplier' ] = multipliers ['second' ]
886
937
token = self .peek ()
887
938
if token in multipliers :
@@ -1379,15 +1430,13 @@ def v_property(self, v):
1379
1430
target = self .getVariable (v ['target' ])
1380
1431
target = self .getSymbolValue (target )
1381
1432
content = target ['content' ]
1382
- if content == '' :
1383
- content = ''
1384
- content ['name' ] = '(anon)'
1433
+ val = content .get (name )
1385
1434
value = {}
1386
- value ['type ' ] = 'text'
1387
- if content . get ( name ):
1388
- value ['content ' ] = content [ name ]
1435
+ value ['content ' ] = val
1436
+ if isinstance ( v , numbers . Number ):
1437
+ value ['type ' ] = 'int'
1389
1438
else :
1390
- value ['content ' ] = ''
1439
+ value ['type ' ] = 'text '
1391
1440
return value
1392
1441
1393
1442
def v_random (self , v ):
@@ -1572,7 +1621,10 @@ def c_includes(self, condition):
1572
1621
1573
1622
def c_empty (self , condition ):
1574
1623
value = self .getRuntimeValue (condition ['value1' ])
1575
- comparison = len (value ) == 0
1624
+ if value == None :
1625
+ comparison = True
1626
+ else :
1627
+ comparison = len (value ) == 0
1576
1628
return not comparison if condition ['negate' ] else comparison
1577
1629
1578
1630
def c_exists (self , condition ):
0 commit comments