• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisione8d97b579ee7fd491183514720a4b9cd749b26e6 (tree)
Time2023-09-02 19:30:29
AuthorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

The 1ste run of 'The Sieve' (in hack/run) works (HeHe)

Change Summary

Incremental Difference

diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py Sat Sep 02 12:30:29 2023 +0200
@@ -35,6 +35,10 @@
3535 def _debug_name(self):
3636 return '<<debug_name to be done>>'
3737
38+ def _class_name(self):
39+ return str(self.__class__.__name__)
40+
41+
3842 def _obj_name(obj):
3943 return obj._debug_name() if obj else "None"
4044
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py Sat Sep 02 12:30:29 2023 +0200
@@ -22,30 +22,34 @@
2222 trace_level = int(argv[2]) if len(argv)>2 else 1
2323 print ("Starting Sieve_in_rPython/" + prog + " ".join(argv[1:]) + " [trace_level=%s]" % trace_level) #Python-2 & -3 compatible
2424
25- if trace_level>=5:
25+ if trace_level>=6:
2626 FinderMoat.debug()
2727 FinderClass.debug()
2828 SimpleSieve.debug() #protocol
2929
30- if trace_level>=4:
30+ if trace_level>=5:
3131 SieveMoat.debug()
3232 SieveClass.debug()
3333
34- if trace_level>=3:
34+ if trace_level>=4:
3535 hack.connectFs()
3636 hack.connectSs()
3737
38- if trace_level>=2:
38+ if trace_level>=3:
3939 GeneratorMoat.debug()
4040 StartSieve.debug() #protocol
4141 GeneratorClass.debug()
4242
43- if trace_level>=1:
43+ if trace_level>=2:
4444 hack.connectGSF()
4545
46+ if trace_level>=1:
47+ MainMoat.debug()
48+ MainClass.debug()
49+
4650 # ToDo:
47- MainMoat.debug()
48- MainClass.debug()
51+ hack.run()
52+
4953
5054 return 0
5155
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py Sat Sep 02 12:30:29 2023 +0200
@@ -76,7 +76,7 @@
7676 }
7777 ///end"""
7878
79- print ("@@ TRACE: %s.SimpleSieve_input__newPrimefoundPrime=%s" % (self._debug_(name_only=True), foundPrime))
79+ print ("@@ TRACE: %s.SimpleSieve_input__newPrime foundPrime=%s" % (self._debug_(name_only=True), foundPrime))
8080
8181 outport = self.found; assert isinstance(outport, buildin.CC_B_OutPort), "outport is not CC_B_OutPort, but %s" % type(outport)
8282 receiver = outport.connection;
@@ -86,7 +86,7 @@
8686 assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
8787 handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list"
8888 handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
89- print ('=== TRACE trigger .found:: handler=%s, receiver=%s' % (receiver._debug_(), _debug.handler_name(handler)))
89+ print ('=== TRACE trigger .found.input:: receiver=%s, handler=%s' % (receiver._debug_(), _debug.handler_name(handler)))
9090
9191 # XXX REFACTOR: do not hard-code the Machinery :-)
9292 assert machinery.Machinery == machinery.DirectCall, "Only 'machinery.DirectCall' is supported"
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/GeneratorClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/GeneratorClass.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/GeneratorClass.py Sat Sep 02 12:30:29 2023 +0200
@@ -71,12 +71,13 @@
7171 outport = self.outlet; assert isinstance(outport, buildin.CC_B_OutPort), "outport is not CC_B_OutPort, but %s" % type(outport)
7272 receiver = outport.connection
7373 if not receiver:
74- print ("=== TRACE `self.coprime` not connected :: skip")
74+ print ("=== TRACE<i=%s> `self.coprime` not connected :: skip" % i)
7575 else:
7676 assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
7777 handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list"
7878 handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
79- print ('=== TRACE trigger .outport:: handler=%s, receiver=%s' % (receiver._debug_(), _debug.handler_name(handler)))
79+ print ('=== TRACE(<i=%s>trigger .outport.input:: receiver=%s, handler=%s' % (
80+ i, receiver._debug_(), _debug.handler_name(handler)))
8081
8182 # XXX REFACTOR: do not hard-code the Machinery :-)
8283 assert machinery.Machinery == machinery.DirectCall, "Only 'machinery.DirectCall' is supported"
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/MainClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/MainClass.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/MainClass.py Sat Sep 02 12:30:29 2023 +0200
@@ -48,27 +48,34 @@
4848 .generator.outlet = .finder.newPrime; // Initially, there aren't any Sieves
4949
5050 self.lastSieve := Ground;
51+
52+ ??? connect hack??? "pin 1"
5153 }
5254 ///end"""
5355 # XXX ??? self := super.init()
5456 self.generator = GeneratorClass.CC_Generator()
5557 self.finder = FinderClass.CC_Finder()
5658
57- # connect
59+ #line ``.generator.outlet = .finder.newPrime``
5860 self.generator.outlet.connection = self.finder
5961 self.generator.outlet.handlers = FinderClass.cc_S_Finder_newPrime
6062
63+ #line ``self.lastSieve := Ground``
6164 self.lastSieve = None
6265
66+ #line connect hack pin 1 ``.finder.found = self."pin 1"``
67+ self.finder.found.connection = self
68+ self.finder.found.handlers = cc_S_Main__pin1 # handCompiled: `cc_S_Main_pin__generator_found`
69+
6370 def _debug_attr_(self, name_only=True):
6471 # Same order as __init__
6572 if name_only:
6673 return buildin.CC_B_Component._debug_attr_(self, name_only=name_only)
6774 else:
6875 return (buildin.CC_B_Component._debug_attr_(self)
69- + "sub generator=" + self.generator._debug_() if self.generator else ""
70- + "sub finder=" + self.finder._debug_() if self.finder else ""
71- + "alias lastSieve=" + self.lastSieve._debug_() if self.lastSieve else "Ground"
76+ + ", sub:generator=" + (self.generator._debug_() if self.generator else "")
77+ + ", sub:finder=" + (self.finder._debug_() if self.finder else "")
78+ + ", alias:lastSieve=" + (self.lastSieve._debug_() if self.lastSieve else "Ground")
7279 )
7380
7481
@@ -80,36 +87,59 @@
8087
8188 s:= Sieve.new(newPrime);
8289 s.coprime = self.finder.newPrime;
83- if (not self.lastSieve == Ground) { // .lastSieve == Ground, so not connected, so we have the first Sieve to connect to .generator
90+
91+ if (self.lastSieve == Ground) { // .lastSieve == Ground, so not connected, so we have the first Sieve to connect to .generator
8492 self.generator.outlet = s.try;
85- self.generator.outlet.queue.removeLimit();
93+ #self.generator.outlet.queue.removeLimit();
8694 } else {
8795 self.lastSieve.coprime = s.try;
88- self.lastSieve.coprime.queue.removeLimit();
96+ #self.lastSieve.coprime.queue.removeLimit();
8997 }
9098 .lastSieve := s;
9199
92- self.generator.collect.input(newPrime); // forward the prime to the Generator
100+ .generator.collect.input(newPrime); // forward the prime to the Generator
93101 }
94102 ///end"""
95103 print ("@@ TRACE: %s. SimpleSieve_try__generator_found(%s)" % (self._debug_(name_only=True), newPrime))
96104
97- s = SieveClass.CC_Sieve(newPrime)
105+ s = SieveClass.CC_Sieve(newPrime); s._set_label('s%s' % newPrime)
106+
98107 s.coprime.connection = self.finder
99- s.coprime.handlers = SieveClass.cc_S_Sieve_try
108+ s.coprime.handlers = FinderClass.cc_S_Finder_newPrime
100109
101- if not self.lastSieve == None:
102- self.generator.outlet.connection = s.try_
103- self.generator.outlet.handlers = SieveClass.cc_S_Sieve_try
110+ print ("=== TRACE self=%s s=%s, " % (self._debug_(name_only=False), s._debug_(name_only=False)))
111+
112+ if self.lastSieve == None:
113+ print ("=== TRACE/CONNECT:\tCastleCode:: ``.generator.outlet = s.try``")
114+ self.generator.outlet.connection = s
115+ self.generator.outlet.handlers = SieveClass.cc_S_Sieve_try #<<< HardCoded DispatchTable
104116 # XXX ToDo self.generator.outlet.queue.removeLimit()
105117 else:
106- self.lastSieve.outlet.connection = s.try_
107- self.lastSieve.outlet.handlers = SieveClass.cc_S_Sieve_try
118+ print ("=== TRACE/Connect:\tCastleCode:: ``lastSieve.coprime = s.try``")
119+ self.lastSieve.coprime.connection = s
120+ self.lastSieve.coprime.handlers = SieveClass.cc_S_Sieve_try #<<< HardCoded DispatchTable
108121 # XXX ToDo self.lastSieve.outlet.queue.removeLimit()
109122 self.lastSieve = s
110123
111- GeneratorClass.cc_S_Generator_collect[SimpleSieve.CC_P_SimpleSieve_input](self.generator, newPrime)
112- #end SimpleSieve.try(newPrime) on self.generator.found
124+ print ("=== TRACE self=%s" % (self._debug_(name_only=False)))
125+
126+ #line:``.generator.collect.input(newPrime)`` // forward the prime to the Generator
127+ print ("=== TRACE/trigger-direct:\tCastleCode:: ``self.generator.collect.input(newPrime)`` ??")
128+
129+ receiver = self.generator
130+ if not receiver:
131+ print ("=== TRACE receiver `self.generator` not connected :: skip")
132+ elif False:
133+ # OLD, BUGGY
134+ assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
135+ handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list" #XXX outport=None
136+ handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
137+ print ('=== TRACE trigger .found.input:: receiver=%s, handler=%s' % (receiver._debug_(), _debug.handler_name(handler)))
138+ # XXX REFACTOR: do not hard-code the Machinery :-)
139+ assert machinery.Machinery == machinery.DirectCall, "Only 'machinery.DirectCall' is supported"
140+ handler(receiver, foundPrime)
141+ else:
142+ GeneratorClass.cc_S_Generator_collect[SimpleSieve.CC_P_SimpleSieve_input](self.generator, newPrime)
113143
114144
115145 def powerOn__power(self):
@@ -124,7 +154,7 @@
124154 print ("@@ TRACE: %s.powerOn__power(s)" % (self._debug_(name_only=True),))
125155
126156 max = 10
127- Generator.cc_S_Generator_controll[StartSieve.CC_P_StartSieve_runTo](self.generator, max)
157+ GeneratorClass.cc_S_Generator_controll[StartSieve.CC_P_StartSieve_runTo](self.generator, max)
128158 #End CC_Main
129159
130160
@@ -135,10 +165,22 @@
135165 #instance_size = sys.getsizeof(CC_Main), Not needed for rPython
136166 )
137167
138-cc_S_Main_controll = [
139- "ToDo",
140- "XXX",
168+CC_P_Power_On = 1
169+cc_S_Main_power = [
170+ None,
171+ CC_Main.powerOn__power,
141172 ]
173+assert CC_P_Power_On == 1, "Trivials - set above"
174+assert cc_S_Main_power[CC_P_Power_On] == CC_Main.powerOn__power
175+
176+cc_S_Main__pin1 = [
177+ None, None, None, None, None, None, # 0-5: not relevant here
178+ CC_Main.SimpleSieve_try__generator_found, # 6/CC_P_SimpleSieve_input
179+ ]
180+assert SimpleSieve.CC_P_SimpleSieve_input == 6, " Event should be on the correct index"
181+assert cc_S_Main__pin1[SimpleSieve.CC_P_SimpleSieve_input] == CC_Main.SimpleSieve_try__generator_found
182+
183+
142184
143185 def debug(name_only=False):
144186 from CC import _debug
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/NOTES.rst
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/NOTES.rst Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/NOTES.rst Sat Sep 02 12:30:29 2023 +0200
@@ -2,6 +2,12 @@
22 (development) NOTES
33 ===================
44
5+.. todo:: PRIO: DispatchTable of receiver, not hardcoded!
6+
7+ Currently the (name of) the DispatchTable is hardcoded. THIS IS WRONG
8+
9+ By example: When using TheSieve (aka MainClass) via hack.run(), it goes wrong in SieveClass
10+
511 .. todo:: init-parameters
612
713 When creating a ``Sieve`` (element) the parameter “myPrime” s needed. This is used in CastleCode:
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py Sat Sep 02 12:30:29 2023 +0200
@@ -26,6 +26,7 @@
2626 self.coprime = buildin.CC_B_OutPort()
2727 # Then the local/member vars
2828 self._castle_init(onPrime=args[0])
29+ print ("=== TRACE Created: %s" % self._debug_(name_only=False))
2930
3031 def _castle_init(self, onPrime): # In handCompiledC: C_Mi_Sieve__init
3132 """///CastleCode
@@ -58,19 +59,19 @@
5859 }
5960 ///end"""
6061
61- print ("@@ TRACE: %s.SimpleSieve_input__try(try=%s)" % (self._debug_(name_only=True), try_))
62+ print ("@@ TRACE: CC_Sieve.SimpleSieve_input__try(%s, try=%s)" % (self._debug_(name_only=True), try_))
6263
6364 if try_ % self.myPrime:
6465 outport = self.coprime; assert isinstance(outport, buildin.CC_B_OutPort), "outport is not CC_B_OutPort, but %s" % type(outport)
6566 receiver = outport.connection
6667 if not receiver:
67- print ("=== TRACE `self.coprime` not connected :: skip")
68+ print ("=== TRACE (Sieve) `self.coprime` not connected :: skip")
6869 else:
6970 assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
7071 handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list"
7172 handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
72- print ('=== TRACE trigger .coprime:: handler=%s, receiver=%s' % (receiver._debug_(), _debug.handler_name(handler)))
73-
73+ print ('=== TRACE (Sieve) trigger .coprime.input():: receiver=%s, handler=%s' % (
74+ receiver._debug_(), _debug.handler_name(handler)))
7475 # XXX REFACTOR: do not hard-code the Machinery :-)
7576 assert machinery.Machinery == machinery.DirectCall, "Only 'machinery.DirectCall' is supported"
7677 handler(receiver, try_)
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/__init__.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/__init__.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/__init__.py Sat Sep 02 12:30:29 2023 +0200
@@ -2,3 +2,4 @@
22 from .connectFs import connectFs
33 from .connectSs import connectSs
44 from .connectGSF import connectGSF
5+from .run import run
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/connectGSF.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/connectGSF.py Fri Sep 01 17:18:28 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/connectGSF.py Sat Sep 02 12:30:29 2023 +0200
@@ -12,7 +12,7 @@
1212 print ("""\
1313 +-----------+ +=-------------+ +----------------+
1414 |g | |s2 | |f |
15- >.controll | | | | |
15+ >.controll | | | | |
1616 | .outlet >=======>.try .coprime >=======>.newPrime .found>==\\
1717 | .collect | | | | | ||
1818 +-^---------+ +--------------+ +----------------+ ||
@@ -37,7 +37,7 @@
3737 f.found.handlers = GeneratorClass.cc_S_Generator_collect
3838 print ("Now\t f: %s" % (f._debug_(name_only=False)))
3939
40- print ("=== HACK limit g.controll.runTo(8) -- See note!!")
40+ print ("=== HACK/trigger g.controll.runTo(8) -- See note!!")
4141 GeneratorClass.cc_S_Generator_controll[StartSieve.CC_P_StartSieve_runTo](g,8)
4242 print ("+ Note: It only/always sieves on '2' -- expect 3,5,7, ...")
4343
diff -r 4f83a4c9c101 -r e8d97b579ee7 CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/run.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/hack/run.py Sat Sep 02 12:30:29 2023 +0200
@@ -0,0 +1,26 @@
1+import MainClass
2+
3+def run():
4+ print ("""
5+XXX
6+XXX HACK::run()
7+XXX""")
8+ #board isn't a great, name; but the old Castle/handCompiled code uses it to.
9+ board = MainClass.CC_Main(); board._set_label('The Sieve')
10+ print ("""\
11+ +-------------------------------------------------+
12+ | board:Main:Board |
13+ | |
14+ > .power |
15+ | 'The Sieve' |
16+ +-------------------------------------------------+
17+ board: %s""" % board._debug_(name_only=False))
18+
19+ print ('XXX')
20+ print ('board.generator: ' + board.generator._debug_(name_only=False))
21+ print ('board.finder: ' +board.finder._debug_(name_only=False))
22+
23+ print ("=== HACK/trigger: board.power.powerOn()")
24+ MainClass.cc_S_Main_power[MainClass.CC_P_Power_On](board) # XXX Main=>Power
25+
26+