changeset 80:c976a8bbe8c5

add stac.h and Stac.cbc
author tobaru
date Wed, 09 Oct 2019 20:41:51 +0900
parents e6043075a1aa
children d41e0a5f7e2f
files src/CMakeLists.txt src/SingleLinkedStack.cbc src/Stack.h src/gearsTools/pmake.pl src/proc.h
diffstat 5 files changed, 165 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/CMakeLists.txt	Fri Aug 02 19:36:19 2019 +0900
+++ b/src/CMakeLists.txt	Wed Oct 09 20:41:51 2019 +0900
@@ -105,5 +105,6 @@
   SOURCES
 	string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc 
 	start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c
+  SingleLinkedStack.cbc
          entry.S 
 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/SingleLinkedStack.cbc	Wed Oct 09 20:41:51 2019 +0900
@@ -0,0 +1,109 @@
+#include "../context.h"
+#interface "Stack.h"
+
+// typedef struct SingleLinkedStack {
+//     struct Element* top;
+// } SingleLinkedStack;
+
+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;
+    // if (node == NULL) {
+    //     printf("NULL");
+    // } else {
+    //     printf("key = %d ,", node->key);
+    //     printStack1((union Data*)data->Element.next);
+    // }
+}
+
+void printStack(union Data* data) {
+    printStack1(data);
+    // printf("\n");
+}
+
+__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
+    stack->top = NULL;
+    goto next(...);
+}
+
+__code pushSingleLinkedStack(struct SingleLinkedStack* stack, union Data* data, __code next(...)) {
+    Element* element = new Element();
+    element->next = stack->top;
+    element->data = data;
+    stack->top = element;
+    goto next(...);
+}
+
+__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
+    if (stack->top) {
+        data = stack->top->data;
+        stack->top = stack->top->next;
+    } else {
+        data = NULL;
+    }
+    goto next(data, ...);
+}
+
+__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
+    if (stack->top) {
+        data = stack->top->data;
+        stack->top = stack->top->next;
+    } else {
+        data = NULL;
+    }
+    if (stack->top) {
+        data1 = stack->top->data;
+        stack->top = stack->top->next;
+    } else {
+        data1 = NULL;
+    }
+    goto next(data, data1, ...);
+}
+
+
+__code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
+    if (stack->top)
+        data = stack->top->data;
+    else
+        data = NULL;
+    goto next(data, ...);
+}
+
+__code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
+    if (stack->top) {
+        data = stack->top->data;
+        if (stack->top->next) {
+            data1 = stack->top->next->data;
+        } else {
+            data1 = NULL;
+        }
+    } else {
+        data = NULL;
+        data1 = NULL;
+    }
+    goto next(data, data1, ...);
+}
+    
+__code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
+    if (stack->top) {
+        goto next(...);
+    } else {
+        goto whenEmpty(...);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Stack.h	Wed Oct 09 20:41:51 2019 +0900
@@ -0,0 +1,17 @@
+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 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 next(...);
+} Stack;
--- a/src/gearsTools/pmake.pl	Fri Aug 02 19:36:19 2019 +0900
+++ b/src/gearsTools/pmake.pl	Wed Oct 09 20:41:51 2019 +0900
@@ -73,6 +73,8 @@
   system(join(' ',@query));
 }
 
+
+
 __DATA__
 cp  initcode ./CMakeFiles/kernel.dir/initcode 
 cp  fs.img ./CMakeFiles/kernel.dir/fs.img
@@ -120,3 +122,17 @@
 binary \
 initcode \
 fs.img 
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+pmake.pl - pmake is a wrapper at cmake in xv6.
+
+=head1 SYNOPSIS
+
+     pmake.pl <build directory> <cbcxv6 src direcory>
+
+=cut
--- a/src/proc.h	Fri Aug 02 19:36:19 2019 +0900
+++ b/src/proc.h	Wed Oct 09 20:41:51 2019 +0900
@@ -86,6 +86,28 @@
     struct spinlock *lk;
 };
 
+// typedef struct context_interface<Type,Imple>{
+//     // union Data* stack;
+//     // union Data* data;
+// 
+//     // __code push(Impl* stack,Type* data, __code next(...));
+//     // __code next(...);
+// 
+//     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;
+// }context_interface;
+
+
 // Process memory is laid out contiguously, low addresses first:
 //   text
 //   original data and bss