changeset 725:d15c754615da

remove SingleLinkedStack constructor
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 18 Nov 2020 17:06:09 +0900
parents 451967f2be7a
children 8520b8b3c891
files src/parallel_execution/SingleLinkedStack.cbc src/parallel_execution/Stack.h src/parallel_execution/lib/Gears/Interface.pm src/parallel_execution/plautogen/impl/SingleLinkedStack.h
diffstat 4 files changed, 30 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/SingleLinkedStack.cbc	Wed Nov 18 15:37:19 2020 +0900
+++ b/src/parallel_execution/SingleLinkedStack.cbc	Wed Nov 18 17:06:09 2020 +0900
@@ -1,26 +1,9 @@
 #include "../context.h"
-#interface "Stack.h"
 #include <stdio.h>
 
-//include "Node.h"
-// typedef struct SingleLinkedStack {
-//     struct Element* top;
-// } SingleLinkedStack;
+#impl "Stack.h" for "SingleLinkedStack.h"
+#data "Node.h"
 
-Stack* createSingleLinkedStack(struct Context* context) {
-    struct Stack* stack = new Stack();
-    struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
-    stack->stack = (union Data*)singleLinkedStack;
-    singleLinkedStack->top = NULL;
-    stack->push = C_pushSingleLinkedStack;
-    stack->pop  = C_popSingleLinkedStack;
-    stack->pop2  = C_pop2SingleLinkedStack;
-    stack->get  = C_getSingleLinkedStack;
-    stack->get2  = C_get2SingleLinkedStack;
-    stack->isEmpty = C_isEmptySingleLinkedStack;
-    stack->clear = C_clearSingleLinkedStack;
-    return stack;
-}
 
 void printStack1(union Data* data) {
     struct Node* node = &data->Element.data->Node;
@@ -100,7 +83,7 @@
     }
     goto next(data, data1, ...);
 }
-    
+
 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
     if (stack->top) {
         goto next(...);
--- a/src/parallel_execution/Stack.h	Wed Nov 18 15:37:19 2020 +0900
+++ b/src/parallel_execution/Stack.h	Wed Nov 18 17:06:09 2020 +0900
@@ -1,17 +1,11 @@
 typedef struct Stack<Type, Impl>{
-        union Data* stack;
-        union Data* data;
-        union Data* data1;
-        /* Type* stack; */
-        /* Type* data; */
-        /* Type* data1; */
-        __code whenEmpty(...);
         __code clear(Impl* stack,__code next(...));
-        __code push(Impl* stack,Type* data, __code next(...));
-        __code pop(Impl* stack, __code next(Type* data, ...));
-        __code pop2(Impl* stack, __code next(Type* data, Type* data1, ...));
+        __code push(Impl* stack,union Data* data, __code next(...));
+        __code pop(Impl* stack, __code next(union Data* data, ...));
+        __code pop2(Impl* stack, __code next(union Data* data, union Data* data1, ...));
         __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
-        __code get(Impl* stack, __code next(Type* data, ...));
-        __code get2(Impl* stack, __code next(Type* data, Type* data1, ...));
+        __code get(Impl* stack, __code next(union Data* data, ...));
+        __code get2(Impl* stack, __code next(union Data* data, union Data* data1, ...));
         __code next(...);
+        __code whenEmpty(...);
 } Stack;
--- a/src/parallel_execution/lib/Gears/Interface.pm	Wed Nov 18 15:37:19 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Interface.pm	Wed Nov 18 17:06:09 2020 +0900
@@ -57,6 +57,8 @@
   }
 
   my @data_gears;
+  my $inner_code_gears;
+
   while ($line = <$fh>) {
     chomp $line;
     if ($line =~ m|\s*/\*|) {
@@ -77,13 +79,17 @@
       #In the case of writing field variables one line at a time, cancel the following
       next if $static_data_gear_write_mode;
 
+
       my $args = $';
       #$args eq  (Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...));
       while ($args =~ /\s*(struct|union|const|enum)?\s*([\w*\[\]_]+)\s*(\w+)?,?/g) {
         my $const_type = $1;
         my $type = $2;
         my $vname = $3;
-        next if ($type eq '__code');
+        if ($type eq '__code') {
+          $inner_code_gears->{$vname} = 1; #collect inner code gears (ex. next, whenEmpty)
+          next;
+        }
         next unless $vname; # __code hoge(int ret, __code next(ret, ...); this is second "ret" case
         $type =~ s/^(?:Impl|Type|Isa)\s*(\*)?/union Data$1/;
 
@@ -99,6 +105,7 @@
     $static_data_gear_write_mode = 1;
   }
 
+  $ir->{inner_code_gears} = $inner_code_gears;
   push(@{$ir->{content}}, Gears::Util->uniq(@data_gears));
   return $ir;
 }
@@ -128,20 +135,25 @@
   my @have_output_data;
   my @inner_code_gears;
 
+  my @output_code_gears;
+
   while (($i < scalar @code_gears) && (my $line = <$fh>)) {
       my $codeGearName = $code_gears[$i];
+
+      if (exists $ir->{inner_code_gears}->{$codeGearName}) {
+        $i++;
+        next;
+      }
+
       if ($line =~ m|__code $codeGearName\(([()\.\*\s\w,_]+)\)|) {
         my $arg = $1;
-        $code_gears[$i] = {
+        push(@output_code_gears, {
           name => $codeGearName,
           args => $arg,
-        };
+        });
         # args  eq "Impl* stack, __code next(Type* data, Type* data1, ...)",
-        if ($arg =~ /__code (\w+?)\((.+),\s*\.\.\.\s*\)/) {
-          my $inner_code_gear_name = $1;
-          my $outputArgs = $2;
-          push(@inner_code_gears, $inner_code_gear_name);
-
+        if ($arg =~ /__code \w+\((.+),\s*\.\.\.\s*\)/) {
+          my $outputArgs = $1;
           while ($outputArgs =~ /(struct|union|const|enum)?\s*([\w*]+)\s(\w+),?/g) {
             my $structType = $1;
             my $ttype = $2;
@@ -154,7 +166,7 @@
   }
 
 
-  $ir->{codes} = \@code_gears;
+  $ir->{codes} = \@output_code_gears;
   $ir->{data}  = \@data_gears;
   return $ir;
 }
--- a/src/parallel_execution/plautogen/impl/SingleLinkedStack.h	Wed Nov 18 15:37:19 2020 +0900
+++ b/src/parallel_execution/plautogen/impl/SingleLinkedStack.h	Wed Nov 18 17:06:09 2020 +0900
@@ -1,26 +1,3 @@
 typedef struct SingleLinkedStack<Type, Isa> impl Stack {
   struct Element* top;
 } SingleLinkedStack;
-
-/*
-    // Stack Interface
-    struct Stack {
-        union Data* stack;
-        union Data* data;
-        union Data* data1;
-        enum Code whenEmpty;
-        enum Code clear;
-        enum Code push;
-        enum Code pop;
-        enum Code pop2;
-        enum Code isEmpty;
-        enum Code get;
-        enum Code get2;
-        enum Code next;
-    } Stack;
-    // Stack implementations
-    struct SingleLinkedStack {
-        struct Element* top;
-    } SingleLinkedStack;
-    */
-