view paper/src/GearsDirectoryImpl.cbc @ 25:b16f42511c3e

add appendix
author matac42 <matac@cr.ie.u-ryukyu.ac.jp>
date Thu, 27 Jan 2022 11:03:59 +0900
parents
children
line wrap: on
line source

#include "../../../context.h"
#interface "GearsDirectory.h"
#interface "Stack.h"
#interface "FTree.h"
#interface "Integer.h"
#impl "GearsDirectory.h" as "GearsDirectoryImpl.h"

// ----
// typedef struct GearsDirectoryImpl <> impl GearsDirectory {
//   struct FTree* currentDirectory;
//   struct Stack* directoryStack;
// } GearsDirectoryImpl;
// ----

GearsDirectory* createGearsDirectoryImpl(struct Context* context) {
    struct GearsDirectory* gearsDirectory  = new GearsDirectory();
    struct GearsDirectoryImpl* gears_directory_impl = new GearsDirectoryImpl();
    gearsDirectory->gearsDirectory = (union Data*)gears_directory_impl;

    struct FTree* firstDirectory = createFileSystemTree(context, NULL);
    struct FTree* iNodeTree = createFileSystemTree(context, NULL);    
    gears_directory_impl->currentDirectory = firstDirectory;
    gears_directory_impl->iNodeTree = iNodeTree;
    gears_directory_impl->directoryStack = createSingleLinkedStack(context);
    gears_directory_impl->INodeNumber = 0;
    gearsDirectory->mkdir = C_mkdirGearsDirectoryImpl;
    gearsDirectory->ls = C_lsGearsDirectoryImpl;
    gearsDirectory->cd2Child = C_cd2ChildGearsDirectoryImpl;
    gearsDirectory->cd2Parent = C_cd2ParentGearsDirectoryImpl;
    return gearsDirectory;
}

__code mkdir(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
    struct FTree* newDirectory = createFileSystemTree(context, gearsDirectory->currentDirectory);
    Node* inode = new Node();
    inode->key = gearsDirectory->INodeNumber;
    inode->value = newDirectory;
    struct FTree* cDirectory = new FTree();
    cDirectory = gearsDirectory->iNodeTree;
    goto cDirectory->put(inode, mkdir2);
}

__code mkdir2(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
    Node* dir = new Node();
    dir->key = name->value;
    Integer* iNum = new Integer();
    iNum->value = gearsDirectory->INodeNumber;
    dir->value = iNum;
    gearsDirectory->INodeNumber = gearsDirectory->INodeNumber + 1;
    struct FTree* cDirectory = new FTree();
    cDirectory = gearsDirectory->currentDirectory;
    goto cDirectory->put(dir, next(...));
}

__code ls(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
    Node* dir = new Node();
    dir->key = name->value;
    struct FTree* cDirectory = new FTree();
    cDirectory = gearsDirectory->currentDirectory;
    goto cDirectory->get(dir, ls2);
}

__code ls2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
    printf("%d\n", node->key);
    goto next(...);
}

__code ls2_stub(struct Context* context) {
	GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
	Integer* name = Gearef(context, FTree)->node;
	enum Code next = Gearef(context, GearsDirectory)->next;
	goto ls2(context, gearsDirectory, name, next);
}

__code cd2Child(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
    struct FTree* cDirectory = new FTree();
    cDirectory = gearsDirectory->currentDirectory;
    struct Node* node = new Node();
    node->key = name->value;
    goto cDirectory->get(node, cd2Child2);
}

__code cd2Child2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
    struct FTree* iNodeTree = new FTree();
    iNodeTree = gearsDirectory->iNodeTree;
    goto iNodeTree->get(node->value, cd2Child3);
}

__code cd2Child2_stub(struct Context* context) {
	GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
	enum Code next = Gearef(context, GearsDirectory)->next;
    Node* node0 = Gearef(context, FTree)->node;
	goto cd2Child2(context, gearsDirectory, node0, next);
}

__code cd2Child3(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
    gearsDirectory->currentDirectory = node->value;
    goto next(...);
}

__code cd2Child3_stub(struct Context* context) {
	GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
	Integer* name = Gearef(context, FTree)->node;
	enum Code next = Gearef(context, GearsDirectory)->next;
	goto ls2(context, gearsDirectory, name, next);
}



__code cd2Parent(struct GearsDirectoryImpl* gearsDirectory, __code next(...)) {
    gearsDirectory->currentDirectory = gearsDirectory->currentDirectory->treeParent;
    goto next(...);
}