changeset 7:171cc032eb29

Fix tableau2
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Fri, 25 Dec 2015 18:31:20 +0900
parents 4a68716b7488
children a15437a1e94c
files .hgignore ltl.cbc ltl.h tableau2.cbc
diffstat 4 files changed, 57 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Dec 25 18:19:55 2015 +0900
+++ b/.hgignore	Fri Dec 25 18:31:20 2015 +0900
@@ -6,3 +6,5 @@
 
 dpp
 dpp2
+tableau
+tableau2
--- a/ltl.cbc	Fri Dec 25 18:19:55 2015 +0900
+++ b/ltl.cbc	Fri Dec 25 18:31:20 2015 +0900
@@ -16,7 +16,7 @@
     return 1;
 }
 
-code check(int *always_flag, PhilsPtr phils, TaskPtr list)
+__code check(int *always_flag, PhilsPtr phils, TaskPtr list)
 {
     if (p(list->phils)) {
 	*always_flag = 0;
--- a/ltl.h	Fri Dec 25 18:19:55 2015 +0900
+++ b/ltl.h	Fri Dec 25 18:31:20 2015 +0900
@@ -1,7 +1,7 @@
 #ifndef _LTL_H_
 #define _LTL_H_
 
-extern code
+extern __code
 check(int *always_flag, struct phils *phils, struct task *list);
 
 extern void
--- a/tableau2.cbc	Fri Dec 25 18:19:55 2015 +0900
+++ b/tableau2.cbc	Fri Dec 25 18:31:20 2015 +0900
@@ -2,7 +2,7 @@
 ** Dining Philosophers Problem's scheduler
 **    with state developper as a tableau method
 
-** 連絡先: 琉球大学情報工学科 河野 真治  
+** 連絡先: 琉球大学情報工学科 河野 真治
 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
 **
 **    このソースのいかなる複写,改変,修正も許諾します。ただし、
@@ -12,10 +12,10 @@
 **    バイナリの配布の際にはversion messageを保存することを条件とします。
 **    このプログラムについては特に何の保証もしない、悪しからず。
 **
-**    Everyone is permitted to do anything on this program 
+**    Everyone is permitted to do anything on this program
 **    including copying, modifying, improving,
 **    as long as you don't try to pretend that you wrote it.
-**    i.e., the above copyright notice has to appear in all copies.  
+**    i.e., the above copyright notice has to appear in all copies.
 **    Binary distribution requires original version messages.
 **    You don't have to ask before copying, redistribution or publishing.
 **    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
@@ -31,7 +31,6 @@
 
 int NUM_PHILOSOPHER = 5;    /* A number of philosophers must be more than 2. */
 
-static code (*ret)(int);
 static void *env;
 
 static PhilsPtr phils_list = NULL;
@@ -43,6 +42,34 @@
 static StateNode st;
 static int always_flag;  // for LTL
 
+// FIXME
+__code do_action(PhilsPtr phils, TaskPtr list)
+{
+    switch (phils->next) {
+        case PutDownLeftFork:
+            goto putdown_lfork(phils, list);
+        case PutDownRightFork:
+            goto putdown_rfork(phils, list);
+        case PickUpLeftFork:
+            goto pickup_lfork(phils, list);
+        case PickUpRightFork:
+            goto pickup_rfork(phils, list);
+        case Thinking:
+            goto thinking(phils, list);
+        case Eating:
+            goto eating(phils, list);
+        case WaitRightFork:
+            goto hungry2(phils, list);
+        case WaitLeftFork:
+            goto hungry1(phils, list);
+        default:
+            printf("invalid action¥n");
+            exit(1);
+    }
+    __code (*action) (PhilsPtr, TaskPtr) = thinking;
+    goto action(phils, list);
+}
+
 int
 list_length(TaskPtr list)
 {
@@ -81,7 +108,7 @@
  */
 
 
-code tableau(TaskPtr list)
+__code tableau(TaskPtr list)
 {
     StateDB out;
 
@@ -96,7 +123,7 @@
 		printf("All done count %d\n",count);
 		memory_usage();
 		show_result(always_flag);
-		goto ret(0),env;
+        exit(0);
 	    }
 	    //printf("no more branch %d\n",count);
 	    depth--;
@@ -115,10 +142,10 @@
     }
     //printf("depth %d count %d\n", depth, count++);
     count++;
-    goto list->phils->next(list->phils,list);
+    goto do_action(list->phils,list);
 }
 
-code get_next_task_fifo(TaskPtr list)
+__code get_next_task_fifo(TaskPtr list)
 {
     TaskPtr t = list;
     TaskPtr e;
@@ -126,18 +153,18 @@
     if (max_step--<0) goto die("Simuration end.");
 
     list = list->next;
-    goto list->phils->next(list->phils,list);
+    goto do_action(list->phils,list);
 }
 
-code scheduler(PhilsPtr phils, TaskPtr list)
+__code scheduler(PhilsPtr phils, TaskPtr list)
 {
     goto check(&always_flag, phils, list);
     // goto next_next_task_fifo(list);
 }
 
-code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last);
+__code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last);
 
