QuickNote: Sending Events (generated code)
The handCompiled, generated to send an event is about 4 to 6 lines; depending on the The Machinery (ToDo), with a lot of similarity. It is however buried in lot of other code, notes, ect. And therefore hard to see the difference.
Here, we collect al those pieces, and see which lines/fragments are common – and can go into a template. And which parts we have to fill-in.
See also
.../SIEVE/1.WorkCopy/CC-event-sieve.Castle-handCompiled.c
(also on OSDN)The Machinery part is now in QuickNote: Sending Events & Machinery
The Jinja templating study can be found in QuickNote: Jinja Events (templating)
Tip
The assert & printf/debug statements (in C code) are removed, for clarity. As are most comments
CC_E_Generator__StartSieve_runTo__controll
self.outlet.input(i);
Generated
{
struct CC_B_OutPort outport = self->outlet;
CC_ComponentType receiver = outport.connection;
CC_B_eDispatchTable handlers = outport.handlers;
CC_E_SimpleSieve_input_FT signal = (CC_E_SimpleSieve_input_FT)handlers[CC_P_SimpleSieve_input];
signal(receiver, (CC_selfType)self, i);
}
CC_E_Sieve__SimpleSieve_input__try
self.coprime.input(try)
Generated
{
struct CC_B_OutPort outport = self->coprime;
CC_ComponentType receiver = outport.connection;
CC_B_eDispatchTable handlers = outport.handlers;
CC_E_SimpleSieve_input_FT signal = (CC_E_SimpleSieve_input_FT)handlers[CC_P_SimpleSieve_input];
signal(receiver, (CC_selfType)self, try);
}
CC_E_Finder__SimpleSieve_input__newPrime
self.found.input(foundPrime);
Generated
{
struct CC_B_OutPort outport = self->found;
CC_ComponentType receiver = outport.connection;
CC_B_eDispatchTable handlers = outport.handlers;
CC_E_SimpleSieve_input_FT signal = (CC_E_SimpleSieve_input_FT)handlers[CC_P_SimpleSieve_input];
signal(receiver, (CC_selfType)self, foundPrime);
}
CC_E_Main__powerOn__power
This one differs a bit, as .generator
is a sub(component), not a port<out>
Error
Probably, the Castle code was wrong: a Generator can handle runTo
, but only on it’s controll port.
The code is, but see below for an improved version
self.generator.runTo(max);
Which was generated into:
{
CC_ComponentType receiver = self->generator;
CC_B_eDispatchTable handlers = cc_S_Generator_controll; //XXX =self->generator->"controll"
CC_E_StartSieve_runTo_FT signal = (CC_E_StartSieve_runTo_FT)handlers[CC_P_StartSieve_runTo];
signal(receiver, (CC_selfType)self, max);
}
Note
As you can see, there is abit of magic here
The improved Castle code is:
self.generator.controll.runTo(max);
Generated
That improved Castle-code is “generated again”:
{
CC_ComponentType sub = self->generator; // One extra line to find the sub-component
struct CC_B_OutPort outport = sub->controll;
CC_ComponentType receiver = outport.connection;
CC_B_eDispatchTable handlers = outport.handlers;
CC_E_StartSieve_runTo_FT signal = (CC_E_StartSieve_runTo_FT)handlers[CC_P_StartSieve_runTo];
signal(receiver, (CC_selfType)self, max);
}
Inline
When inlining the first two lines, we get the basic structure again
{
struct CC_B_OutPort outport = self->generator->controll; // Inline the first 2 lines
CC_ComponentType receiver = outport.connection;
CC_B_eDispatchTable handlers = outport.handlers;
CC_E_StartSieve_runTo_FT signal = (CC_E_StartSieve_runTo_FT)handlers[CC_P_StartSieve_runTo];
signal(receiver, (CC_selfType)self, max);
}
Comments
comments powered by Disqus