changeset 715:fd9b9fa4ec98

fix pop_and_push test
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 28 Aug 2020 16:43:39 +0900
parents d5bd1c640db0
children 284fa7d7326e
files src/parallel_execution/examples/pop_and_push/StackTest.h src/parallel_execution/examples/pop_and_push/StackTestImpl.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/perlTests/generate_stub.t
diffstat 4 files changed, 45 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/examples/pop_and_push/StackTest.h	Fri Aug 28 12:24:42 2020 +0900
+++ b/src/parallel_execution/examples/pop_and_push/StackTest.h	Fri Aug 28 16:43:39 2020 +0900
@@ -1,7 +1,8 @@
 typedef struct StackTest <Type, Impl> {
   __code insertTest1(Impl* stackTest, struct Stack* stack, __code next(...));
   __code insertTest2(Impl* stackTest, struct Stack* stack, __code next(...));
-  __code insertTest3(Impl* stackTest, struct Stack* stack, __code next(...));
+  __code insertTest3(Impl* stackTest, struct Stack* stack, __code next(union Data* data, union Data* data1, ...));
+  __code insertTest4(Impl* stackTest, struct Stack* stack, __code next(...));
   __code pop2Test(Impl* stackTest, struct Stack* stack, __code next(...));
   __code pop2Test1(Impl* stackTest, union Data* data, union Data* data1, struct Stack* stack, __code next(...));
   __code next(...);
--- a/src/parallel_execution/examples/pop_and_push/StackTestImpl.cbc	Fri Aug 28 12:24:42 2020 +0900
+++ b/src/parallel_execution/examples/pop_and_push/StackTestImpl.cbc	Fri Aug 28 16:43:39 2020 +0900
@@ -1,5 +1,5 @@
 #include "../../../context.h"
-#interface "StackTest.h"
+#impl "StackTest.h"
 #interface "StackTest2.h"
 #interface "Stack.h"
 #include <stdio.h>
@@ -16,38 +16,50 @@
     struct StackTest* stack_test  = new StackTest();
     struct StackTestImpl* stack_test_impl = new StackTestImpl();
     stack_test->stackTest = (union Data*)stack_test_impl;
-    stack_test->insertTest1 = C_insertTest1_StackTestImpl;
-    stack_test->insertTest2 = C_insertTest2_StackTestImpl;
+    stack_test->insertTest1 = C_insertTest1StackTestImpl;
+    stack_test->insertTest2 = C_insertTest2StackTestImpl;
     return stack_test;
 }
 