-code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
+__code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
 {
     if (!q) {
 	goto die("Can't allocate Task\n");
@@ -147,7 +174,7 @@
     }
 }
 
-code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last)
+__code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last)
 {
     StateDB out;
     /*
@@ -166,17 +193,17 @@
 	lookup_StateDB(&st, &state_db, &out);
 	task_iter = create_task_iterator(list,out,0);
 	// start first task
-	goto list->phils->next(list->phils,list);
+    goto do_action(list->phils,list);
     }
 }
 
-code task_entry0(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q)
+__code task_entry0(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q)
 {
     add_memory_range(q,sizeof(Task),&mem);
     goto task_entry1(count, self, q, q);
 }
 
-code init_final(PhilsPtr self)
+__code init_final(PhilsPtr self)
 {
     self->right = phils_list;
     phils_list->left = self;
@@ -188,7 +215,7 @@
     goto create_queue(1, self, 0, 0, task_entry0);
 }
 
-code init_phils2(PhilsPtr self, int count, int id)
+__code init_phils2(PhilsPtr self, int count, int id)
 {
     PhilsPtr tmp_self;
 
@@ -202,7 +229,7 @@
     tmp_self->left_fork = self->right_fork;
     tmp_self->right = NULL;
     tmp_self->left = self;
-    tmp_self->next = thinking;
+    tmp_self->next = Thinking;
     add_memory_range(tmp_self,sizeof(Phils),&mem);
 
     count--;
@@ -215,7 +242,7 @@
     }
 }
 
-code init_fork2(PhilsPtr self, int count, int id)
+__code init_fork2(PhilsPtr self, int count, int id)
 {
     ForkPtr tmp_fork;
 
@@ -231,7 +258,7 @@
     goto init_phils2(self, count, id);
 }
 
-code init_phils1(ForkPtr fork, int count, int id)
+__code init_phils1(ForkPtr fork, int count, int id)
 {
     PhilsPtr self;
 
@@ -245,7 +272,7 @@
     self->left_fork = fork;
     self->right = NULL;
     self->left = NULL;
-    self->next = thinking;
+    self->next = Thinking;
     add_memory_range(self,sizeof(Phils),&mem);
 
     count--;
@@ -254,7 +281,7 @@
     goto init_fork2(self, count, id);
 }
 
-code init_fork1(int count)
+__code init_fork1(int count)
 {
     ForkPtr fork;
     int id = 1;
@@ -270,16 +297,15 @@
     goto init_phils1(fork, count, id);
 }
 
-code die(char *err)
+__code die(char *err)
 {
     printf("%s\n", err);
-    goto ret(1), env;
+    exit(1);
 }
 
 int main(int ac, char *av[])
 {
-    ret = return;
-    env = environment;
+    env = __environment;
     // srand((unsigned)time(NULL));
     // srandom((unsigned long)time(NULL));
     srandom(555);
@@ -288,7 +314,7 @@
 	NUM_PHILOSOPHER = atoi(av[1]);
 	if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
 	    printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
-	    return 1; 
+	    return 1;
 	}
 	printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
     }