annotate Paper/src/GearsDirectoryImpl.cbc @ 3:00deefffb582

fix: ~6
author matac42 <matac@cr.ie.u-ryukyu.ac.jp>
date Tue, 03 May 2022 13:52:01 +0900
parents 0df9610b1d6a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "../../../context.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #interface "GearsDirectory.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #interface "Stack.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #interface "FTree.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #interface "Integer.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #impl "GearsDirectory.h" as "GearsDirectoryImpl.h"
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 // ----
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // typedef struct GearsDirectoryImpl <> impl GearsDirectory {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // struct FTree* currentDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // struct Stack* directoryStack;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // } GearsDirectoryImpl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 // ----
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GearsDirectory* createGearsDirectoryImpl(struct Context* context) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 struct GearsDirectory* gearsDirectory = new GearsDirectory();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 struct GearsDirectoryImpl* gears_directory_impl = new GearsDirectoryImpl();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 gearsDirectory->gearsDirectory = (union Data*)gears_directory_impl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 struct FTree* firstDirectory = createFileSystemTree(context, NULL);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 struct FTree* iNodeTree = createFileSystemTree(context, NULL);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 gears_directory_impl->currentDirectory = firstDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 gears_directory_impl->iNodeTree = iNodeTree;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 gears_directory_impl->directoryStack = createSingleLinkedStack(context);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 gears_directory_impl->INodeNumber = 0;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 gearsDirectory->mkdir = C_mkdirGearsDirectoryImpl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 gearsDirectory->ls = C_lsGearsDirectoryImpl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 gearsDirectory->cd2Child = C_cd2ChildGearsDirectoryImpl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 gearsDirectory->cd2Parent = C_cd2ParentGearsDirectoryImpl;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 return gearsDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 __code mkdir(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 struct FTree* newDirectory = createFileSystemTree(context, gearsDirectory->currentDirectory);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 Node* inode = new Node();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 inode->key = gearsDirectory->INodeNumber;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 inode->value = newDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 struct FTree* cDirectory = new FTree();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 cDirectory = gearsDirectory->iNodeTree;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 goto cDirectory->put(inode, mkdir2);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 __code mkdir2(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 Node* dir = new Node();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 dir->key = name->value;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 Integer* iNum = new Integer();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 iNum->value = gearsDirectory->INodeNumber;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 dir->value = iNum;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 gearsDirectory->INodeNumber = gearsDirectory->INodeNumber + 1;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 struct FTree* cDirectory = new FTree();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 cDirectory = gearsDirectory->currentDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 goto cDirectory->put(dir, next(...));
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 __code ls(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 Node* dir = new Node();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 dir->key = name->value;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 struct FTree* cDirectory = new FTree();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 cDirectory = gearsDirectory->currentDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 goto cDirectory->get(dir, ls2);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 __code ls2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 printf("%d\n", node->key);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 goto next(...);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 __code ls2_stub(struct Context* context) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 Integer* name = Gearef(context, FTree)->node;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 enum Code next = Gearef(context, GearsDirectory)->next;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 goto ls2(context, gearsDirectory, name, next);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 __code cd2Child(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 struct FTree* cDirectory = new FTree();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 cDirectory = gearsDirectory->currentDirectory;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 struct Node* node = new Node();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 node->key = name->value;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 goto cDirectory->get(node, cd2Child2);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 __code cd2Child2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 struct FTree* iNodeTree = new FTree();
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 iNodeTree = gearsDirectory->iNodeTree;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 goto iNodeTree->get(node->value, cd2Child3);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 __code cd2Child2_stub(struct Context* context) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 enum Code next = Gearef(context, GearsDirectory)->next;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 Node* node0 = Gearef(context, FTree)->node;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 goto cd2Child2(context, gearsDirectory, node0, next);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 __code cd2Child3(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 gearsDirectory->currentDirectory = node->value;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 goto next(...);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 __code cd2Child3_stub(struct Context* context) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 Integer* name = Gearef(context, FTree)->node;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 enum Code next = Gearef(context, GearsDirectory)->next;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 goto ls2(context, gearsDirectory, name, next);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 __code cd2Parent(struct GearsDirectoryImpl* gearsDirectory, __code next(...)) {
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 gearsDirectory->currentDirectory = gearsDirectory->currentDirectory->treeParent;
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 goto next(...);
matac42 <matac@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 }