Commit d19b237f authored by Savva Golubitsky's avatar Savva Golubitsky

pregen idle run ready

parent 9689f34c
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -34,7 +34,7 @@ class Func():
def __str__(self):
if self.module =="" or self.name =="":
return ''
return "{}_{}".format(self.module, self.name)
return "{}_{};".format(self.module, self.name)
class Selector(Func):
def __init__(self, ntransf, module="", name="", dummy=False):
......
......@@ -258,14 +258,6 @@ class Parser():
dot = re.sub(r"((digraph)|}|{)", "", dot)
dot = re.sub(r"\/\/.*", "", dot)
dot = re.sub(r"^\n$", "", dot)
#print("Checking graph...")
#graphcheck = re.search(r"\A(digraph)\w+\n?{((\/\/)*.*\n*)+}\Z", dot)
#if graphcheck is None:
# print("Incorrect graph, check syntax!")
# exit()
#
#print("Graph id good, processing!")
#dot = re.sub(r"//*$", "", dot)
dotlines = dot.splitlines()
dotlines = list(filter(None, dotlines))
self.fact.name = dotlines[0]
......@@ -305,8 +297,69 @@ class Parser():
self.edgemap[root] = list(filter(lambda x: x["morph"] != '', edges))
return
checked=[]
bushes = []
def generate_cpp(self):
self._gen_branch(self.fact.graph.init_state)
print(self.edgemap)
states_to_check = [self.fact.graph.init_state]
while len(states_to_check)!=0:
for st in states_to_check:
self.checked.append(st)
states_to_check.remove(st)
bush = _Bush(st)
print("ins:", bush.state.name)
bush.grow_bush()
self.bushes.append(bush)
for i, br in enumerate(bush.branches):
for b in br:
print(i, b)
print("outs:")
for outs in bush.outstates:
print(outs.name)
if outs not in states_to_check and outs not in self.checked:
states_to_check.append(outs)
class _Tr():
slots=(
'pred',
'morph'
)
def __init__(self, transf):
self.pred = transf.edge.pred_f
self.morph = transf.edge.morph_f
def __str__(self):
return "{}\n{}\n".format(self.pred, self.morph)
class _Bush():
__slots__=(
'state',
'selector',
'branches',
'outstates'
)
def __init__(self, state):
self.state = state
self.selector = state.selector
self.branches = []
self.outstates = []
def grow_bush(self):
for t in self.state.transfers:
branch = [_Tr(t)]
self._gen_branch(t.output_state, branch)
def _gen_branch(self, cur_state, branch):
# print("generating", cur_state.name)
while len(cur_state.transfers)==1 and cur_state.input_edges_number==1:
tr = cur_state.transfers[0]
branch.append(_Tr(tr))
cur_state = tr.output_state
self.branches.append(branch)
if cur_state not in self.outstates:
self.outstates.append(cur_state)
\ No newline at end of file
......@@ -4,7 +4,7 @@
typedef std::function<int(com::Anymap)> IntFunc;
typedef std::function<bool(com::Anymap)> BoolFunc;
typedef std::function<std::list<bool>(com::Anymap)> BoolListFunc;
typedef std::function<bool*(com::Anymap)> BoolArrFunc;
IntFunc LoadEntry(std::string lib, std::string func) {
DllHandle handler;
......@@ -16,12 +16,11 @@ BoolFunc LoadPred(std::string lib, std::string func) {
return com::lib::loadFunction<int (com::Anymap), DllHandle>(lib.c_str(), func.c_str(), handler);
}
BoolListFunc LoadSelector(std::string lib, std::string func){
BoolArrFunc LoadSelector(std::string lib, std::string func){
DllHandle handler;
return com::lib::loadFunction<std::list<bool> (com::Anymap), DllHandle>(lib.c_str(), func.c_str(), handler);
}
int main(int argc, char const *argv[])
{
auto data = com::Anymap();
......@@ -35,23 +34,15 @@ int main(int argc, char const *argv[])
}
entrFunc(data);
SELECTOR:
ST_selector_val = selector(data);
for (int i=0; i<ST_selector_val.size(); i++) {
std::thread thr();
goto TERM;
//if (ST_selector_val.begin+0) {
// ST_selector_val.begin+0 = !ST_selector_val.begin+0;
// goto TERM;
//}
//if (ST_selector_val.begin+1) {
// ST_selector_val.begin+1 = !ST_selector_val.begin+1;
// goto SELECTOR;
//}
if (ST_selector_val[0]) {
branch1();
}
if(ST_selector_val[1]) {
branch2();
}
TERM:
std::cout<<"Termination!\n";
return 0;
......
No preview for this file type
No preview for this file type
......@@ -11,8 +11,11 @@ from comsdk.edge import Edge
prsr = pars.Parser(tocpp=True)
data = {"a":10}
gr = prsr.parse_file('./tests/adot/testsimple.adot')
gr.run(data)
print (data)
# gr.run(data)
# print (data)
print(prsr.generate_cpp())
for b in prsr.bushes:
......@@ -2,9 +2,19 @@ digraph SIMPLE {
FUNC [module=libprinters, entry_func=PrintHello]
PRED [module=libprinters, entry_func=ReturnTrue]
MORPH [predicate=PRED, function=FUNC]
FUNC1 [module=libprinters, entry_func=PrintHello1]
PRED1 [module=libprinters, entry_func=ReturnTrue1]
MORPH1 [predicate=PRED1, function=FUNC1]
FUNC2 [module=libprinters, entry_func=PrintHello2]
PRED2 [module=libprinters, entry_func=ReturnTrue2]
MORPH2 [predicate=PRED2, function=FUNC2]
__BEGIN__ -> ST1 [morphism = MORPH]
ST1 -> ST2 [morphism = MORPH]
ST1 -> ST2, ST21 [morphism = (MORPH, MORPH1)]
ST2 -> ST3[morphism = MORPH]
ST3 -> ST4[morphism = MORPH]
ST4 -> __END__
ST21 -> ST31, ST312[morphism =(MORPH1,MORPH2)]
ST3, ST31, ST312 -> ST4[morphism = (MORPH,MORPH1,MORPH2) ]
ST4 -> ST1, __END__
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment