• 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

Revision13d14ce7755e1e647daeedf4beab56a7222294e7 (tree)
Time2023-08-25 22:00:01
AuthorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Imlementing Sieve

Change Summary

Incremental Difference

diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/_debug.py Fri Aug 25 15:00:01 2023 +0200
@@ -18,6 +18,7 @@
1818 if name_only:
1919 return (str(self.__class__.__name__)
2020 + (("[_label=%s]" % self._debug_label) if self._debug_label != DebugMixIn._debug_label else "")
21+ + "()"
2122 )
2223 else:
2324 return str(self.__class__.__name__) + "(" + self._debug_attr_(name_only) + ")"
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/buildin/CC_B_Component.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/buildin/CC_B_Component.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/CC/buildin/CC_B_Component.py Fri Aug 25 15:00:01 2023 +0200
@@ -8,9 +8,6 @@
88 def _debug_attr_(self, name_only=True):
99 # Same order as __init__
1010 # Don't call _debug.DebugMixIn._debug_attr_
11- if name_only:
12- return ""
13- else:
14- return ("isa=" + self.isa._debug_(name_only=True))
11+ return ("isa=" + self.isa._debug_(name_only=name_only))
1512
1613
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/Demo__Sieve.py Fri Aug 25 15:00:01 2023 +0200
@@ -31,9 +31,9 @@
3131 # ToDo: S->S
3232 pass
3333
34- FinderMoat.debug() # To compare with SieveMoat
3534 SieveMoat.debug()
36- #SieveClass.debug()
35+ FinderClass.debug() # To compare with SieveMoat
36+ SieveClass.debug()
3737
3838 return 0
3939
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderClass.py Fri Aug 25 15:00:01 2023 +0200
@@ -5,7 +5,6 @@
55 # Hi-lock: (("@@ TRACE:?" (0 (quote ediff-fine-diff-C) prepend)))
66
77 import SimpleSieve
8-from SimpleSieve import CC_P_SimpleSieve_input #XXX
98
109 from CC import buildin
1110 from CC import base
@@ -53,9 +52,11 @@
5352 self.found = buildin.CC_B_OutPort()
5453
5554 # Then the local/member vars
55+ self._castle_init()
56+
57+ def _castle_init(self):
5658 pass
5759
58-
5960 def _debug_attr_(self, name_only=True):
6061 # Same order as __init__
6162 if name_only:
@@ -69,7 +70,7 @@
6970 # GAM/Note: As the methods are 'in' the CC_Finder namespace, the '*_Finder' prefix is not needed ...
7071 # ... ``CC_E_Finder__SimpleSieve_input__newPrime`` => SimpleSieve_input__newPrime
7172
72- def SimpleSieve_input__newPrime(self, foundPrime):
73+ def SimpleSieve_input__newPrime(self, foundPrime): # handCompiledC: CC_E_Finder__SimpleSieve_input__newPrime
7374 """///CastleCode
7475 SimpleSieve.input(foundPrime) on self.newPrime
7576 {
@@ -78,7 +79,7 @@
7879 ///end"""
7980
8081 print ("@@ TRACE: %s.SimpleSieve_input__newPrime" % self._debug_(name_only=True)
81- + "foundPrime= %s" %foundPrime)
82+ + "foundPrime=%s" % foundPrime)
8283
8384 outport = self.found; assert isinstance(outport, buildin.CC_B_OutPort), "outport is not CC_B_OutPort, but %s" % type(outport)
8485 receiver = outport.connection;
@@ -90,7 +91,7 @@
9091 assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
9192 handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list"
9293
93- handler = handlers[CC_P_SimpleSieve_input] # NOTE: in handCompiled: 'signal'; now handler
94+ handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
9495 print ('=== TRACE SimpleSieve_input__newPrime:: handler=' + _debug.handler_name(handler))
9596
9697 # XXX REFACTOR: do not hard-code the Machinery :-)
@@ -117,12 +118,12 @@
117118
118119
119120
120-def debug():
121+def debug(name_only=False):
121122 from CC import _debug
122123 # Remember: print for Python 2&3
123124 print ("DEBUG: " + _debug.file_stem(__file__))
124125 print ("The generated class:: CC_Finder()")
125- print ("< " + CC_Finder()._debug_())
126- print ("> cc_C_Finder=" + cc_C_Finder._debug_())
126+ print ("< " + CC_Finder()._debug_(name_only=name_only))
127+ print ("> cc_C_Finder=" + cc_C_Finder._debug_(name_only=name_only))
127128
128129
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderMoat.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderMoat.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/FinderMoat.py Fri Aug 25 15:00:01 2023 +0200
@@ -37,7 +37,6 @@
3737
3838
3939
40-
4140 def debug(name_only=False):
4241 from CC import _debug
4342 # Remember: print for Python 2&3
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveClass.py Fri Aug 25 15:00:01 2023 +0200
@@ -1,38 +1,106 @@
1-# Hi-lock: (("///.*$" (0 (quote hi-pink) prepend)))
1+
22 # Hi-lock: (("^ *def [^:]+:" (0 (quote info-title-4) prepend)))
33 # Hi-lock: (("^ *class [^:]+:" (0 (quote info-title-3) prepend)))
44 # Hi-lock: (("=== TRACE:?" (0 (quote ediff-fine-diff-Ancestor) prepend)))
55 # Hi-lock: (("@@ TRACE:?" (0 (quote ediff-fine-diff-C) prepend)))
66
77 import SimpleSieve
8-from SimpleSieve import cc_P_SimpleSieve
9-
108 from CC import buildin
119 from CC import base
1210 from CC import _debug
1311 from CC import machinery
14-import FinderMoat
12+import SieveMoat
1513
1614 """///CastleCode
1715 implement Sieve {
1816 int myPrime;
1917 ///end"""
2018
21-"""///CastleCode
22--init(onPrime:int)
23-{
24- super.init(); //note 'super' acts as a port
25- self.myPrime := onPrime;
26-}
27-///end"""
19+class CC_Sieve(buildin.CC_B_Component) : # Generated class;
2820
29-"""///CastleCode
30-SimpleSieve.input(try) on .try
31-{
32- if ( (try % self.myPrime) !=0 ) {
33- self.coprime.input(try);
34- }
35-}
36-} //@end Sieve
37-///end"""
21+ def __init__(self, *args): #NOTE: **kwags not supported in rPython
22+ #First, the inherited members #GAM: Py2&3 & static version of super()
23+ buildin.CC_B_Component.__init__(self, isa=cc_C_Sieve)
3824
25+ # Then the outports (not the inport)
26+ self.coprime = buildin.CC_B_OutPort()
27+
28+ # Then the local/member vars
29+ self._castle_init(onPrime=args[0])
30+
31+ def _castle_init(self, onPrime): # In handCompiledC: C_Mi_Sieve__init
32+ """///CastleCode
33+ -init(onPrime:int)
34+ {
35+ super.init(); //note 'super' acts as a port
36+ self.myPrime := onPrime;
37+ }
38+ ///end"""
39+ self.myPrime=onPrime
40+
41+ def _debug_attr_(self, name_only=True):
42+ # Same order as __init__
43+ if name_only:
44+ return buildin.CC_B_Component._debug_attr_(self, name_only)
45+ else:
46+ return (buildin.CC_B_Component._debug_attr_(self)
47+ + ", self.coprime=" + self.coprime._debug_()
48+ + ", .myPrime=%s" % self.myPrime
49+ )
50+
51+ #GAM Note: ``try`` is not an allowed var in python; use try_
52+ def SimpleSieve_input__try(self, try_): # handCompiledC: CC_E_Sieve__SimpleSieve_input__try
53+ """///CastleCode
54+ SimpleSieve.input(try) on .try
55+ {
56+ if ( (try % self.myPrime) !=0 ) {
57+ self.coprime.input(try);
58+ }
59+ }
60+ } //@end Sieve
61+ ///end"""
62+
63+ print ("@@ TRACE: %s.SimpleSieve_input__try" % self._debug_(name_only=True)
64+ + "try=%s" % try_)
65+
66+
67+ if try_ % self.myPrime:
68+
69+ outport = self.coprime; assert isinstance(outport, buildin.CC_B_OutPort), "outport is not CC_B_OutPort, but %s" % type(outport)
70+ receiver = outport.connection
71+ if not receiver:
72+ print ("""-XXX For now: skip when outport.connection==None""")
73+ return
74+ assert isinstance(receiver, buildin.CC_B_Component), "receiver is not CC_B_Component[aka: CC_ComponentType], but %s" % type(receiver)
75+ handlers = outport.handlers; assert handlers, "handlers shouldn't be None, nor an empty list"
76+ handler = handlers[SimpleSieve.CC_P_SimpleSieve_input]
77+ # XXX REFACTOR: do not hard-code the Machinery :-)
78+ if machinery.Machinery == machinery.DirectCall:
79+ handler(try_)
80+ elif machinery.Machinery == machinery.LibDispatch:
81+ assert False, "machinery: %s unsupported (yet)" % machinery.Machinery
82+ elif machinery.Machinery == machinery.DDS:
83+ assert False, "machinery: %s unsupported" % machinery.Machinery
84+ else:
85+ assert False, "machinery: %s is unknown" % machinery.Machinery
86+ return
87+
88+ # XXXX
89+cc_C_Sieve = buildin.CC_B_ComponentClass(
90+ interface = SieveMoat.cc_CI_Sieve,
91+ methods = [], # XXX Is this needed? As the are 'in" CC_Sieve"
92+ isa = None, # Later: use for meta-classes; For now isa is optional
93+ #instance_size = sys.getsizeof(CC_Sieve), Not needed for rPython
94+ )
95+
96+
97+
98+def debug(name_only=False):
99+ from CC import _debug
100+ # Remember: print for Python 2&3
101+ print ("DEBUG: " + _debug.file_stem(__file__))
102+ print ("The generated class:: CC_Sieve(-42)")
103+ print ("< " + CC_Sieve(-42)._debug_(name_only=name_only))
104+ print ("> cc_C_Sieve=" + cc_C_Sieve._debug_(name_only=name_only))
105+
106+
diff -r 7581c0ffc9b0 -r 13d14ce7755e CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveMoat.py
--- a/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveMoat.py Fri Aug 25 11:52:30 2023 +0200
+++ b/CMP_OTHER_LANGUAGES/Sieve_in_rPython/SieveMoat.py Fri Aug 25 15:00:01 2023 +0200
@@ -14,7 +14,7 @@
1414
1515 cc_CI_Sieve = buildin.CC_B_ComponentInterface(name = "Sieve",
1616 inherit_from = base.cc_CI_Component,
17- ports = []) #Need to append afterwards
17+ ports = []) # GAM:SEE Note in FinderMoat
1818
1919 cc_CI_Sieve.ports.append(
2020 buildin.CC_B_C_PortID(name="try",
@@ -32,6 +32,7 @@
3232 #/// Moat part is done
3333
3434
35+
3536 def debug(name_only=False):
3637 # Remember: print for Python 2&3
3738 from CC import _debug