pgvm 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pgvm-0.2.0 → pgvm-0.2.2}/PKG-INFO +1 -1
- {pgvm-0.2.0 → pgvm-0.2.2}/pyproject.toml +1 -1
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm/editable_graph.py +70 -37
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm.egg-info/PKG-INFO +1 -1
- {pgvm-0.2.0 → pgvm-0.2.2}/tests/test_graph_execution.py +5 -4
- {pgvm-0.2.0 → pgvm-0.2.2}/LICENSE.txt +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/README.md +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/setup.cfg +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm/__init__.py +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm/error.py +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm.egg-info/SOURCES.txt +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm.egg-info/dependency_links.txt +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm.egg-info/requires.txt +0 -0
- {pgvm-0.2.0 → pgvm-0.2.2}/src/pgvm.egg-info/top_level.txt +0 -0
|
@@ -9,20 +9,29 @@ class EditableGraph():
|
|
|
9
9
|
|
|
10
10
|
@Desc:
|
|
11
11
|
- node番号は非負整数である。負の値はerror用。
|
|
12
|
+
|
|
13
|
+
@ClsVars:
|
|
14
|
+
ROOT_NODE:
|
|
15
|
+
@Summ: root nodeの番号。
|
|
16
|
+
@Type: Int
|
|
17
|
+
@Default: 0
|
|
18
|
+
PATH_DELIMITER:
|
|
19
|
+
@Summ: pathの区切り文字。
|
|
20
|
+
@Type: Str
|
|
21
|
+
@Default: "/"
|
|
12
22
|
"""
|
|
23
|
+
ROOT_NODE=0
|
|
13
24
|
PATH_DELIMITER="/"
|
|
14
25
|
|
|
15
|
-
def __init__(self
|
|
26
|
+
def __init__(self):
|
|
16
27
|
"""
|
|
17
28
|
@Summ: constructor.
|
|
18
29
|
|
|
19
30
|
@InsVars:
|
|
20
|
-
|
|
21
|
-
@Summ:
|
|
31
|
+
graph:
|
|
32
|
+
@Summ: PGVMが扱うgraph data.
|
|
33
|
+
@SemType: {node番号(int):{edgeLabel(str):node番号(int)}}。
|
|
22
34
|
@Type: Dict
|
|
23
|
-
rootNode:
|
|
24
|
-
@Summ: root nodeのnode番号。
|
|
25
|
-
@Type: Int
|
|
26
35
|
maxNodeIdx:
|
|
27
36
|
@Summ: node番号の最大値を記録する。
|
|
28
37
|
@Type: Int
|
|
@@ -37,15 +46,37 @@ class EditableGraph():
|
|
|
37
46
|
@Summ: 次に実行するprogramの行数を記録する。
|
|
38
47
|
@Type: Int
|
|
39
48
|
"""
|
|
40
|
-
self.graph=
|
|
41
|
-
self.rootNode=rootNode
|
|
49
|
+
self.graph={self.ROOT_NODE:{}}
|
|
42
50
|
self.maxNodeIdx=None
|
|
43
|
-
self.program=
|
|
51
|
+
self.program=[]
|
|
44
52
|
self.programCounter=0
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
self.programLength=0
|
|
54
|
+
|
|
55
|
+
def importGraph(self,path:str,graph:dict,connectingNode:int):
|
|
56
|
+
"""
|
|
57
|
+
@Summ: graph dataをimportする関数。
|
|
58
|
+
|
|
59
|
+
@Args:
|
|
60
|
+
path:
|
|
61
|
+
@Summ: 新しいgraphを繋げる場所を指定する。
|
|
62
|
+
@Desc: 未到達度1である必要がある。
|
|
63
|
+
@Type: Str
|
|
64
|
+
graph:
|
|
65
|
+
@Summ: graph構造のdata.
|
|
66
|
+
@Type: Dict
|
|
67
|
+
connectingNode:
|
|
68
|
+
@Summ: pathに繋げるnode番号を指定する。
|
|
69
|
+
@Type: Int
|
|
70
|
+
"""
|
|
71
|
+
edgeList=path.split(self.PATH_DELIMITER)
|
|
72
|
+
history,unreached=self.accessNode(edgeList)
|
|
73
|
+
if(unreached!=1):
|
|
74
|
+
raise RuntimeError(f"{path} is invalid.")
|
|
75
|
+
self.graph|=graph #graphの合体。
|
|
76
|
+
lastEdge=edgeList[-1]
|
|
77
|
+
lastNode=history[-1]
|
|
78
|
+
self.graph[lastNode][lastEdge]=connectingNode
|
|
79
|
+
|
|
49
80
|
|
|
50
81
|
def loadProgramCSV(self,csvFile):
|
|
51
82
|
"""
|
|
@@ -79,48 +110,48 @@ class EditableGraph():
|
|
|
79
110
|
digraph.attr("graph",rankdir="LR")
|
|
80
111
|
digraph.node(name="start")
|
|
81
112
|
digraph.node(name="end")
|
|
82
|
-
digraph.edge("start","
|
|
113
|
+
digraph.edge("start","0:head")
|
|
83
114
|
for i in range(self.programLength):
|
|
84
115
|
argList=self.program[i]
|
|
85
116
|
command=argList[0]
|
|
86
117
|
match command:
|
|
87
118
|
case "gn":
|
|
88
|
-
nodeLabel=f"<
|
|
119
|
+
nodeLabel=f"<head> line_{i}|{command}|{argList[1]}|<jump1> {argList[2]}"
|
|
89
120
|
if(int(argList[2])<self.programLength):
|
|
90
|
-
digraph.edge(tail_name=f"
|
|
121
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[2]}:head")
|
|
91
122
|
else:
|
|
92
|
-
digraph.edge(tail_name=f"
|
|
123
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name="end")
|
|
93
124
|
case "ge":
|
|
94
|
-
nodeLabel=f"<
|
|
125
|
+
nodeLabel=f"<head> line_{i}|{command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}"
|
|
95
126
|
if(int(argList[3])<self.programLength):
|
|
96
|
-
digraph.edge(tail_name=f"
|
|
127
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
|
|
97
128
|
else:
|
|
98
|
-
digraph.edge(tail_name=f"
|
|
129
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name="end")
|
|
99
130
|
case "se":
|
|
100
|
-
nodeLabel=f"<
|
|
131
|
+
nodeLabel=f"<head> line_{i}|{command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}"
|
|
101
132
|
if(int(argList[3])<self.programLength):
|
|
102
|
-
digraph.edge(tail_name=f"
|
|
133
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
|
|
103
134
|
else:
|
|
104
|
-
digraph.edge(tail_name=f"
|
|
135
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name="end")
|
|
105
136
|
case "del":
|
|
106
|
-
nodeLabel=f"<
|
|
137
|
+
nodeLabel=f"<head> line_{i}|{command}|{argList[1]}|<jump1> {argList[2]}"
|
|
107
138
|
if(int(argList[2])<self.programLength):
|
|
108
|
-
digraph.edge(tail_name=f"
|
|
139
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[2]}:head")
|
|
109
140
|
else:
|
|
110
|
-
digraph.edge(tail_name=f"
|
|
141
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name="end")
|
|
111
142
|
case "if":
|
|
112
|
-
nodeLabel=f"<
|
|
143
|
+
nodeLabel=f"<head> line_{i}|{command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}|<jump2> {argList[4]}"
|
|
113
144
|
if(int(argList[3])<self.programLength):
|
|
114
|
-
digraph.edge(tail_name=f"
|
|
145
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
|
|
115
146
|
else:
|
|
116
|
-
digraph.edge(tail_name=f"
|
|
147
|
+
digraph.edge(tail_name=f"{i}:jump1",head_name="end")
|
|
117
148
|
if(int(argList[4])<self.programLength):
|
|
118
|
-
digraph.edge(tail_name=f"
|
|
149
|
+
digraph.edge(tail_name=f"{i}:jump2",head_name=f"{argList[4]}:head")
|
|
119
150
|
else:
|
|
120
|
-
digraph.edge(tail_name=f"
|
|
151
|
+
digraph.edge(tail_name=f"{i}:jump2",head_name="end")
|
|
121
152
|
case _:
|
|
122
153
|
raise PGVMSyntaxError(self.programCounter, f"{command} is invalid command.")
|
|
123
|
-
digraph.node(name=f"
|
|
154
|
+
digraph.node(name=f"{i}",label=nodeLabel, shape="record")
|
|
124
155
|
digraph.render()
|
|
125
156
|
|
|
126
157
|
|
|
@@ -143,7 +174,7 @@ class EditableGraph():
|
|
|
143
174
|
|
|
144
175
|
def visualize(self,filename):
|
|
145
176
|
"""
|
|
146
|
-
@Summ: graphvizで可視化する関数。
|
|
177
|
+
@Summ: self.graphをgraphvizで可視化する関数。
|
|
147
178
|
"""
|
|
148
179
|
digraph=graphviz.Digraph()
|
|
149
180
|
digraph.filename=filename
|
|
@@ -172,8 +203,8 @@ class EditableGraph():
|
|
|
172
203
|
@Desc: 0で到達完了を表す。
|
|
173
204
|
@Type: Int
|
|
174
205
|
"""
|
|
175
|
-
history=[self.
|
|
176
|
-
curEdgeDict=self.graph[self.
|
|
206
|
+
history=[self.ROOT_NODE]
|
|
207
|
+
curEdgeDict=self.graph[self.ROOT_NODE]
|
|
177
208
|
pathLength=len(path)
|
|
178
209
|
unreached=pathLength
|
|
179
210
|
for i in range(pathLength):
|
|
@@ -333,6 +364,8 @@ class EditableGraph():
|
|
|
333
364
|
"""
|
|
334
365
|
@Summ: if文を実行する関数。
|
|
335
366
|
|
|
367
|
+
@Desc: <path1>または<path2>に存在しないpathを指定したら必ずfalseを出力。
|
|
368
|
+
|
|
336
369
|
@Args:
|
|
337
370
|
path1:
|
|
338
371
|
@Summ: if文の第一引数。比較するpathその1。
|
|
@@ -349,9 +382,9 @@ class EditableGraph():
|
|
|
349
382
|
path2EdgeList=path2.split(self.PATH_DELIMITER)
|
|
350
383
|
path2History,path2unreached=self.accessNode(path2EdgeList)
|
|
351
384
|
if(path1unreached!=0):
|
|
352
|
-
|
|
385
|
+
return False
|
|
353
386
|
if(path2unreached!=0):
|
|
354
|
-
|
|
387
|
+
return False
|
|
355
388
|
path1LastNode=path1History[-1]
|
|
356
389
|
path2LastNode=path2History[-1]
|
|
357
390
|
if(path1LastNode==path2LastNode):
|
|
@@ -81,7 +81,8 @@ def testCaseExecution(caseDir:Path,outputName:str="output.yaml",expectedName:str
|
|
|
81
81
|
outputFile=caseDir/outputName
|
|
82
82
|
with open(graphFile,mode="r",encoding="utf-8") as f:
|
|
83
83
|
graphDict=yaml.safe_load(f)
|
|
84
|
-
eg01=EditableGraph(
|
|
84
|
+
eg01=EditableGraph()
|
|
85
|
+
eg01.importGraph("file",graphDict,10)
|
|
85
86
|
if(isDetail):
|
|
86
87
|
eg01.visualize(beforeDot)
|
|
87
88
|
eg01.loadProgramCSV(programFile)
|
|
@@ -102,9 +103,9 @@ def testCaseExecution(caseDir:Path,outputName:str="output.yaml",expectedName:str
|
|
|
102
103
|
|
|
103
104
|
if(__name__=="__main__"):
|
|
104
105
|
suitDir=Path(__file__).parent/"graph_execution"
|
|
105
|
-
caseDir=Path(__file__).parent/"graph_execution"/"
|
|
106
|
+
caseDir=Path(__file__).parent/"graph_execution"/"sandbox"
|
|
106
107
|
# isSuccess=testCaseExecution(caseDir,"expected.yaml",None,True)
|
|
107
108
|
# print(isSuccess)
|
|
108
|
-
|
|
109
|
-
testCaseExecution(caseDir,isDetail=True)
|
|
109
|
+
testSuitExecution(suitDir)
|
|
110
|
+
# testCaseExecution(caseDir,isDetail=True)
|
|
110
111
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|