Skip to content

Commit bcccb77

Browse files
committed
Update Python version
1 parent a2a4650 commit bcccb77

File tree

6 files changed

+293
-0
lines changed

6 files changed

+293
-0
lines changed

py/benchmark.ecs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
script Benchmark
2+
3+
variable Start
4+
variable Finish
5+
variable N
6+
variable M
7+
variable Array
8+
variable X
9+
variable Y
10+
variable Z
11+
file File
12+
13+
dictionary Dictionary
14+
15+
!go to Skip
16+
17+
print `FOR loop counting to 10,000`
18+
put now into Start
19+
put 0 into N
20+
while N is less than 10000 increment N
21+
put now into Finish
22+
take Start from Finish giving N
23+
print N cat ` milliseconds`
24+
25+
! debug step
26+
27+
print `Compare 10,000 long integers for equality`
28+
put now into Start
29+
put 0 into N
30+
while N is less than 10000
31+
begin
32+
if N is 1234567890 begin end
33+
increment N
34+
end
35+
put now into Finish
36+
take Start from Finish giving N
37+
print N cat ` milliseconds`
38+
39+
print `Allocate and initialize a 10,000 element array`
40+
put now into Start
41+
set the elements of Array to 10000
42+
put 0 into N
43+
while N is less than 10000
44+
begin
45+
index Array to N
46+
put N into Array
47+
increment N
48+
end
49+
put now into Finish
50+
take Start from Finish giving N
51+
print N cat ` milliseconds`
52+
53+
print `Allocate and initialize a 50x50 dictionary`
54+
put now into Start
55+
put 0 into N
56+
while N is less than 50
57+
begin
58+
put 0 into M
59+
while M is less than 50
60+
begin
61+
put M into Dictionary as N cat ` ` cat M
62+
increment M
63+
end
64+
increment N
65+
end
66+
put now into Finish
67+
take Start from Finish giving N
68+
print N cat ` milliseconds`
69+
70+
put empty into X
71+
set property `name` of X to `Fred`
72+
print property `name` of X
73+
put empty into Y
74+
put 1 into N
75+
while N is less than 6
76+
begin
77+
append N to Y
78+
increment N
79+
end
80+
set element 2 of Y to `Some data`
81+
print element 2 of Y
82+
if N is numeric print `Numeric`
83+
set Y
84+
print `Set: ` cat Y
85+
clear Y
86+
print `Clear: ` cat Y
87+
toggle Y
88+
print `Toggle: ` cat Y
89+
toggle Y
90+
print `Toggle: ` cat Y
91+
92+
set Y
93+
if Y is boolean print `Boolean` else print `Not Boolean`
94+
put 5 into Y
95+
if Y is boolean print `Boolean` else print `Not Boolean`
96+
put `hello` into Y
97+
if Y is boolean print `Boolean` else print `Not Boolean`
98+
99+
put 0 into N
100+
while N is less than 10
101+
begin
102+
if N is even print N cat ` is even`
103+
if N is odd print N cat ` is odd`
104+
add 1 to N
105+
end
106+
107+
put 51 into N
108+
while N is less than 54
109+
begin
110+
if 52 is greater than N print `52 is greater than ` cat N else print `52 is not greater than cat N
111+
if 52 is less than N print `52 is less than ` cat N else print `52 is not less than ` cat N
112+
if 52 is not greater than N print `52 is not greater than ` cat N else print `52 is greater than ` cat N
113+
if 52 is not less than N print `52 is not less than ` cat N else print `52 is less than ` cat N
114+
add 1 to N
115+
end
116+
117+
print `Start`
118+
fork to Concurrent
119+
put 0 into N
120+
Loop1:
121+
gosub to Print
122+
wait 10 ticks
123+
add 1 to N
124+
if N is less than 10 go to Loop1
125+
126+
open File `/home/graham/test.txt` for writing
127+
write line `Hello, world!` to File
128+
close File
129+
open File `/home/graham/test.txt` for appending
130+
write `I'm back!` to File
131+
close File
132+
133+
Skip:
134+
! put 500 into N
135+
! move to 400 400
136+
! wait 1
137+
! move right N in 1 second
138+
! move down N in 1 second
139+
! move left N in 1 second
140+
! move up N in 1 second
141+
142+
wait 2 seconds
143+
open File `/home/graham/test.txt` for reading
144+
read line X from File
145+
print X
146+
read X from File
147+
print X
148+
close File
149+
print `Exit!`
150+
exit
151+
152+
Print:
153+
print `N = ` cat N
154+
return
155+
156+
Concurrent:
157+
put 0 into M
158+
Loop2:
159+
print ` M = ` cat M
160+
wait 20 ticks
161+
add 1 to M
162+
if M is less than 10 go to Loop2
163+
stop

py/benchmark.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
from ec_program import Program
3+
from ec_core import Core
4+
from ec_autogui import Autogui
5+
6+
class EasyCoder:
7+
8+
def __init__(self):
9+
self.version = 1
10+
11+
domainMap = {}
12+
domainMap['core'] = Core
13+
# domainMap['autogui'] = Autogui
14+
15+
scriptName = '/home/graham/Dropbox/Code/VisualStudio/EasyCoder/easycoder.github.io/py/benchmark.ecs'
16+
f = open(scriptName, 'r')
17+
source = f.read()
18+
f.close()
19+
20+
Program(source, domainMap)
21+
22+
if __name__ == '__main__':
23+
EasyCoder()

py/rbr.ecs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
! RBR
2+
3+
file File
4+
variable Path
5+
variable Rooms
6+
variable Room
7+
variable RoomNumber
8+
variable Spec
9+
variable Sensor
10+
variable Relays
11+
variable Relay
12+
variable Times
13+
variable Value
14+
variable Message
15+
variable R
16+
variable L
17+
18+
script RBR
19+
! debug step
20+
21+
put `/home/graham/Dropbox/Code/VisualStudio/EasyCoder/easycoder.github.io/py` into Path
22+
23+
put the files of Path cat `/rooms` into Rooms
24+
put 0 into RoomNumber
25+
while RoomNumber is less than the count of Rooms
26+
begin
27+
put element RoomNumber of Rooms into Room
28+
gosub to ProcessRoom
29+
add 1 to RoomNumber
30+
end
31+
stop
32+
33+
ProcessRoom:
34+
open File Path cat `/rooms/` cat Room for reading
35+
read Spec from File
36+
close File
37+
put property `sensor` of Spec into Sensor
38+
open File Path cat `/sensors/` cat Sensor cat `/value.txt` for reading
39+
read Value from File
40+
close File
41+
put the length of Room into L
42+
take 5 from L
43+
put left L of Room into Message
44+
print Message cat `: ` cat Value
45+
put property `relays` of Spec into Relays
46+
put 0 into R
47+
while R is less than the count of Relays
48+
begin
49+
put element R of Relays into Relay
50+
post to `http://192.168.1.120:5555/relay/` cat Relay cat `/on`
51+
wait 5 seconds
52+
post to `http://192.168.1.120:5555/relay/` cat Relay cat `/off`
53+
add 1 to R
54+
end
55+
return

py/rbr.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
from ec_program import Program
3+
from ec_core import Core
4+
from ec_autogui import Autogui
5+
6+
class EasyCoder:
7+
8+
def __init__(self):
9+
self.version = 1
10+
11+
domainMap = {}
12+
domainMap['core'] = Core
13+
# domainMap['autogui'] = Autogui
14+
15+
scriptName = '/home/graham/Dropbox/Code/VisualStudio/EasyCoder/easycoder.github.io/py/rbr.ecs'
16+
f = open(scriptName, 'r')
17+
source = f.read()
18+
f.close()
19+
20+
Program(source, domainMap)
21+
22+
if __name__ == '__main__':
23+
EasyCoder()

py/rooms/Office.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"sensor": "6A7384",
3+
"relays": [
4+
51
5+
],
6+
"times": [
7+
{
8+
"start": "07:00",
9+
"finish": "09:00",
10+
"temp": 20
11+
},
12+
{
13+
"start": "09:00",
14+
"finish": "18:00",
15+
"temp": 23
16+
},
17+
{
18+
"start": "18:00",
19+
"finish": "23:00",
20+
"temp": 25
21+
},
22+
{
23+
"start": "23:00",
24+
"finish": "07:00",
25+
"temp": 17
26+
}
27+
]
28+
}

py/sensors/6A7384/value.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
21.38

0 commit comments

Comments
 (0)