Mercurial > hg > Members > Moririn
changeset 358:98c6e13d8ec7
add sort.cbc
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 24 Jun 2017 20:07:27 +0900 |
parents | a9863b41f026 |
children | e68080586c15 |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/context.h src/parallel_execution/examples/SortArray.cbc src/parallel_execution/examples/sort.cbc |
diffstat | 4 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 +)
--- 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;
--- /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<Impl>{ + Integer **array; + int loop_counter; + __code print(Integer* data, Integer i, __code next(...)); + __code make_array(Integer* data, Integer i, __code next(...)); +} SortArray;
--- /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<stdio.h> +#include <stdlib.h> +#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); +} +