changeset 623:f41dee5df182

add piposaru(toy interpreter?)
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 01 Jun 2020 20:16:53 +0900
parents 271408163bed
children d560184a7ce7
files src/parallel_execution/CMakeLists.txt src/parallel_execution/examples/piposaru/lexer.h src/parallel_execution/examples/piposaru/lexer_impl.cbc src/parallel_execution/examples/piposaru/lexer_impl.h src/parallel_execution/examples/piposaru/main.cbc src/parallel_execution/examples/piposaru/string.h src/parallel_execution/examples/piposaru/token.h src/parallel_execution/examples/piposaru/token_impl.cbc src/parallel_execution/examples/piposaru/token_impl.h
diffstat 9 files changed, 155 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Sat May 30 10:17:07 2020 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Mon Jun 01 20:16:53 2020 +0900
@@ -140,3 +140,11 @@
   SOURCES
   examples/boundedBuffer/main.cbc examples/boundedBuffer/initBuffer.cbc examples/boundedBuffer/SemaphoreImpl.cbc examples/boundedBuffer/BoundedBuffer.cbc examples/boundedBuffer/consumer.cbc examples/boundedBuffer/producer.cbc SpinLock.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc MultiDimIterator.cbc AtomicReference.cbc
 )
+
+GearsCommand(
+  TARGET
+     piposaru
+  SOURCES
+  examples/piposaru/lexer_impl.cbc  examples/piposaru/main.cbc  examples/piposaru/token_impl.cbc
+
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/lexer.h	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,6 @@
+typedef struct lexer <Type, Impl> {
+    __code read_char(Impl* lexer, char* ch, __code next(... ));
+    __code eat_whitespace(Impl* lexer, char* ch, __code next(... ));
+    __code next_token(Impl* lexer, __code next(struct token* tok, ...));
+    __code next(....);
+} lexer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/lexer_impl.cbc	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,33 @@
+#include "../../../context.h"
+#interface "lexer.h"
+
+// ----
+// typedef struct lexer_impl <Type, Isa> impl lexer {
+//     __code next(....);
+// } lexer_impl;
+// ----
+
+lexer* createlexer_impl(struct Context* context) {
+    struct lexer* lexer  = new lexer();
+    struct lexer_impl* lexer_impl = new lexer_impl();
+    lexer->lexer = (union Data*)lexer_impl;
+    lexer->read_char = C_read_charlexer_impl;
+    lexer->eat_whitespace = C_eat_whitespacelexer_impl;
+    lexer->next_token = C_next_tokenlexer_impl;
+    return lexer;
+}
+__code read_charlexer_impl(struct lexer_impl* lexer, char* ch, __code next(... )) {
+
+    goto next(... );
+}
+
+__code eat_whitespacelexer_impl(struct lexer_impl* lexer,char* ch, __code next(... )) {
+
+    goto next(... );
+}
+
+__code next_tokenlexer_impl(struct lexer_impl* lexer, __code next(struct token* tok, ...)) {
+
+    goto next(tok, ...);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/lexer_impl.h	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,3 @@
+typedef struct lexer_impl <Type, Isa> impl lexer {
+    __code next(....);
+} lexer_impl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/main.cbc	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../../context.h"
+#interface "TaskManager.h"
+
+int cpu_num = 1;
+int length = 102400;
+int split = 8;
+int* array_ptr;
+int gpu_num = 0;
+int CPU_ANY = -1;
+int CPU_CUDA = -1;
+
+__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
+    // loopCounter->tree = createRedBlackTree(context);
+    loopCounter->i = 0;
+    taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
+    goto code1();
+}
+
+__code code1(struct LoopCounter* loopCounter) {
+    printf("cpus:\t\t%d\n", cpu_num);
+    printf("gpus:\t\t%d\n", gpu_num);
+    printf("length:\t\t%d\n", length);
+    printf("length/task:\t%d\n", length/split);
+    /* puts("queue"); */
+    /* print_queue(context->data[ActiveQueue]->queue.first); */
+    /* puts("tree"); */
+    /* print_tree(context->data[Tree]->tree.root); */
+    /* puts("result"); */
+    goto createTask1();
+}
+
+
+__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
+    lexer* lexer1 = createlexer_impl(context);
+    par goto printest();
+    goto code2();
+}
+
+
+__code printest() {
+  printf("hello!!\n");
+}
+
+__code code2(struct TaskManager* taskManager) {
+    goto taskManager->shutdown(exit_code);
+}
+
+__code code2_stub(struct Context* context) {
+    goto code2(context, &Gearef(context, TaskManager)->taskManager->TaskManager);
+}
+
+void init(int argc, char** argv) {
+    for (int i = 1; argv[i]; ++i) {
+        if (strcmp(argv[i], "-cpu") == 0)
+            cpu_num = (int)atoi(argv[i+1]);
+        else if (strcmp(argv[i], "-l") == 0)
+            length = (int)atoi(argv[i+1]);
+        else if (strcmp(argv[i], "-s") == 0)
+            split = (int)atoi(argv[i+1]);
+        else if (strcmp(argv[i], "-cuda") == 0) {
+            gpu_num = 1;
+            CPU_CUDA = 0;
+        }
+    }
+}
+
+int main(int argc, char** argv) {
+    init(argc, argv);
+    goto initDataGears();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/string.h	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,2 @@
+typedef const char* string;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/token.h	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,4 @@
+typedef struct token <Type, Impl> {
+  __code add(Impl* token, enum DataType tk, char* datum, __code next(...));
+  __code next(....);
+} token;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/token_impl.cbc	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,21 @@
+#include "../context.h"
+#interface "token.h"
+
+// ----
+// typedef struct token_impl <Type, Isa> impl token {
+//     __code next(....);
+// } token_impl;
+// ----
+
+token* createtoken_impl(struct Context* context) {
+    struct token* token  = new token();
+    struct token_impl* token_impl = new token_impl();
+    token->token = (union Data*)token_impl;
+    token->add = C_addtoken_impl;
+    return token;
+}
+__code addtoken_impl(struct token_impl* token, enum DataType tk, char* datum, __code next(...)) {
+
+    goto next(...);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/piposaru/token_impl.h	Mon Jun 01 20:16:53 2020 +0900
@@ -0,0 +1,3 @@
+typedef struct token_impl <Type, Isa> impl token {
+    __code next(....);
+} token_impl;