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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgvm
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: PGVM is an abbreviation for Pointer Graph Virtual Machine.
5
5
  Author-email: masaniki <masaniki.software@gmail.com>
6
6
  License-Expression: MIT
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "pgvm"
8
- version = "0.2.0"
8
+ version = "0.2.2"
9
9
  authors = [
10
10
  { name="masaniki", email="masaniki.software@gmail.com" },
11
11
  ]
@@ -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,graph,rootNode:int,program:list=None):
26
+ def __init__(self):
16
27
  """
17
28
  @Summ: constructor.
18
29
 
19
30
  @InsVars:
20
- data:
21
- @Summ: {node番号(int):{edgeLabel(str):node番号(int)}}。
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=graph
41
- self.rootNode=rootNode
49
+ self.graph={self.ROOT_NODE:{}}
42
50
  self.maxNodeIdx=None
43
- self.program=program
51
+ self.program=[]
44
52
  self.programCounter=0
45
- if(program is None):
46
- self.programLength=0
47
- else:
48
- self.programLength=len(program)
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","row_0:command")
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"<command> {command}|{argList[1]}|<jump1> {argList[2]}"
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"row_{i}:jump1",head_name=f"row_{argList[2]}:head")
121
+ digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[2]}:head")
91
122
  else:
92
- digraph.edge(tail_name=f"row_{i}:jump1",head_name="end")
123
+ digraph.edge(tail_name=f"{i}:jump1",head_name="end")
93
124
  case "ge":
94
- nodeLabel=f"<command> {command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}"
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"row_{i}:jump1",head_name=f"row_{argList[3]}:head")
127
+ digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
97
128
  else:
98
- digraph.edge(tail_name=f"row_{i}:jump1",head_name="end")
129
+ digraph.edge(tail_name=f"{i}:jump1",head_name="end")
99
130
  case "se":
100
- nodeLabel=f"<command> {command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}"
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"row_{i}:jump1",head_name=f"row_{argList[3]}:head")
133
+ digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
103
134
  else:
104
- digraph.edge(tail_name=f"row_{i}:jump1",head_name="end")
135
+ digraph.edge(tail_name=f"{i}:jump1",head_name="end")
105
136
  case "del":
106
- nodeLabel=f"<command> {command}|{argList[1]}|<jump1> {argList[2]}"
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"row_{i}:jump1",head_name=f"row_{argList[2]}:head")
139
+ digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[2]}:head")
109
140
  else:
110
- digraph.edge(tail_name=f"row_{i}:jump1",head_name="end")
141
+ digraph.edge(tail_name=f"{i}:jump1",head_name="end")
111
142
  case "if":
112
- nodeLabel=f"<command> {command}|{argList[1]}|{argList[2]}|<jump1> {argList[3]}|<jump2> {argList[4]}"
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"row_{i}:jump1",head_name=f"row_{argList[3]}:head")
145
+ digraph.edge(tail_name=f"{i}:jump1",head_name=f"{argList[3]}:head")
115
146
  else:
116
- digraph.edge(tail_name=f"row_{i}:jump1",head_name="end")
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"row_{i}:jump2",head_name=f"row_{argList[4]}:head")
149
+ digraph.edge(tail_name=f"{i}:jump2",head_name=f"{argList[4]}:head")
119
150
  else:
120
- digraph.edge(tail_name=f"row_{i}:jump2",head_name="end")
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"row_{i}",label=nodeLabel, shape="record")
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.rootNode]
176
- curEdgeDict=self.graph[self.rootNode]
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
- raise PGVMInvalidPath(self.programCounter, path1)
385
+ return False
353
386
  if(path2unreached!=0):
354
- raise PGVMInvalidPath(self.programCounter, path2)
387
+ return False
355
388
  path1LastNode=path1History[-1]
356
389
  path2LastNode=path2History[-1]
357
390
  if(path1LastNode==path2LastNode):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgvm
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: PGVM is an abbreviation for Pointer Graph Virtual Machine.
5
5
  Author-email: masaniki <masaniki.software@gmail.com>
6
6
  License-Expression: MIT
@@ -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(graphDict,10)
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"/"invalid_command"
106
+ caseDir=Path(__file__).parent/"graph_execution"/"sandbox"
106
107
  # isSuccess=testCaseExecution(caseDir,"expected.yaml",None,True)
107
108
  # print(isSuccess)
108
- # testSuitExecution(suitDir)
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