Mercurial > hg > Document > Growi
changeset 22:8bc110e35f8d
backup 2021-01-14
author | autobackup |
---|---|
date | Thu, 14 Jan 2021 00:10:03 +0900 |
parents | 4a2bfdc45e69 |
children | 6f9bfbfc54c9 |
files | user/anatofuz/note/2021/01/13.md |
diffstat | 1 files changed, 266 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user/anatofuz/note/2021/01/13.md Thu Jan 14 00:10:03 2021 +0900 @@ -0,0 +1,266 @@ +# 2021/01/13 + +```c ++kajika+anatofuz$ perl generate_stub.pl --debug AtomicTImpl.cbc +[getDataGear] match 174 : #interface "AtomicT.h" +[getDataGear] match 136 : typedef struct AtomicT <T>{ +[getDataGear] match 308 : union Data* atomicTImpl; +[getDataGear] match 308 : T newData; +[getDataGear] match 308 : T init; +[getDataGear] match 326 : __code checkAndSet(Impl* atomicTImpl, T init, T newData, __code next(...), __code fail(...)); +[getDataGear] match 326 : __code set(Impl* atomicTImpl, T newData, __code next(...)); +[getDataGear] match 326 : __code next(...); +[getDataGear] match 326 : __code fail(...); +[getDataGear] match 308 : } AtomicT; +[getDataGear] match 335 : } AtomicT; +[getCodeGear] match 380 : typedef struct AtomicT <T>{ +[getCodeGear] match 385 : __code checkAndSet(Impl* atomicTImpl, T init, T newData, __code next(...), __code fail(...)); +[getCodeGear] match 385 : __code set(Impl* atomicTImpl, T newData, __code next(...)); +[getCodeGear] match 385 : __code next(...); +[getCodeGear] match 385 : __code fail(...); +[getDataGear] match 174 : #interface "AtomicTImpl.h" +[getDataGear] match 136 : typedef struct AtomicTImpl <T> impl AtomicT { +[getDataGear] match 308 : T atomic; +[getDataGear] match 308 : T init; +[getDataGear] match 326 : __code next(...); +[getDataGear] match 308 : } AtomicTImpl; +[getDataGear] match 335 : } AtomicTImpl; +[getDataGear] match 205 : __code checkAndSetAtomicT(struct AtomicTImpl* atomicTImpl, T* ptr,T init, T newData, __code next(...), __code fail(...)) { +[getDataGear] match 205 : __code setAtomicT(struct AtomicTImpl* atomicTImpl, T* ptr, T newData, __code next(...) ) { +[generateDataGear] match 654 : #include "../context.h" +[generateDataGear] match 649 : #interface "AtomicT.h" +[generateDataGear] match 649 : #interface "AtomicTImpl.h" +[generateDataGear] match 784 : #include <stdio.h> +[generateDataGear] match 784 : +[generateDataGear] match 784 : AtomicT<T>* createAtomicT(struct Context* context,T init) { +[generateDataGear] match 784 : struct AtomicT* atomicT = new AtomicT<T>(); +[generateDataGear] match 784 : struct AtomicTImpl<T>* atomicTImpl = new AtomicTImpl<T>(); +[generateDataGear] match 784 : atomicT->atomicTImpl = atomicTImpl; +[generateDataGear] match 784 : atomicTImpl->atomic = init; +[generateDataGear] match 784 : atomicTImpl->init = init; +[generateDataGear] match 784 : atomic->checkAndSet = C_checkAndSetAtomicT; +[generateDataGear] match 784 : return atomicT; +[generateDataGear] match 784 : } +[generateDataGear] match 784 : +[generateDataGear] match 673 : __code checkAndSetAtomicT(struct AtomicTImpl* atomicTImpl, T* ptr,T init, T newData, __code next(...), __code fail(...)) { +[generateDataGear] match 1034 : if (__sync_bool_compare_and_swap(ptr, init, newData)) { +[generateDataGear] match 972 : goto next(...); +[generateDataGear] match 1034 : } +[generateDataGear] match 972 : goto fail(...); +[generateDataGear] match 1031 : } +[generateDataGear] match 1055 : } +[generateDataGear] match 784 : +[generateDataGear] match 673 : __code setAtomicT(struct AtomicTImpl* atomicTImpl, T* ptr, T newData, __code next(...) ) { +[generateDataGear] match 1034 : *ptr = newData; +[generateDataGear] match 972 : goto next(...); +[generateDataGear] match 1031 : } +[generateDataGear] match 1055 : } +[generateDataGear] match 784 : +``` + + +```c +#include "../context.h" +#include <stdio.h> + +AtomicT<T>* createAtomicT(struct Context* context,T init) { + struct AtomicT* atomicT = new AtomicT<T>(); + struct AtomicTImpl<T>* atomicTImpl = new AtomicTImpl<T>(); + atomicT->atomicTImpl = atomicTImpl; + atomicTImpl->atomic = init; + atomicTImpl->init = init; + atomic->checkAndSet = C_checkAndSetAtomicT; + return atomicT; +} + +__code checkAndSetAtomicT(struct Context *context,struct AtomicTImpl* atomicTImpl, T* ptr,T init, T newData, enum Code next, enum Code fail) { + if (__sync_bool_compare_and_swap(ptr, init, newData)) { + goto meta(context, next); + } + goto meta(context, fail); +} + +__code checkAndSetAtomicT_stub(struct Context* context) { + AtomicTImpl* atomicTImpl = Gearef(context, AtomicTImpl); + T* ptr = Gearef(context, T); + T init = Gearef(context, T); + T newData = Gearef(context, T); + Code next = Gearef(context, Code); + Code fail = Gearef(context, Code); + goto checkAndSetAtomicT(context, atomicTImpl, ptr, init, newData, next, fail); +} + +__code setAtomicT(struct Context *context,struct AtomicTImpl* atomicTImpl, T* ptr, T newData, enum Code next ) { + *ptr = newData; + goto meta(context, next); +} + +__code setAtomicT_stub(struct Context* context) { + AtomicTImpl* atomicTImpl = Gearef(context, AtomicTImpl); + T* ptr = Gearef(context, T); + T newData = Gearef(context, T); + Code next = Gearef(context, Code); + goto setAtomicT(context, atomicTImpl, ptr, newData, next); +} +``` + + + +``` ++kajika+anatofuz$ perl tools/trans_impl.pl examples/pop_and_push/StackTest2Impl.h +#include "../../../context.h" +#interface "StackTest2.h" + +// ---- +// typedef struct StackTest2Impl <> impl StackTest2 { +// __code next(...); +// } StackTest2Impl; +// ---- + +\ { + codeName { + gotoOtherInterface { + argc 4, + args "Impl* stackTest2, struct Stack* stack, union Data* data1, struct StackTest* stackTest, __code next(...)", + name "gotoOtherInterface" + }, + insertTest1 { + argc 3, + args "Impl* stackTest2, struct Stack* stack, union Data* data1, __code next(...)", + name "insertTest1" + } + }, + codes [ + [0] var{codeName}{insertTest1}, + [1] var{codeName}{gotoOtherInterface} + ], + content [ + [0] "enum Code insertTest1;", + [1] "union Data* stackTest2;", + [2] "struct Stack* stack;", + [3] "union Data* data1;", + [4] "enum Code gotoOtherInterface;", + [5] "struct StackTest* stackTest;", + [6] "enum Code next;", + [7] "" + ], + data [ + [0] "union Data* stackTest2;", + [1] "struct Stack* stack;", + [2] "union Data* data1;", + [3] "struct StackTest* stackTest;", + [4] "" + ], + file_name "/home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/tools/../examples/pop_and_push/StackTest2.h", + hasOutputArgs {}, + inner_code_gears { + next 1 + }, + name "StackTest2" +} +\ { + codeName { + next { + argc 1, + args "...", + name "next" + } + }, + codes [ + [0] var{codeName}{next} + ], + content [ + [0] "enum Code next;" + ], + data [], + file_name "/home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/examples/pop_and_push/StackTest2Impl.h", + hasOutputArgs {}, + inner_code_gears {}, + isa "StackTest2", + name "StackTest2Impl" +} +StackTest2* createStackTest2Impl(struct Context* context) { + struct StackTest2* stackTest2 = new StackTest2(); + struct StackTest2Impl* stack_test2impl = new StackTest2Impl(); + stackTest2->stackTest2 = (union Data*)stack_test2impl; + stackTest2->stack = NULL; + stackTest2->data1 = NULL; + stackTest2->stackTest = NULL; + stackTest2->insertTest1 = C_insertTest1StackTest2Impl; + stackTest2->gotoOtherInterface = C_gotoOtherInterfaceStackTest2Impl; + return stackTest2; +} +__code insertTest1_StackTest2Impl(struct StackTest2Impl* stackTest2, struct Stack* stack, union Data* data1, __code next(...)) { + + goto next(...); +} + +__code gotoOtherInterface_StackTest2Impl(struct StackTest2Impl* stackTest2, struct Stack* stack, union Data* data1, struct StackTest* stackTest, __code next(...)) { + + goto next(...); +} + +``` + + +```diff +[0;36m1d0[0;0m +[0;31m< +kajika+anatofuz$ perl tools/trans_impl.pl examples/pop_and_push/StackTest2Impl.h[0;0m +[0;36m30,32c29,31[0;0m +[0;31m< [1] "union Data* stackTest2;",[0;0m +[0;31m< [2] "struct Stack* stack;",[0;0m +[0;31m< [3] "union Data* data1;",[0;0m +[0;0m---[0;0m +[0;32m> [1] "union Data stackTest2*;",[0;0m +[0;32m> [2] "struct Stack stack*;",[0;0m +[0;32m> [3] "union Data data1*;",[0;0m +[0;36m34c33[0;0m +[0;31m< [5] "struct StackTest* stackTest;",[0;0m +[0;0m---[0;0m +[0;32m> [5] "struct StackTest stackTest*;",[0;0m +[0;36m39,42c38,41[0;0m +[0;31m< [0] "union Data* stackTest2;",[0;0m +[0;31m< [1] "struct Stack* stack;",[0;0m +[0;31m< [2] "union Data* data1;",[0;0m +[0;31m< [3] "struct StackTest* stackTest;",[0;0m +[0;0m---[0;0m +[0;32m> [0] "union Data stackTest2*;",[0;0m +[0;32m> [1] "struct Stack stack*;",[0;0m +[0;32m> [2] "union Data data1*;",[0;0m +[0;32m> [3] "struct StackTest stackTest*;",[0;0m +[0;36m74c73[0;0m +[0;31m< struct StackTest2* stackTest2 = new StackTest2();[0;0m +[0;0m---[0;0m +[0;32m> struct StackTest2* union Data stackTest2*; = new StackTest2();[0;0m +[0;36m76,82c75,84[0;0m +[0;31m< stackTest2->stackTest2 = (union Data*)stack_test2impl;[0;0m +[0;31m< stackTest2->stack = NULL;[0;0m +[0;31m< stackTest2->data1 = NULL;[0;0m +[0;31m< stackTest2->stackTest = NULL;[0;0m +[0;31m< stackTest2->insertTest1 = C_insertTest1StackTest2Impl;[0;0m +[0;31m< stackTest2->gotoOtherInterface = C_gotoOtherInterfaceStackTest2Impl;[0;0m +[0;31m< return stackTest2;[0;0m +[0;0m---[0;0m +[0;32m> union Data stackTest2*;->union Data stackTest2*; = (union Data*)stack_test2impl;[0;0m +[0;32m> union Data stackTest2*;->stack = 0;[0;0m +[0;32m> union Data stackTest2*;->Stack = 0;[0;0m +[0;32m> union Data stackTest2*;->data1 = 0;[0;0m +[0;32m> union Data stackTest2*;->Data = 0;[0;0m +[0;32m> union Data stackTest2*;->stackTest = 0;[0;0m +[0;32m> union Data stackTest2*;->StackTest = 0;[0;0m +[0;32m> union Data stackTest2*;->insertTest1 = C_insertTest1StackTest2Impl;[0;0m +[0;32m> union Data stackTest2*;->gotoOtherInterface = C_gotoOtherInterfaceStackTest2Impl;[0;0m +[0;32m> return union Data stackTest2*;;[0;0m +``` + +これかぁ原因 + +```diff +< [1] "union Data* stackTest2;", +< [2] "struct Stack* stack;", +< [3] "union Data* data1;", +--- +> [1] "union Data stackTest2*;", +> [2] "struct Stack stack*;", +> [3] "union Data data1*;", +```