-__code insertTest1_StackTestImpl(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
+__code insertTest1(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
     String* str = NEW(String);
     str->size = 99;
-    goto stack->push((union Data*)str, insertTest2_StackTestImpl);
+    goto stack->push((union Data*)str, insertTest2);
 }
 
-__code insertTest2_StackTestImpl(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
+__code insertTest2(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
     String* str = NEW(String);
     str->size = 100;
-    goto stack->push((union Data*)str, pop2Test_StackTestImpl);
+    goto stack->push((union Data*)str, pop2Test);
 }
 
 
-__code pop2Test_StackTestImpl(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
-  goto stack->pop2(pop2Test1_StackTestImpl);
-}
-
-__code pop2Test3_StackTestImpl(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
+__code insertTest3(struct StackTestImpl* stackTest, struct Stack* stack, __code next(union Data* data, union Data* data1, ...)) {
   String* str = NEW(String);
   str->size = 200;
   String* str1 = NEW(String);
   str1->size = 300;
-  goto pop2Test1_StackTestImpl(stackTest, (union Data*)str, (union Data*)str1);
+  data = (union Data*)str;
+  data1 = (union Data*)str1;
+
+  goto pop2Test1(stackTest, data, data1);
 }
 
 
-__code pop2Test1_StackTestImpl(struct StackTestImpl* stackTest, union Data* data, union Data* data1, struct Stack* stack, __code next(...)) {
+__code insertTest4(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
+    StackTest2* stackTest2 = createStackTest2Impl(context);
+    String* str = NEW(String);
+    str->size = 100;
+    goto stackTest2->insertTest1(stack, (union Data*)str, pop2Test);
+}
+
+
+__code pop2Test(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
+  goto stack->pop2(pop2Test1);
+}
+
+
+__code pop2Test1(struct StackTestImpl* stackTest, union Data* data, union Data* data1, struct Stack* stack, __code next(...)) {
     String* str = (String*)data;
     String* str2 = (String*)data1;
 
@@ -57,11 +69,4 @@
 }
 
 
-__code insertTest3_StackTestImpl(struct StackTestImpl* stackTest, struct Stack* stack, __code next(...)) {
-    StackTest2* stackTest2 = createStackTest2Impl(context);
-    String* str = NEW(String);
-    str->size = 100;
-    goto stackTest2->insertTest1((union Data*)str, pop2Test_StackTestImpl);
-}
 
-//insertTest1_StackTest2Impl
--- a/src/parallel_execution/generate_stub.pl	Fri Aug 28 12:24:42 2020 +0900
+++ b/src/parallel_execution/generate_stub.pl	Fri Aug 28 16:43:39 2020 +0900
@@ -135,9 +135,9 @@
                 $code{$name} = {};
                 $generic{$name} = [];
             } elsif (/^(\w+)(\*)+ create(\w+)\(/) { # this case implementation constructor
-                if (defined $implInterfaceInfo->{interface} ) {
-                   die "duplicate interface $implInterfaceInfo->{interface}\n";
-                }
+              #if (defined $implInterfaceInfo->{interface} ) {
+              #     die "duplicate interface $implInterfaceInfo->{interface}\n";
+              #  }
                 my $interfaceName = $1;
                 $implInterfaceInfo->{isImpl} = 1;
                 $implInterfaceInfo->{interface} = $interfaceName;
@@ -567,6 +567,8 @@
                 $inTypedef = 1;
             } elsif (/^int main\((.*)\) \{/) {
                 $inMain = 1;
+            } elsif(/^#impl "(.*)"/) {
+              next;
             } elsif(/^#interface "(.*)"/) {
                 my $interfaceHeader = $1;
                 # #interface not write
@@ -656,9 +658,9 @@
                             my $typeName = $2;
                             my $ptrType = $3;
                             my $varName = $4;
-                        if ($structType =~ /(const|enum)/) {
-                            $typeName = "$structType $typeName";
-                        }
+                            if ($structType =~ /(const|enum)/) {
+                                $typeName = "$structType $typeName";
+                            }
                             my $typeField = lcfirst($typeName);
                             push(@{$outputArgs{$codeGearName}->{$next}}, $varName);
                             if (generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $implInterfaceInfo,1)) {
@@ -877,6 +879,13 @@
                     # continuation arguments
                     $v = 1  if ( $n eq $next);
                 }
+
+                if (exists_codegear_in_interface({codeGearName => $next, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) {
+                    my $replaceCodeGear = "${next}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack
+                    if ($replaceCodeGearNames->{$next}) {
+                      $next = $replaceCodeGear;
+                    }
+                }
                 if ($v || ($implInterfaceInfo->{isImpl} && defined $code{$implInterfaceInfo->{interface}}->{$next})) {
                     # write continuation's arguments into the interface arguments
                     # we may need a commit for a shared DataGear
@@ -940,7 +949,7 @@
     }
     if (defined $prevCodeGearName) {
         if (!defined $stub{$prevCodeGearName."_stub"}->{wrote}) {
-            $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
+            $stub{$prevCodeGearName."_stub"}->{wrote} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
         }
     }
 
--- a/src/parallel_execution/perlTests/generate_stub.t	Fri Aug 28 12:24:42 2020 +0900
+++ b/src/parallel_execution/perlTests/generate_stub.t	Fri Aug 28 16:43:39 2020 +0900
@@ -31,5 +31,6 @@
 
 compareCbC2C('examples/boundedBuffer/BoundedBuffer.cbc', "$FindBin::Bin/BoundedBuffer.c");
 compareCbC2C('examples/twice/main.cbc', "$FindBin::Bin/testfiles/twice/main.c");
+compareCbC2C('examples/pop_and_push/StackTestImpl3.cbc', "$FindBin::Bin/pop_and_push/StackTestImpl3.c");
 
 done_testing;