# HG changeset patch # User Nozomi Teruya # Date 1498302447 -32400 # Node ID 98c6e13d8ec74a37ec160d2b1a439aee6090c0b0 # Parent a9863b41f0267c2614a9d5d79cd9470560b303ea add sort.cbc diff -r a9863b41f026 -r 98c6e13d8ec7 src/parallel_execution/CMakeLists.txt --- a/src/parallel_execution/CMakeLists.txt Wed Jun 07 15:17:36 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Sat Jun 24 20:07:27 2017 +0900 @@ -94,3 +94,9 @@ test/stack_test.cbc SingleLinkedStack.cbc ) +GearsCommand( + TARGET + sort + SOURCES + examples/sort.cbc +) diff -r a9863b41f026 -r 98c6e13d8ec7 src/parallel_execution/context.h --- a/src/parallel_execution/context.h Wed Jun 07 15:17:36 2017 +0900 +++ b/src/parallel_execution/context.h Sat Jun 24 20:07:27 2017 +0900 @@ -288,6 +288,12 @@ struct Integer { int value; } Integer; + struct SortArray {//そもそもこれは必要なのか? + struct Integer **array;//Array arrayじゃできない? + int loop_counter; + enum Code make_array; + enum Code print; + }SortArray; }; // union Data end this is necessary for context generator typedef union Data Data; diff -r a9863b41f026 -r 98c6e13d8ec7 src/parallel_execution/examples/SortArray.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/SortArray.cbc Sat Jun 24 20:07:27 2017 +0900 @@ -0,0 +1,6 @@ +typedef struct SortArray{ + Integer **array; + int loop_counter; + __code print(Integer* data, Integer i, __code next(...)); + __code make_array(Integer* data, Integer i, __code next(...)); +} SortArray; diff -r a9863b41f026 -r 98c6e13d8ec7 src/parallel_execution/examples/sort.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/sort.cbc Sat Jun 24 20:07:27 2017 +0900 @@ -0,0 +1,40 @@ +#include +#include +#include "../../context.h" +#define MAX 20 + +int main(int argc, char const* argv[]) { + struct Context* main_context = NEW(struct Context); + initContext(main_context); + main_context->next = C_sort_start; + goto start_code(main_context); +} + +__code sort_start(struct SortArray* sortArray){ + sortArray = new SortArray(); + sortArray->array = (Integer**)ALLOC_ARRAY(context, Integer, MAX);//ALLOC_ARRAYはDSの配列なのでintではできない + sortArray->loop_counter = 0; + goto meta(context, C_make_array); +} + +__code make_array(struct SortArray* sortArray){ + if (sortArray->loop_counter == MAX){ + sortArray->loop_counter = 0; + goto meta(context, C_print); + } + struct Integer* integer = new Integer(); + integer->value = rand() % MAX; + sortArray->array[sortArray->loop_counter] = integer; + sortArray->loop_counter++; + goto meta(context, C_make_array); +} + +__code print(struct SortArray* sortArray){ + if (sortArray->loop_counter == MAX){ + goto meta(context, C_exit_code); + } + printf("%d, ", sortArray->array[sortArray->loop_counter]->value); + sortArray->loop_counter++; + goto meta(context, C_print); +} +